r112129 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112128‎ | r112129 | r112130 >
Date:18:37, 22 February 2012
Author:jdlrobson
Status:ok
Tags:
Comment:
abstract ajax function to fix tests in opera

this allows us to stub out any ajax request in
the test suite. Opera was throwing an exception
causing many of the tests to break.
It also allows us the opportunity going forward
to swap code out for another library.
Modified paths:
  • /trunk/extensions/MobileFrontend/javascripts/application.js (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/beta_application.js (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/opensearch.js (modified) (history)
  • /trunk/extensions/MobileFrontend/tests/js/test_opensearch.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/tests/js/test_opensearch.js
@@ -1,11 +1,14 @@
22 var MFEOS = MobileFrontend.opensearch;
3 -
 3+var _ajax;
44 module("MobileFrontend opensearch.js - writeResults", {
55 setup: function() {
 6+ _ajax = MobileFrontend.utils.ajax;
 7+ MobileFrontend.utils.ajax = function() {};
68 $('<div id="sq"><input type="search" id="search"></div>').appendTo(document.body);
79 $('<div id="results"></div>').appendTo(document.body);
810 },
911 teardown: function() {
 12+ MobileFrontend.utils.ajax = _ajax;
1013 $("#results,#search").remove();
1114 }
1215 });
Index: trunk/extensions/MobileFrontend/javascripts/opensearch.js
@@ -57,23 +57,13 @@
5858 };
5959
6060 function searchApi( term ) {
61 - var xmlHttp, url;
62 - if ( window.XMLHttpRequest ) {
63 - xmlHttp = new XMLHttpRequest();
64 - } else {
65 - xmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
66 - }
67 - xmlHttp.overrideMimeType( 'text/xml' );
68 - xmlHttp.onreadystatechange = function() {
69 - if ( xmlHttp.readyState === 4 && xmlHttp.status === 200 ) {
70 - var sections = createObjectArray( xmlHttp.responseXML );
71 - writeResults( sections );
72 - }
73 - };
7461 term = encodeURIComponent( term );
7562 url = apiUrl + '?action=opensearch&limit=' + numResults + '&namespace=0&format=xml&search=' + term;
76 - xmlHttp.open( 'GET', url, true );
77 - xmlHttp.send();
 63+ u.ajax( { url: url,
 64+ success: function(xml) {
 65+ writeResults( createObjectArray( xml ) );
 66+ }
 67+ } );
7868 }
7969
8070 function createObjectArray( responseXml ) {
Index: trunk/extensions/MobileFrontend/javascripts/beta_application.js
@@ -220,6 +220,22 @@
221221 removeClass: removeClass
222222 };
223223 }
 224+ utilities.ajax = function( options ) {
 225+ var xmlHttp, url;
 226+ if ( window.XMLHttpRequest ) {
 227+ xmlHttp = new XMLHttpRequest();
 228+ } else {
 229+ xmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
 230+ }
 231+ xmlHttp.overrideMimeType( 'text/xml' );
 232+ xmlHttp.onreadystatechange = function() {
 233+ if ( xmlHttp.readyState === 4 && xmlHttp.status === 200 ) {
 234+ options.success( xmlHttp.responseXML );
 235+ }
 236+ };
 237+ xmlHttp.open( 'GET', options.url, true );
 238+ xmlHttp.send();
 239+ };
224240
225241 return {
226242 readCookie: readCookie,
Index: trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js
@@ -150,22 +150,12 @@
151151 };
152152
153153 function searchApi( term ) {
154 - var xmlHttp, url;
155 - if ( window.XMLHttpRequest ) {
156 - xmlHttp = new XMLHttpRequest();
157 - } else {
158 - xmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
159 - }
160 - xmlHttp.overrideMimeType( 'text/xml' );
161 - xmlHttp.onreadystatechange = function() {
162 - if ( xmlHttp.readyState === 4 && xmlHttp.status === 200 ) {
163 - var sections = createObjectArray( xmlHttp.responseXML );
164 - writeResults( sections );
165 - }
166 - };
167154 url = apiUrl + '?action=opensearch&limit=' + numResults + '&namespace=0&format=xml&search=' + term;
168 - xmlHttp.open( 'GET', url, true );
169 - xmlHttp.send();
 155+ u.ajax( { url: url,
 156+ success: function(xml) {
 157+ writeResults( createObjectArray( xml ) );
 158+ }
 159+ } );
170160 }
171161
172162 function createObjectArray( responseXml ) {
Index: trunk/extensions/MobileFrontend/javascripts/application.js
@@ -208,6 +208,22 @@
209209 removeClass: removeClass
210210 };
211211 }
 212+ utilities.ajax = function( options ) {
 213+ var xmlHttp, url;
 214+ if ( window.XMLHttpRequest ) {
 215+ xmlHttp = new XMLHttpRequest();
 216+ } else {
 217+ xmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
 218+ }
 219+ xmlHttp.overrideMimeType( 'text/xml' );
 220+ xmlHttp.onreadystatechange = function() {
 221+ if ( xmlHttp.readyState === 4 && xmlHttp.status === 200 ) {
 222+ options.success( xmlHttp.responseXML );
 223+ }
 224+ };
 225+ xmlHttp.open( 'GET', options.url, true );
 226+ xmlHttp.send();
 227+ };
212228
213229 return {
214230 readCookie: readCookie,

Status & tagging log