* JavaScript backwards-compatibility and support
*/
-// Make calling .indexOf() on an array work on older browsers
-if ( typeof Array.prototype.indexOf === 'undefined' ) {
- Array.prototype.indexOf = function( needle ) {
- for ( var i = 0; i < this.length; i++ ) {
- if ( this[i] === needle ) {
- return i;
- }
- }
- return -1;
+// New fallback String trimming functionality, was introduced natively in JavaScript 1.8.1
+if (typeof String.prototype.trimx === 'undefined') {
+// Add removing trailing and leading whitespace functionality cross-browser
+// See also: http://blog.stevenlevithan.com/archives/faster-trim-javascript
+ String.prototype.trim = function () {
+ return this.replace(/^\s+|\s+$/g, '');
+ };
+}
+if (typeof String.prototype.trimLeft === 'undefined') {
+ String.prototype.trimLeft = function () {
+ return this.replace(/^\s\s*/, "");
+ };
+}
+
+if (typeof String.prototype.trimRight === 'undefined') {
+ String.prototype.trimRight = function () {
+ return this.replace(/\s\s*$/, "");
};
}
+
// Add array comparison functionality
-if ( typeof Array.prototype.compare === 'undefined' ) {
- Array.prototype.compare = function( against ) {
- if ( this.length != against.length ) {
+if (typeof Array.prototype.compare === 'undefined') {
+ Array.prototype.compare = function (against) {
+ if (this.length !== against.length) {
return false;
}
- for ( var i = 0; i < against.length; i++ ) {
- if ( this[i].compare ) {
- if ( !this[i].compare( against[i] ) ) {
+ for (var i = 0; i < against.length; i++) {
+ if (this[i].compare) {
+ if (!this[i].compare(against[i])) {
return false;
}
}
- if ( this[i] !== against[i] ) {
+ if (this[i] !== against[i]) {
return false;
}
}
};
}
+// Make calling .indexOf() on an array work on older browsers
+if (typeof Array.prototype.indexOf === 'undefined') {
+ Array.prototype.indexOf = function (needle) {
+ for (var i = 0; i < this.length; i++) {
+ if (this[i] === needle) {
+ return i;
+ }
+ }
+ return -1;
+ };
+}
+
/*
* Core MediaWiki JavaScript Library
*/
-/*jslint white: true, browser: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true */
/*
* Utilities
*/
return $box;
};
+ // Prototype enhancements
+ if (typeof String.prototype.ucFirst === 'undefined') {
+ String.prototype.ucFirst = function () {
+ return this.substr(0, 1).toUpperCase() + this.substr(1, this.length);
+ };
+ }
+
// Any initialisation after the DOM is ready
$(function () {
$('input[type=checkbox]:not(.noshiftselect)').enableCheckboxShiftClick();
return wgServer + wgArticlePath.replace('$1', this.wikiUrlencode(str));
},
+ /**
+ * Check is a variable is empty. Support for strings, booleans, arrays and objects.
+ * String "0" is considered empty. String containing only whitespace (ie. " ") is considered not empty.
+ *
+ * @param Mixed v the variable to check for empty ness
+ */
+ 'isEmpty' : function (v) {
+ var key;
+ if (v === "" || v === 0 || v === "0" || v === null || v === false || typeof v === 'undefined') {
+ return true;
+ }
+ if (v.length === 0) {
+ return true;
+ }
+ if (typeof v === 'object') {
+ for (key in v) {
+ return false;
+ }
+ return true;
+ }
+ return false;
+ },
+
/**
* Grabs the url parameter value for the given parameter