'getParamValue' : function( param, url ) {
url = url ? url : document.location.href;
// Get last match, stop at hash
- var re = new RegExp( '[^#]*[&?]' + param.escapeRE() + '=([^&#]*)' );
+ var re = new RegExp( '[^#]*[&?]' + $.escapeRE( param ) + '=([^&#]*)' );
var m = re.exec( url );
if ( m && m.length > 1 ) {
return decodeURIComponent( m[1] );
contain = result;
}
this.addedTests.push([code, result, contain]);
- this.$table.append('<tr><td>' + mw.html.escape(code) + '</td><td>' + mw.html.escape(result) + '<td></td></td><td>?</td></tr>');
+ this.$table.append('<tr><td>' + mw.html.escape(code).replace(/ /g, ' ') + '</td><td>' + mw.html.escape(result).replace(/ /g, ' ') + '<td></td></td><td>?</td></tr>');
},
/* Initialisation */
mw.util.$content.html(
'<p>Below is a list of tests to confirm proper functionality of the mediaWiki.util functions</p>' +
'<hr />' +
- '<table id="mw-mwutiltest-table" class="wikitable sortable"><tr><th>Exec</th><th>Should return</th><th>Does return</th><th>Equal ?</th></tr></table>'
+ '<table id="mw-mwutiltest-table" class="wikitable sortable" style="white-space:break; font-family:monospace,\'Courier New\'">' +
+ '<tr><th>Exec</th><th>Should return</th><th>Does return</th><th>Equal ?</th></tr>' +
+ '</table>'
);
mw.test.$table = $('table#mw-mwutiltest-table');
// Populate tests
- mw.test.addTest('typeof String.prototype.trim',
+ mw.test.addTest('typeof $.trimLeft',
'function (string)');
- mw.test.addTest('typeof String.prototype.trimLeft',
+ mw.test.addTest('$.trimLeft(\' foo bar \')',
+ 'foo bar (string)');
+ mw.test.addTest('typeof $.trimRight',
'function (string)');
- mw.test.addTest('typeof String.prototype.trimRight',
- 'function (string)');
- mw.test.addTest('typeof Array.prototype.compare',
- 'function (string)');
- mw.test.addTest('typeof Array.prototype.indexOf',
+ mw.test.addTest('$.trimRight(\' foo bar \')',
+ ' foo bar (string)');
+ mw.test.addTest('typeof $.compareArray',
'function (string)');
+ mw.test.addTest('$.compareArray( [1, "a", [], [2, \'b\'] ], [1, \'a\', [], [2, "b"] ] )',
+ 'true (boolean)');
+ mw.test.addTest('$.compareArray( [1], [2] )',
+ 'false (boolean)');
mw.test.addTest('4',
'4 (number)');
mw.test.addTest('typeof mediaWiki',
'object (string)');
mw.test.addTest('typeof mw.html',
'object (string)');
- mw.test.addTest('typeof String.prototype.ucFirst',
+ mw.test.addTest('typeof $.ucFirst',
'function (string)');
- mw.test.addTest('\'mediawiki\'.ucFirst()',
+ mw.test.addTest('$.ucFirst( \'mediawiki\' )',
'Mediawiki (string)');
- mw.test.addTest('typeof String.prototype.escapeRE',
+ mw.test.addTest('typeof $.escapeRE',
'function (string)');
- mw.test.addTest('\'.st{e}$st\'.escapeRE()',
+ mw.test.addTest('$.escapeRE( \'.st{e}$st\' )',
'\\.st\\{e\\}\\$st (string)');
mw.test.addTest('typeof $.fn.checkboxShiftClick',
'function (string)');
/*
- * JavaScript backwards-compatibility and support
+ * JavaScript backwards-compatibility alternatives and convenience functions
*/
-// Implementation of string trimming functionality introduced natively in JavaScript 1.8.1
-if ( typeof String.prototype.trim === 'undefined' ) {
- // Add removing trailing and leading whitespace functionality cross-browser
- // See also: http://blog.stevenlevithan.com/archives/faster-trim-javascript
- String.prototype.trim = function() {
- return this.replace( /^\s+|\s+$/g, '' );
- };
-}
-if ( typeof String.prototype.trimLeft === 'undefined' ) {
- String.prototype.trimLeft = function() {
- return this.replace( /^\s\s*/, "" );
- };
-}
-if ( typeof String.prototype.trimRight === 'undefined' ) {
- String.prototype.trimRight = function() {
- return this.replace(/\s\s*$/, "");
- };
-}
-
-/*
- * Prototype enhancements
- */
-
-// Capitalize the first character of the given string
-if ( typeof String.prototype.ucFirst === 'undefined' ) {
- String.prototype.ucFirst = function() {
- return this.substr(0, 1).toUpperCase() + this.substr(1, this.length);
- };
-}
-
-// Escape all RegExp special characters such that the result can be safely used
-// in a RegExp as a literal.
-if ( typeof String.prototype.escapeRE === 'undefined' ) {
- String.prototype.escapeRE = function() {
- return this.replace (/([\\{}()|.?*+^$\[\]])/g, "\\$1");
- };
-}
+jQuery.extend({
+ trimLeft : function( str ) {
+ return str == null ? '' : str.toString().replace( /^\s+/, '' );
+ },
+ trimRight : function( str ) {
+ return str == null ?
+ '' : str.toString().replace( /\s+$/, '' );
+ },
+ ucFirst : function( str ) {
+ return str.substr( 0, 1 ).toUpperCase() + str.substr( 1, str.length );
+ },
+ escapeRE : function( str ) {
+ return str.replace ( /([\\{}()|.?*+^$\[\]])/g, "\\$1" );
+ },
+ compareArray : function( arrThis, arrAgainst ) {
+ if ( arrThis.length != arrAgainst.length ) {
+ return false;
+ }
+ for ( var i = 0; i < arrThis.length; i++ ) {
+ if ( arrThis[i] instanceof Array ) {
+ if ( !$.compareArray( arrThis[i], arrAgainst[i] ) ) {
+ return false;
+ }
+ } else if ( arrThis[i] !== arrAgainst[i] ) {
+ return false;
+ }
+ }
+ return true;
+ }
+});
/*
* Core MediaWiki JavaScript Library