http://www.mediawiki.org/wiki/Special:Code/MediaWiki/75294
Revision: 75294
Author: krinkle
Date: 2010-10-23 21:08:58 +0000 (Sat, 23 Oct 2010)
Log Message:
-----------
added string trimming for older browsers
Modified Paths:
--------------
trunk/phase3/resources/mediawiki/mediawiki.js
trunk/phase3/resources/mediawiki/mediawiki.util.js
Modified: trunk/phase3/resources/mediawiki/mediawiki.js
===================================================================
--- trunk/phase3/resources/mediawiki/mediawiki.js 2010-10-23 21:01:54 UTC
(rev 75293)
+++ trunk/phase3/resources/mediawiki/mediawiki.js 2010-10-23 21:08:58 UTC
(rev 75294)
@@ -2,30 +2,39 @@
* 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;
}
}
@@ -33,6 +42,18 @@
};
}
+// 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
*/
Modified: trunk/phase3/resources/mediawiki/mediawiki.util.js
===================================================================
--- trunk/phase3/resources/mediawiki/mediawiki.util.js 2010-10-23 21:01:54 UTC
(rev 75293)
+++ trunk/phase3/resources/mediawiki/mediawiki.util.js 2010-10-23 21:08:58 UTC
(rev 75294)
@@ -1,4 +1,3 @@
-/*jslint white: true, browser: true, nomen: true, eqeqeq: true, plusplus:
true, bitwise: true, regexp: true, newcap: true */
/*
* Utilities
*/
@@ -44,6 +43,13 @@
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();
@@ -88,7 +94,30 @@
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
* Returns null if not found
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs