Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js |
— | — | @@ -60,6 +60,14 @@ |
61 | 61 | 'function (string)'); |
62 | 62 | mw.test.addTest('$.trimRight(\' foo bar \')', |
63 | 63 | ' foo bar (string)'); |
| 64 | + mw.test.addTest('typeof $.isEmpty', |
| 65 | + 'function (string)'); |
| 66 | + mw.test.addTest('$.isEmpty(\'string\')', |
| 67 | + 'false (boolean)'); |
| 68 | + mw.test.addTest('$.isEmpty(\'0\')', |
| 69 | + 'true (boolean)'); |
| 70 | + mw.test.addTest('$.isEmpty([])', |
| 71 | + 'true (boolean)'); |
64 | 72 | mw.test.addTest('typeof $.compareArray', |
65 | 73 | 'function (string)'); |
66 | 74 | mw.test.addTest('$.compareArray( [1, "a", [], [2, \'b\'] ], [1, \'a\', [], [2, "b"] ] )', |
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js |
— | — | @@ -128,33 +128,6 @@ |
129 | 129 | }, |
130 | 130 | |
131 | 131 | /** |
132 | | - * Check is a variable is empty. Supports strings, booleans, arrays and |
133 | | - * objects. The string "0" is considered empty. A string containing only |
134 | | - * whitespace (ie. " ") is considered not empty. |
135 | | - * |
136 | | - * @param v The variable to check for emptyness |
137 | | - */ |
138 | | - 'isEmpty' : function( v ) { |
139 | | - var key; |
140 | | - if ( v === "" || v === 0 || v === "0" || v === null |
141 | | - || v === false || typeof v === 'undefined' ) |
142 | | - { |
143 | | - return true; |
144 | | - } |
145 | | - if ( v.length === 0 ) { |
146 | | - return true; |
147 | | - } |
148 | | - if ( typeof v === 'object' ) { |
149 | | - for ( key in v ) { |
150 | | - return false; |
151 | | - } |
152 | | - return true; |
153 | | - } |
154 | | - return false; |
155 | | - }, |
156 | | - |
157 | | - |
158 | | - /** |
159 | 132 | * Grab the URL parameter value for the given parameter. |
160 | 133 | * Returns null if not found. |
161 | 134 | * |
Index: trunk/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | /* |
3 | | - * JavaScript backwards-compatibility alternatives and convenience functions |
| 3 | + * JavaScript backwards-compatibility alternatives and other convenience functions |
4 | 4 | */ |
5 | 5 | |
6 | 6 | jQuery.extend({ |
— | — | @@ -16,6 +16,26 @@ |
17 | 17 | escapeRE : function( str ) { |
18 | 18 | return str.replace ( /([\\{}()|.?*+^$\[\]])/g, "\\$1" ); |
19 | 19 | }, |
| 20 | + isEmpty : function( v ) { |
| 21 | + var key; |
| 22 | + if ( v === "" || v === 0 || v === "0" || v === null |
| 23 | + || v === false || typeof v === 'undefined' ) |
| 24 | + { |
| 25 | + return true; |
| 26 | + } |
| 27 | + // the for-loop could potentially contain prototypes |
| 28 | + // to avoid that we check it's length first |
| 29 | + if ( v.length === 0 ) { |
| 30 | + return true; |
| 31 | + } |
| 32 | + if ( typeof v === 'object' ) { |
| 33 | + for ( key in v ) { |
| 34 | + return false; |
| 35 | + } |
| 36 | + return true; |
| 37 | + } |
| 38 | + return false; |
| 39 | + }, |
20 | 40 | compareArray : function( arrThis, arrAgainst ) { |
21 | 41 | if ( arrThis.length != arrAgainst.length ) { |
22 | 42 | return false; |