Index: trunk/extensions/UploadWizard/resources/mw.Utilities.js |
— | — | @@ -3,42 +3,16 @@ |
4 | 4 | ( function( mw ) { |
5 | 5 | |
6 | 6 | /** |
7 | | - * Check if an object is empty or if its an empty string. |
| 7 | + * Check if a value is null, undefined, or the empty string. |
8 | 8 | * |
9 | 9 | * @param {Object} object Object to be checked |
10 | 10 | * @return {Boolean} |
11 | 11 | */ |
12 | | - mw.isEmpty = function( obj ) { |
13 | | - if( typeof obj === 'string' ) { |
14 | | - if( obj === '' ) return true; |
15 | | - // Non empty string: |
16 | | - return false; |
17 | | - } |
18 | | - |
19 | | - // If an array check length: |
20 | | - if( Object.prototype.toString.call( obj ) === "[object Array]" |
21 | | - && obj.length === 0 ) { |
22 | | - return true; |
23 | | - } |
24 | | - |
25 | | - // Else check as an obj: |
26 | | - for( var i in obj ) { return false; } |
27 | | - |
28 | | - // Else obj is empty: |
29 | | - return true; |
| 12 | + mw.isEmpty = function( o ) { |
| 13 | + return ! mw.isDefined( o ) || o === null || ( typeof o === 'string' && o === '' ); |
30 | 14 | }; |
31 | 15 | |
32 | 16 | /** |
33 | | - * Opposite of mw.isEmpty |
34 | | - * |
35 | | - * @param {Object} object Object to be checked |
36 | | - * @return {Boolean} |
37 | | - */ |
38 | | - mw.isFull = function( obj ) { |
39 | | - return ! mw.isEmpty( obj ); |
40 | | - }; |
41 | | - |
42 | | - /** |
43 | 17 | * Check if something is defined |
44 | 18 | * (inlineable?) |
45 | 19 | * @param {Object} |
Index: trunk/extensions/UploadWizard/resources/mw.Uri.js |
— | — | @@ -58,7 +58,7 @@ |
59 | 59 | */ |
60 | 60 | mw.Uri = function( uri, strictMode ) { |
61 | 61 | strictMode = !!strictMode; |
62 | | - if ( mw.isFull( uri ) ) { |
| 62 | + if ( !mw.isEmpty( uri ) ) { |
63 | 63 | if ( typeof uri === 'string' ) { |
64 | 64 | this._parse( uri, strictMode ); |
65 | 65 | } else if ( typeof uri === 'object' ) { |
— | — | @@ -158,9 +158,9 @@ |
159 | 159 | */ |
160 | 160 | getUserInfo: function() { |
161 | 161 | var userInfo = ''; |
162 | | - if ( mw.isFull( this.user ) ) { |
| 162 | + if ( !mw.isEmpty( this.user ) ) { |
163 | 163 | userInfo += this.encode( this.user ); |
164 | | - if ( mw.isFull( this.password ) ) { |
| 164 | + if ( !mw.isEmpty( this.password ) ) { |
165 | 165 | userInfo += ':' + this.encode( this.password ); |
166 | 166 | } |
167 | 167 | } |
— | — | @@ -173,8 +173,8 @@ |
174 | 174 | */ |
175 | 175 | getHostPort: function() { |
176 | 176 | return this.host |
177 | | - + ( mw.isFull( this.port ) ? ':' + this.port |
178 | | - : '' |
| 177 | + + ( !mw.isEmpty( this.port ) ? ':' + this.port |
| 178 | + : '' |
179 | 179 | ); |
180 | 180 | }, |
181 | 181 | |
— | — | @@ -185,8 +185,8 @@ |
186 | 186 | */ |
187 | 187 | getAuthority: function() { |
188 | 188 | var userInfo = this.getUserInfo(); |
189 | | - return ( mw.isFull( userInfo ) ? userInfo + '@' |
190 | | - : '' |
| 189 | + return ( !mw.isEmpty( userInfo ) ? userInfo + '@' |
| 190 | + : '' |
191 | 191 | ) |
192 | 192 | + this.getHostPort(); |
193 | 193 | }, |
— | — | @@ -212,11 +212,11 @@ |
213 | 213 | getRelativePath: function() { |
214 | 214 | var queryString = this.getQueryString(); |
215 | 215 | return this.path |
216 | | - + ( mw.isFull( queryString ) ? '?' + queryString |
217 | | - : '' |
| 216 | + + ( !mw.isEmpty( queryString ) ? '?' + queryString |
| 217 | + : '' |
218 | 218 | ) |
219 | | - + ( mw.isFull( this.fragment ) ? '#' + this.encode( this.fragment ) |
220 | | - : '' |
| 219 | + + ( !mw.isEmpty( this.fragment ) ? '#' + this.encode( this.fragment ) |
| 220 | + : '' |
221 | 221 | ); |
222 | 222 | }, |
223 | 223 | |