Renaming jquery.mwPrototypes to jquery.mwExtension
authorKrinkle <krinkle@users.mediawiki.org>
Thu, 11 Aug 2011 03:12:12 +0000 (03:12 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Thu, 11 Aug 2011 03:12:12 +0000 (03:12 +0000)
* Originally they were a few prototypes on the native String object, however they were converted to be (static) members extending the jQuery object. Calling them prototypes is confusing. A grep search on /trunk/ didn't reveal any direct uses of this module (it's loaded by default through mediawiki.util's dependencies)

RELEASE-NOTES-1.19
resources/Resources.php
resources/jquery/jquery.mwExtension.js [new file with mode: 0644]
resources/jquery/jquery.mwPrototypes.js [deleted file]
tests/qunit/index.html
tests/qunit/suites/resources/jquery/jquery.mwExtension.js [new file with mode: 0644]
tests/qunit/suites/resources/jquery/jquery.mwPrototypes.js [deleted file]

index 25c619f..86fcf35 100644 (file)
@@ -60,6 +60,7 @@ changes to languages because of Bugzilla reports.
 * Uighur (Latin) (ug-latn) was incorrectly marked as right-to-left language.
 
 === Other changes in 1.19 ===
+* jquery.mwPrototypes module was renamed to jquery.mwExtension.
 
 == Compatibility ==
 
index d51d586..6bcf5ad 100644 (file)
@@ -145,8 +145,8 @@ return array(
        'jquery.mockjax' => array(
                'scripts' => 'resources/jquery/jquery.mockjax.js',
        ),
-       'jquery.mwPrototypes' => array(
-               'scripts' => 'resources/jquery/jquery.mwPrototypes.js',
+       'jquery.mwExtension' => array(
+               'scripts' => 'resources/jquery/jquery.mwExtension.js',
        ),
        'jquery.qunit' => array(
                'scripts' => 'resources/jquery/jquery.qunit.js',
@@ -579,7 +579,7 @@ return array(
                        'jquery.client',
                        'jquery.cookie',
                        'jquery.messageBox',
-                       'jquery.mwPrototypes',
+                       'jquery.mwExtension',
                ),
        ),
        'mediawiki.uri' => array( 
diff --git a/resources/jquery/jquery.mwExtension.js b/resources/jquery/jquery.mwExtension.js
new file mode 100644 (file)
index 0000000..e26a6be
--- /dev/null
@@ -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;
+       }
+});
+
diff --git a/resources/jquery/jquery.mwPrototypes.js b/resources/jquery/jquery.mwPrototypes.js
deleted file mode 100644 (file)
index e26a6be..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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;
-       }
-});
-
index a581920..a88a662 100644 (file)
@@ -25,7 +25,7 @@
        <script src="../../resources/mediawiki/mediawiki.user.js"></script>
 
        <script src="../../resources/jquery/jquery.messageBox.js"></script>
-       <script src="../../resources/jquery/jquery.mwPrototypes.js"></script>
+       <script src="../../resources/jquery/jquery.mwExtension.js"></script>
        <script src="../../resources/mediawiki/mediawiki.util.js"></script>
 
        <script src="../../resources/jquery/jquery.checkboxShiftClick.js"></script>
@@ -63,7 +63,7 @@
        <script src="suites/resources/mediawiki/mediawiki.user.js"></script>
 
        <script src="suites/resources/jquery/jquery.client.js"></script>
-       <script src="suites/resources/jquery/jquery.mwPrototypes.js"></script>
+       <script src="suites/resources/jquery/jquery.mwExtension.js"></script>
        <script src="suites/resources/mediawiki/mediawiki.util.js"></script>
 
        <script src="suites/resources/jquery/jquery.autoEllipsis.js"></script>
