[Slashdotjp-dev 1434] [965] Add all-minified.js.prefix to make cross-browser String.split()

Zurück zum Archiv-Index

svnno****@sourc***** svnno****@sourc*****
2009年 1月 21日 (水) 18:24:19 JST


Revision: 965
          http://svn.sourceforge.jp/view?root=slashdotjp&view=rev&rev=965
Author:   tach
Date:     2009-01-21 18:24:19 +0900 (Wed, 21 Jan 2009)

Log Message:
-----------
Add all-minified.js.prefix to make cross-browser String.split()
It was downloaded from http://blog.stevenlevithan.com/archives/cross-browser-split

Modified Paths:
--------------
    images/trunk/Makefile
    images/trunk/all-minified.js

Added Paths:
-----------
    images/trunk/all-minified.js.prefix


-------------- next part --------------
Modified: images/trunk/Makefile
===================================================================
--- images/trunk/Makefile	2009-01-21 08:04:40 UTC (rev 964)
+++ images/trunk/Makefile	2009-01-21 09:24:19 UTC (rev 965)
@@ -44,9 +44,10 @@
 css/%.css.orig:
 	wget --no-proxy --no-verbose http://images.slashdot.org/$(patsubst css/%.orig,%, $@) -O $@
 
-all-minified.js: %: %.orig %.jp
+all-minified.js: %: %.orig %.jp %.prefix
 $(jses): %: %.js
 $(patsubst %, %.js, $(jses)): %: %.orig
+	if [ -f $@.prefix ]; then cat $@.prefix > $@; fi
 	cat $@.orig | \
 		sed -e 's/if(name=="usermode"){/if(name=="firehose_usermode"){/' | \
 		sed -e 's/ Firehose / アレたま /' | \
@@ -80,7 +81,7 @@
 		sed -e 's/visible to the --LEFTORTOP-- of the discussion.)</</' | \
 		sed -e "s/'top' : 'left';/'上の' : '左の';/" | \
 		sed -e 's/hidden comment</個の隠れコメント</' | \
-		sed -e 's/hidden comments</個の隠れコメント</' > $@
+		sed -e 's/hidden comments</個の隠れコメント</' >> $@
 	echo >> $@
 	if [ -f $@.jp ]; then cat $@.jp >> $@; fi
 

