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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/webshims-rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/webshims/extras/modernizr-custom.js +114 -104
  4. data/vendor/assets/javascripts/webshims/extras/mousepress.js +5 -5
  5. data/vendor/assets/javascripts/webshims/polyfiller.js +156 -207
  6. data/vendor/assets/javascripts/webshims/shims/$ajax.js +862 -0
  7. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/flashcanvas.js +20 -0
  8. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/flashcanvas.js +20 -0
  9. data/vendor/assets/javascripts/webshims/shims/color-picker.js +12 -12
  10. data/vendor/assets/javascripts/webshims/shims/combos/1.js +62 -32
  11. data/vendor/assets/javascripts/webshims/shims/combos/10.js +192 -509
  12. data/vendor/assets/javascripts/webshims/shims/combos/11.js +96 -415
  13. data/vendor/assets/javascripts/webshims/shims/combos/12.js +36 -26
  14. data/vendor/assets/javascripts/webshims/shims/combos/13.js +36 -26
  15. data/vendor/assets/javascripts/webshims/shims/combos/14.js +1007 -359
  16. data/vendor/assets/javascripts/webshims/shims/combos/15.js +310 -235
  17. data/vendor/assets/javascripts/webshims/shims/combos/16.js +313 -237
  18. data/vendor/assets/javascripts/webshims/shims/combos/17.js +96 -415
  19. data/vendor/assets/javascripts/webshims/shims/combos/18.js +1003 -678
  20. data/vendor/assets/javascripts/webshims/shims/combos/19.js +1085 -387
  21. data/vendor/assets/javascripts/webshims/shims/combos/2.js +161 -127
  22. data/vendor/assets/javascripts/webshims/shims/combos/20.js +1086 -388
  23. data/vendor/assets/javascripts/webshims/shims/combos/21.js +168 -96
  24. data/vendor/assets/javascripts/webshims/shims/combos/22.js +36 -27
  25. data/vendor/assets/javascripts/webshims/shims/combos/23.js +2 -1
  26. data/vendor/assets/javascripts/webshims/shims/combos/24.js +411 -172
  27. data/vendor/assets/javascripts/webshims/shims/combos/25.js +1085 -387
  28. data/vendor/assets/javascripts/webshims/shims/combos/26.js +96 -94
  29. data/vendor/assets/javascripts/webshims/shims/combos/3.js +163 -140
  30. data/vendor/assets/javascripts/webshims/shims/combos/30.js +166 -141
  31. data/vendor/assets/javascripts/webshims/shims/combos/31.js +159 -126
  32. data/vendor/assets/javascripts/webshims/shims/combos/4.js +103 -109
  33. data/vendor/assets/javascripts/webshims/shims/combos/5.js +98 -417
  34. data/vendor/assets/javascripts/webshims/shims/combos/6.js +101 -418
  35. data/vendor/assets/javascripts/webshims/shims/combos/7.js +168 -142
  36. data/vendor/assets/javascripts/webshims/shims/combos/8.js +165 -141
  37. data/vendor/assets/javascripts/webshims/shims/combos/9.js +195 -510
  38. data/vendor/assets/javascripts/webshims/shims/details.js +2 -2
  39. data/vendor/assets/javascripts/webshims/shims/dom-extend.js +96 -94
  40. data/vendor/assets/javascripts/webshims/shims/es5.js +908 -264
  41. data/vendor/assets/javascripts/webshims/shims/excanvas.js +16 -1
  42. data/vendor/assets/javascripts/webshims/shims/form-combat.js +147 -0
  43. data/vendor/assets/javascripts/webshims/shims/form-core.js +60 -31
  44. data/vendor/assets/javascripts/webshims/shims/form-datalist-lazy.js +114 -33
  45. data/vendor/assets/javascripts/webshims/shims/form-datalist.js +3 -1
  46. data/vendor/assets/javascripts/webshims/shims/form-message.js +7 -15
  47. data/vendor/assets/javascripts/webshims/shims/form-native-extend.js +2 -2
  48. data/vendor/assets/javascripts/webshims/shims/form-number-date-ui.js +88 -410
  49. data/vendor/assets/javascripts/webshims/shims/form-shim-extend.js +143 -93
  50. data/vendor/assets/javascripts/webshims/shims/form-shim-extend2.js +268 -79
  51. data/vendor/assets/javascripts/webshims/shims/form-validation.js +116 -81
  52. data/vendor/assets/javascripts/webshims/shims/form-validators.js +23 -10
  53. data/vendor/assets/javascripts/webshims/shims/forms-picker.js +605 -9
  54. data/vendor/assets/javascripts/webshims/shims/geolocation.js +51 -39
  55. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-de.js +78 -33
  56. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-en.js +24 -6
  57. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-nl.js +110 -49
  58. data/vendor/assets/javascripts/webshims/shims/json-storage.js +3 -1
  59. data/vendor/assets/javascripts/webshims/shims/mediaelement-core.js +2 -1
  60. data/vendor/assets/javascripts/webshims/shims/mediaelement-jaris.js +81 -30
  61. data/vendor/assets/javascripts/webshims/shims/mediaelement-yt.js +131 -54
  62. data/vendor/assets/javascripts/webshims/shims/plugins/jquery.ui.position.js +497 -0
  63. data/vendor/assets/javascripts/webshims/shims/range-ui.js +8 -5
  64. data/vendor/assets/javascripts/webshims/shims/sizzle.js +2026 -0
  65. data/vendor/assets/javascripts/webshims/shims/styles/forms-ext.css +401 -521
  66. data/vendor/assets/javascripts/webshims/shims/styles/scss/forms-ext.scss +1 -1
  67. data/vendor/assets/javascripts/webshims/shims/styles/scss/shim.scss +94 -82
  68. data/vendor/assets/javascripts/webshims/shims/styles/shim.css +250 -321
  69. data/vendor/assets/javascripts/webshims/shims/swf/JarisFLVPlayer.swf +0 -0
  70. data/vendor/assets/javascripts/webshims/shims/track-ui.js +1 -1
  71. data/vendor/assets/javascripts/webshims/shims/track.js +34 -25
  72. 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
