Index: trunk/phase3/resources/mediawiki/mediawiki.util.js |
— | — | @@ -1,4 +1,3 @@ |
2 | | -/*jslint white: true, browser: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true */ |
3 | 2 | /* |
4 | 3 | * Utilities |
5 | 4 | */ |
— | — | @@ -44,6 +43,13 @@ |
45 | 44 | return $box; |
46 | 45 | }; |
47 | 46 | |
| 47 | + // Prototype enhancements |
| 48 | + if (typeof String.prototype.ucFirst === 'undefined') { |
| 49 | + String.prototype.ucFirst = function () { |
| 50 | + return this.substr(0, 1).toUpperCase() + this.substr(1, this.length); |
| 51 | + }; |
| 52 | + } |
| 53 | + |
48 | 54 | // Any initialisation after the DOM is ready |
49 | 55 | $(function () { |
50 | 56 | $('input[type=checkbox]:not(.noshiftselect)').enableCheckboxShiftClick(); |
— | — | @@ -88,7 +94,30 @@ |
89 | 95 | return wgServer + wgArticlePath.replace('$1', this.wikiUrlencode(str)); |
90 | 96 | }, |
91 | 97 | |
| 98 | + /** |
| 99 | + * Check is a variable is empty. Support for strings, booleans, arrays and objects. |
| 100 | + * String "0" is considered empty. String containing only whitespace (ie. " ") is considered not empty. |
| 101 | + * |
| 102 | + * @param Mixed v the variable to check for empty ness |
| 103 | + */ |
| 104 | + 'isEmpty' : function (v) { |
| 105 | + var key; |
| 106 | + if (v === "" || v === 0 || v === "0" || v === null || v === false || typeof v === 'undefined') { |
| 107 | + return true; |
| 108 | + } |
| 109 | + if (v.length === 0) { |
| 110 | + return true; |
| 111 | + } |
| 112 | + if (typeof v === 'object') { |
| 113 | + for (key in v) { |
| 114 | + return false; |
| 115 | + } |
| 116 | + return true; |
| 117 | + } |
| 118 | + return false; |
| 119 | + }, |
92 | 120 | |
| 121 | + |
93 | 122 | /** |
94 | 123 | * Grabs the url parameter value for the given parameter |
95 | 124 | * Returns null if not found |
Index: trunk/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -2,30 +2,39 @@ |
3 | 3 | * JavaScript backwards-compatibility and support |
4 | 4 | */ |
5 | 5 | |
6 | | -// Make calling .indexOf() on an array work on older browsers |
7 | | -if ( typeof Array.prototype.indexOf === 'undefined' ) { |
8 | | - Array.prototype.indexOf = function( needle ) { |
9 | | - for ( var i = 0; i < this.length; i++ ) { |
10 | | - if ( this[i] === needle ) { |
11 | | - return i; |
12 | | - } |
13 | | - } |
14 | | - return -1; |
| 6 | +// New fallback String trimming functionality, was introduced natively in JavaScript 1.8.1 |
| 7 | +if (typeof String.prototype.trimx === 'undefined') { |
| 8 | +// Add removing trailing and leading whitespace functionality cross-browser |
| 9 | +// See also: http://blog.stevenlevithan.com/archives/faster-trim-javascript |
| 10 | + String.prototype.trim = function () { |
| 11 | + return this.replace(/^\s+|\s+$/g, ''); |
15 | 12 | }; |
16 | 13 | } |
| 14 | +if (typeof String.prototype.trimLeft === 'undefined') { |
| 15 | + String.prototype.trimLeft = function () { |
| 16 | + return this.replace(/^\s\s*/, ""); |
| 17 | + }; |
| 18 | +} |
| 19 | + |
| 20 | +if (typeof String.prototype.trimRight === 'undefined') { |
| 21 | + String.prototype.trimRight = function () { |
| 22 | + return this.replace(/\s\s*$/, ""); |
| 23 | + }; |
| 24 | +} |
| 25 | + |
17 | 26 | // Add array comparison functionality |
18 | | -if ( typeof Array.prototype.compare === 'undefined' ) { |
19 | | - Array.prototype.compare = function( against ) { |
20 | | - if ( this.length != against.length ) { |
| 27 | +if (typeof Array.prototype.compare === 'undefined') { |
| 28 | + Array.prototype.compare = function (against) { |
| 29 | + if (this.length !== against.length) { |
21 | 30 | return false; |
22 | 31 | } |
23 | | - for ( var i = 0; i < against.length; i++ ) { |
24 | | - if ( this[i].compare ) { |
25 | | - if ( !this[i].compare( against[i] ) ) { |
| 32 | + for (var i = 0; i < against.length; i++) { |
| 33 | + if (this[i].compare) { |
| 34 | + if (!this[i].compare(against[i])) { |
26 | 35 | return false; |
27 | 36 | } |
28 | 37 | } |
29 | | - if ( this[i] !== against[i] ) { |
| 38 | + if (this[i] !== against[i]) { |
30 | 39 | return false; |
31 | 40 | } |
32 | 41 | } |
— | — | @@ -33,6 +42,18 @@ |
34 | 43 | }; |
35 | 44 | } |
36 | 45 | |
| 46 | +// Make calling .indexOf() on an array work on older browsers |
| 47 | +if (typeof Array.prototype.indexOf === 'undefined') { |
| 48 | + Array.prototype.indexOf = function (needle) { |
| 49 | + for (var i = 0; i < this.length; i++) { |
| 50 | + if (this[i] === needle) { |
| 51 | + return i; |
| 52 | + } |
| 53 | + } |
| 54 | + return -1; |
| 55 | + }; |
| 56 | +} |
| 57 | + |
37 | 58 | /* |
38 | 59 | * Core MediaWiki JavaScript Library |
39 | 60 | */ |