Index: trunk/extensions/MobileFrontend/tests/js/test_opensearch.js |
— | — | @@ -1,11 +1,14 @@ |
2 | 2 | var MFEOS = MobileFrontend.opensearch; |
3 | | - |
| 3 | +var _ajax; |
4 | 4 | module("MobileFrontend opensearch.js - writeResults", { |
5 | 5 | setup: function() { |
| 6 | + _ajax = MobileFrontend.utils.ajax; |
| 7 | + MobileFrontend.utils.ajax = function() {}; |
6 | 8 | $('<div id="sq"><input type="search" id="search"></div>').appendTo(document.body); |
7 | 9 | $('<div id="results"></div>').appendTo(document.body); |
8 | 10 | }, |
9 | 11 | teardown: function() { |
| 12 | + MobileFrontend.utils.ajax = _ajax; |
10 | 13 | $("#results,#search").remove(); |
11 | 14 | } |
12 | 15 | }); |
Index: trunk/extensions/MobileFrontend/javascripts/opensearch.js |
— | — | @@ -57,23 +57,13 @@ |
58 | 58 | }; |
59 | 59 | |
60 | 60 | 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 | | - }; |
74 | 61 | term = encodeURIComponent( term ); |
75 | 62 | 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 | + } ); |
78 | 68 | } |
79 | 69 | |
80 | 70 | function createObjectArray( responseXml ) { |
Index: trunk/extensions/MobileFrontend/javascripts/beta_application.js |
— | — | @@ -220,6 +220,22 @@ |
221 | 221 | removeClass: removeClass |
222 | 222 | }; |
223 | 223 | } |
| 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 | + }; |
224 | 240 | |
225 | 241 | return { |
226 | 242 | readCookie: readCookie, |
Index: trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js |
— | — | @@ -150,22 +150,12 @@ |
151 | 151 | }; |
152 | 152 | |
153 | 153 | 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 | | - }; |
167 | 154 | 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 | + } ); |
170 | 160 | } |
171 | 161 | |
172 | 162 | function createObjectArray( responseXml ) { |
Index: trunk/extensions/MobileFrontend/javascripts/application.js |
— | — | @@ -208,6 +208,22 @@ |
209 | 209 | removeClass: removeClass |
210 | 210 | }; |
211 | 211 | } |
| 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 | + }; |
212 | 228 | |
213 | 229 | return { |
214 | 230 | readCookie: readCookie, |