From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- resources/jquery/jquery.mwPrototypes.js | 120 ++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 resources/jquery/jquery.mwPrototypes.js (limited to 'resources/jquery/jquery.mwPrototypes.js') diff --git a/resources/jquery/jquery.mwPrototypes.js b/resources/jquery/jquery.mwPrototypes.js new file mode 100644 index 00000000..e26a6be6 --- /dev/null +++ b/resources/jquery/jquery.mwPrototypes.js @@ -0,0 +1,120 @@ +/* + * JavaScript backwards-compatibility alternatives and other convenience functions + */ + +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 ); + }, + escapeRE : function( str ) { + return str.replace ( /([\\{}()|.?*+\-^$\[\]])/g, "\\$1" ); + }, + isDomElement : function( el ) { + return !!el && !!el.nodeType; + }, + 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; + } + 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; + }, + compareObject : function( objectA, objectB ) { + + // Do a simple check if the types match + if ( typeof objectA == typeof objectB ) { + + // Only loop over the contents if it really is an object + if ( typeof objectA == 'object' ) { + // If they are aliases of the same object (ie. mw and mediaWiki) return now + if ( objectA === objectB ) { + return true; + } else { + var prop; + // Iterate over each property + for ( prop in objectA ) { + // Check if this property is also present in the other object + if ( prop in objectB ) { + // Compare the types of the properties + var type = typeof objectA[prop]; + if ( type == typeof objectB[prop] ) { + // Recursively check objects inside this one + switch ( type ) { + case 'object' : + if ( !$.compareObject( objectA[prop], objectB[prop] ) ) { + return false; + } + break; + case 'function' : + // Functions need to be strings to compare them properly + if ( objectA[prop].toString() !== objectB[prop].toString() ) { + return false; + } + break; + default: + // Strings, numbers + if ( objectA[prop] !== objectB[prop] ) { + return false; + } + break; + } + } else { + return false; + } + } else { + return false; + } + } + // Check for properties in B but not in A + // This is about 15% faster (tested in Safari 5 and Firefox 3.6) + // ...than incrementing a count variable in the above and below loops + // See also: http://www.mediawiki.org/wiki/ResourceLoader/Default_modules/compareObject_test#Results + for ( prop in objectB ) { + if ( !( prop in objectA ) ) { + return false; + } + } + } + } + } else { + return false; + } + return true; + } +}); + -- cgit v1.2.3-54-g00ecf