- // -- kriskowal Kris Kowal Copyright (C) 2009-2011 MIT License
3
- // -- tlrobinson Tom Robinson Copyright (C) 2009-2010 MIT License (Narwhal Project)
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 Draft
34
- * http://www.ecma-international.org/publications/files/drafts/tc39-2009-050.pdf
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
- /*whatsupdoc*/
51
-
52
- // Shortcut to an often accessed properties, in order to avoid multiple
53
- // dereference that costs universally.
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://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf
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(); // TODO message
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 = slice.call(arguments, 1); // for normal call
36
+ var args = _Array_slice_.call(arguments, 1); // for normal call
77
37
  // 4. Let F be a new native ECMAScript object.
78
- // 9. Set the [[Prototype]] internal property of F to the standard
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
- // 10. Set the [[Call]] internal property of F as described in
40
+ // 12. Set the [[Call]] internal property of F as described in
81
41
  // 15.3.4.5.1.
82
- // 11. Set the [[Construct]] internal property of F as described in
42
+ // 13. Set the [[Construct]] internal property of F as described in
83
43
  // 15.3.4.5.2.
84
- // 12. Set the [[HasInstance]] internal property of F as described in
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
- var F = function(){};
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
- self,
111
- args.concat(slice.call(arguments))
66
+ this,
67
+ args.concat(_Array_slice_.call(arguments))
112
68
  );