diff --git a/tests/qunit/suites/resources/jquery/jquery.mwExtension.js b/tests/qunit/suites/resources/jquery/jquery.mwExtension.js
new file mode 100644 (file)
index 0000000..f68bd58
--- /dev/null
@@ -0,0 +1,56 @@
+module( 'jquery.mwExtension.js' );
+
+test( 'String functions', function() {
+
+       equal( $.trimLeft( '  foo bar  ' ), 'foo bar  ', 'trimLeft' );
+       equal( $.trimRight( '  foo bar  ' ), '  foo bar', 'trimRight' );
+       equal( $.ucFirst( 'foo'), 'Foo', 'ucFirst' );
+
+       equal( $.escapeRE( '<!-- ([{+mW+}]) $^|?>' ),
+        '<!\\-\\- \\(\\[\\{\\+mW\\+\\}\\]\\) \\$\\^\\|\\?>', 'escapeRE - Escape specials' );
+       equal( $.escapeRE( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ),
+        'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'escapeRE - Leave uppercase alone' );
+       equal( $.escapeRE( 'abcdefghijklmnopqrstuvwxyz' ),
+        'abcdefghijklmnopqrstuvwxyz', 'escapeRE - Leave lowercase alone' );
+       equal( $.escapeRE( '0123456789' ), '0123456789', 'escapeRE - Leave numbers alone' );
+});
+
+test( 'Is functions', function() {
+
+       strictEqual( $.isDomElement( document.getElementById( 'qunit-header' ) ), true,
+        'isDomElement: #qunit-header Node' );
+       strictEqual( $.isDomElement( document.getElementById( 'random-name' ) ), false,
+        'isDomElement: #random-name (null)' );
+       strictEqual( $.isDomElement( document.getElementsByTagName( 'div' ) ), false,
+        'isDomElement: getElementsByTagName Array' );
+       strictEqual( $.isDomElement( document.getElementsByTagName( 'div' )[0] ), true,
+        'isDomElement: getElementsByTagName(..)[0] Node' );
+       strictEqual( $.isDomElement( $( 'div' ) ), false,
+        'isDomElement: jQuery object' );
+       strictEqual( $.isDomElement( $( 'div' ).get(0) ), true,
+        'isDomElement: jQuery object > Get node' );
+       strictEqual( $.isDomElement( document.createElement( 'div' ) ), true,
+        'isDomElement: createElement' );
+       strictEqual( $.isDomElement( { foo: 1 } ), false,
+        'isDomElement: Object' );
+
+       strictEqual( $.isEmpty( 'string' ), false, 'isEmptry: "string"' );
+       strictEqual( $.isEmpty( '0' ), true, 'isEmptry: "0"' );
+       strictEqual( $.isEmpty( [] ), true, 'isEmptry: []' );
+       strictEqual( $.isEmpty( {} ), true, 'isEmptry: {}' );
+
+       // Documented behaviour
+       strictEqual( $.isEmpty( { length: 0 } ), true, 'isEmptry: { length: 0 }' );
+});
+
+test( 'Comparison functions', function() {
+
+       ok( $.compareArray( [0, 'a', [], [2, 'b'] ], [0, "a", [], [2, "b"] ] ),
+        'compareArray: Two deep arrays that are excactly the same' );
+       ok( !$.compareArray( [1], [2] ), 'compareArray: Two different arrays (false)' );
+
+       ok( $.compareObject( {}, {} ), 'compareObject: Two empty objects' );
+       ok( $.compareObject( { foo: 1 }, { foo: 1 } ), 'compareObject: Two the same objects' );
+       ok( !$.compareObject( { bar: true }, { baz: false } ),
+        'compareObject: Two different objects (false)' );
+});
diff --git a/tests/qunit/suites/resources/jquery/jquery.mwPrototypes.js b/tests/qunit/suites/resources/jquery/jquery.mwPrototypes.js
deleted file mode 100644 (file)
index bb6d2a1..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-module( 'jquery.mwPrototypes.js' );
-
-test( 'String functions', function() {
-
-       equal( $.trimLeft( '  foo bar  ' ), 'foo bar  ', 'trimLeft' );
-       equal( $.trimRight( '  foo bar  ' ), '  foo bar', 'trimRight' );
-       equal( $.ucFirst( 'foo'), 'Foo', 'ucFirst' );
-
-       equal( $.escapeRE( '<!-- ([{+mW+}]) $^|?>' ),
-        '<!\\-\\- \\(\\[\\{\\+mW\\+\\}\\]\\) \\$\\^\\|\\?>', 'escapeRE - Escape specials' );
-       equal( $.escapeRE( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ),
-        'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'escapeRE - Leave uppercase alone' );
-       equal( $.escapeRE( 'abcdefghijklmnopqrstuvwxyz' ),
-        'abcdefghijklmnopqrstuvwxyz', 'escapeRE - Leave lowercase alone' );
-       equal( $.escapeRE( '0123456789' ), '0123456789', 'escapeRE - Leave numbers alone' );
-});
-
-test( 'Is functions', function() {
-
-       strictEqual( $.isDomElement( document.getElementById( 'qunit-header' ) ), true,
-        'isDomElement: #qunit-header Node' );
-       strictEqual( $.isDomElement( document.getElementById( 'random-name' ) ), false,
-        'isDomElement: #random-name (null)' );
-       strictEqual( $.isDomElement( document.getElementsByTagName( 'div' ) ), false,
-        'isDomElement: getElementsByTagName Array' );
-       strictEqual( $.isDomElement( document.getElementsByTagName( 'div' )[0] ), true,
-        'isDomElement: getElementsByTagName(..)[0] Node' );
-       strictEqual( $.isDomElement( $( 'div' ) ), false,
-        'isDomElement: jQuery object' );
-       strictEqual( $.isDomElement( $( 'div' ).get(0) ), true,
-        'isDomElement: jQuery object > Get node' );
-       strictEqual( $.isDomElement( document.createElement( 'div' ) ), true,
-        'isDomElement: createElement' );
-       strictEqual( $.isDomElement( { foo: 1 } ), false,
-        'isDomElement: Object' );
-
-       strictEqual( $.isEmpty( 'string' ), false, 'isEmptry: "string"' );
-       strictEqual( $.isEmpty( '0' ), true, 'isEmptry: "0"' );
-       strictEqual( $.isEmpty( [] ), true, 'isEmptry: []' );
-       strictEqual( $.isEmpty( {} ), true, 'isEmptry: {}' );
-
-       // Documented behaviour
-       strictEqual( $.isEmpty( { length: 0 } ), true, 'isEmptry: { length: 0 }' );
-});
-
-test( 'Comparison functions', function() {
-
-       ok( $.compareArray( [0, 'a', [], [2, 'b'] ], [0, "a", [], [2, "b"] ] ),
-        'compareArray: Two deep arrays that are excactly the same' );
-       ok( !$.compareArray( [1], [2] ), 'compareArray: Two different arrays (false)' );
-
-       ok( $.compareObject( {}, {} ), 'compareObject: Two empty objects' );
-       ok( $.compareObject( { foo: 1 }, { foo: 1 } ), 'compareObject: Two the same objects' );
-       ok( !$.compareObject( { bar: true }, { baz: false } ),
-        'compareObject: Two different objects (false)' );
-});