https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112129
Revision: 112129
Author: jdlrobson
Date: 2012-02-22 18:37:05 +0000 (Wed, 22 Feb 2012)
Log Message:
-----------
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
trunk/extensions/MobileFrontend/javascripts/beta_application.js
trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js
trunk/extensions/MobileFrontend/javascripts/opensearch.js
trunk/extensions/MobileFrontend/tests/js/test_opensearch.js
Modified: trunk/extensions/MobileFrontend/javascripts/application.js
===================================================================
--- trunk/extensions/MobileFrontend/javascripts/application.js 2012-02-22
18:29:18 UTC (rev 112128)
+++ trunk/extensions/MobileFrontend/javascripts/application.js 2012-02-22
18:37:05 UTC (rev 112129)
@@ -208,6 +208,22 @@
removeClass: removeClass
};
}
+ utilities.ajax = function( options ) {
+ var xmlHttp, url;
+ if ( window.XMLHttpRequest ) {
+ xmlHttp = new XMLHttpRequest();
+ } else {
+ xmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
+ }
+ xmlHttp.overrideMimeType( 'text/xml' );
+ xmlHttp.onreadystatechange = function() {
+ if ( xmlHttp.readyState === 4 && xmlHttp.status === 200
) {
+ options.success( xmlHttp.responseXML );
+ }
+ };
+ xmlHttp.open( 'GET', options.url, true );
+ xmlHttp.send();
+ };
return {
readCookie: readCookie,
Modified: trunk/extensions/MobileFrontend/javascripts/beta_application.js
===================================================================
--- trunk/extensions/MobileFrontend/javascripts/beta_application.js
2012-02-22 18:29:18 UTC (rev 112128)
+++ trunk/extensions/MobileFrontend/javascripts/beta_application.js
2012-02-22 18:37:05 UTC (rev 112129)
@@ -220,6 +220,22 @@
removeClass: removeClass
};
}
+ utilities.ajax = function( options ) {
+ var xmlHttp, url;
+ if ( window.XMLHttpRequest ) {
+ xmlHttp = new XMLHttpRequest();
+ } else {
+ xmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
+ }
+ xmlHttp.overrideMimeType( 'text/xml' );
+ xmlHttp.onreadystatechange = function() {
+ if ( xmlHttp.readyState === 4 && xmlHttp.status === 200
) {
+ options.success( xmlHttp.responseXML );
+ }
+ };
+ xmlHttp.open( 'GET', options.url, true );
+ xmlHttp.send();
+ };
return {
readCookie: readCookie,
Modified: trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js
===================================================================
--- trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js
2012-02-22 18:29:18 UTC (rev 112128)
+++ trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js
2012-02-22 18:37:05 UTC (rev 112129)
@@ -150,22 +150,12 @@
};
function searchApi( term ) {
- var xmlHttp, url;
- if ( window.XMLHttpRequest ) {
- xmlHttp = new XMLHttpRequest();
- } else {
- xmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
- }
- xmlHttp.overrideMimeType( 'text/xml' );
- xmlHttp.onreadystatechange = function() {
- if ( xmlHttp.readyState === 4 && xmlHttp.status === 200
) {
- var sections = createObjectArray(
xmlHttp.responseXML );
- writeResults( sections );
- }
- };
url = apiUrl + '?action=opensearch&limit=' + numResults +
'&namespace=0&format=xml&search=' + term;
- xmlHttp.open( 'GET', url, true );
- xmlHttp.send();
+ u.ajax( { url: url,
+ success: function(xml) {
+ writeResults( createObjectArray( xml ) );
+ }
+ } );
}
function createObjectArray( responseXml ) {
Modified: trunk/extensions/MobileFrontend/javascripts/opensearch.js
===================================================================
--- trunk/extensions/MobileFrontend/javascripts/opensearch.js 2012-02-22
18:29:18 UTC (rev 112128)
+++ trunk/extensions/MobileFrontend/javascripts/opensearch.js 2012-02-22
18:37:05 UTC (rev 112129)
@@ -57,23 +57,13 @@
};
function searchApi( term ) {
- var xmlHttp, url;
- if ( window.XMLHttpRequest ) {
- xmlHttp = new XMLHttpRequest();
- } else {
- xmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
- }
- xmlHttp.overrideMimeType( 'text/xml' );
- xmlHttp.onreadystatechange = function() {
- if ( xmlHttp.readyState === 4 && xmlHttp.status === 200
) {
- var sections = createObjectArray(
xmlHttp.responseXML );
- writeResults( sections );
- }
- };
term = encodeURIComponent( term );
url = apiUrl + '?action=opensearch&limit=' + numResults +
'&namespace=0&format=xml&search=' + term;
- xmlHttp.open( 'GET', url, true );
- xmlHttp.send();
+ u.ajax( { url: url,
+ success: function(xml) {
+ writeResults( createObjectArray( xml ) );
+ }
+ } );
}
function createObjectArray( responseXml ) {
Modified: trunk/extensions/MobileFrontend/tests/js/test_opensearch.js
===================================================================
--- trunk/extensions/MobileFrontend/tests/js/test_opensearch.js 2012-02-22
18:29:18 UTC (rev 112128)
+++ trunk/extensions/MobileFrontend/tests/js/test_opensearch.js 2012-02-22
18:37:05 UTC (rev 112129)
@@ -1,11 +1,14 @@
var MFEOS = MobileFrontend.opensearch;
-
+var _ajax;
module("MobileFrontend opensearch.js - writeResults", {
setup: function() {
+ _ajax = MobileFrontend.utils.ajax;
+ MobileFrontend.utils.ajax = function() {};
$('<div id="sq"><input type="search"
id="search"></div>').appendTo(document.body);
$('<div id="results"></div>').appendTo(document.body);
},
teardown: function() {
+ MobileFrontend.utils.ajax = _ajax;
$("#results,#search").remove();
}
});
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs