* Added closure so that "mw.util.wikiScript" doesn't access
global "mw" directory but uses local reference to global
"mediaWiki".
* Keps names as-is, as such disabled camelcase rule locally
for this file. This code will be wrap-deprecated and removed
over the next 2 releases.
* Turned into local cross-references and exposed those, that
way the individual methods don't all call implied globals but
are ensured to be referring to the original methods as they
were defined in the same scope.
* Fixed clashing 'e' variable name.
* Removed unexpected "delete x" statement. Does nothing and
causes a lint warning.
* Replaced "delete request" with "request = undefined". The
purpose of the statement is to explicitly dereference the
XHR object in older IE browsers. However "delete" is not
allowed for local varables, setting to undefined has the
same effect.
* Moved debug_mode and request_type down to the other exposures.
Change-Id: Ib45ed9bd8c6f4ebdb060a527a63eaf59d2839493
# legacy scripts
skins/common/IEFixes.js
# legacy scripts
skins/common/IEFixes.js
skins/common/config.js
skins/common/protect.js
skins/common/upload.js
skins/common/config.js
skins/common/protect.js
skins/common/upload.js
-// remote scripting library
-// (c) copyright 2005 modernmethod, inc
-window.sajax_debug_mode = false;
-window.sajax_request_type = 'GET';
+/**
+ * Remote Scripting Library
+ * Copyright 2005 modernmethod, inc
+ * Under the open source BSD license
+ * http://www.modernmethod.com/sajax/
+ */
+
+/*jshint camelcase:false, onevar:false */
+/*global alert */
+( function ( mw ) {
- * if sajax_debug_mode is true, this function outputs given the message into
- * the element with id = sajax_debug; if no such element exists in the document,
+ * if sajax_debug_mode is true, this function outputs given the message into
+ * the element with id = sajax_debug; if no such element exists in the document,
-window.sajax_debug = function(text) {
- if (!sajax_debug_mode) return false;
+function debug( text ) {
+ if ( !window.sajax_debug_mode ) {
+ return false;
+ }
var e = document.getElementById( 'sajax_debug' );
var e = document.getElementById( 'sajax_debug' );
e.appendChild( m );
return true;
e.appendChild( m );
return true;
/**
* Compatibility wrapper for creating a new XMLHttpRequest object.
*/
/**
* Compatibility wrapper for creating a new XMLHttpRequest object.
*/
-window.sajax_init_object = function() {
- sajax_debug( 'sajax_init_object() called..' );
- var A;
+function createXhr() {
+ debug( 'sajax_init_object() called..' );
+ var a;
try {
// Try the new style before ActiveX so we don't
// unnecessarily trigger warnings in IE 7 when
// set to prompt about ActiveX usage
try {
// Try the new style before ActiveX so we don't
// unnecessarily trigger warnings in IE 7 when
// set to prompt about ActiveX usage
- A = new XMLHttpRequest();
- } catch ( e ) {
+ a = new XMLHttpRequest();
+ } catch ( xhrE ) {
- A = new ActiveXObject( 'Msxml2.XMLHTTP' );
- } catch ( e ) {
+ a = new window.ActiveXObject( 'Msxml2.XMLHTTP' );
+ } catch ( msXmlE ) {
- A = new ActiveXObject( 'Microsoft.XMLHTTP' );
- } catch ( oc ) {
- A = null;
+ a = new window.ActiveXObject( 'Microsoft.XMLHTTP' );
+ } catch ( msXhrE ) {
+ a = null;
- if ( !A ) {
- sajax_debug( 'Could not create connection object.' );
+ if ( !a ) {
+ debug( 'Could not create connection object.' );
/**
* Perform an AJAX call to MediaWiki. Calls are handled by AjaxDispatcher.php
/**
* Perform an AJAX call to MediaWiki. Calls are handled by AjaxDispatcher.php
* (1, 2, 3) as the parameter list, and will show the result in the element
* with id = showFoo
*/
* (1, 2, 3) as the parameter list, and will show the result in the element
* with id = showFoo
*/
-window.sajax_do_call = function(func_name, args, target) {
- var i, x, n;
+function doAjaxRequest( func_name, args, target ) {
+ var i, x;
var uri;
var post_data;
uri = mw.util.wikiScript() + '?action=ajax';
var uri;
var post_data;
uri = mw.util.wikiScript() + '?action=ajax';
- if ( sajax_request_type == 'GET' ) {
- if ( uri.indexOf( '?' ) == -1 ) {
+ if ( window.sajax_request_type === 'GET' ) {
+ if ( uri.indexOf( '?' ) === -1 ) {
uri = uri + '?rs=' + encodeURIComponent( func_name );
} else {
uri = uri + '&rs=' + encodeURIComponent( func_name );
uri = uri + '?rs=' + encodeURIComponent( func_name );
} else {
uri = uri + '&rs=' + encodeURIComponent( func_name );
post_data = post_data + '&rsargs[]=' + encodeURIComponent( args[i] );
}
}
post_data = post_data + '&rsargs[]=' + encodeURIComponent( args[i] );
}
}
- x = sajax_init_object();
if ( !x ) {
alert( 'AJAX not supported' );
return false;
}
try {
if ( !x ) {
alert( 'AJAX not supported' );
return false;
}
try {
- x.open( sajax_request_type, uri, true );
+ x.open( window.sajax_request_type, uri, true );
- if ( window.location.hostname == 'localhost' ) {
- alert( "Your browser blocks XMLHttpRequest to 'localhost', try using a real hostname for development/testing." );
+ if ( location.hostname === 'localhost' ) {
+ alert( 'Your browser blocks XMLHttpRequest to "localhost", try using a real hostname for development/testing.' );
- if ( sajax_request_type == 'POST' ) {
+ if ( window.sajax_request_type === 'POST' ) {
x.setRequestHeader( 'Method', 'POST ' + uri + ' HTTP/1.1' );
x.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
}
x.setRequestHeader( 'Pragma', 'cache=yes' );
x.setRequestHeader( 'Cache-Control', 'no-transform' );
x.setRequestHeader( 'Method', 'POST ' + uri + ' HTTP/1.1' );
x.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
}
x.setRequestHeader( 'Pragma', 'cache=yes' );
x.setRequestHeader( 'Cache-Control', 'no-transform' );
- x.onreadystatechange = function() {
- if ( x.readyState != 4 ) {
+ x.onreadystatechange = function () {
+ if ( x.readyState !== 4 ) {
- sajax_debug( 'received (' + x.status + ' ' + x.statusText + ') ' + x.responseText );
+ debug( 'received (' + x.status + ' ' + x.statusText + ') ' + x.responseText );
//if ( x.status != 200 )
// alert( 'Error: ' + x.status + ' ' + x.statusText + ': ' + x.responseText );
//else
//if ( x.status != 200 )
// alert( 'Error: ' + x.status + ' ' + x.statusText + ': ' + x.responseText );
//else
- if ( typeof( target ) == 'function' ) {
+ if ( typeof target === 'function' ) {
- } else if ( typeof( target ) == 'object' ) {
- if ( target.tagName == 'INPUT' ) {
- if ( x.status == 200 ) {
+ } else if ( typeof target === 'object' ) {
+ if ( target.tagName === 'INPUT' ) {
+ if ( x.status === 200 ) {
target.value= x.responseText;
}
//else alert( 'Error: ' + x.status + ' ' + x.statusText + ' (' + x.responseText + ')' );
} else {
target.value= x.responseText;
}
//else alert( 'Error: ' + x.status + ' ' + x.statusText + ' (' + x.responseText + ')' );
} else {
- if ( x.status == 200 ) {
+ if ( x.status === 200 ) {
target.innerHTML = x.responseText;
} else {
target.innerHTML = '<div class="error">Error: ' + x.status +
target.innerHTML = x.responseText;
} else {
target.innerHTML = '<div class="error">Error: ' + x.status +
- alert( 'bad target for sajax_do_call: not a function or object: ' + target );
+ alert( 'Bad target for sajax_do_call: not a function or object: ' + target );
- sajax_debug( func_name + ' uri = ' + uri + ' / post = ' + post_data );
+ debug( func_name + ' uri = ' + uri + ' / post = ' + post_data );
- sajax_debug( func_name + ' waiting..' );
- delete x;
+ debug( func_name + ' waiting..' );
- * @return boolean whether the browser supports XMLHttpRequest
+ * @return {boolean} Whether the browser supports AJAX
-window.wfSupportsAjax = function() {
- var request = sajax_init_object();
+function wfSupportsAjax() {
+ var request = createXhr();
var supportsAjax = request ? true : false;
var supportsAjax = request ? true : false;
+}
+
+// Expose
+
+// Configuration
+window.sajax_debug_mode = false;
+window.sajax_request_type = 'GET';
+
+// Methods
+window.sajax_debug = debug;
+window.sajax_init_object = createXhr;
+window.sajax_do_call = doAjaxRequest;
+window.wfSupportsAjax = wfSupportsAjax;
+
+}( mediaWiki ) );