return wgServer + wgArticlePath.replace( '$1', this.wikiUrlencode( str ) );
},
- /**
- * Check is a variable is empty. Supports strings, booleans, arrays and
- * objects. The string "0" is considered empty. A string containing only
- * whitespace (ie. " ") is considered not empty.
- *
- * @param v The variable to check for emptyness
- */
- 'isEmpty' : function( v ) {
- var key;
- if ( v === "" || v === 0 || v === "0" || v === null
- || v === false || typeof v === 'undefined' )
- {
- return true;
- }
- if ( v.length === 0 ) {
- return true;
- }
- if ( typeof v === 'object' ) {
- for ( key in v ) {
- return false;
- }
- return true;
- }
- return false;
- },
-
-
/**
* Grab the URL parameter value for the given parameter.
* Returns null if not found.
'function (string)');
mw.test.addTest('$.trimRight(\' foo bar \')',
' foo bar (string)');
+ mw.test.addTest('typeof $.isEmpty',
+ 'function (string)');
+ mw.test.addTest('$.isEmpty(\'string\')',
+ 'false (boolean)');
+ mw.test.addTest('$.isEmpty(\'0\')',
+ 'true (boolean)');
+ mw.test.addTest('$.isEmpty([])',
+ 'true (boolean)');
mw.test.addTest('typeof $.compareArray',
'function (string)');
mw.test.addTest('$.compareArray( [1, "a", [], [2, \'b\'] ], [1, \'a\', [], [2, "b"] ] )',
/*
- * JavaScript backwards-compatibility alternatives and convenience functions
+ * JavaScript backwards-compatibility alternatives and other convenience functions
*/
jQuery.extend({
escapeRE : function( str ) {
return str.replace ( /([\\{}()|.?*+^$\[\]])/g, "\\$1" );
},
+ isEmpty : function( v ) {
+ var key;
+ if ( v === "" || v === 0 || v === "0" || v === null
+ || v === false || typeof v === 'undefined' )
+ {
+ return true;
+ }
+ // the for-loop could potentially contain prototypes
+ // to avoid that we check it's length first
+ if ( v.length === 0 ) {
+ return true;
+ }
+ if ( typeof v === 'object' ) {
+ for ( key in v ) {
+ return false;
+ }
+ return true;
+ }
+ return false;
+ },
compareArray : function( arrThis, arrAgainst ) {
if ( arrThis.length != arrAgainst.length ) {
return false;