r94227 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94226‎ | r94227 | r94228 >
Date:03:12, 11 August 2011
Author:krinkle
Status:ok
Tags:
Comment:
Renaming jquery.mwPrototypes to jquery.mwExtension
* 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)
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/jquery/jquery.mwExtension.js (added) (history)
  • /trunk/phase3/resources/jquery/jquery.mwPrototypes.js (deleted) (history)
  • /trunk/phase3/tests/qunit/index.html (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.mwExtension.js (added) (history)
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.mwPrototypes.js (deleted) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -60,6 +60,7 @@
6161 * Uighur (Latin) (ug-latn) was incorrectly marked as right-to-left language.
6262
6363 === Other changes in 1.19 ===
 64+* jquery.mwPrototypes module was renamed to jquery.mwExtension.
6465
6566 == Compatibility ==
6667
Index: trunk/phase3/tests/qunit/index.html
@@ -25,7 +25,7 @@
2626 <script src="../../resources/mediawiki/mediawiki.user.js"></script>
2727
2828 <script src="../../resources/jquery/jquery.messageBox.js"></script>
29 - <script src="../../resources/jquery/jquery.mwPrototypes.js"></script>
 29+ <script src="../../resources/jquery/jquery.mwExtension.js"></script>
3030 <script src="../../resources/mediawiki/mediawiki.util.js"></script>
3131
3232 <script src="../../resources/jquery/jquery.checkboxShiftClick.js"></script>
@@ -63,7 +63,7 @@
6464 <script src="suites/resources/mediawiki/mediawiki.user.js"></script>
6565
6666 <script src="suites/resources/jquery/jquery.client.js"></script>
67 - <script src="suites/resources/jquery/jquery.mwPrototypes.js"></script>
 67+ <script src="suites/resources/jquery/jquery.mwExtension.js"></script>
6868 <script src="suites/resources/mediawiki/mediawiki.util.js"></script>
6969
7070 <script src="suites/resources/jquery/jquery.autoEllipsis.js"></script>
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.mwPrototypes.js
@@ -1,56 +0,0 @@
2 -module( 'jquery.mwPrototypes.js' );
3 -
4 -test( 'String functions', function() {
5 -
6 - equal( $.trimLeft( ' foo bar ' ), 'foo bar ', 'trimLeft' );
7 - equal( $.trimRight( ' foo bar ' ), ' foo bar', 'trimRight' );
8 - equal( $.ucFirst( 'foo'), 'Foo', 'ucFirst' );
9 -
10 - equal( $.escapeRE( '<!-- ([{+mW+}]) $^|?>' ),
11 - '<!\\-\\- \\(\\[\\{\\+mW\\+\\}\\]\\) \\$\\^\\|\\?>', 'escapeRE - Escape specials' );
12 - equal( $.escapeRE( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ),
13 - 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'escapeRE - Leave uppercase alone' );
14 - equal( $.escapeRE( 'abcdefghijklmnopqrstuvwxyz' ),
15 - 'abcdefghijklmnopqrstuvwxyz', 'escapeRE - Leave lowercase alone' );
16 - equal( $.escapeRE( '0123456789' ), '0123456789', 'escapeRE - Leave numbers alone' );
17 -});
18 -
19 -test( 'Is functions', function() {
20 -
21 - strictEqual( $.isDomElement( document.getElementById( 'qunit-header' ) ), true,
22 - 'isDomElement: #qunit-header Node' );
23 - strictEqual( $.isDomElement( document.getElementById( 'random-name' ) ), false,
24 - 'isDomElement: #random-name (null)' );
25 - strictEqual( $.isDomElement( document.getElementsByTagName( 'div' ) ), false,
26 - 'isDomElement: getElementsByTagName Array' );
27 - strictEqual( $.isDomElement( document.getElementsByTagName( 'div' )[0] ), true,
28 - 'isDomElement: getElementsByTagName(..)[0] Node' );
29 - strictEqual( $.isDomElement( $( 'div' ) ), false,
30 - 'isDomElement: jQuery object' );
31 - strictEqual( $.isDomElement( $( 'div' ).get(0) ), true,
32 - 'isDomElement: jQuery object > Get node' );
33 - strictEqual( $.isDomElement( document.createElement( 'div' ) ), true,
34 - 'isDomElement: createElement' );
35 - strictEqual( $.isDomElement( { foo: 1 } ), false,
36 - 'isDomElement: Object' );
37 -
38 - strictEqual( $.isEmpty( 'string' ), false, 'isEmptry: "string"' );
39 - strictEqual( $.isEmpty( '0' ), true, 'isEmptry: "0"' );
40 - strictEqual( $.isEmpty( [] ), true, 'isEmptry: []' );
41 - strictEqual( $.isEmpty( {} ), true, 'isEmptry: {}' );
42 -
43 - // Documented behaviour
44 - strictEqual( $.isEmpty( { length: 0 } ), true, 'isEmptry: { length: 0 }' );
45 -});
46 -
47 -test( 'Comparison functions', function() {
48 -
49 - ok( $.compareArray( [0, 'a', [], [2, 'b'] ], [0, "a", [], [2, "b"] ] ),
50 - 'compareArray: Two deep arrays that are excactly the same' );
51 - ok( !$.compareArray( [1], [2] ), 'compareArray: Two different arrays (false)' );
52 -
53 - ok( $.compareObject( {}, {} ), 'compareObject: Two empty objects' );
54 - ok( $.compareObject( { foo: 1 }, { foo: 1 } ), 'compareObject: Two the same objects' );
55 - ok( !$.compareObject( { bar: true }, { baz: false } ),
56 - 'compareObject: Two different objects (false)' );
57 -});
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.mwExtension.js
@@ -0,0 +1,56 @@
 2+module( 'jquery.mwExtension.js' );
 3+
 4+test( 'String functions', function() {
 5+
 6+ equal( $.trimLeft( ' foo bar ' ), 'foo bar ', 'trimLeft' );
 7+ equal( $.trimRight( ' foo bar ' ), ' foo bar', 'trimRight' );
 8+ equal( $.ucFirst( 'foo'), 'Foo', 'ucFirst' );
 9+
 10+ equal( $.escapeRE( '<!-- ([{+mW+}]) $^|?>' ),
 11+ '<!\\-\\- \\(\\[\\{\\+mW\\+\\}\\]\\) \\$\\^\\|\\?>', 'escapeRE - Escape specials' );
 12+ equal( $.escapeRE( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ),
 13+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'escapeRE - Leave uppercase alone' );
 14+ equal( $.escapeRE( 'abcdefghijklmnopqrstuvwxyz' ),
 15+ 'abcdefghijklmnopqrstuvwxyz', 'escapeRE - Leave lowercase alone' );
 16+ equal( $.escapeRE( '0123456789' ), '0123456789', 'escapeRE - Leave numbers alone' );
 17+});
 18+
 19+test( 'Is functions', function() {
 20+
 21+ strictEqual( $.isDomElement( document.getElementById( 'qunit-header' ) ), true,
 22+ 'isDomElement: #qunit-header Node' );
 23+ strictEqual( $.isDomElement( document.getElementById( 'random-name' ) ), false,
 24+ 'isDomElement: #random-name (null)' );
 25+ strictEqual( $.isDomElement( document.getElementsByTagName( 'div' ) ), false,
 26+ 'isDomElement: getElementsByTagName Array' );
 27+ strictEqual( $.isDomElement( document.getElementsByTagName( 'div' )[0] ), true,
 28+ 'isDomElement: getElementsByTagName(..)[0] Node' );
 29+ strictEqual( $.isDomElement( $( 'div' ) ), false,
 30+ 'isDomElement: jQuery object' );
 31+ strictEqual( $.isDomElement( $( 'div' ).get(0) ), true,
 32+ 'isDomElement: jQuery object > Get node' );
 33+ strictEqual( $.isDomElement( document.createElement( 'div' ) ), true,
 34+ 'isDomElement: createElement' );
 35+ strictEqual( $.isDomElement( { foo: 1 } ), false,
 36+ 'isDomElement: Object' );
 37+
 38+ strictEqual( $.isEmpty( 'string' ), false, 'isEmptry: "string"' );
 39+ strictEqual( $.isEmpty( '0' ), true, 'isEmptry: "0"' );
 40+ strictEqual( $.isEmpty( [] ), true, 'isEmptry: []' );
 41+ strictEqual( $.isEmpty( {} ), true, 'isEmptry: {}' );
 42+
 43+ // Documented behaviour
 44+ strictEqual( $.isEmpty( { length: 0 } ), true, 'isEmptry: { length: 0 }' );
 45+});
 46+
 47+test( 'Comparison functions', function() {
 48+
 49+ ok( $.compareArray( [0, 'a', [], [2, 'b'] ], [0, "a", [], [2, "b"] ] ),
 50+ 'compareArray: Two deep arrays that are excactly the same' );
 51+ ok( !$.compareArray( [1], [2] ), 'compareArray: Two different arrays (false)' );
 52+
 53+ ok( $.compareObject( {}, {} ), 'compareObject: Two empty objects' );
 54+ ok( $.compareObject( { foo: 1 }, { foo: 1 } ), 'compareObject: Two the same objects' );
 55+ ok( !$.compareObject( { bar: true }, { baz: false } ),
 56+ 'compareObject: Two different objects (false)' );
 57+});
Property changes on: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.mwExtension.js
___________________________________________________________________
Added: svn:eol-style
158 + native
Index: trunk/phase3/resources/jquery/jquery.mwPrototypes.js
@@ -1,120 +0,0 @@
2 -/*
3 - * JavaScript backwards-compatibility alternatives and other convenience functions
4 - */
5 -
6 -jQuery.extend({
7 - trimLeft : function( str ) {
8 - return str === null ? '' : str.toString().replace( /^\s+/, '' );
9 - },
10 - trimRight : function( str ) {
11 - return str === null ?
12 - '' : str.toString().replace( /\s+$/, '' );
13 - },
14 - ucFirst : function( str ) {
15 - return str.substr( 0, 1 ).toUpperCase() + str.substr( 1 );
16 - },
17 - escapeRE : function( str ) {
18 - return str.replace ( /([\\{}()|.?*+\-^$\[\]])/g, "\\$1" );
19 - },
20 - isDomElement : function( el ) {
21 - return !!el && !!el.nodeType;
22 - },
23 - isEmpty : function( v ) {
24 - var key;
25 - if ( v === "" || v === 0 || v === "0" || v === null
26 - || v === false || typeof v === 'undefined' )
27 - {
28 - return true;
29 - }
30 - // the for-loop could potentially contain prototypes
31 - // to avoid that we check it's length first
32 - if ( v.length === 0 ) {
33 - return true;
34 - }
35 - if ( typeof v === 'object' ) {
36 - for ( key in v ) {
37 - return false;
38 - }
39 - return true;
40 - }
41 - return false;
42 - },
43 - compareArray : function( arrThis, arrAgainst ) {
44 - if ( arrThis.length != arrAgainst.length ) {
45 - return false;
46 - }
47 - for ( var i = 0; i < arrThis.length; i++ ) {
48 - if ( arrThis[i] instanceof Array ) {
49 - if ( !$.compareArray( arrThis[i], arrAgainst[i] ) ) {
50 - return false;
51 - }
52 - } else if ( arrThis[i] !== arrAgainst[i] ) {
53 - return false;
54 - }
55 - }
56 - return true;
57 - },
58 - compareObject : function( objectA, objectB ) {
59 -
60 - // Do a simple check if the types match
61 - if ( typeof objectA == typeof objectB ) {
62 -
63 - // Only loop over the contents if it really is an object
64 - if ( typeof objectA == 'object' ) {
65 - // If they are aliases of the same object (ie. mw and mediaWiki) return now
66 - if ( objectA === objectB ) {
67 - return true;
68 - } else {
69 - var prop;
70 - // Iterate over each property
71 - for ( prop in objectA ) {
72 - // Check if this property is also present in the other object
73 - if ( prop in objectB ) {
74 - // Compare the types of the properties
75 - var type = typeof objectA[prop];
76 - if ( type == typeof objectB[prop] ) {
77 - // Recursively check objects inside this one
78 - switch ( type ) {
79 - case 'object' :
80 - if ( !$.compareObject( objectA[prop], objectB[prop] ) ) {
81 - return false;
82 - }
83 - break;
84 - case 'function' :
85 - // Functions need to be strings to compare them properly
86 - if ( objectA[prop].toString() !== objectB[prop].toString() ) {
87 - return false;
88 - }
89 - break;
90 - default:
91 - // Strings, numbers
92 - if ( objectA[prop] !== objectB[prop] ) {
93 - return false;
94 - }
95 - break;
96 - }
97 - } else {
98 - return false;
99 - }
100 - } else {
101 - return false;
102 - }
103 - }
104 - // Check for properties in B but not in A
105 - // This is about 15% faster (tested in Safari 5 and Firefox 3.6)
106 - // ...than incrementing a count variable in the above and below loops
107 - // See also: http://www.mediawiki.org/wiki/ResourceLoader/Default_modules/compareObject_test#Results
108 - for ( prop in objectB ) {
109 - if ( !( prop in objectA ) ) {
110 - return false;
111 - }
112 - }
113 - }
114 - }
115 - } else {
116 - return false;
117 - }
118 - return true;
119 - }
120 -});
121 -
Index: trunk/phase3/resources/jquery/jquery.mwExtension.js
@@ -0,0 +1,120 @@
 2+/*
 3+ * JavaScript backwards-compatibility alternatives and other convenience functions
 4+ */
 5+
 6+jQuery.extend({
 7+ trimLeft : function( str ) {
 8+ return str === null ? '' : str.toString().replace( /^\s+/, '' );
 9+ },
 10+ trimRight : function( str ) {
 11+ return str === null ?
 12+ '' : str.toString().replace( /\s+$/, '' );
 13+ },
 14+ ucFirst : function( str ) {
 15+ return str.substr( 0, 1 ).toUpperCase() + str.substr( 1 );
 16+ },
 17+ escapeRE : function( str ) {
 18+ return str.replace ( /([\\{}()|.?*+\-^$\[\]])/g, "\\$1" );
 19+ },
 20+ isDomElement : function( el ) {
 21+ return !!el && !!el.nodeType;
 22+ },
 23+ isEmpty : function( v ) {
 24+ var key;
 25+ if ( v === "" || v === 0 || v === "0" || v === null
 26+ || v === false || typeof v === 'undefined' )
 27+ {
 28+ return true;
 29+ }
 30+ // the for-loop could potentially contain prototypes
 31+ // to avoid that we check it's length first
 32+ if ( v.length === 0 ) {
 33+ return true;
 34+ }
 35+ if ( typeof v === 'object' ) {
 36+ for ( key in v ) {
 37+ return false;
 38+ }
 39+ return true;
 40+ }
 41+ return false;
 42+ },
 43+ compareArray : function( arrThis, arrAgainst ) {
 44+ if ( arrThis.length != arrAgainst.length ) {
 45+ return false;
 46+ }
 47+ for ( var i = 0; i < arrThis.length; i++ ) {
 48+ if ( arrThis[i] instanceof Array ) {
 49+ if ( !$.compareArray( arrThis[i], arrAgainst[i] ) ) {
 50+ return false;
 51+ }
 52+ } else if ( arrThis[i] !== arrAgainst[i] ) {
 53+ return false;
 54+ }
 55+ }
 56+ return true;
 57+ },
 58+ compareObject : function( objectA, objectB ) {
 59+
 60+ // Do a simple check if the types match
 61+ if ( typeof objectA == typeof objectB ) {
 62+
 63+ // Only loop over the contents if it really is an object
 64+ if ( typeof objectA == 'object' ) {
 65+ // If they are aliases of the same object (ie. mw and mediaWiki) return now
 66+ if ( objectA === objectB ) {
 67+ return true;
 68+ } else {
 69+ var prop;
 70+ // Iterate over each property
 71+ for ( prop in objectA ) {
 72+ // Check if this property is also present in the other object
 73+ if ( prop in objectB ) {
 74+ // Compare the types of the properties
 75+ var type = typeof objectA[prop];
 76+ if ( type == typeof objectB[prop] ) {
 77+ // Recursively check objects inside this one
 78+ switch ( type ) {
 79+ case 'object' :
 80+ if ( !$.compareObject( objectA[prop], objectB[prop] ) ) {
 81+ return false;
 82+ }
 83+ break;
 84+ case 'function' :
 85+ // Functions need to be strings to compare them properly
 86+ if ( objectA[prop].toString() !== objectB[prop].toString() ) {
 87+ return false;
 88+ }
 89+ break;
 90+ default:
 91+ // Strings, numbers
 92+ if ( objectA[prop] !== objectB[prop] ) {
 93+ return false;
 94+ }
 95+ break;
 96+ }
 97+ } else {
 98+ return false;
 99+ }
 100+ } else {
 101+ return false;
 102+ }
 103+ }
 104+ // Check for properties in B but not in A
 105+ // This is about 15% faster (tested in Safari 5 and Firefox 3.6)
 106+ // ...than incrementing a count variable in the above and below loops
 107+ // See also: http://www.mediawiki.org/wiki/ResourceLoader/Default_modules/compareObject_test#Results
 108+ for ( prop in objectB ) {
 109+ if ( !( prop in objectA ) ) {
 110+ return false;
 111+ }
 112+ }
 113+ }
 114+ }
 115+ } else {
 116+ return false;
 117+ }
 118+ return true;
 119+ }
 120+});
 121+
Property changes on: trunk/phase3/resources/jquery/jquery.mwExtension.js
___________________________________________________________________
Added: svn:eol-style
1122 + native
Index: trunk/phase3/resources/Resources.php
@@ -145,8 +145,8 @@
146146 'jquery.mockjax' => array(
147147 'scripts' => 'resources/jquery/jquery.mockjax.js',
148148 ),
149 - 'jquery.mwPrototypes' => array(
150 - 'scripts' => 'resources/jquery/jquery.mwPrototypes.js',
 149+ 'jquery.mwExtension' => array(
 150+ 'scripts' => 'resources/jquery/jquery.mwExtension.js',
151151 ),
152152 'jquery.qunit' => array(
153153 'scripts' => 'resources/jquery/jquery.qunit.js',
@@ -579,7 +579,7 @@
580580 'jquery.client',
581581 'jquery.cookie',
582582 'jquery.messageBox',
583 - 'jquery.mwPrototypes',
 583+ 'jquery.mwExtension',
584584 ),
585585 ),
586586 'mediawiki.uri' => array(

Sign-offs

UserFlagDate
Hasharinspected08:19, 12 August 2011

Status & tagging log