113
- if (result !== null && Object(result) === result)
69
+ if (Object(result) === result) {
114
70
  return result;
115
- return self;
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 list
130
- // boundArgs in the same order followed by the same values as
131
- // the list ExtraArgs in the same order. 5. Return the
132
- // result of calling the [[Call]] internal method of target
133
- // providing boundThis as the this value and providing args
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(slice.call(arguments))
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
- // 16. The length own property of F is given attributes as specified in
148
- // 15.3.5.1.
149
- // TODO
150
- // 17. Set the [[Extensible]] internal property of F to true.
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. Call the [[DefineOwnProperty]] internal method of F with
153
- // arguments "caller", PropertyDescriptor {[[Value]]: null,
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. Call the [[DefineOwnProperty]] internal method of F with
158
- // arguments "arguments", PropertyDescriptor {[[Value]]: null,
159
- // [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]:
160
- // false}, and false.
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
- // XXX can't delete it in pure-js.
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
- toString = call.bind(prototypeOfObject.toString);
170
- owns = call.bind(prototypeOfObject.hasOwnProperty);
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);
171
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 toString(obj) == "[object Array]";
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
- // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/foreach
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 self = toObject(this),
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 = 0,
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 (toString(fun) != "[object Function]") {
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 context
215
- fun.call(thisp, self[i], i, self);
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 self = toObject(this),
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 (toString(fun) != "[object Function]") {
233
- throw new TypeError(); // TODO message
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, self);
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 self = toObject(this),
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 (toString(fun) != "[object Function]") {
254
- throw new TypeError(); // TODO message
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 && fun.call(thisp, self[i], i, self))
259
- result.push(self[i]);
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 self = toObject(this),
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 (toString(fun) != "[object Function]") {
274
- throw new TypeError(); // TODO message
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, self))
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 self = toObject(this),
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 (toString(fun) != "[object Function]") {
295
- throw new TypeError(); // TODO message
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, self))
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 self = toObject(this),
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 (toString(fun) != "[object Function]") {
315
- throw new TypeError(); // TODO message
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(); // TODO message
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(); // TODO message
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, self);
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 self = toObject(this),
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 (toString(fun) != "[object Function]") {
357
- throw new TypeError(); // TODO message
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(); // TODO message
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(); // TODO message
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, self);
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 = toObject(this),
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 - Math.abs(i);
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
- if (!Array.prototype.lastIndexOf) {
416
- Array.prototype.lastIndexOf = function (sought /*, fromIndex */) {
417
- var self = toObject(this),
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://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
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 ((typeof object != "object" && typeof object != "function") || object === null)
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
- // Format a Date object as a string according to a simplified subset of the ISO 8601
516
- // standard as defined in 15.9.1.15.
517
- if (!Date.prototype.toISOString) {
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 = [this.getUTCFullYear(), this.getUTCMonth() + 1, this.getUTCDate(),
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 digits.
531
- if (value < 10)
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 result.slice(0, 3).join("-") + "T" + result.slice(3).join(":") + "." +
536
- ("000" + this.getUTCMilliseconds()).slice(-3) + "Z";
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
- if (!Date.prototype.toJSON) {
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
- // This function provides a String representation of a Date object for
551
- // use by JSON.stringify (15.12.3). When the toJSON method is called
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 ToPrimitive(O, hint Number).
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
- // XXX
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 this.toISOString != "function")
563
- throw new TypeError(); // TODO message
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
- // toISO with O as the this value and an empty argument list.
566
- return this.toISOString();
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
- // String
924
+ // Number
582
925
  // ======
583
926
  //
584
927
 
585
- // ES5 15.5.4.20
586
- var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
587
- "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
588
- "\u2029\uFEFF";
589
- if (!String.prototype.trim || ws.trim()) {
590
- // http://blog.stevenlevithan.com/archives/faster-trim-javascript
591
- // http://perfectionkills.com/whitespace-deviations/
592
- ws = "[" + ws + "]";
593
- var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
594
- trimEndRegexp = new RegExp(ws + ws + "*$");
595
- String.prototype.trim = function trim() {
596
- return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
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, which is the this value (converted to a String). If limit is not undefined, then the output array is truncated so that it contains no more than limit elements.
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 oldSplit.apply(this, arguments);
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 non-normative section suggesting uniform semantics
615
- // and it should be normalized across all browsers
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 oldSubstr = String.prototype.substr;
1204
+ var string_substr = String.prototype.substr;
619
1205
  /**
620
- * Get the substring of a string
621
- * @param {integer} start where to start the substring
622
- * @param {integer} length how many characters to return
623
- * @return {string}
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 oldSubstr.call(this, start < 0 ? (start = this.length + start) < 0 ? 0 : start : start, length);
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
- var toInteger = function (n) {
1249
+
1250
+ function toInteger(n) {
637
1251
  n = +n;
638
- if (n !== n) // isNaN
639
- n = -1;
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
- var prepareString = "a"[0] != "a",
646
- // ES5 9.9
647
- toObject = function (o) {
648
- if (o == null) { // this matches both null and undefined
649
- throw new TypeError(); // TODO message
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
- // If the implementation doesn't support by-index access of
652
- // string characters (ex. IE < 7), split the string
653
- if (prepareString && typeof o == "string" && o) {
654
- return o.split("");
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
- return Object(o);
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);
@@ -1447,8 +2091,11 @@ webshims.register('form-number-date-api', function($, webshims, window, document
1447
2091
 
1448
2092
  if(this._init && val == o.value && oVal == val){return;}
1449
2093
  this.options.value = val;
1450
- this.thumb.stop();
1451
- this.range.stop();
2094
+
2095
+ if($.fn.stop){
2096
+ this.thumb.stop();
2097
+ this.range.stop();
2098
+ }
1452
2099
 
1453
2100
  rangeStyle[this.dirs.width] = left+'%';
1454
2101
  if(this.vertical){
@@ -1457,7 +2104,7 @@ webshims.register('form-number-date-api', function($, webshims, window, document
1457
2104
  thumbStyle[this.dirs.left] = left+'%';
1458
2105
 
1459
2106
 
1460
- if(!animate){
2107
+ if(!animate || !$.fn.animate){
1461
2108
  this.thumb.css(thumbStyle);
1462
2109
  this.range.css(rangeStyle);
1463
2110
  } else {
@@ -1746,9 +2393,9 @@ webshims.register('form-number-date-api', function($, webshims, window, document
1746
2393
  $(window).off('blur', removeWin);
1747
2394
  if(!o.readonly && !o.disabled){
1748
2395
  normalizeTouch(e);
1749
- that.element.focus();
2396
+ that.element.trigger('focus');
1750
2397
  that.addRemoveClass('ws-active', true);
1751
- leftOffset = that.element.focus().offset();
2398
+ leftOffset = that.element.offset();
1752
2399
  widgetUnits = that.element[that.dirs.innerWidth]();
1753
2400
  if(!widgetUnits || !leftOffset){return;}
1754
2401
  outerWidth = that.thumb[that.dirs.outerWidth]();
@@ -2089,6 +2736,32 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
2089
2736
  return val.length == 1 ? '0'+val : val;
2090
2737
  };
2091
2738
 
2739
+ var loadPicker = function(type, name){
2740
+ type = (type == 'color' ? 'color' : 'forms')+'-picker';
2741
+ if(!loadPicker[name+'Loaded'+type]){
2742
+ loadPicker[name+'Loaded'+type] = true;
2743
+ webshims.ready(name, function(){
2744
+ webshims.loader.loadList([type]);
2745
+
2746
+ });
2747
+ }
2748
+ return type;
2749
+ };
2750
+
2751
+
2752
+ options.addZero = addZero;
2753
+ webshims.loader.addModule('forms-picker', {
2754
+ noAutoCallback: true,
2755
+ options: options
2756
+ });
2757
+ webshims.loader.addModule('color-picker', {
2758
+ noAutoCallback: true,
2759
+ css: 'jpicker/jpicker.css',
2760
+ options: options,
2761
+ d: ['forms-picker']
2762
+ });
2763
+
2764
+ options.steps = steps;
2092
2765
 
2093
2766
  (function(){
2094
2767
 
@@ -2201,7 +2874,7 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
2201
2874
  langCfg.date.monthDigits = monthDigits;
2202
2875
  langCfg.numberSigns += '-';
2203
2876
  if(langCfg.meridian){
2204
- langCfg.timeSigns += langCfg.meridian[0] + langCfg.meridian[1];
2877
+ langCfg.timeSigns += langCfg.meridian[0] + langCfg.meridian[1] + langCfg.meridian[0].toLowerCase() + langCfg.meridian[1].toLowerCase();
2205
2878
  }
2206
2879
  $.each(langCfg.date.monthNames, create);
2207
2880
  $.each(langCfg.date.monthNamesShort, create);
@@ -2227,43 +2900,24 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
2227
2900
  $(document).triggerHandler('wslocalechange');
2228
2901
  };
2229
2902
 
2230
- triggerLocaleChange();
2231
2903
 
2232
- webshims.activeLang({
2233
- register: 'form-core',
2234
- callback: function(){
2235
- $.each(arguments, function(i, val){
2236
- if(formcfg[val]){
2237
- if(formcfg[val] != curCfg){
2238
- curCfg = formcfg[val];
2239
- triggerLocaleChange();
2240
- }
2241
- return false;
2242
- }
2243
- });
2244
- }
2245
- });
2246
- webshims.activeLang({
2247
- langObj: formcfg,
2248
- module: 'form-core',
2249
- callback: function(val){
2250
- if(curCfg != val){
2251
- curCfg = val;
2252
- triggerLocaleChange();
2253
- }
2254
- }
2904
+
2905
+
2906
+ curCfg = webshims.activeLang(formcfg);
2907
+
2908
+ triggerLocaleChange();
2909
+
2910
+ $(formcfg).on('change', function(){
2911
+ curCfg = formcfg.__active;
2912
+ triggerLocaleChange();
2255
2913
  });
2914
+
2256
2915
  })();
2257
2916
 
2258
2917
 
2259
2918
 
2260
2919
  (function(){
2261
2920
 
2262
-
2263
- var mousePress = function(e){
2264
- $(this)[e.type == 'mousepressstart' ? 'addClass' : 'removeClass']('mousepress-ui');
2265
- };
2266
-
2267
2921
  var retDefault = function(val, def){
2268
2922
  if(!(typeof val == 'number' || (val && val == val * 1))){
2269
2923
  return def;
@@ -2375,6 +3029,7 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
2375
3029
  time: function(val){
2376
3030
  var fVal;
2377
3031
  if(val && curCfg.meridian){
3032
+ val = val.toUpperCase();
2378
3033
  if(val.substr(0,2) === "12"){
2379
3034
  val = "00" + val.substr(2);
2380
3035
  }
@@ -2598,300 +3253,32 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
2598
3253
  }
2599
3254
  },
2600
3255
  addBindings: function(){
2601
- var isFocused;
2602
-
2603
3256
  var that = this;
2604
3257
  var o = this.options;
2605
-
2606
- var eventTimer = (function(){
2607
- var events = {};
2608
- return {
2609
- init: function(name, curVal, fn){
2610
- if(!events[name]){
2611
- events[name] = {fn: fn};
2612
- $(that.orig).on(name, function(){
2613
- events[name].val = $.prop(that.orig, 'value');
2614
- });
2615
- }
2616
- events[name].val = curVal;
2617
- },
2618
- call: function(name, val){
2619
- if(events[name] && events[name].val != val){
2620
- clearTimeout(events[name].timer);
2621
- events[name].val = val;
2622
- events[name].timer = setTimeout(function(){
2623
- events[name].fn(val, that);
2624
- }, 9);
2625
- }
2626
- }
2627
- };
2628
- })();
2629
- var initChangeEvents = function(){
2630
- eventTimer.init('input', $.prop(that.orig, 'value'), that.options.input);
2631
- eventTimer.init('change', $.prop(that.orig, 'value'), that.options.change);
3258
+ var run = function(){
3259
+ that._addBindings();
2632
3260
  };
3261
+ if(this._addBindings){
3262
+ run();
3263
+ } else {
3264
+ webshims.ready('forms-picker', run);
3265
+ loadPicker(this.type, 'WINDOWLOAD');
3266
+ }
2633
3267
 
2634
- var step = {};
2635
-
2636
- var preventBlur = function(e){
2637
- if(preventBlur.prevent){
2638
- e.preventDefault();
2639
- (isFocused || that.element.getShadowFocusElement()).focus();
2640
- stopPropagation(e);
2641
- return true;
2642
- }
2643
- };
2644
- var callSplitChange = (function(){
2645
- var timer;
2646
-
2647
- var call = function(e){
2648
- var val;
2649
- clearTimeout(timer);
2650
- val = that.parseValue();
2651
- if(that.type == 'color'){
2652
- that.inputElements.val(val);
2653
- }
2654
- $.prop(that.orig, 'value', val);
2655
- eventTimer.call('input', val);
2656
- if(!e || e.type != 'wsupdatevalue'){
2657
- eventTimer.call('change', val);
2658
- }
2659
- };
2660
-
2661
- var onFocus = function(){
2662
- clearTimeout(timer);
2663
- };
2664
- var onBlur = function(e){
2665
- clearTimeout(timer);
2666
- timer = setTimeout(call, 0);
2667
-
2668
- if(e.type == 'change'){
2669
- stopPropagation(e);
2670
- if(!o.splitInput){
2671
- call();
2672
- }
2673
- }
2674
- };
2675
-
2676
- that.element.on('wsupdatevalue', call);
2677
-
2678
- that.inputElements
2679
- .add(that.buttonWrapper)
2680
- .add(that.element)
2681
- .on(
2682
- {
2683
- 'focus focusin': onFocus,
2684
- 'blur focusout change': onBlur
2685
- }
2686
- )
2687
- ;
2688
- setTimeout(function(){
2689
- if(that.popover){
2690
- that.popover.element.on('wspopoverhide', onBlur);
2691
- $('> *', that.popover.element)
2692
- .on({
2693
- 'focusin': onFocus,
2694
- 'focusout': onBlur
2695
- })
2696
- ;
2697
- }
2698
- }, 0);
2699
- })();
2700
-
2701
- var spinEvents = {};
2702
- var spinElement = o.splitInput ? this.inputElements.filter('.ws-spin') : this.inputElements.eq(0);
2703
- var elementEvts = {
2704
- blur: function(e){
2705
- if(!preventBlur(e) && !o.disabled && !o.readonly){
2706
- if(!preventBlur.prevent){
2707
- isFocused = false;
2708
- }
2709
- }
2710
- stopPropagation(e);
2711
- },
2712
- focus: function(e){
2713
- if(!isFocused){
2714
- initChangeEvents();
2715
- isFocused = this;
2716
- }
2717
- },
2718
- keypress: function(e){
2719
- if(e.isDefaultPrevented()){return;}
2720
- var chr;
2721
- var stepped = true;
2722
- var code = e.keyCode;
2723
- if(!e.ctrlKey && !e.metaKey && curCfg[that.type+'Signs']){
2724
- chr = String.fromCharCode(e.charCode == null ? code : e.charCode);
2725
- stepped = !(chr < " " || (curCfg[that.type+'Signs']+'0123456789').indexOf(chr) > -1);
2726
- } else {
2727
- stepped = false;
2728
- }
2729
- if(stepped){
2730
- e.preventDefault();
3268
+ this.inputElements
3269
+ .add(this.buttonWrapper)
3270
+ .add(this.element)
3271
+ .one('mousedown focusin', function(e){
3272
+ loadPicker(that.type, 'DOM');
3273
+ })
3274
+ .on({
3275
+ 'change input focus focusin blur focusout': function(e){
3276
+ $(e.target).trigger('ws__'+e.type);
2731
3277
  }
2732
- },
2733
- input: (this.type == 'color' && this.isValid) ?
2734
- $.noop :
2735
- (function(){
2736
- var timer;
2737
- var check = function(){
2738
- var val = that.parseValue(true);
2739
- if(val && that.isValid(val)){
2740
- that.setInput(val);
2741
- }
2742
-
2743
- };
2744
- return function(){
2745
- clearTimeout(timer);
2746
- timer = setTimeout(check, 200);
2747
- };
2748
- })(),
2749
- 'input keydown keypress': (function(){
2750
- var timer;
2751
- var isStopped = false;
2752
- var releaseTab = function(){
2753
- if(isStopped === true){
2754
- isStopped = 'semi';
2755
- timer = setTimeout(releaseTab, 250);
2756
- } else {
2757
- isStopped = false;
2758
- }
2759
- };
2760
- var stopTab = function(){
2761
- isStopped = true;
2762
- clearTimeout(timer);
2763
- timer = setTimeout(releaseTab, 300);
2764
- };
2765
- var select = function(){
2766
- var elem = this;
2767
- setTimeout(function(){
2768
- elem.focus();
2769
- elem.select();
2770
- }, 4);
2771
-
2772
- stopTab();
2773
- };
2774
-
2775
- return function(e){
2776
- if(o.splitInput && o.jumpInputs){
2777
- if(e.type == 'input'){
2778
- if($.prop(this, 'value').length === $.prop(this, 'maxLength')){
2779
- try {
2780
- $(this)
2781
- .next()
2782
- .next('input, select')
2783
- .each(select)
2784
- ;
2785
- } catch(er){}
2786
- }
2787
- } else if(!e.shiftKey && !e.crtlKey && e.keyCode == 9 && (isStopped === true || (isStopped && !$.prop(this, 'value')))){
2788
- e.preventDefault();
2789
- }
2790
- }
2791
- };
2792
- })()
2793
- };
2794
- var mouseDownInit = function(){
2795
- if(!o.disabled && !isFocused){
2796
- that.element.getShadowFocusElement().focus();
2797
- }
2798
- preventBlur.set();
3278
+ })
2799
3279
 
2800
- return false;
2801
- };
2802
-
2803
- preventBlur.set = (function(){
2804
- var timer;
2805
- var reset = function(){
2806
- preventBlur.prevent = false;
2807
- };
2808
- return function(){
2809
- clearTimeout(timer);
2810
- preventBlur.prevent = true;
2811
- setTimeout(reset, 9);
2812
- };
2813
- })();
2814
-
2815
-
2816
- this.buttonWrapper.on('mousedown', mouseDownInit);
2817
-
2818
- this.setInput = function(value){
2819
- that.value(value);
2820
- eventTimer.call('input', value);
2821
- };
2822
- this.setChange = function(value){
2823
- that.setInput(value);
2824
- eventTimer.call('change', value);
2825
- };
2826
-
2827
-
2828
-
2829
- this.inputElements.on(elementEvts);
3280
+ ;
2830
3281
 
2831
- if(steps[this.type]){
2832
- ['stepUp', 'stepDown'].forEach(function(name){
2833
- step[name] = function(factor){
2834
- if(!o.disabled && !o.readonly){
2835
- if(!isFocused){
2836
- mouseDownInit();
2837
- }
2838
- var ret = false;
2839
- if (!factor) {
2840
- factor = 1;
2841
- }
2842
- try {
2843
- that.elemHelper[name](factor);
2844
-
2845
- ret = that.elemHelper.prop('value');
2846
-
2847
- } catch (er) {
2848
- if(!o.value && that.maxAsNumber >= that.minAsNumber){
2849
- ret = o.defValue;
2850
- }
2851
- }
2852
- if(ret !== false && o.value != ret){
2853
- that.value(ret);
2854
- eventTimer.call('input', ret);
2855
- }
2856
- return ret;
2857
- }
2858
- };
2859
- });
2860
- if(!o.noSpinbtn){
2861
- spinEvents[$.fn.mwheelIntent ? 'mwheelIntent' : 'mousewheel'] = function(e, delta){
2862
- if(delta && isFocused && !o.disabled){
2863
- step[delta > 0 ? 'stepUp' : 'stepDown']();
2864
- e.preventDefault();
2865
- }
2866
- };
2867
- spinEvents.keydown = function(e){
2868
- if(o.list || e.isDefaultPrevented() || (e.altKey && e.keyCode == 40) || $.attr(this, 'list')){return;}
2869
- var stepped = true;
2870
- var code = e.keyCode;
2871
- if (code == 38) {
2872
- step.stepUp();
2873
- } else if (code == 40) {
2874
- step.stepDown();
2875
- } else {
2876
- stepped = false;
2877
- }
2878
- if(stepped){
2879
- e.preventDefault();
2880
- }
2881
- };
2882
-
2883
- spinElement.attr({'autocomplete': 'off', role: 'spinbutton'}).on(spinEvents);
2884
- }
2885
- $(this.buttonWrapper)
2886
- .on('mousepressstart mousepressend', '.step-up, .step-down', mousePress)
2887
- .on('mousedown mousepress', '.step-up', function(e){
2888
- step.stepUp();
2889
- })
2890
- .on('mousedown mousepress', '.step-down', function(e){
2891
- step.stepDown();
2892
- })
2893
- ;
2894
- }
2895
3282
  if(this.type != 'color'){
2896
3283
  (function(){
2897
3284
  var localeChange ;
@@ -2915,8 +3302,6 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
2915
3302
  $(that.orig).onWSOff('wslocalechange', localeChange);
2916
3303
  })();
2917
3304
  }
2918
-
2919
- initChangeEvents();
2920
3305
  },
2921
3306
  required: function(val, boolVal){
2922
3307
  this.inputElements.attr({'aria-required': ''+boolVal});
@@ -2950,34 +3335,6 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
2950
3335
  this.element.prop('placeholder', placeholder);
2951
3336
  }
2952
3337
  },
2953
- initDataList: function(){
2954
- var listTimer;
2955
- var that = this;
2956
- var updateList = function(){
2957
- $(that.orig)
2958
- .jProp('list')
2959
- .off('updateDatalist', updateList)
2960
- .on('updateDatalist', updateList)
2961
- ;
2962
- clearTimeout(listTimer);
2963
- listTimer = setTimeout(function(){
2964
- if(that.list){
2965
- that.list();
2966
- }
2967
- }, 9);
2968
-
2969
- };
2970
-
2971
- $(this.orig).onTrigger('listdatalistchange', updateList);
2972
- },
2973
- getOptions: function(){
2974
- var options = {};
2975
- var datalist = $(this.orig).jProp('list');
2976
- datalist.find('option').each(function(){
2977
- options[$.prop(this, 'value')] = $.prop(this, 'label');
2978
- });
2979
- return [options, datalist.data('label')];
2980
- },
2981
3338
  list: function(val){
2982
3339
  if(this.type == 'number'){
2983
3340
  this.element.attr('list', $.attr(this.orig, 'list'));
@@ -3107,31 +3464,6 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
3107
3464
  }, 9);
3108
3465
  }
3109
3466
  },
3110
- value: function(val, force){
3111
-
3112
- if(!this._init || force || this.options.value !== val){
3113
- this.valueAsNumber = this.asNumber(val);
3114
- this.options.value = val;
3115
-
3116
- if(isNaN(this.valueAsNumber) || (!isNaN(this.minAsNumber) && this.valueAsNumber < this.minAsNumber) || (!isNaN(this.maxAsNumber) && this.valueAsNumber > this.maxAsNumber)){
3117
- this._setStartInRange();
3118
- } else {
3119
- this.elemHelper.prop('value', val);
3120
- this.options.defValue = "";
3121
- }
3122
-
3123
- val = formatVal[this.type](val, this.options);
3124
- if(this.options.splitInput){
3125
- $.each(this.splits, function(i, elem){
3126
- $.prop(elem, 'value', val[i]);
3127
- });
3128
- } else {
3129
- this.element.prop('value', val);
3130
- }
3131
- this._propertyChange('value');
3132
- this.mirrorValidity();
3133
- }
3134
- },
3135
3467
  step: function(val){
3136
3468
  var defStep = steps[this.type];
3137
3469
  this.options.step = val;
@@ -3203,6 +3535,8 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
3203
3535
  });
3204
3536
  };
3205
3537
 
3538
+ $.fn.wsBaseWidget.wsProto = wsWidgetProto;
3539
+
3206
3540
  $.fn.spinbtnUI = function(opts){
3207
3541
  opts = $.extend({
3208
3542
  monthNames: 'monthNames',
@@ -3217,32 +3551,14 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
3217
3551
  }, opts);
3218
3552
  });
3219
3553
  };
3554
+
3555
+ $.fn.spinbtnUI.wsProto = spinBtnProto;
3556
+
3220
3557
  })();
3221
3558
 
3222
3559
  (function(){
3223
3560
  var picker = {};
3224
3561
 
3225
- var loadPicker = function(type, name){
3226
- type = (type == 'color' ? 'color' : 'forms')+'-picker';
3227
- if(!loadPicker[name+'Loaded'+type]){
3228
- loadPicker[name+'Loaded'+type] = true;
3229
- webshims.ready(name, function(){
3230
- webshims.loader.loadList([type]);
3231
- });
3232
- }
3233
- return type;
3234
- };
3235
- options.addZero = addZero;
3236
- webshims.loader.addModule('forms-picker', {
3237
- noAutoCallback: true,
3238
- options: options
3239
- });
3240
- webshims.loader.addModule('color-picker', {
3241
- noAutoCallback: true,
3242
- css: 'jpicker/jpicker.css',
3243
- options: options
3244
- });
3245
-
3246
3562
  webshims.inlinePopover = {
3247
3563
  _create: function(){
3248
3564
  this.element = $('<div class="ws-inline-picker"><div class="ws-po-box" /></div>').data('wspopover', this);
@@ -3286,7 +3602,7 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
3286
3602
  cancel: function(val, popover, data){
3287
3603
  if(!data.options.inlinePicker){
3288
3604
  popover.stopOpen = true;
3289
- data.element.getShadowFocusElement().focus();
3605
+ data.element.getShadowFocusElement().trigger('focus');
3290
3606
  setTimeout(function(){
3291
3607
  popover.stopOpen = false;
3292
3608
  }, 9);
@@ -3375,9 +3691,16 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
3375
3691
 
3376
3692
  picker._common = function(data){
3377
3693
  var options = data.options;
3378
- var popover = webshims.objectCreate(options.inlinePicker ? webshims.inlinePopover : webshims.wsPopover, {}, {prepareFor: options.inlinePicker ? data.buttonWrapper : data.element, position: options.widgetPosition});
3694
+ var popover = webshims.objectCreate(options.inlinePicker ? webshims.inlinePopover : webshims.wsPopover, {}, $.extend(options.popover || {}, {prepareFor: options.inlinePicker ? data.buttonWrapper : data.element}));
3379
3695
  var opener = $('<button type="button" class="ws-popover-opener"><span /></button>').appendTo(data.buttonWrapper);
3380
3696
 
3697
+ if(options.widgetPosition){
3698
+ webshims.error('options.widgetPosition was removed use options.popover.position instead');
3699
+ }
3700
+
3701
+ if(options.openOnFocus && popover.options && (popover.options.appendTo == 'auto' || popover.options.appendTo == 'element')){
3702
+ webshims.error('openOnFocus and popover.appendTo "auto/element" can prduce a11y problems try to change appendTo to body or similiar or use openOnMouseFocus instead');
3703
+ }
3381
3704
 
3382
3705
  var showPickerContent = function(){
3383
3706
  (picker[data.type].showPickerContent || picker.showPickerContent)(data, popover);
@@ -3529,7 +3852,6 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
3529
3852
  if(options.inlinePicker){
3530
3853
  show();
3531
3854
  }
3532
- loadPicker(data.type, 'WINDOWLOAD');
3533
3855
  };
3534
3856
 
3535
3857
  picker.month = picker._common;
@@ -3545,7 +3867,7 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
3545
3867
  .find('.ws-color-indicator')
3546
3868
  ;
3547
3869
  var showColor = function(){
3548
- colorIndicator.css({backgroundColor: $.prop(this, 'value') || '#000'})
3870
+ colorIndicator.css({backgroundColor: $.prop(this, 'value') || '#000000'});
3549
3871
  };
3550
3872
  var showOpacity = (function(){
3551
3873
  var timer;
@@ -3702,11 +4024,8 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
3702
4024
  data = {};
3703
4025
  optsName = type;
3704
4026
 
3705
- //todo: do we need deep extend?
3706
-
3707
4027
  labels = $(this).jProp('labels');
3708
-
3709
- opts = $.extend({}, options.widgets, options[type], $($.prop(this, 'form')).data(type) || {}, $(this).data(type) || {}, {
4028
+ opts = $.extend(webshims.getOptions(this, type, [options.widgets, options[type], $($.prop(this, 'form')).data(type)]), {
3710
4029
  orig: this,
3711
4030
  type: type,
3712
4031
  labels: labels,
@@ -3728,7 +4047,6 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
3728
4047
  containerElements: []
3729
4048
  });
3730
4049
 
3731
-
3732
4050
  for(i = 0; i < copyProps.length; i++){
3733
4051
  opts[copyProps[i]] = $.prop(this, copyProps[i]);
3734
4052
  }
@@ -3882,8 +4200,8 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
3882
4200
  opts.splitInput = false;
3883
4201
  }
3884
4202
  var markup = opts.splitInput ?
3885
- '<span class="ws-'+name+' ws-input" role="group"></span>' :
3886
- '<input class="ws-'+name+'" type="text" />';
4203
+ '<span class="ws-'+name+' ws-input ws-inputreplace" role="group"></span>' :
4204
+ '<input class="ws-'+name+' ws-inputreplace" type="text" />';
3887
4205
  var data = $(markup).insertAfter(opts.orig);
3888
4206
  if(steps[name]){
3889
4207
  data = data.spinbtnUI(opts).data('wsWidget'+name);
@@ -3900,13 +4218,20 @@ webshims.register('form-number-date-ui', function($, webshims, window, document,
3900
4218
  }
3901
4219
  });
3902
4220
 
4221
+ var init = function(){
4222
+ webshims.addReady(function(context, contextElem){
4223
+ $('input', context)
4224
+ .add(contextElem.filter('input'))
4225
+ .each(implementType)
4226
+ ;
4227
+ });
4228
+ };
4229
+ if(formcfg._isLoading){
4230
+ $(formcfg).one('change', init);
4231
+ } else {
4232
+ init();
4233
+ }
3903
4234
 
3904
- webshims.addReady(function(context, contextElem){
3905
- $('input', context)
3906
- .add(contextElem.filter('input'))
3907
- .each(implementType)
3908
- ;
3909
- });
3910
4235
  })();
3911
4236
  });
3912
4237