webshims-rails 1.11.3.1 → 1.11.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/webshims-rails/version.rb +2 -2
- data/vendor/assets/javascripts/webshims/extras/modernizr-custom.js +114 -104
- data/vendor/assets/javascripts/webshims/extras/mousepress.js +5 -5
- data/vendor/assets/javascripts/webshims/polyfiller.js +156 -207
- data/vendor/assets/javascripts/webshims/shims/$ajax.js +862 -0
- data/vendor/assets/javascripts/webshims/shims/FlashCanvas/flashcanvas.js +20 -0
- data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/flashcanvas.js +20 -0
- data/vendor/assets/javascripts/webshims/shims/color-picker.js +12 -12
- data/vendor/assets/javascripts/webshims/shims/combos/1.js +62 -32
- data/vendor/assets/javascripts/webshims/shims/combos/10.js +192 -509
- data/vendor/assets/javascripts/webshims/shims/combos/11.js +96 -415
- data/vendor/assets/javascripts/webshims/shims/combos/12.js +36 -26
- data/vendor/assets/javascripts/webshims/shims/combos/13.js +36 -26
- data/vendor/assets/javascripts/webshims/shims/combos/14.js +1007 -359
- data/vendor/assets/javascripts/webshims/shims/combos/15.js +310 -235
- data/vendor/assets/javascripts/webshims/shims/combos/16.js +313 -237
- data/vendor/assets/javascripts/webshims/shims/combos/17.js +96 -415
- data/vendor/assets/javascripts/webshims/shims/combos/18.js +1003 -678
- data/vendor/assets/javascripts/webshims/shims/combos/19.js +1085 -387
- data/vendor/assets/javascripts/webshims/shims/combos/2.js +161 -127
- data/vendor/assets/javascripts/webshims/shims/combos/20.js +1086 -388
- data/vendor/assets/javascripts/webshims/shims/combos/21.js +168 -96
- data/vendor/assets/javascripts/webshims/shims/combos/22.js +36 -27
- data/vendor/assets/javascripts/webshims/shims/combos/23.js +2 -1
- data/vendor/assets/javascripts/webshims/shims/combos/24.js +411 -172
- data/vendor/assets/javascripts/webshims/shims/combos/25.js +1085 -387
- data/vendor/assets/javascripts/webshims/shims/combos/26.js +96 -94
- data/vendor/assets/javascripts/webshims/shims/combos/3.js +163 -140
- data/vendor/assets/javascripts/webshims/shims/combos/30.js +166 -141
- data/vendor/assets/javascripts/webshims/shims/combos/31.js +159 -126
- data/vendor/assets/javascripts/webshims/shims/combos/4.js +103 -109
- data/vendor/assets/javascripts/webshims/shims/combos/5.js +98 -417
- data/vendor/assets/javascripts/webshims/shims/combos/6.js +101 -418
- data/vendor/assets/javascripts/webshims/shims/combos/7.js +168 -142
- data/vendor/assets/javascripts/webshims/shims/combos/8.js +165 -141
- data/vendor/assets/javascripts/webshims/shims/combos/9.js +195 -510
- data/vendor/assets/javascripts/webshims/shims/details.js +2 -2
- data/vendor/assets/javascripts/webshims/shims/dom-extend.js +96 -94
- data/vendor/assets/javascripts/webshims/shims/es5.js +908 -264
- data/vendor/assets/javascripts/webshims/shims/excanvas.js +16 -1
- data/vendor/assets/javascripts/webshims/shims/form-combat.js +147 -0
- data/vendor/assets/javascripts/webshims/shims/form-core.js +60 -31
- data/vendor/assets/javascripts/webshims/shims/form-datalist-lazy.js +114 -33
- data/vendor/assets/javascripts/webshims/shims/form-datalist.js +3 -1
- data/vendor/assets/javascripts/webshims/shims/form-message.js +7 -15
- data/vendor/assets/javascripts/webshims/shims/form-native-extend.js +2 -2
- data/vendor/assets/javascripts/webshims/shims/form-number-date-ui.js +88 -410
- data/vendor/assets/javascripts/webshims/shims/form-shim-extend.js +143 -93
- data/vendor/assets/javascripts/webshims/shims/form-shim-extend2.js +268 -79
- data/vendor/assets/javascripts/webshims/shims/form-validation.js +116 -81
- data/vendor/assets/javascripts/webshims/shims/form-validators.js +23 -10
- data/vendor/assets/javascripts/webshims/shims/forms-picker.js +605 -9
- data/vendor/assets/javascripts/webshims/shims/geolocation.js +51 -39
- data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-de.js +78 -33
- data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-en.js +24 -6
- data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-nl.js +110 -49
- data/vendor/assets/javascripts/webshims/shims/json-storage.js +3 -1
- data/vendor/assets/javascripts/webshims/shims/mediaelement-core.js +2 -1
- data/vendor/assets/javascripts/webshims/shims/mediaelement-jaris.js +81 -30
- data/vendor/assets/javascripts/webshims/shims/mediaelement-yt.js +131 -54
- data/vendor/assets/javascripts/webshims/shims/plugins/jquery.ui.position.js +497 -0
- data/vendor/assets/javascripts/webshims/shims/range-ui.js +8 -5
- data/vendor/assets/javascripts/webshims/shims/sizzle.js +2026 -0
- data/vendor/assets/javascripts/webshims/shims/styles/forms-ext.css +401 -521
- data/vendor/assets/javascripts/webshims/shims/styles/scss/forms-ext.scss +1 -1
- data/vendor/assets/javascripts/webshims/shims/styles/scss/shim.scss +94 -82
- data/vendor/assets/javascripts/webshims/shims/styles/shim.css +250 -321
- data/vendor/assets/javascripts/webshims/shims/swf/JarisFLVPlayer.swf +0 -0
- data/vendor/assets/javascripts/webshims/shims/track-ui.js +1 -1
- data/vendor/assets/javascripts/webshims/shims/track.js +34 -25
- metadata +7 -3
@@ -1,97 +1,55 @@
|
|
1
|
+
// Copyright 2009-2012 by contributors, MIT License
|
1
2
|
// vim: ts=4 sts=4 sw=4 expandtab
|
2
|
-
|
3
|
-
|
4
|
-
// -- dantman Daniel Friesen Copyright (C) 2010 XXX TODO License or CLA
|
5
|
-
// -- fschaefer Florian Schäfer Copyright (C) 2010 MIT License
|
6
|
-
// -- Gozala Irakli Gozalishvili Copyright (C) 2010 MIT License
|
7
|
-
// -- kitcambridge Kit Cambridge Copyright (C) 2011 MIT License
|
8
|
-
// -- kossnocorp Sasha Koss XXX TODO License or CLA
|
9
|
-
// -- bryanforbes Bryan Forbes XXX TODO License or CLA
|
10
|
-
// -- killdream Quildreen Motta Copyright (C) 2011 MIT Licence
|
11
|
-
// -- michaelficarra Michael Ficarra Copyright (C) 2011 3-clause BSD License
|
12
|
-
// -- sharkbrainguy Gerard Paapu Copyright (C) 2011 MIT License
|
13
|
-
// -- bbqsrc Brendan Molloy XXX TODO License or CLA
|
14
|
-
// -- iwyg XXX TODO License or CLA
|
15
|
-
// -- DomenicDenicola Domenic Denicola XXX TODO License or CLA
|
16
|
-
// -- xavierm02 Montillet Xavier XXX TODO License or CLA
|
17
|
-
// -- Raynos Raynos XXX TODO License or CLA
|
18
|
-
// -- samsonjs Sami Samhuri XXX TODO License or CLA
|
19
|
-
// -- rwldrn Rick Waldron Copyright (C) 2011 MIT License
|
20
|
-
// -- lexer Alexey Zakharov XXX TODO License or CLA
|
21
|
-
|
22
|
-
/*!
|
23
|
-
Copyright (c) 2009, 280 North Inc. http://280north.com/
|
24
|
-
MIT License. http://github.com/280north/narwhal/blob/master/README.md
|
25
|
-
*/
|
26
|
-
|
27
|
-
(function (undefined) {
|
3
|
+
|
4
|
+
(function () {
|
28
5
|
|
29
6
|
/**
|
30
7
|
* Brings an environment as close to ECMAScript 5 compliance
|
31
8
|
* as is possible with the facilities of erstwhile engines.
|
32
9
|
*
|
33
|
-
* ES5
|
34
|
-
* http://www.ecma-international.org/publications/files/
|
35
|
-
*
|
36
|
-
* NOTE: this is a draft, and as such, the URL is subject to change. If the
|
37
|
-
* link is broken, check in the parent directory for the latest TC39 PDF.
|
38
|
-
* http://www.ecma-international.org/publications/files/drafts/
|
39
|
-
*
|
40
|
-
* Previous ES5 Draft
|
41
|
-
* http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf
|
42
|
-
* This is a broken link to the previous draft of ES5 on which most of the
|
43
|
-
* numbered specification references and quotes herein were taken. Updating
|
44
|
-
* these references and quotes to reflect the new document would be a welcome
|
45
|
-
* volunteer project.
|
46
|
-
*
|
47
|
-
* @module
|
10
|
+
* Annotated ES5: http://es5.github.com/ (specific links below)
|
11
|
+
* ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
|
12
|
+
* Required reading: http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
|
48
13
|
*/
|
49
14
|
|
50
|
-
|
51
|
-
|
52
|
-
//
|
53
|
-
//
|
54
|
-
// _Please note: Shortcuts are defined after `Function.prototype.bind` as we
|
55
|
-
// us it in defining shortcuts.
|
56
|
-
var call = Function.prototype.call;
|
57
|
-
var prototypeOfArray = Array.prototype;
|
58
|
-
var prototypeOfObject = Object.prototype;
|
59
|
-
var slice = prototypeOfArray.slice;
|
60
|
-
var owns;
|
61
|
-
var toString;
|
15
|
+
//
|
16
|
+
// Function
|
17
|
+
// ========
|
18
|
+
//
|
62
19
|
|
63
20
|
// ES-5 15.3.4.5
|
64
|
-
// http://
|
21
|
+
// http://es5.github.com/#x15.3.4.5
|
22
|
+
|
23
|
+
function Empty() {}
|
65
24
|
|
66
25
|
if (!Function.prototype.bind) {
|
67
|
-
Function.prototype.bind = function (that) { // .length is 1
|
26
|
+
Function.prototype.bind = function bind(that) { // .length is 1
|
68
27
|
// 1. Let Target be the this value.
|
69
28
|
var target = this;
|
70
29
|
// 2. If IsCallable(Target) is false, throw a TypeError exception.
|
71
|
-
if (typeof target != "function")
|
72
|
-
throw new TypeError(
|
30
|
+
if (typeof target != "function") {
|
31
|
+
throw new TypeError("Function.prototype.bind called on incompatible " + target);
|
32
|
+
}
|
73
33
|
// 3. Let A be a new (possibly empty) internal list of all of the
|
74
34
|
// argument values provided after thisArg (arg1, arg2 etc), in order.
|
75
35
|
// XXX slicedArgs will stand in for "A" if used
|
76
|
-
var args =
|
36
|
+
var args = _Array_slice_.call(arguments, 1); // for normal call
|
77
37
|
// 4. Let F be a new native ECMAScript object.
|
78
|
-
//
|
38
|
+
// 11. Set the [[Prototype]] internal property of F to the standard
|
79
39
|
// built-in Function prototype object as specified in 15.3.3.1.
|
80
|
-
//
|
40
|
+
// 12. Set the [[Call]] internal property of F as described in
|
81
41
|
// 15.3.4.5.1.
|
82
|
-
//
|
42
|
+
// 13. Set the [[Construct]] internal property of F as described in
|
83
43
|
// 15.3.4.5.2.
|
84
|
-
//
|
44
|
+
// 14. Set the [[HasInstance]] internal property of F as described in
|
85
45
|
// 15.3.4.5.3.
|
86
|
-
// 13. The [[Scope]] internal property of F is unused and need not
|
87
|
-
// exist.
|
88
46
|
var bound = function () {
|
89
47
|
|
90
48
|
if (this instanceof bound) {
|
91
49
|
// 15.3.4.5.2 [[Construct]]
|
92
50
|
// When the [[Construct]] internal method of a function object,
|
93
51
|
// F that was created using the bind function is called with a
|
94
|
-
// list of arguments ExtraArgs the following steps are taken:
|
52
|
+
// list of arguments ExtraArgs, the following steps are taken:
|
95
53
|
// 1. Let target be the value of F's [[TargetFunction]]
|
96
54
|
// internal property.
|
97
55
|
// 2. If target has no [[Construct]] internal method, a
|
@@ -101,24 +59,23 @@ if (!Function.prototype.bind) {
|
|
101
59
|
// 4. Let args be a new list containing the same values as the
|
102
60
|
// list boundArgs in the same order followed by the same
|
103
61
|
// values as the list ExtraArgs in the same order.
|
104
|
-
|
105
|
-
|
106
|
-
F.prototype = target.prototype;
|
107
|
-
var self = new F;
|
62
|
+
// 5. Return the result of calling the [[Construct]] internal
|
63
|
+
// method of target providing args as the arguments.
|
108
64
|
|
109
65
|
var result = target.apply(
|
110
|
-
|
111
|
-
args.concat(
|
66
|
+
this,
|
67
|
+
args.concat(_Array_slice_.call(arguments))
|
112
68
|
);
|
113
|
-
if (
|
69
|
+
if (Object(result) === result) {
|
114
70
|
return result;
|
115
|
-
|
71
|
+
}
|
72
|
+
return this;
|
116
73
|
|
117
74
|
} else {
|
118
75
|
// 15.3.4.5.1 [[Call]]
|
119
76
|
// When the [[Call]] internal method of a function object, F,
|
120
77
|
// which was created using the bind function is called with a
|
121
|
-
// this value and a list of arguments ExtraArgs the following
|
78
|
+
// this value and a list of arguments ExtraArgs, the following
|
122
79
|
// steps are taken:
|
123
80
|
// 1. Let boundArgs be the value of F's [[BoundArgs]] internal
|
124
81
|
// property.
|
@@ -126,59 +83,207 @@ if (!Function.prototype.bind) {
|
|
126
83
|
// property.
|
127
84
|
// 3. Let target be the value of F's [[TargetFunction]] internal
|
128
85
|
// property.
|
129
|
-
// 4. Let args be a new list containing the same values as the
|
130
|
-
// boundArgs in the same order followed by the same
|
131
|
-
// the list ExtraArgs in the same order.
|
132
|
-
//
|
133
|
-
// providing boundThis as the this value and
|
134
|
-
// as the arguments.
|
86
|
+
// 4. Let args be a new list containing the same values as the
|
87
|
+
// list boundArgs in the same order followed by the same
|
88
|
+
// values as the list ExtraArgs in the same order.
|
89
|
+
// 5. Return the result of calling the [[Call]] internal method
|
90
|
+
// of target providing boundThis as the this value and
|
91
|
+
// providing args as the arguments.
|
135
92
|
|
136
93
|
// equiv: target.call(this, ...boundArgs, ...args)
|
137
94
|
return target.apply(
|
138
95
|
that,
|
139
|
-
args.concat(
|
96
|
+
args.concat(_Array_slice_.call(arguments))
|
140
97
|
);
|
141
98
|
|
142
99
|
}
|
143
100
|
|
144
101
|
};
|
102
|
+
if(target.prototype) {
|
103
|
+
Empty.prototype = target.prototype;
|
104
|
+
bound.prototype = new Empty();
|
105
|
+
// Clean up dangling references.
|
106
|
+
Empty.prototype = null;
|
107
|
+
}
|
145
108
|
// XXX bound.length is never writable, so don't even try
|
146
109
|
//
|
147
|
-
//
|
148
|
-
//
|
149
|
-
//
|
150
|
-
//
|
110
|
+
// 15. If the [[Class]] internal property of Target is "Function", then
|
111
|
+
// a. Let L be the length property of Target minus the length of A.
|
112
|
+
// b. Set the length own property of F to either 0 or L, whichever is
|
113
|
+
// larger.
|
114
|
+
// 16. Else set the length own property of F to 0.
|
115
|
+
// 17. Set the attributes of the length own property of F to the values
|
116
|
+
// specified in 15.3.5.1.
|
117
|
+
|
151
118
|
// TODO
|
152
|
-
// 18.
|
153
|
-
|
154
|
-
// [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]:
|
155
|
-
// false}, and false.
|
119
|
+
// 18. Set the [[Extensible]] internal property of F to true.
|
120
|
+
|
156
121
|
// TODO
|
157
|
-
// 19.
|
158
|
-
//
|
159
|
-
//
|
160
|
-
// false}, and
|
122
|
+
// 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
|
123
|
+
// 20. Call the [[DefineOwnProperty]] internal method of F with
|
124
|
+
// arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
|
125
|
+
// thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
|
126
|
+
// false.
|
127
|
+
// 21. Call the [[DefineOwnProperty]] internal method of F with
|
128
|
+
// arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
|
129
|
+
// [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
|
130
|
+
// and false.
|
131
|
+
|
161
132
|
// TODO
|
162
133
|
// NOTE Function objects created using Function.prototype.bind do not
|
163
|
-
// have a prototype property
|
164
|
-
//
|
134
|
+
// have a prototype property or the [[Code]], [[FormalParameters]], and
|
135
|
+
// [[Scope]] internal properties.
|
136
|
+
// XXX can't delete prototype in pure-js.
|
137
|
+
|
138
|
+
// 22. Return F.
|
165
139
|
return bound;
|
166
140
|
};
|
167
141
|
}
|
168
142
|
|
169
|
-
|
170
|
-
|
171
|
-
|
143
|
+
// Shortcut to an often accessed properties, in order to avoid multiple
|
144
|
+
// dereference that costs universally.
|
145
|
+
// _Please note: Shortcuts are defined after `Function.prototype.bind` as we
|
146
|
+
// us it in defining shortcuts.
|
147
|
+
var call = Function.prototype.call;
|
148
|
+
var prototypeOfArray = Array.prototype;
|
149
|
+
var prototypeOfObject = Object.prototype;
|
150
|
+
var _Array_slice_ = prototypeOfArray.slice;
|
151
|
+
// Having a toString local variable name breaks in Opera so use _toString.
|
152
|
+
var _toString = call.bind(prototypeOfObject.toString);
|
153
|
+
var owns = call.bind(prototypeOfObject.hasOwnProperty);
|
154
|
+
|
155
|
+
// If JS engine supports accessors creating shortcuts.
|
156
|
+
var defineGetter;
|
157
|
+
var defineSetter;
|
158
|
+
var lookupGetter;
|
159
|
+
var lookupSetter;
|
160
|
+
var supportsAccessors;
|
161
|
+
if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
|
162
|
+
defineGetter = call.bind(prototypeOfObject.__defineGetter__);
|
163
|
+
defineSetter = call.bind(prototypeOfObject.__defineSetter__);
|
164
|
+
lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
|
165
|
+
lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
|
166
|
+
}
|
172
167
|
|
173
168
|
//
|
174
169
|
// Array
|
175
170
|
// =====
|
176
171
|
//
|
177
172
|
|
173
|
+
// ES5 15.4.4.12
|
174
|
+
// http://es5.github.com/#x15.4.4.12
|
175
|
+
// Default value for second param
|
176
|
+
// [bugfix, ielt9, old browsers]
|
177
|
+
// IE < 9 bug: [1,2].splice(0).join("") == "" but should be "12"
|
178
|
+
if ([1,2].splice(0).length != 2) {
|
179
|
+
var array_splice = Array.prototype.splice;
|
180
|
+
|
181
|
+
if(function() { // test IE < 9 to splice bug - see issue #138
|
182
|
+
function makeArray(l) {
|
183
|
+
var a = [];
|
184
|
+
while (l--) {
|
185
|
+
a.unshift(l)
|
186
|
+
}
|
187
|
+
return a
|
188
|
+
}
|
189
|
+
|
190
|
+
var array = []
|
191
|
+
, lengthBefore
|
192
|
+
;
|
193
|
+
|
194
|
+
array.splice.bind(array, 0, 0).apply(null, makeArray(20));
|
195
|
+
array.splice.bind(array, 0, 0).apply(null, makeArray(26));
|
196
|
+
|
197
|
+
lengthBefore = array.length; //20
|
198
|
+
array.splice(5, 0, "XXX"); // add one element
|
199
|
+
|
200
|
+
if(lengthBefore + 1 == array.length) {
|
201
|
+
return true;// has right splice implementation without bugs
|
202
|
+
}
|
203
|
+
// else {
|
204
|
+
// IE8 bug
|
205
|
+
// }
|
206
|
+
}()) {//IE 6/7
|
207
|
+
Array.prototype.splice = function(start, deleteCount) {
|
208
|
+
if (!arguments.length) {
|
209
|
+
return [];
|
210
|
+
} else {
|
211
|
+
return array_splice.apply(this, [
|
212
|
+
start === void 0 ? 0 : start,
|
213
|
+
deleteCount === void 0 ? (this.length - start) : deleteCount
|
214
|
+
].concat(_Array_slice_.call(arguments, 2)))
|
215
|
+
}
|
216
|
+
};
|
217
|
+
}
|
218
|
+
else {//IE8
|
219
|
+
Array.prototype.splice = function(start, deleteCount) {
|
220
|
+
var result
|
221
|
+
, args = _Array_slice_.call(arguments, 2)
|
222
|
+
, addElementsCount = args.length
|
223
|
+
;
|
224
|
+
|
225
|
+
if(!arguments.length) {
|
226
|
+
return [];
|
227
|
+
}
|
228
|
+
|
229
|
+
if(start === void 0) { // default
|
230
|
+
start = 0;
|
231
|
+
}
|
232
|
+
if(deleteCount === void 0) { // default
|
233
|
+
deleteCount = this.length - start;
|
234
|
+
}
|
235
|
+
|
236
|
+
if(addElementsCount > 0) {
|
237
|
+
if(deleteCount <= 0) {
|
238
|
+
if(start == this.length) { // tiny optimisation #1
|
239
|
+
this.push.apply(this, args);
|
240
|
+
return [];
|
241
|
+
}
|
242
|
+
|
243
|
+
if(start == 0) { // tiny optimisation #2
|
244
|
+
this.unshift.apply(this, args);
|
245
|
+
return [];
|
246
|
+
}
|
247
|
+
}
|
248
|
+
|
249
|
+
// Array.prototype.splice implementation
|
250
|
+
result = _Array_slice_.call(this, start, start + deleteCount);// delete part
|
251
|
+
args.push.apply(args, _Array_slice_.call(this, start + deleteCount, this.length));// right part
|
252
|
+
args.unshift.apply(args, _Array_slice_.call(this, 0, start));// left part
|
253
|
+
|
254
|
+
// delete all items from this array and replace it to 'left part' + _Array_slice_.call(arguments, 2) + 'right part'
|
255
|
+
args.unshift(0, this.length);
|
256
|
+
|
257
|
+
array_splice.apply(this, args);
|
258
|
+
|
259
|
+
return result;
|
260
|
+
}
|
261
|
+
|
262
|
+
return array_splice.call(this, start, deleteCount);
|
263
|
+
}
|
264
|
+
|
265
|
+
}
|
266
|
+
}
|
267
|
+
|
268
|
+
// ES5 15.4.4.12
|
269
|
+
// http://es5.github.com/#x15.4.4.13
|
270
|
+
// Return len+argCount.
|
271
|
+
// [bugfix, ielt8]
|
272
|
+
// IE < 8 bug: [].unshift(0) == undefined but should be "1"
|
273
|
+
if ([].unshift(0) != 1) {
|
274
|
+
var array_unshift = Array.prototype.unshift;
|
275
|
+
Array.prototype.unshift = function() {
|
276
|
+
array_unshift.apply(this, arguments);
|
277
|
+
return this.length;
|
278
|
+
};
|
279
|
+
}
|
280
|
+
|
178
281
|
// ES5 15.4.3.2
|
282
|
+
// http://es5.github.com/#x15.4.3.2
|
283
|
+
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
|
179
284
|
if (!Array.isArray) {
|
180
|
-
Array.isArray = function (obj) {
|
181
|
-
return
|
285
|
+
Array.isArray = function isArray(obj) {
|
286
|
+
return _toString(obj) == "[object Array]";
|
182
287
|
};
|
183
288
|
}
|
184
289
|
|
@@ -195,129 +300,169 @@ if (!Array.isArray) {
|
|
195
300
|
// expressions.
|
196
301
|
|
197
302
|
// ES5 15.4.4.18
|
198
|
-
//
|
303
|
+
// http://es5.github.com/#x15.4.4.18
|
304
|
+
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
|
305
|
+
|
306
|
+
// Check failure of by-index access of string characters (IE < 9)
|
307
|
+
// and failure of `0 in boxedString` (Rhino)
|
308
|
+
var boxedString = Object("a"),
|
309
|
+
splitString = boxedString[0] != "a" || !(0 in boxedString);
|
310
|
+
|
199
311
|
if (!Array.prototype.forEach) {
|
200
|
-
Array.prototype.forEach = function (fun /*, thisp*/) {
|
201
|
-
var
|
312
|
+
Array.prototype.forEach = function forEach(fun /*, thisp*/) {
|
313
|
+
var object = toObject(this),
|
314
|
+
self = splitString && _toString(this) == "[object String]" ?
|
315
|
+
this.split("") :
|
316
|
+
object,
|
202
317
|
thisp = arguments[1],
|
203
|
-
i =
|
318
|
+
i = -1,
|
204
319
|
length = self.length >>> 0;
|
205
320
|
|
206
321
|
// If no callback function or if callback is not a callable function
|
207
|
-
if (
|
322
|
+
if (_toString(fun) != "[object Function]") {
|
208
323
|
throw new TypeError(); // TODO message
|
209
324
|
}
|
210
325
|
|
211
|
-
while (i < length) {
|
326
|
+
while (++i < length) {
|
212
327
|
if (i in self) {
|
213
328
|
// Invoke the callback function with call, passing arguments:
|
214
|
-
// context, property value, property key, thisArg object
|
215
|
-
|
329
|
+
// context, property value, property key, thisArg object
|
330
|
+
// context
|
331
|
+
fun.call(thisp, self[i], i, object);
|
216
332
|
}
|
217
|
-
i++;
|
218
333
|
}
|
219
334
|
};
|
220
335
|
}
|
221
336
|
|
222
337
|
// ES5 15.4.4.19
|
338
|
+
// http://es5.github.com/#x15.4.4.19
|
223
339
|
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
|
224
340
|
if (!Array.prototype.map) {
|
225
|
-
Array.prototype.map = function (fun /*, thisp*/) {
|
226
|
-
var
|
341
|
+
Array.prototype.map = function map(fun /*, thisp*/) {
|
342
|
+
var object = toObject(this),
|
343
|
+
self = splitString && _toString(this) == "[object String]" ?
|
344
|
+
this.split("") :
|
345
|
+
object,
|
227
346
|
length = self.length >>> 0,
|
228
347
|
result = Array(length),
|
229
348
|
thisp = arguments[1];
|
230
349
|
|
231
350
|
// If no callback function or if callback is not a callable function
|
232
|
-
if (
|
233
|
-
throw new TypeError(
|
351
|
+
if (_toString(fun) != "[object Function]") {
|
352
|
+
throw new TypeError(fun + " is not a function");
|
234
353
|
}
|
235
354
|
|
236
355
|
for (var i = 0; i < length; i++) {
|
237
356
|
if (i in self)
|
238
|
-
result[i] = fun.call(thisp, self[i], i,
|
357
|
+
result[i] = fun.call(thisp, self[i], i, object);
|
239
358
|
}
|
240
359
|
return result;
|
241
360
|
};
|
242
361
|
}
|
243
362
|
|
244
363
|
// ES5 15.4.4.20
|
364
|
+
// http://es5.github.com/#x15.4.4.20
|
365
|
+
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
|
245
366
|
if (!Array.prototype.filter) {
|
246
|
-
Array.prototype.filter = function (fun /*, thisp */) {
|
247
|
-
var
|
367
|
+
Array.prototype.filter = function filter(fun /*, thisp */) {
|
368
|
+
var object = toObject(this),
|
369
|
+
self = splitString && _toString(this) == "[object String]" ?
|
370
|
+
this.split("") :
|
371
|
+
object,
|
248
372
|
length = self.length >>> 0,
|
249
373
|
result = [],
|
374
|
+
value,
|
250
375
|
thisp = arguments[1];
|
251
376
|
|
252
377
|
// If no callback function or if callback is not a callable function
|
253
|
-
if (
|
254
|
-
throw new TypeError(
|
378
|
+
if (_toString(fun) != "[object Function]") {
|
379
|
+
throw new TypeError(fun + " is not a function");
|
255
380
|
}
|
256
381
|
|
257
382
|
for (var i = 0; i < length; i++) {
|
258
|
-
if (i in self
|
259
|
-
|
383
|
+
if (i in self) {
|
384
|
+
value = self[i];
|
385
|
+
if (fun.call(thisp, value, i, object)) {
|
386
|
+
result.push(value);
|
387
|
+
}
|
388
|
+
}
|
260
389
|
}
|
261
390
|
return result;
|
262
391
|
};
|
263
392
|
}
|
264
393
|
|
265
394
|
// ES5 15.4.4.16
|
395
|
+
// http://es5.github.com/#x15.4.4.16
|
396
|
+
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
|
266
397
|
if (!Array.prototype.every) {
|
267
|
-
Array.prototype.every = function (fun /*, thisp */) {
|
268
|
-
var
|
398
|
+
Array.prototype.every = function every(fun /*, thisp */) {
|
399
|
+
var object = toObject(this),
|
400
|
+
self = splitString && _toString(this) == "[object String]" ?
|
401
|
+
this.split("") :
|
402
|
+
object,
|
269
403
|
length = self.length >>> 0,
|
270
404
|
thisp = arguments[1];
|
271
405
|
|
272
406
|
// If no callback function or if callback is not a callable function
|
273
|
-
if (
|
274
|
-
throw new TypeError(
|
407
|
+
if (_toString(fun) != "[object Function]") {
|
408
|
+
throw new TypeError(fun + " is not a function");
|
275
409
|
}
|
276
410
|
|
277
411
|
for (var i = 0; i < length; i++) {
|
278
|
-
if (i in self && !fun.call(thisp, self[i], i,
|
412
|
+
if (i in self && !fun.call(thisp, self[i], i, object)) {
|
279
413
|
return false;
|
414
|
+
}
|
280
415
|
}
|
281
416
|
return true;
|
282
417
|
};
|
283
418
|
}
|
284
419
|
|
285
420
|
// ES5 15.4.4.17
|
421
|
+
// http://es5.github.com/#x15.4.4.17
|
286
422
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
|
287
423
|
if (!Array.prototype.some) {
|
288
|
-
Array.prototype.some = function (fun /*, thisp */) {
|
289
|
-
var
|
424
|
+
Array.prototype.some = function some(fun /*, thisp */) {
|
425
|
+
var object = toObject(this),
|
426
|
+
self = splitString && _toString(this) == "[object String]" ?
|
427
|
+
this.split("") :
|
428
|
+
object,
|
290
429
|
length = self.length >>> 0,
|
291
430
|
thisp = arguments[1];
|
292
431
|
|
293
432
|
// If no callback function or if callback is not a callable function
|
294
|
-
if (
|
295
|
-
throw new TypeError(
|
433
|
+
if (_toString(fun) != "[object Function]") {
|
434
|
+
throw new TypeError(fun + " is not a function");
|
296
435
|
}
|
297
436
|
|
298
437
|
for (var i = 0; i < length; i++) {
|
299
|
-
if (i in self && fun.call(thisp, self[i], i,
|
438
|
+
if (i in self && fun.call(thisp, self[i], i, object)) {
|
300
439
|
return true;
|
440
|
+
}
|
301
441
|
}
|
302
442
|
return false;
|
303
443
|
};
|
304
444
|
}
|
305
445
|
|
306
446
|
// ES5 15.4.4.21
|
447
|
+
// http://es5.github.com/#x15.4.4.21
|
307
448
|
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
|
308
449
|
if (!Array.prototype.reduce) {
|
309
|
-
Array.prototype.reduce = function (fun /*, initial*/) {
|
310
|
-
var
|
450
|
+
Array.prototype.reduce = function reduce(fun /*, initial*/) {
|
451
|
+
var object = toObject(this),
|
452
|
+
self = splitString && _toString(this) == "[object String]" ?
|
453
|
+
this.split("") :
|
454
|
+
object,
|
311
455
|
length = self.length >>> 0;
|
312
456
|
|
313
457
|
// If no callback function or if callback is not a callable function
|
314
|
-
if (
|
315
|
-
throw new TypeError(
|
458
|
+
if (_toString(fun) != "[object Function]") {
|
459
|
+
throw new TypeError(fun + " is not a function");
|
316
460
|
}
|
317
461
|
|
318
462
|
// no value to return if no initial value and an empty array
|
319
|
-
if (!length && arguments.length == 1)
|
320
|
-
throw new TypeError(
|
463
|
+
if (!length && arguments.length == 1) {
|
464
|
+
throw new TypeError("reduce of empty array with no initial value");
|
465
|
+
}
|
321
466
|
|
322
467
|
var i = 0;
|
323
468
|
var result;
|
@@ -331,14 +476,16 @@ if (!Array.prototype.reduce) {
|
|
331
476
|
}
|
332
477
|
|
333
478
|
// if array contains no values, no initial value to return
|
334
|
-
if (++i >= length)
|
335
|
-
throw new TypeError(
|
479
|
+
if (++i >= length) {
|
480
|
+
throw new TypeError("reduce of empty array with no initial value");
|
481
|
+
}
|
336
482
|
} while (true);
|
337
483
|
}
|
338
484
|
|
339
485
|
for (; i < length; i++) {
|
340
|
-
if (i in self)
|
341
|
-
result = fun.call(void 0, result, self[i], i,
|
486
|
+
if (i in self) {
|
487
|
+
result = fun.call(void 0, result, self[i], i, object);
|
488
|
+
}
|
342
489
|
}
|
343
490
|
|
344
491
|
return result;
|
@@ -346,20 +493,25 @@ if (!Array.prototype.reduce) {
|
|
346
493
|
}
|
347
494
|
|
348
495
|
// ES5 15.4.4.22
|
496
|
+
// http://es5.github.com/#x15.4.4.22
|
349
497
|
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
|
350
498
|
if (!Array.prototype.reduceRight) {
|
351
|
-
Array.prototype.reduceRight = function (fun /*, initial*/) {
|
352
|
-
var
|
499
|
+
Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
|
500
|
+
var object = toObject(this),
|
501
|
+
self = splitString && _toString(this) == "[object String]" ?
|
502
|
+
this.split("") :
|
503
|
+
object,
|
353
504
|
length = self.length >>> 0;
|
354
505
|
|
355
506
|
// If no callback function or if callback is not a callable function
|
356
|
-
if (
|
357
|
-
throw new TypeError(
|
507
|
+
if (_toString(fun) != "[object Function]") {
|
508
|
+
throw new TypeError(fun + " is not a function");
|
358
509
|
}
|
359
510
|
|
360
511
|
// no value to return if no initial value, empty array
|
361
|
-
if (!length && arguments.length == 1)
|
362
|
-
throw new TypeError(
|
512
|
+
if (!length && arguments.length == 1) {
|
513
|
+
throw new TypeError("reduceRight of empty array with no initial value");
|
514
|
+
}
|
363
515
|
|
364
516
|
var result, i = length - 1;
|
365
517
|
if (arguments.length >= 2) {
|
@@ -372,14 +524,20 @@ if (!Array.prototype.reduceRight) {
|
|
372
524
|
}
|
373
525
|
|
374
526
|
// if array contains no values, no initial value to return
|
375
|
-
if (--i < 0)
|
376
|
-
throw new TypeError(
|
527
|
+
if (--i < 0) {
|
528
|
+
throw new TypeError("reduceRight of empty array with no initial value");
|
529
|
+
}
|
377
530
|
} while (true);
|
378
531
|
}
|
379
532
|
|
533
|
+
if (i < 0) {
|
534
|
+
return result;
|
535
|
+
}
|
536
|
+
|
380
537
|
do {
|
381
|
-
if (i in this)
|
382
|
-
result = fun.call(void 0, result, self[i], i,
|
538
|
+
if (i in this) {
|
539
|
+
result = fun.call(void 0, result, self[i], i, object);
|
540
|
+
}
|
383
541
|
} while (i--);
|
384
542
|
|
385
543
|
return result;
|
@@ -387,21 +545,26 @@ if (!Array.prototype.reduceRight) {
|
|
387
545
|
}
|
388
546
|
|
389
547
|
// ES5 15.4.4.14
|
548
|
+
// http://es5.github.com/#x15.4.4.14
|
390
549
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
|
391
|
-
if (!Array.prototype.indexOf) {
|
392
|
-
Array.prototype.indexOf = function (sought /*, fromIndex */ ) {
|
393
|
-
var self =
|
550
|
+
if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
|
551
|
+
Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
|
552
|
+
var self = splitString && _toString(this) == "[object String]" ?
|
553
|
+
this.split("") :
|
554
|
+
toObject(this),
|
394
555
|
length = self.length >>> 0;
|
395
556
|
|
396
|
-
if (!length)
|
557
|
+
if (!length) {
|
397
558
|
return -1;
|
559
|
+
}
|
398
560
|
|
399
561
|
var i = 0;
|
400
|
-
if (arguments.length > 1)
|
562
|
+
if (arguments.length > 1) {
|
401
563
|
i = toInteger(arguments[1]);
|
564
|
+
}
|
402
565
|
|
403
566
|
// handle negative indices
|
404
|
-
i = i >= 0 ? i : length
|
567
|
+
i = i >= 0 ? i : Math.max(0, length + i);
|
405
568
|
for (; i < length; i++) {
|
406
569
|
if (i in self && self[i] === sought) {
|
407
570
|
return i;
|
@@ -412,59 +575,42 @@ if (!Array.prototype.indexOf) {
|
|
412
575
|
}
|
413
576
|
|
414
577
|
// ES5 15.4.4.15
|
415
|
-
|
416
|
-
|
417
|
-
|
578
|
+
// http://es5.github.com/#x15.4.4.15
|
579
|
+
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
|
580
|
+
if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
|
581
|
+
Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
|
582
|
+
var self = splitString && _toString(this) == "[object String]" ?
|
583
|
+
this.split("") :
|
584
|
+
toObject(this),
|
418
585
|
length = self.length >>> 0;
|
419
586
|
|
420
|
-
if (!length)
|
587
|
+
if (!length) {
|
421
588
|
return -1;
|
589
|
+
}
|
422
590
|
var i = length - 1;
|
423
|
-
if (arguments.length > 1)
|
424
|
-
i = toInteger(arguments[1]);
|
591
|
+
if (arguments.length > 1) {
|
592
|
+
i = Math.min(i, toInteger(arguments[1]));
|
593
|
+
}
|
425
594
|
// handle negative indices
|
426
595
|
i = i >= 0 ? i : length - Math.abs(i);
|
427
596
|
for (; i >= 0; i--) {
|
428
|
-
if (i in self && sought === self[i])
|
597
|
+
if (i in self && sought === self[i]) {
|
429
598
|
return i;
|
599
|
+
}
|
430
600
|
}
|
431
601
|
return -1;
|
432
602
|
};
|
433
603
|
}
|
434
604
|
|
435
|
-
//
|
436
|
-
// Array
|
437
|
-
// =====
|
438
|
-
//
|
439
|
-
|
440
|
-
// ES5 15.4.4.12
|
441
|
-
// http://es5.github.com/#x15.4.4.12
|
442
|
-
// Default value for second param
|
443
|
-
// [bugfix, ielt9, old browsers]
|
444
|
-
// IE < 9 bug: [1,2].splice(0).join("") == "" but should be "12"
|
445
|
-
if([1,2].splice(0).length != 2) {
|
446
|
-
var _origArraySplice = Array.prototype.splice;
|
447
|
-
|
448
|
-
Array.prototype.splice = function(start, deleteCount) {
|
449
|
-
if(!arguments.length)return [];
|
450
|
-
|
451
|
-
return _origArraySplice.apply(this, [
|
452
|
-
start === void 0 ? 0 : start,
|
453
|
-
deleteCount === void 0 ? (this.length - start) : deleteCount
|
454
|
-
].concat(slice.call(arguments, 2)))
|
455
|
-
};
|
456
|
-
}
|
457
|
-
|
458
605
|
//
|
459
606
|
// Object
|
460
607
|
// ======
|
461
608
|
//
|
462
609
|
|
463
|
-
|
464
610
|
// ES5 15.2.3.14
|
465
|
-
// http://
|
611
|
+
// http://es5.github.com/#x15.2.3.14
|
466
612
|
if (!Object.keys) {
|
467
|
-
|
613
|
+
// http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
|
468
614
|
var hasDontEnumBug = true,
|
469
615
|
dontEnums = [
|
470
616
|
"toString",
|
@@ -477,13 +623,18 @@ if (!Object.keys) {
|
|
477
623
|
],
|
478
624
|
dontEnumsLength = dontEnums.length;
|
479
625
|
|
480
|
-
for (var key in {"toString": null})
|
626
|
+
for (var key in {"toString": null}) {
|
481
627
|
hasDontEnumBug = false;
|
628
|
+
}
|
482
629
|
|
483
630
|
Object.keys = function keys(object) {
|
484
631
|
|
485
|
-
if (
|
632
|
+
if (
|
633
|
+
(typeof object != "object" && typeof object != "function") ||
|
634
|
+
object === null
|
635
|
+
) {
|
486
636
|
throw new TypeError("Object.keys called on a non-object");
|
637
|
+
}
|
487
638
|
|
488
639
|
var keys = [];
|
489
640
|
for (var name in object) {
|
@@ -500,7 +651,6 @@ if (!Object.keys) {
|
|
500
651
|
}
|
501
652
|
}
|
502
653
|
}
|
503
|
-
|
504
654
|
return keys;
|
505
655
|
};
|
506
656
|
|
@@ -512,58 +662,102 @@ if (!Object.keys) {
|
|
512
662
|
//
|
513
663
|
|
514
664
|
// ES5 15.9.5.43
|
515
|
-
//
|
516
|
-
//
|
517
|
-
|
665
|
+
// http://es5.github.com/#x15.9.5.43
|
666
|
+
// This function returns a String value represent the instance in time
|
667
|
+
// represented by this Date object. The format of the String is the Date Time
|
668
|
+
// string format defined in 15.9.1.15. All fields are present in the String.
|
669
|
+
// The time zone is always UTC, denoted by the suffix Z. If the time value of
|
670
|
+
// this object is not a finite Number a RangeError exception is thrown.
|
671
|
+
var negativeDate = -62198755200000,
|
672
|
+
negativeYearString = "-000001";
|
673
|
+
if (
|
674
|
+
!Date.prototype.toISOString ||
|
675
|
+
(new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1)
|
676
|
+
) {
|
518
677
|
Date.prototype.toISOString = function toISOString() {
|
519
|
-
var result, length, value;
|
520
|
-
if (!isFinite(this))
|
521
|
-
throw new RangeError;
|
678
|
+
var result, length, value, year, month;
|
679
|
+
if (!isFinite(this)) {
|
680
|
+
throw new RangeError("Date.prototype.toISOString called on non-finite value.");
|
681
|
+
}
|
682
|
+
|
683
|
+
year = this.getUTCFullYear();
|
684
|
+
|
685
|
+
month = this.getUTCMonth();
|
686
|
+
// see https://github.com/kriskowal/es5-shim/issues/111
|
687
|
+
year += Math.floor(month / 12);
|
688
|
+
month = (month % 12 + 12) % 12;
|
522
689
|
|
523
690
|
// the date time string format is specified in 15.9.1.15.
|
524
|
-
result = [
|
691
|
+
result = [month + 1, this.getUTCDate(),
|
525
692
|
this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
|
693
|
+
year = (
|
694
|
+
(year < 0 ? "-" : (year > 9999 ? "+" : "")) +
|
695
|
+
("00000" + Math.abs(year))
|
696
|
+
.slice(0 <= year && year <= 9999 ? -4 : -6)
|
697
|
+
);
|
526
698
|
|
527
699
|
length = result.length;
|
528
700
|
while (length--) {
|
529
701
|
value = result[length];
|
530
|
-
// pad months, days, hours, minutes, and seconds to have two
|
531
|
-
|
702
|
+
// pad months, days, hours, minutes, and seconds to have two
|
703
|
+
// digits.
|
704
|
+
if (value < 10) {
|
532
705
|
result[length] = "0" + value;
|
706
|
+
}
|
533
707
|
}
|
534
708
|
// pad milliseconds to have three digits.
|
535
|
-
return
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
// ES5 15.9.4.4
|
541
|
-
if (!Date.now) {
|
542
|
-
Date.now = function now() {
|
543
|
-
return new Date().getTime();
|
709
|
+
return (
|
710
|
+
year + "-" + result.slice(0, 2).join("-") +
|
711
|
+
"T" + result.slice(2).join(":") + "." +
|
712
|
+
("000" + this.getUTCMilliseconds()).slice(-3) + "Z"
|
713
|
+
);
|
544
714
|
};
|
545
715
|
}
|
546
716
|
|
717
|
+
|
547
718
|
// ES5 15.9.5.44
|
548
|
-
|
719
|
+
// http://es5.github.com/#x15.9.5.44
|
720
|
+
// This function provides a String representation of a Date object for use by
|
721
|
+
// JSON.stringify (15.12.3).
|
722
|
+
var dateToJSONIsSupported = false;
|
723
|
+
try {
|
724
|
+
dateToJSONIsSupported = (
|
725
|
+
Date.prototype.toJSON &&
|
726
|
+
new Date(NaN).toJSON() === null &&
|
727
|
+
new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1 &&
|
728
|
+
Date.prototype.toJSON.call({ // generic
|
729
|
+
toISOString: function () {
|
730
|
+
return true;
|
731
|
+
}
|
732
|
+
})
|
733
|
+
);
|
734
|
+
} catch (e) {
|
735
|
+
}
|
736
|
+
if (!dateToJSONIsSupported) {
|
549
737
|
Date.prototype.toJSON = function toJSON(key) {
|
550
|
-
//
|
551
|
-
//
|
552
|
-
// with argument key, the following steps are taken:
|
738
|
+
// When the toJSON method is called with argument key, the following
|
739
|
+
// steps are taken:
|
553
740
|
|
554
741
|
// 1. Let O be the result of calling ToObject, giving it the this
|
555
742
|
// value as its argument.
|
556
|
-
// 2. Let tv be
|
743
|
+
// 2. Let tv be toPrimitive(O, hint Number).
|
744
|
+
var o = Object(this),
|
745
|
+
tv = toPrimitive(o),
|
746
|
+
toISO;
|
557
747
|
// 3. If tv is a Number and is not finite, return null.
|
558
|
-
|
748
|
+
if (typeof tv === "number" && !isFinite(tv)) {
|
749
|
+
return null;
|
750
|
+
}
|
559
751
|
// 4. Let toISO be the result of calling the [[Get]] internal method of
|
560
752
|
// O with argument "toISOString".
|
753
|
+
toISO = o.toISOString;
|
561
754
|
// 5. If IsCallable(toISO) is false, throw a TypeError exception.
|
562
|
-
if (typeof
|
563
|
-
throw new TypeError(
|
755
|
+
if (typeof toISO != "function") {
|
756
|
+
throw new TypeError("toISOString property is not callable");
|
757
|
+
}
|
564
758
|
// 6. Return the result of calling the [[Call]] internal method of
|
565
|
-
//
|
566
|
-
return
|
759
|
+
// toISO with O as the this value and an empty argument list.
|
760
|
+
return toISO.call(o);
|
567
761
|
|
568
762
|
// NOTE 1 The argument is ignored.
|
569
763
|
|
@@ -576,90 +770,540 @@ if (!Date.prototype.toJSON) {
|
|
576
770
|
};
|
577
771
|
}
|
578
772
|
|
773
|
+
// ES5 15.9.4.2
|
774
|
+
// http://es5.github.com/#x15.9.4.2
|
775
|
+
// based on work shared by Daniel Friesen (dantman)
|
776
|
+
// http://gist.github.com/303249
|
777
|
+
if (!Date.parse || "Date.parse is buggy") {
|
778
|
+
// XXX global assignment won't work in embeddings that use
|
779
|
+
// an alternate object for the context.
|
780
|
+
Date = (function(NativeDate) {
|
781
|
+
|
782
|
+
// Date.length === 7
|
783
|
+
function Date(Y, M, D, h, m, s, ms) {
|
784
|
+
var length = arguments.length;
|
785
|
+
if (this instanceof NativeDate) {
|
786
|
+
var date = length == 1 && String(Y) === Y ? // isString(Y)
|
787
|
+
// We explicitly pass it through parse:
|
788
|
+
new NativeDate(Date.parse(Y)) :
|
789
|
+
// We have to manually make calls depending on argument
|
790
|
+
// length here
|
791
|
+
length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
|
792
|
+
length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
|
793
|
+
length >= 5 ? new NativeDate(Y, M, D, h, m) :
|
794
|
+
length >= 4 ? new NativeDate(Y, M, D, h) :
|
795
|
+
length >= 3 ? new NativeDate(Y, M, D) :
|
796
|
+
length >= 2 ? new NativeDate(Y, M) :
|
797
|
+
length >= 1 ? new NativeDate(Y) :
|
798
|
+
new NativeDate();
|
799
|
+
// Prevent mixups with unfixed Date object
|
800
|
+
date.constructor = Date;
|
801
|
+
return date;
|
802
|
+
}
|
803
|
+
return NativeDate.apply(this, arguments);
|
804
|
+
};
|
805
|
+
|
806
|
+
// 15.9.1.15 Date Time String Format.
|
807
|
+
var isoDateExpression = new RegExp("^" +
|
808
|
+
"(\\d{4}|[\+\-]\\d{6})" + // four-digit year capture or sign +
|
809
|
+
// 6-digit extended year
|
810
|
+
"(?:-(\\d{2})" + // optional month capture
|
811
|
+
"(?:-(\\d{2})" + // optional day capture
|
812
|
+
"(?:" + // capture hours:minutes:seconds.milliseconds
|
813
|
+
"T(\\d{2})" + // hours capture
|
814
|
+
":(\\d{2})" + // minutes capture
|
815
|
+
"(?:" + // optional :seconds.milliseconds
|
816
|
+
":(\\d{2})" + // seconds capture
|
817
|
+
"(?:(\\.\\d{1,}))?" + // milliseconds capture
|
818
|
+
")?" +
|
819
|
+
"(" + // capture UTC offset component
|
820
|
+
"Z|" + // UTC capture
|
821
|
+
"(?:" + // offset specifier +/-hours:minutes
|
822
|
+
"([-+])" + // sign capture
|
823
|
+
"(\\d{2})" + // hours offset capture
|
824
|
+
":(\\d{2})" + // minutes offset capture
|
825
|
+
")" +
|
826
|
+
")?)?)?)?" +
|
827
|
+
"$");
|
828
|
+
|
829
|
+
var months = [
|
830
|
+
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
|
831
|
+
];
|
832
|
+
|
833
|
+
function dayFromMonth(year, month) {
|
834
|
+
var t = month > 1 ? 1 : 0;
|
835
|
+
return (
|
836
|
+
months[month] +
|
837
|
+
Math.floor((year - 1969 + t) / 4) -
|
838
|
+
Math.floor((year - 1901 + t) / 100) +
|
839
|
+
Math.floor((year - 1601 + t) / 400) +
|
840
|
+
365 * (year - 1970)
|
841
|
+
);
|
842
|
+
}
|
843
|
+
|
844
|
+
// Copy any custom methods a 3rd party library may have added
|
845
|
+
for (var key in NativeDate) {
|
846
|
+
Date[key] = NativeDate[key];
|
847
|
+
}
|
848
|
+
|
849
|
+
// Copy "native" methods explicitly; they may be non-enumerable
|
850
|
+
Date.now = NativeDate.now;
|
851
|
+
Date.UTC = NativeDate.UTC;
|
852
|
+
Date.prototype = NativeDate.prototype;
|
853
|
+
Date.prototype.constructor = Date;
|
854
|
+
|
855
|
+
// Upgrade Date.parse to handle simplified ISO 8601 strings
|
856
|
+
Date.parse = function parse(string) {
|
857
|
+
var match = isoDateExpression.exec(string);
|
858
|
+
if (match) {
|
859
|
+
// parse months, days, hours, minutes, seconds, and milliseconds
|
860
|
+
// provide default values if necessary
|
861
|
+
// parse the UTC offset component
|
862
|
+
var year = Number(match[1]),
|
863
|
+
month = Number(match[2] || 1) - 1,
|
864
|
+
day = Number(match[3] || 1) - 1,
|
865
|
+
hour = Number(match[4] || 0),
|
866
|
+
minute = Number(match[5] || 0),
|
867
|
+
second = Number(match[6] || 0),
|
868
|
+
millisecond = Math.floor(Number(match[7] || 0) * 1000),
|
869
|
+
// When time zone is missed, local offset should be used
|
870
|
+
// (ES 5.1 bug)
|
871
|
+
// see https://bugs.ecmascript.org/show_bug.cgi?id=112
|
872
|
+
offset = !match[4] || match[8] ?
|
873
|
+
0 : Number(new NativeDate(1970, 0)),
|
874
|
+
signOffset = match[9] === "-" ? 1 : -1,
|
875
|
+
hourOffset = Number(match[10] || 0),
|
876
|
+
minuteOffset = Number(match[11] || 0),
|
877
|
+
result;
|
878
|
+
if (
|
879
|
+
hour < (
|
880
|
+
minute > 0 || second > 0 || millisecond > 0 ?
|
881
|
+
24 : 25
|
882
|
+
) &&
|
883
|
+
minute < 60 && second < 60 && millisecond < 1000 &&
|
884
|
+
month > -1 && month < 12 && hourOffset < 24 &&
|
885
|
+
minuteOffset < 60 && // detect invalid offsets
|
886
|
+
day > -1 &&
|
887
|
+
day < (
|
888
|
+
dayFromMonth(year, month + 1) -
|
889
|
+
dayFromMonth(year, month)
|
890
|
+
)
|
891
|
+
) {
|
892
|
+
result = (
|
893
|
+
(dayFromMonth(year, month) + day) * 24 +
|
894
|
+
hour +
|
895
|
+
hourOffset * signOffset
|
896
|
+
) * 60;
|
897
|
+
result = (
|
898
|
+
(result + minute + minuteOffset * signOffset) * 60 +
|
899
|
+
second
|
900
|
+
) * 1000 + millisecond + offset;
|
901
|
+
if (-8.64e15 <= result && result <= 8.64e15) {
|
902
|
+
return result;
|
903
|
+
}
|
904
|
+
}
|
905
|
+
return NaN;
|
906
|
+
}
|
907
|
+
return NativeDate.parse.apply(this, arguments);
|
908
|
+
};
|
909
|
+
|
910
|
+
return Date;
|
911
|
+
})(Date);
|
912
|
+
}
|
913
|
+
|
914
|
+
// ES5 15.9.4.4
|
915
|
+
// http://es5.github.com/#x15.9.4.4
|
916
|
+
if (!Date.now) {
|
917
|
+
Date.now = function now() {
|
918
|
+
return new Date().getTime();
|
919
|
+
};
|
920
|
+
}
|
921
|
+
|
579
922
|
|
580
923
|
//
|
581
|
-
//
|
924
|
+
// Number
|
582
925
|
// ======
|
583
926
|
//
|
584
927
|
|
585
|
-
// ES5 15.
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
928
|
+
// ES5.1 15.7.4.5
|
929
|
+
// http://es5.github.com/#x15.7.4.5
|
930
|
+
if (!Number.prototype.toFixed || (0.00008).toFixed(3) !== '0.000' || (0.9).toFixed(0) === '0' || (1.255).toFixed(2) !== '1.25' || (1000000000000000128).toFixed(0) !== "1000000000000000128") {
|
931
|
+
// Hide these variables and functions
|
932
|
+
(function () {
|
933
|
+
var base, size, data, i;
|
934
|
+
|
935
|
+
base = 1e7;
|
936
|
+
size = 6;
|
937
|
+
data = [0, 0, 0, 0, 0, 0];
|
938
|
+
|
939
|
+
function multiply(n, c) {
|
940
|
+
var i = -1;
|
941
|
+
while (++i < size) {
|
942
|
+
c += n * data[i];
|
943
|
+
data[i] = c % base;
|
944
|
+
c = Math.floor(c / base);
|
945
|
+
}
|
946
|
+
}
|
947
|
+
|
948
|
+
function divide(n) {
|
949
|
+
var i = size, c = 0;
|
950
|
+
while (--i >= 0) {
|
951
|
+
c += data[i];
|
952
|
+
data[i] = Math.floor(c / n);
|
953
|
+
c = (c % n) * base;
|
954
|
+
}
|
955
|
+
}
|
956
|
+
|
957
|
+
function toString() {
|
958
|
+
var i = size;
|
959
|
+
var s = '';
|
960
|
+
while (--i >= 0) {
|
961
|
+
if (s !== '' || i === 0 || data[i] !== 0) {
|
962
|
+
var t = String(data[i]);
|
963
|
+
if (s === '') {
|
964
|
+
s = t;
|
965
|
+
} else {
|
966
|
+
s += '0000000'.slice(0, 7 - t.length) + t;
|
967
|
+
}
|
968
|
+
}
|
969
|
+
}
|
970
|
+
return s;
|
971
|
+
}
|
972
|
+
|
973
|
+
function pow(x, n, acc) {
|
974
|
+
return (n === 0 ? acc : (n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc)));
|
975
|
+
}
|
976
|
+
|
977
|
+
function log(x) {
|
978
|
+
var n = 0;
|
979
|
+
while (x >= 4096) {
|
980
|
+
n += 12;
|
981
|
+
x /= 4096;
|
982
|
+
}
|
983
|
+
while (x >= 2) {
|
984
|
+
n += 1;
|
985
|
+
x /= 2;
|
986
|
+
}
|
987
|
+
return n;
|
988
|
+
}
|
989
|
+
|
990
|
+
Number.prototype.toFixed = function (fractionDigits) {
|
991
|
+
var f, x, s, m, e, z, j, k;
|
992
|
+
|
993
|
+
// Test for NaN and round fractionDigits down
|
994
|
+
f = Number(fractionDigits);
|
995
|
+
f = f !== f ? 0 : Math.floor(f);
|
996
|
+
|
997
|
+
if (f < 0 || f > 20) {
|
998
|
+
throw new RangeError("Number.toFixed called with invalid number of decimals");
|
999
|
+
}
|
1000
|
+
|
1001
|
+
x = Number(this);
|
1002
|
+
|
1003
|
+
// Test for NaN
|
1004
|
+
if (x !== x) {
|
1005
|
+
return "NaN";
|
1006
|
+
}
|
1007
|
+
|
1008
|
+
// If it is too big or small, return the string value of the number
|
1009
|
+
if (x <= -1e21 || x >= 1e21) {
|
1010
|
+
return String(x);
|
1011
|
+
}
|
1012
|
+
|
1013
|
+
s = "";
|
1014
|
+
|
1015
|
+
if (x < 0) {
|
1016
|
+
s = "-";
|
1017
|
+
x = -x;
|
1018
|
+
}
|
1019
|
+
|
1020
|
+
m = "0";
|
1021
|
+
|
1022
|
+
if (x > 1e-21) {
|
1023
|
+
// 1e-21 < x < 1e21
|
1024
|
+
// -70 < log2(x) < 70
|
1025
|
+
e = log(x * pow(2, 69, 1)) - 69;
|
1026
|
+
z = (e < 0 ? x * pow(2, -e, 1) : x / pow(2, e, 1));
|
1027
|
+
z *= 0x10000000000000; // Math.pow(2, 52);
|
1028
|
+
e = 52 - e;
|
1029
|
+
|
1030
|
+
// -18 < e < 122
|
1031
|
+
// x = z / 2 ^ e
|
1032
|
+
if (e > 0) {
|
1033
|
+
multiply(0, z);
|
1034
|
+
j = f;
|
1035
|
+
|
1036
|
+
while (j >= 7) {
|
1037
|
+
multiply(1e7, 0);
|
1038
|
+
j -= 7;
|
1039
|
+
}
|
1040
|
+
|
1041
|
+
multiply(pow(10, j, 1), 0);
|
1042
|
+
j = e - 1;
|
1043
|
+
|
1044
|
+
while (j >= 23) {
|
1045
|
+
divide(1 << 23);
|
1046
|
+
j -= 23;
|
1047
|
+
}
|
1048
|
+
|
1049
|
+
divide(1 << j);
|
1050
|
+
multiply(1, 1);
|
1051
|
+
divide(2);
|
1052
|
+
m = toString();
|
1053
|
+
} else {
|
1054
|
+
multiply(0, z);
|
1055
|
+
multiply(1 << (-e), 0);
|
1056
|
+
m = toString() + '0.00000000000000000000'.slice(2, 2 + f);
|
1057
|
+
}
|
1058
|
+
}
|
1059
|
+
|
1060
|
+
if (f > 0) {
|
1061
|
+
k = m.length;
|
1062
|
+
|
1063
|
+
if (k <= f) {
|
1064
|
+
m = s + '0.0000000000000000000'.slice(0, f - k + 2) + m;
|
1065
|
+
} else {
|
1066
|
+
m = s + m.slice(0, k - f) + '.' + m.slice(k - f);
|
1067
|
+
}
|
1068
|
+
} else {
|
1069
|
+
m = s + m;
|
1070
|
+
}
|
1071
|
+
|
1072
|
+
return m;
|
1073
|
+
}
|
1074
|
+
}());
|
598
1075
|
}
|
599
1076
|
|
1077
|
+
|
1078
|
+
//
|
1079
|
+
// String
|
1080
|
+
// ======
|
1081
|
+
//
|
1082
|
+
|
1083
|
+
|
600
1084
|
// ES5 15.5.4.14
|
601
1085
|
// http://es5.github.com/#x15.5.4.14
|
1086
|
+
|
1087
|
+
// [bugfix, IE lt 9, firefox 4, Konqueror, Opera, obscure browsers]
|
1088
|
+
// Many browsers do not split properly with regular expressions or they
|
1089
|
+
// do not perform the split correctly under obscure conditions.
|
1090
|
+
// See http://blog.stevenlevithan.com/archives/cross-browser-split
|
1091
|
+
// I've tested in many browsers and this seems to cover the deviant ones:
|
1092
|
+
// 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
|
1093
|
+
// '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
|
1094
|
+
// 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
|
1095
|
+
// [undefined, "t", undefined, "e", ...]
|
1096
|
+
// ''.split(/.?/) should be [], not [""]
|
1097
|
+
// '.'.split(/()()/) should be ["."], not ["", "", "."]
|
1098
|
+
|
1099
|
+
var string_split = String.prototype.split;
|
1100
|
+
if (
|
1101
|
+
'ab'.split(/(?:ab)*/).length !== 2 ||
|
1102
|
+
'.'.split(/(.?)(.?)/).length !== 4 ||
|
1103
|
+
'tesst'.split(/(s)*/)[1] === "t" ||
|
1104
|
+
''.split(/.?/).length === 0 ||
|
1105
|
+
'.'.split(/()()/).length > 1
|
1106
|
+
) {
|
1107
|
+
(function () {
|
1108
|
+
var compliantExecNpcg = /()??/.exec("")[1] === void 0; // NPCG: nonparticipating capturing group
|
1109
|
+
|
1110
|
+
String.prototype.split = function (separator, limit) {
|
1111
|
+
var string = this;
|
1112
|
+
if (separator === void 0 && limit === 0)
|
1113
|
+
return [];
|
1114
|
+
|
1115
|
+
// If `separator` is not a regex, use native split
|
1116
|
+
if (Object.prototype.toString.call(separator) !== "[object RegExp]") {
|
1117
|
+
return string_split.apply(this, arguments);
|
1118
|
+
}
|
1119
|
+
|
1120
|
+
var output = [],
|
1121
|
+
flags = (separator.ignoreCase ? "i" : "") +
|
1122
|
+
(separator.multiline ? "m" : "") +
|
1123
|
+
(separator.extended ? "x" : "") + // Proposed for ES6
|
1124
|
+
(separator.sticky ? "y" : ""), // Firefox 3+
|
1125
|
+
lastLastIndex = 0,
|
1126
|
+
// Make `global` and avoid `lastIndex` issues by working with a copy
|
1127
|
+
separator = new RegExp(separator.source, flags + "g"),
|
1128
|
+
separator2, match, lastIndex, lastLength;
|
1129
|
+
string += ""; // Type-convert
|
1130
|
+
if (!compliantExecNpcg) {
|
1131
|
+
// Doesn't need flags gy, but they don't hurt
|
1132
|
+
separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags);
|
1133
|
+
}
|
1134
|
+
/* Values for `limit`, per the spec:
|
1135
|
+
* If undefined: 4294967295 // Math.pow(2, 32) - 1
|
1136
|
+
* If 0, Infinity, or NaN: 0
|
1137
|
+
* If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
|
1138
|
+
* If negative number: 4294967296 - Math.floor(Math.abs(limit))
|
1139
|
+
* If other: Type-convert, then use the above rules
|
1140
|
+
*/
|
1141
|
+
limit = limit === void 0 ?
|
1142
|
+
-1 >>> 0 : // Math.pow(2, 32) - 1
|
1143
|
+
limit >>> 0; // ToUint32(limit)
|
1144
|
+
while (match = separator.exec(string)) {
|
1145
|
+
// `separator.lastIndex` is not reliable cross-browser
|
1146
|
+
lastIndex = match.index + match[0].length;
|
1147
|
+
if (lastIndex > lastLastIndex) {
|
1148
|
+
output.push(string.slice(lastLastIndex, match.index));
|
1149
|
+
// Fix browsers whose `exec` methods don't consistently return `undefined` for
|
1150
|
+
// nonparticipating capturing groups
|
1151
|
+
if (!compliantExecNpcg && match.length > 1) {
|
1152
|
+
match[0].replace(separator2, function () {
|
1153
|
+
for (var i = 1; i < arguments.length - 2; i++) {
|
1154
|
+
if (arguments[i] === void 0) {
|
1155
|
+
match[i] = void 0;
|
1156
|
+
}
|
1157
|
+
}
|
1158
|
+
});
|
1159
|
+
}
|
1160
|
+
if (match.length > 1 && match.index < string.length) {
|
1161
|
+
Array.prototype.push.apply(output, match.slice(1));
|
1162
|
+
}
|
1163
|
+
lastLength = match[0].length;
|
1164
|
+
lastLastIndex = lastIndex;
|
1165
|
+
if (output.length >= limit) {
|
1166
|
+
break;
|
1167
|
+
}
|
1168
|
+
}
|
1169
|
+
if (separator.lastIndex === match.index) {
|
1170
|
+
separator.lastIndex++; // Avoid an infinite loop
|
1171
|
+
}
|
1172
|
+
}
|
1173
|
+
if (lastLastIndex === string.length) {
|
1174
|
+
if (lastLength || !separator.test("")) {
|
1175
|
+
output.push("");
|
1176
|
+
}
|
1177
|
+
} else {
|
1178
|
+
output.push(string.slice(lastLastIndex));
|
1179
|
+
}
|
1180
|
+
return output.length > limit ? output.slice(0, limit) : output;
|
1181
|
+
};
|
1182
|
+
}());
|
1183
|
+
|
602
1184
|
// [bugfix, chrome]
|
603
|
-
// If separator is undefined, then the result array contains just one String,
|
1185
|
+
// If separator is undefined, then the result array contains just one String,
|
1186
|
+
// which is the this value (converted to a String). If limit is not undefined,
|
1187
|
+
// then the output array is truncated so that it contains no more than limit
|
1188
|
+
// elements.
|
604
1189
|
// "0".split(undefined, 0) -> []
|
605
|
-
if("0".split(void 0, 0).length) {
|
606
|
-
var oldSplit = String.prototype.split;
|
1190
|
+
} else if ("0".split(void 0, 0).length) {
|
607
1191
|
String.prototype.split = function(separator, limit) {
|
608
|
-
if(separator === void 0 && limit === 0)return [];
|
609
|
-
return
|
1192
|
+
if (separator === void 0 && limit === 0) return [];
|
1193
|
+
return string_split.apply(this, arguments);
|
610
1194
|
}
|
611
1195
|
}
|
612
1196
|
|
1197
|
+
|
613
1198
|
// ECMA-262, 3rd B.2.3
|
614
|
-
// Note an ECMAScript standart, although ECMAScript 3rd Edition has a
|
615
|
-
// and it should be
|
1199
|
+
// Note an ECMAScript standart, although ECMAScript 3rd Edition has a
|
1200
|
+
// non-normative section suggesting uniform semantics and it should be
|
1201
|
+
// normalized across all browsers
|
616
1202
|
// [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
|
617
1203
|
if("".substr && "0b".substr(-1) !== "b") {
|
618
|
-
var
|
1204
|
+
var string_substr = String.prototype.substr;
|
619
1205
|
/**
|
620
|
-
*
|
621
|
-
*
|
622
|
-
*
|
623
|
-
*
|
624
|
-
*/
|
1206
|
+
* Get the substring of a string
|
1207
|
+
* @param {integer} start where to start the substring
|
1208
|
+
* @param {integer} length how many characters to return
|
1209
|
+
* @return {string}
|
1210
|
+
*/
|
625
1211
|
String.prototype.substr = function(start, length) {
|
626
|
-
return
|
1212
|
+
return string_substr.call(
|
1213
|
+
this,
|
1214
|
+
start < 0 ? ((start = this.length + start) < 0 ? 0 : start) : start,
|
1215
|
+
length
|
1216
|
+
);
|
627
1217
|
}
|
628
1218
|
}
|
629
1219
|
|
1220
|
+
// ES5 15.5.4.20
|
1221
|
+
// http://es5.github.com/#x15.5.4.20
|
1222
|
+
var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
|
1223
|
+
"\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
|
1224
|
+
"\u2029\uFEFF";
|
1225
|
+
if (!String.prototype.trim || ws.trim()) {
|
1226
|
+
// http://blog.stevenlevithan.com/archives/faster-trim-javascript
|
1227
|
+
// http://perfectionkills.com/whitespace-deviations/
|
1228
|
+
ws = "[" + ws + "]";
|
1229
|
+
var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
|
1230
|
+
trimEndRegexp = new RegExp(ws + ws + "*$");
|
1231
|
+
String.prototype.trim = function trim() {
|
1232
|
+
if (this === void 0 || this === null) {
|
1233
|
+
throw new TypeError("can't convert "+this+" to object");
|
1234
|
+
}
|
1235
|
+
return String(this)
|
1236
|
+
.replace(trimBeginRegexp, "")
|
1237
|
+
.replace(trimEndRegexp, "");
|
1238
|
+
};
|
1239
|
+
}
|
1240
|
+
|
630
1241
|
//
|
631
1242
|
// Util
|
632
1243
|
// ======
|
633
1244
|
//
|
634
1245
|
|
1246
|
+
// ES5 9.4
|
1247
|
+
// http://es5.github.com/#x9.4
|
635
1248
|
// http://jsperf.com/to-integer
|
636
|
-
|
1249
|
+
|
1250
|
+
function toInteger(n) {
|
637
1251
|
n = +n;
|
638
|
-
if (n !== n) // isNaN
|
639
|
-
n =
|
640
|
-
else if (n !== 0 && n !== (1/0) && n !== -(1/0))
|
1252
|
+
if (n !== n) { // isNaN
|
1253
|
+
n = 0;
|
1254
|
+
} else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
|
641
1255
|
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
1256
|
+
}
|
642
1257
|
return n;
|
643
|
-
}
|
1258
|
+
}
|
644
1259
|
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
1260
|
+
function isPrimitive(input) {
|
1261
|
+
var type = typeof input;
|
1262
|
+
return (
|
1263
|
+
input === null ||
|
1264
|
+
type === "undefined" ||
|
1265
|
+
type === "boolean" ||
|
1266
|
+
type === "number" ||
|
1267
|
+
type === "string"
|
1268
|
+
);
|
1269
|
+
}
|
1270
|
+
|
1271
|
+
function toPrimitive(input) {
|
1272
|
+
var val, valueOf, toString;
|
1273
|
+
if (isPrimitive(input)) {
|
1274
|
+
return input;
|
1275
|
+
}
|
1276
|
+
valueOf = input.valueOf;
|
1277
|
+
if (typeof valueOf === "function") {
|
1278
|
+
val = valueOf.call(input);
|
1279
|
+
if (isPrimitive(val)) {
|
1280
|
+
return val;
|
650
1281
|
}
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
1282
|
+
}
|
1283
|
+
toString = input.toString;
|
1284
|
+
if (typeof toString === "function") {
|
1285
|
+
val = toString.call(input);
|
1286
|
+
if (isPrimitive(val)) {
|
1287
|
+
return val;
|
655
1288
|
}
|
656
|
-
|
657
|
-
|
1289
|
+
}
|
1290
|
+
throw new TypeError();
|
1291
|
+
}
|
1292
|
+
|
1293
|
+
// ES5 9.9
|
1294
|
+
// http://es5.github.com/#x9.9
|
1295
|
+
var toObject = function (o) {
|
1296
|
+
if (o == null) { // this matches both null and undefined
|
1297
|
+
throw new TypeError("can't convert "+o+" to object");
|
1298
|
+
}
|
1299
|
+
return Object(o);
|
1300
|
+
};
|
658
1301
|
|
659
1302
|
})();
|
660
1303
|
|
661
1304
|
|
662
1305
|
|
1306
|
+
|
663
1307
|
(function($, shims){
|
664
1308
|
var defineProperty = 'defineProperty';
|
665
1309
|
var advancedObjectProperties = !!(Object.create && Object.defineProperties && Object.getOwnPropertyDescriptor);
|