Modified: images/trunk/all-minified.js
===================================================================
--- images/trunk/all-minified.js	2009-01-21 08:04:40 UTC (rev 964)
+++ images/trunk/all-minified.js	2009-01-21 09:24:19 UTC (rev 965)
@@ -1,3 +1,81 @@
+/*
+	Cross-Browser Split 0.3
+	By Steven Levithan <http://stevenlevithan.com>
+	MIT license
+	Provides a consistent cross-browser, ECMA-262 v3 compliant split method
+*/
+
+String.prototype._$$split = String.prototype._$$split || String.prototype.split;
+
+String.prototype.split = function (s /* separator */, limit) {
+	// if separator is not a regex, use the native split method
+	if (!(s instanceof RegExp))
+		return String.prototype._$$split.apply(this, arguments);
+
+	var	flags = (s.global ? "g" : "") + (s.ignoreCase ? "i" : "") + (s.multiline ? "m" : ""),
+		s2 = new RegExp("^" + s.source + "$", flags),
+		output = [],
+		origLastIndex = s.lastIndex,
+		lastLastIndex = 0,
+		i = 0, match, lastLength;
+
+	/* behavior for limit: if it's...
+	- undefined: no limit
+	- NaN or zero: return an empty array
+	- a positive number: use limit after dropping any decimal
+	- a negative number: no limit
+	- other: type-convert, then use the above rules
+	*/
+	if (limit === undefined || +limit < 0) {
+		limit = false;
+	} else {
+		limit = Math.floor(+limit);
+		if (!limit)
+			return [];
+	}
+
+	if (s.global)
+		s.lastIndex = 0;
+	else
+		s = new RegExp(s.source, "g" + flags);
+
+	while ((!limit || i++ <= limit) && (match = s.exec(this))) {
+		var emptyMatch = !match[0].length;
+
+		// Fix IE's infinite-loop-resistant but incorrect lastIndex
+		if (emptyMatch && s.lastIndex > match.index)
+			s.lastIndex--;
+
+		if (s.lastIndex > lastLastIndex) {
+			// Fix browsers whose exec methods don't consistently return undefined for non-participating capturing groups
+			if (match.length > 1) {
+				match[0].replace(s2, function () {
+					for (var j = 1; j < arguments.length - 2; j++) {
+						if (arguments[j] === undefined)
+							match[j] = undefined;
+					}
+				});
+			}
+
+			output = output.concat(this.slice(lastLastIndex, match.index));
+			if (1 < match.length && match.index < this.length)
+				output = output.concat(match.slice(1));
+			lastLength = match[0].length; // only needed if s.lastIndex === this.length
+			lastLastIndex = s.lastIndex;
+		}
+
+		if (emptyMatch)
+			s.lastIndex++; // avoid an infinite loop
+	}
+
+	// since this uses test(), output must be generated before restoring lastIndex
+	output = lastLastIndex === this.length ?
+		(s.test("") && !lastLength ? output : output.concat("")) :
+		(limit ? output : output.concat(this.slice(lastLastIndex)));
+	s.lastIndex = origLastIndex; // only needed if s.global, else we're working with a copy of the regex
+	return output;
+};
+
 (function(){var _jQuery=window.jQuery,_$=window.$;var jQuery=window.jQuery=window.$=function(selector,context){return new jQuery.fn.init(selector,context);};var quickExpr=/^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/,isSimple=/^.[^:#\[\.]*$/,undefined;jQuery.fn=jQuery.prototype={init:function(selector,context){selector=selector||document;if(selector.nodeType){this[0]=selector;this.length=1;return this;}
 if(typeof selector=="string"){var match=quickExpr.exec(selector);if(match&&(match[1]||!context)){if(match[1])
 selector=jQuery.clean([match[1]],context);else{var elem=document.getElementById(match[3]);if(elem){if(elem.id!=match[3])

Added: images/trunk/all-minified.js.prefix
===================================================================
--- images/trunk/all-minified.js.prefix	                        (rev 0)
+++ images/trunk/all-minified.js.prefix	2009-01-21 09:24:19 UTC (rev 965)
@@ -0,0 +1,78 @@
+/*
+	Cross-Browser Split 0.3
+	By Steven Levithan <http://stevenlevithan.com>
+	MIT license
+	Provides a consistent cross-browser, ECMA-262 v3 compliant split method
+*/
+
+String.prototype._$$split = String.prototype._$$split || String.prototype.split;
+
+String.prototype.split = function (s /* separator */, limit) {
+	// if separator is not a regex, use the native split method
+	if (!(s instanceof RegExp))
+		return String.prototype._$$split.apply(this, arguments);
+
+	var	flags = (s.global ? "g" : "") + (s.ignoreCase ? "i" : "") + (s.multiline ? "m" : ""),
+		s2 = new RegExp("^" + s.source + "$", flags),
+		output = [],
+		origLastIndex = s.lastIndex,
+		lastLastIndex = 0,
+		i = 0, match, lastLength;
+
+	/* behavior for limit: if it's...
+	- undefined: no limit
+	- NaN or zero: return an empty array
+	- a positive number: use limit after dropping any decimal
+	- a negative number: no limit
+	- other: type-convert, then use the above rules
+	*/
+	if (limit === undefined || +limit < 0) {
+		limit = false;
+	} else {
+		limit = Math.floor(+limit);
+		if (!limit)
+			return [];
+	}
+
+	if (s.global)
+		s.lastIndex = 0;
+	else
+		s = new RegExp(s.source, "g" + flags);
+
+	while ((!limit || i++ <= limit) && (match = s.exec(this))) {
+		var emptyMatch = !match[0].length;
+
+		// Fix IE's infinite-loop-resistant but incorrect lastIndex
+		if (emptyMatch && s.lastIndex > match.index)
+			s.lastIndex--;
+
+		if (s.lastIndex > lastLastIndex) {
+			// Fix browsers whose exec methods don't consistently return undefined for non-participating capturing groups
+			if (match.length > 1) {
+				match[0].replace(s2, function () {
+					for (var j = 1; j < arguments.length - 2; j++) {
+						if (arguments[j] === undefined)
+							match[j] = undefined;
+					}
+				});
+			}
+
+			output = output.concat(this.slice(lastLastIndex, match.index));
+			if (1 < match.length && match.index < this.length)
+				output = output.concat(match.slice(1));
+			lastLength = match[0].length; // only needed if s.lastIndex === this.length
+			lastLastIndex = s.lastIndex;
+		}
+
+		if (emptyMatch)
+			s.lastIndex++; // avoid an infinite loop
+	}
+
+	// since this uses test(), output must be generated before restoring lastIndex
+	output = lastLastIndex === this.length ?
+		(s.test("") && !lastLength ? output : output.concat("")) :
+		(limit ? output : output.concat(this.slice(lastLastIndex)));
+	s.lastIndex = origLastIndex; // only needed if s.global, else we're working with a copy of the regex
+	return output;
+};
+


Slashdotjp-dev メーリングリストの案内
Zurück zum Archiv-Index