webshims-rails 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/lib/webshims-rails/version.rb +2 -2
  2. data/vendor/assets/javascripts/webshims/extras/custom-validity.js +261 -261
  3. data/vendor/assets/javascripts/webshims/extras/modernizr-custom.js +534 -534
  4. data/vendor/assets/javascripts/webshims/extras/mousepress.js +60 -60
  5. data/vendor/assets/javascripts/webshims/minified/extras/custom-validity.js +1 -1
  6. data/vendor/assets/javascripts/webshims/minified/polyfiller.js +24 -24
  7. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/README +82 -82
  8. data/vendor/assets/javascripts/webshims/minified/shims/combos/1.js +35 -34
  9. data/vendor/assets/javascripts/webshims/minified/shims/combos/10.js +79 -82
  10. data/vendor/assets/javascripts/webshims/minified/shims/combos/11.js +45 -44
  11. data/vendor/assets/javascripts/webshims/minified/shims/combos/12.js +43 -42
  12. data/vendor/assets/javascripts/webshims/minified/shims/combos/13.js +28 -27
  13. data/vendor/assets/javascripts/webshims/minified/shims/combos/15.js +4 -4
  14. data/vendor/assets/javascripts/webshims/minified/shims/combos/16.js +57 -59
  15. data/vendor/assets/javascripts/webshims/minified/shims/combos/17.js +64 -66
  16. data/vendor/assets/javascripts/webshims/minified/shims/combos/18.js +53 -54
  17. data/vendor/assets/javascripts/webshims/minified/shims/combos/19.js +64 -66
  18. data/vendor/assets/javascripts/webshims/minified/shims/combos/2.js +72 -73
  19. data/vendor/assets/javascripts/webshims/minified/shims/combos/20.js +42 -46
  20. data/vendor/assets/javascripts/webshims/minified/shims/combos/21.js +52 -50
  21. data/vendor/assets/javascripts/webshims/minified/shims/combos/22.js +55 -59
  22. data/vendor/assets/javascripts/webshims/minified/shims/combos/23.js +66 -64
  23. data/vendor/assets/javascripts/webshims/minified/shims/combos/24.js +80 -82
  24. data/vendor/assets/javascripts/webshims/minified/shims/combos/25.js +60 -59
  25. data/vendor/assets/javascripts/webshims/minified/shims/combos/26.js +79 -81
  26. data/vendor/assets/javascripts/webshims/minified/shims/combos/27.js +101 -104
  27. data/vendor/assets/javascripts/webshims/minified/shims/combos/3.js +94 -95
  28. data/vendor/assets/javascripts/webshims/minified/shims/combos/4.js +26 -29
  29. data/vendor/assets/javascripts/webshims/minified/shims/combos/5.js +33 -36
  30. data/vendor/assets/javascripts/webshims/minified/shims/combos/59.js +51 -54
  31. data/vendor/assets/javascripts/webshims/minified/shims/combos/6.js +27 -28
  32. data/vendor/assets/javascripts/webshims/minified/shims/combos/7.js +27 -28
  33. data/vendor/assets/javascripts/webshims/minified/shims/combos/8.js +39 -38
  34. data/vendor/assets/javascripts/webshims/minified/shims/combos/9.js +65 -68
  35. data/vendor/assets/javascripts/webshims/minified/shims/details.js +4 -4
  36. data/vendor/assets/javascripts/webshims/minified/shims/dom-extend.js +23 -22
  37. data/vendor/assets/javascripts/webshims/minified/shims/form-core.js +19 -22
  38. data/vendor/assets/javascripts/webshims/minified/shims/form-datalist.js +14 -14
  39. data/vendor/assets/javascripts/webshims/minified/shims/form-number-date-api.js +9 -9
  40. data/vendor/assets/javascripts/webshims/minified/shims/form-number-date-ui.js +18 -19
  41. data/vendor/assets/javascripts/webshims/minified/shims/form-shim-extend.js +45 -43
  42. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-de.txt +33 -33
  43. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-en.txt +34 -34
  44. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-core.js +12 -12
  45. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-jaris.js +23 -0
  46. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-native-fix.js +1 -1
  47. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-swf.js +26 -30
  48. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-yt.js +3 -3
  49. data/vendor/assets/javascripts/webshims/minified/shims/styles/shim.css +689 -686
  50. data/vendor/assets/javascripts/webshims/minified/shims/swf/JarisFLVPlayer.swf +0 -0
  51. data/vendor/assets/javascripts/webshims/minified/shims/track-ui.js +9 -9
  52. data/vendor/assets/javascripts/webshims/minified/shims/track.js +21 -21
  53. data/vendor/assets/javascripts/webshims/polyfiller.js +1191 -1175
  54. data/vendor/assets/javascripts/webshims/shims/combos/1.js +1754 -1714
  55. data/vendor/assets/javascripts/webshims/shims/combos/10.js +3247 -3320
  56. data/vendor/assets/javascripts/webshims/shims/combos/11.js +1633 -1588
  57. data/vendor/assets/javascripts/webshims/shims/combos/12.js +1636 -1591
  58. data/vendor/assets/javascripts/webshims/shims/combos/13.js +1100 -1058
  59. data/vendor/assets/javascripts/webshims/shims/combos/14.js +476 -476
  60. data/vendor/assets/javascripts/webshims/shims/combos/15.js +316 -314
  61. data/vendor/assets/javascripts/webshims/shims/combos/16.js +2094 -2104
  62. data/vendor/assets/javascripts/webshims/shims/combos/17.js +2258 -2267
  63. data/vendor/assets/javascripts/webshims/shims/combos/18.js +1380 -1364
  64. data/vendor/assets/javascripts/webshims/shims/combos/19.js +2239 -2247
  65. data/vendor/assets/javascripts/webshims/shims/combos/2.js +2339 -2294
  66. data/vendor/assets/javascripts/webshims/shims/combos/20.js +1493 -1606
  67. data/vendor/assets/javascripts/webshims/shims/combos/21.js +1733 -1635
  68. data/vendor/assets/javascripts/webshims/shims/combos/22.js +2295 -2408
  69. data/vendor/assets/javascripts/webshims/shims/combos/23.js +2269 -2168
  70. data/vendor/assets/javascripts/webshims/shims/combos/24.js +2775 -2780
  71. data/vendor/assets/javascripts/webshims/shims/combos/25.js +1505 -1456
  72. data/vendor/assets/javascripts/webshims/shims/combos/26.js +2111 -2115
  73. data/vendor/assets/javascripts/webshims/shims/combos/27.js +3264 -3331
  74. data/vendor/assets/javascripts/webshims/shims/combos/3.js +3020 -2970
  75. data/vendor/assets/javascripts/webshims/shims/combos/4.js +770 -822
  76. data/vendor/assets/javascripts/webshims/shims/combos/5.js +1025 -1077
  77. data/vendor/assets/javascripts/webshims/shims/combos/59.js +1706 -1753
  78. data/vendor/assets/javascripts/webshims/shims/combos/6.js +444 -433
  79. data/vendor/assets/javascripts/webshims/shims/combos/7.js +699 -688
  80. data/vendor/assets/javascripts/webshims/shims/combos/8.js +1488 -1445
  81. data/vendor/assets/javascripts/webshims/shims/combos/9.js +2445 -2518
  82. data/vendor/assets/javascripts/webshims/shims/details.js +148 -146
  83. data/vendor/assets/javascripts/webshims/shims/dom-extend.js +952 -912
  84. data/vendor/assets/javascripts/webshims/shims/es5.js +802 -802
  85. data/vendor/assets/javascripts/webshims/shims/excanvas.js +924 -924
  86. data/vendor/assets/javascripts/webshims/shims/form-core.js +606 -659
  87. data/vendor/assets/javascripts/webshims/shims/form-datalist.js +681 -676
  88. data/vendor/assets/javascripts/webshims/shims/form-message.js +164 -163
  89. data/vendor/assets/javascripts/webshims/shims/form-native-extend.js +255 -255
  90. data/vendor/assets/javascripts/webshims/shims/form-number-date-api.js +383 -383
  91. data/vendor/assets/javascripts/webshims/shims/form-number-date-ui.js +61 -50
  92. data/vendor/assets/javascripts/webshims/shims/form-shim-extend.js +1569 -1472
  93. data/vendor/assets/javascripts/webshims/shims/geolocation.js +168 -168
  94. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ar.js +32 -32
  95. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ch-ZN.js +32 -32
  96. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-de.txt +33 -33
  97. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-el.js +32 -32
  98. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-en.txt +34 -34
  99. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-es.js +31 -31
  100. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-fr.js +32 -32
  101. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-he.js +32 -32
  102. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-hi.js +32 -32
  103. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-hu.js +32 -32
  104. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-it.js +32 -32
  105. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ja.js +32 -32
  106. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-nl.js +32 -32
  107. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-pt-PT.js +32 -32
  108. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ru.js +31 -31
  109. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-sv.js +32 -32
  110. data/vendor/assets/javascripts/webshims/shims/json-storage.js +308 -308
  111. data/vendor/assets/javascripts/webshims/shims/mediaelement-core.js +536 -533
  112. data/vendor/assets/javascripts/webshims/shims/mediaelement-jaris.js +861 -0
  113. data/vendor/assets/javascripts/webshims/shims/mediaelement-native-fix.js +98 -98
  114. data/vendor/assets/javascripts/webshims/shims/mediaelement-swf.js +957 -1073
  115. data/vendor/assets/javascripts/webshims/shims/mediaelement-yt.js +543 -543
  116. data/vendor/assets/javascripts/webshims/shims/styles/shim.css +689 -686
  117. data/vendor/assets/javascripts/webshims/shims/swf/JarisFLVPlayer.swf +0 -0
  118. data/vendor/assets/javascripts/webshims/shims/track-ui.js +9 -8
  119. data/vendor/assets/javascripts/webshims/shims/track.js +17 -11
  120. metadata +6 -6
  121. data/vendor/assets/javascripts/webshims/minified/shims/form-native-fix.js +0 -7
  122. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/README +0 -62
  123. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/README +0 -82
  124. data/vendor/assets/javascripts/webshims/shims/form-native-fix.js +0 -261
@@ -1,1317 +1,1322 @@
1
- jQuery.webshims.register('form-datalist', function($, webshims, window, document, undefined){
2
- var doc = document;
3
-
4
- /*
5
- * implement propType "element" currently only used for list-attribute (will be moved to dom-extend, if needed)
6
- */
7
- webshims.propTypes.element = function(descs){
8
- webshims.createPropDefault(descs, 'attr');
9
- if(descs.prop){return;}
10
- descs.prop = {
11
- get: function(){
12
- var elem = descs.attr.get.call(this);
13
- if(elem){
14
- elem = document.getElementById(elem);
15
- if(elem && descs.propNodeName && !$.nodeName(elem, descs.propNodeName)){
16
- elem = null;
17
- }
18
- }
19
- return elem || null;
20
- },
21
- writeable: false
22
- };
23
- };
24
-
25
-
26
- /*
27
- * Implements datalist element and list attribute
28
- */
29
-
30
- (function(){
31
- var formsCFG = $.webshims.cfg.forms;
32
- var listSupport = Modernizr.input.list;
33
- if(listSupport && !formsCFG.customDatalist){return;}
34
-
35
- var initializeDatalist = function(){
36
-
37
-
38
- if(!listSupport){
39
- webshims.defineNodeNameProperty('datalist', 'options', {
40
- prop: {
41
- writeable: false,
42
- get: function(){
43
- var elem = this;
44
- var select = $('select', elem);
45
- var options;
46
- if(select[0]){
47
- options = select[0].options;
48
- } else {
49
- options = $('option', elem).get();
50
- if(options.length){
51
- webshims.warn('you should wrap your option-elements for a datalist in a select element to support IE and other old browsers.');
52
- }
53
- }
54
- return options;
55
- }
56
- }
57
- });
58
- }
59
-
60
- var inputListProto = {
61
- //override autocomplete
62
- autocomplete: {
63
- attr: {
64
- get: function(){
65
- var elem = this;
66
- var data = $.data(elem, 'datalistWidget');
67
- if(data){
68
- return data._autocomplete;
69
- }
70
- return ('autocomplete' in elem) ? elem.autocomplete : elem.getAttribute('autocomplete');
71
- },
72
- set: function(value){
73
- var elem = this;
74
- var data = $.data(elem, 'datalistWidget');
75
- if(data){
76
- data._autocomplete = value;
77
- if(value == 'off'){
78
- data.hideList();
79
- }
80
- } else {
81
- if('autocomplete' in elem){
82
- elem.autocomplete = value;
83
- } else {
84
- elem.setAttribute('autocomplete', value);
85
- }
86
- }
87
- }
88
- }
89
- }
90
- };
91
-
92
- // if(formsCFG.customDatalist && (!listSupport || !('selectedOption') in $('<input />')[0])){
93
- // //currently not supported x-browser (FF4 has not implemented and is not polyfilled )
94
- // inputListProto.selectedOption = {
95
- // prop: {
96
- // writeable: false,
97
- // get: function(){
98
- // var elem = this;
99
- // var list = $.prop(elem, 'list');
100
- // var ret = null;
101
- // var value, options;
102
- // if(!list){return ret;}
103
- // value = $.prop(elem, 'value');
104
- // if(!value){return ret;}
105
- // options = $.prop(list, 'options');
106
- // if(!options.length){return ret;}
107
- // $.each(options, function(i, option){
108
- // if(value == $.prop(option, 'value')){
109
- // ret = option;
110
- // return false;
111
- // }
112
- // });
113
- // return ret;
114
- // }
115
- // }
116
- // };
117
- // }
118
-
119
- if(!listSupport){
120
- inputListProto['list'] = {
121
- attr: {
122
- get: function(){
123
- var val = webshims.contentAttr(this, 'list');
124
- return (val == null) ? undefined : val;
125
- },
126
- set: function(value){
127
- var elem = this;
128
- webshims.contentAttr(elem, 'list', value);
129
- webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
130
- }
131
- },
132
- initAttr: true,
133
- reflect: true,
134
- propType: 'element',
135
- propNodeName: 'datalist'
136
- };
137
- } else {
138
- //options only return options, if option-elements are rooted: but this makes this part of HTML5 less backwards compatible
139
- if(!($('<datalist><select><option></option></select></datalist>').prop('options') || []).length ){
140
- webshims.defineNodeNameProperty('datalist', 'options', {
141
- prop: {
142
- writeable: false,
143
- get: function(){
144
- var options = this.options || [];
145
- if(!options.length){
146
- var elem = this;
147
- var select = $('select', elem);
148
- if(select[0] && select[0].options && select[0].options.length){
149
- options = select[0].options;
150
- }
151
- }
152
- return options;
153
- }
154
- }
155
- });
156
- }
157
- inputListProto['list'] = {
158
- attr: {
159
- get: function(){
160
- var val = webshims.contentAttr(this, 'list');
161
- if(val != null){
162
- this.removeAttribute('list');
163
- } else {
164
- val = $.data(this, 'datalistListAttr');
165
- }
166
-
167
- return (val == null) ? undefined : val;
168
- },
169
- set: function(value){
170
- var elem = this;
171
- $.data(elem, 'datalistListAttr', value);
172
- webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
173
- }
174
- },
175
- initAttr: true,
176
- reflect: true,
177
- propType: 'element',
178
- propNodeName: 'datalist'
179
- };
180
- }
181
-
182
-
183
- webshims.defineNodeNameProperties('input', inputListProto);
184
-
185
- if($.event.customEvent){
186
- $.event.customEvent.updateDatalist = true;
187
- $.event.customEvent.updateInput = true;
188
- $.event.customEvent.datalistselect = true;
189
- }
190
- webshims.addReady(function(context, contextElem){
191
- contextElem
192
- .filter('datalist > select, datalist, datalist > option, datalist > select > option')
193
- .closest('datalist')
194
- .triggerHandler('updateDatalist')
195
- ;
196
-
197
- });
198
-
199
-
200
- };
201
-
202
-
203
- /*
204
- * ShadowList
205
- */
206
- var listidIndex = 0;
207
-
208
- var noDatalistSupport = {
209
- submit: 1,
210
- button: 1,
211
- reset: 1,
212
- hidden: 1,
213
-
214
- //ToDo
215
- range: 1,
216
- date: 1
217
- };
218
- var lteie6 = ($.browser.msie && parseInt($.browser.version, 10) < 7);
219
- var globStoredOptions = {};
220
- var getStoredOptions = function(name){
221
- if(!name){return [];}
222
- if(globStoredOptions[name]){
223
- return globStoredOptions[name];
224
- }
225
- var data;
226
- try {
227
- data = JSON.parse(localStorage.getItem('storedDatalistOptions'+name));
228
- } catch(e){}
229
- globStoredOptions[name] = data || [];
230
- return data || [];
231
- };
232
- var storeOptions = function(name, val){
233
- if(!name){return;}
234
- val = val || [];
235
- try {
236
- localStorage.setItem( 'storedDatalistOptions'+name, JSON.stringify(val) );
237
- } catch(e){}
238
- };
239
-
240
- var getText = function(elem){
241
- return (elem.textContent || elem.innerText || $.text([ elem ]) || '');
242
- };
243
-
244
- var shadowListProto = {
245
- _create: function(opts){
246
-
247
- if(noDatalistSupport[$.prop(opts.input, 'type')]){return;}
248
- var datalist = opts.datalist;
249
- var data = $.data(opts.input, 'datalistWidget');
250
- if(datalist && data && data.datalist !== datalist){
251
- data.datalist = datalist;
252
- data.id = opts.id;
253
-
254
- data.shadowList.prop('className', 'datalist-polyfill '+ (data.datalist.className || '') + ' '+ data.datalist.id +'-shadowdom');
255
- if(formsCFG.positionDatalist){
256
- data.shadowList.insertAfter(opts.input);
257
- } else {
258
- data.shadowList.appendTo('body');
259
- }
260
- $(data.datalist)
261
- .unbind('updateDatalist.datalistWidget')
262
- .bind('updateDatalist.datalistWidget', $.proxy(data, '_resetListCached'))
263
- ;
264
- data._resetListCached();
265
- return;
266
- } else if(!datalist){
267
- if(data){
268
- data.destroy();
269
- }
270
- return;
271
- } else if(data && data.datalist === datalist){
272
- return;
273
- }
274
- listidIndex++;
275
- var that = this;
276
- this.hideList = $.proxy(that, 'hideList');
277
- this.timedHide = function(){
278
- clearTimeout(that.hideTimer);
279
- that.hideTimer = setTimeout(that.hideList, 9);
280
- };
281
- this.datalist = datalist;
282
- this.id = opts.id;
283
- this.hasViewableData = true;
284
- this._autocomplete = $.attr(opts.input, 'autocomplete');
285
- $.data(opts.input, 'datalistWidget', this);
286
- this.shadowList = $('<div class="datalist-polyfill '+ (this.datalist.className || '') + ' '+ this.datalist.id +'-shadowdom' +'" />');
287
-
288
- if(formsCFG.positionDatalist || $(opts.input).hasClass('position-datalist')){
289
- this.shadowList.insertAfter(opts.input);
290
- } else {
291
- this.shadowList.appendTo('body');
292
- }
293
-
294
- this.index = -1;
295
- this.input = opts.input;
296
- this.arrayOptions = [];
297
-
298
- this.shadowList
299
- .delegate('li', 'mouseenter.datalistWidget mousedown.datalistWidget click.datalistWidget', function(e){
300
- var items = $('li:not(.hidden-item)', that.shadowList);
301
- var select = (e.type == 'mousedown' || e.type == 'click');
302
- that.markItem(items.index(e.currentTarget), select, items);
303
- if(e.type == 'click'){
304
- that.hideList();
305
- if(formsCFG.customDatalist){
306
- $(opts.input).trigger('datalistselect');
307
- }
308
- }
309
- return (e.type != 'mousedown');
310
- })
311
- .bind('focusout', this.timedHide)
312
- ;
313
-
314
- opts.input.setAttribute('autocomplete', 'off');
315
-
316
- $(opts.input)
317
- .attr({
318
- //role: 'combobox',
319
- 'aria-haspopup': 'true'
320
- })
321
- .bind('input.datalistWidget', function(){
322
- if(!that.triggeredByDatalist){
323
- that.changedValue = false;
324
- that.showHideOptions();
325
- }
326
- })
327
-
328
- .bind('keydown.datalistWidget', function(e){
329
- var keyCode = e.keyCode;
330
- var activeItem;
331
- var items;
332
- if(keyCode == 40 && !that.showList()){
333
- that.markItem(that.index + 1, true);
334
- return false;
335
- }
336
-
337
- if(!that.isListVisible){return;}
338
-
339
-
340
- if(keyCode == 38){
341
- that.markItem(that.index - 1, true);
342
- return false;
343
- }
344
- if(!e.shiftKey && (keyCode == 33 || keyCode == 36)){
345
- that.markItem(0, true);
346
- return false;
347
- }
348
- if(!e.shiftKey && (keyCode == 34 || keyCode == 35)){
349
- items = $('li:not(.hidden-item)', that.shadowList);
350
- that.markItem(items.length - 1, true, items);
351
- return false;
352
- }
353
- if(keyCode == 13 || keyCode == 27){
354
- if (keyCode == 13){
355
- activeItem = $('li.active-item:not(.hidden-item)', that.shadowList);
356
- that.changeValue( $('li.active-item:not(.hidden-item)', that.shadowList) );
357
- }
358
- that.hideList();
359
- if(formsCFG.customDatalist && activeItem && activeItem[0]){
360
- $(opts.input).trigger('datalistselect');
361
- }
362
- return false;
363
- }
364
- })
365
- .bind('focus.datalistWidget', function(){
366
- if($(this).hasClass('list-focus')){
367
- that.showList();
368
- }
369
- })
370
- .bind('mousedown.datalistWidget', function(){
371
- if($(this).is(':focus')){
372
- that.showList();
373
- }
374
- })
375
- .bind('blur.datalistWidget', this.timedHide)
376
- ;
377
-
378
-
379
- $(this.datalist)
380
- .unbind('updateDatalist.datalistWidget')
381
- .bind('updateDatalist.datalistWidget', $.proxy(this, '_resetListCached'))
382
- ;
383
-
384
- this._resetListCached();
385
-
386
- if(opts.input.form && (opts.input.name || opts.input.id)){
387
- $(opts.input.form).bind('submit.datalistWidget'+opts.input.id, function(){
388
- if(!$(opts.input).hasClass('no-datalist-cache') && that._autocomplete != 'off'){
389
- var val = $.prop(opts.input, 'value');
390
- var name = (opts.input.name || opts.input.id) + $.prop(opts.input, 'type');
391
- if(!that.storedOptions){
392
- that.storedOptions = getStoredOptions( name );
393
- }
394
- if(val && that.storedOptions.indexOf(val) == -1){
395
- that.storedOptions.push(val);
396
- storeOptions(name, that.storedOptions );
397
- }
398
- }
399
- });
400
- }
401
- $(window).bind('unload.datalist'+this.id+' beforeunload.datalist'+this.id, function(){
402
- that.destroy();
403
- });
404
- },
405
- destroy: function(){
406
- var autocomplete = $.attr(this.input, 'autocomplete');
407
- $(this.input)
408
- .unbind('.datalistWidget')
409
- .removeData('datalistWidget')
410
- ;
411
- this.shadowList.remove();
412
- $(document).unbind('.datalist'+this.id);
413
- $(window).unbind('.datalist'+this.id);
414
- if(this.input.form && this.input.id){
415
- $(this.input.form).unbind('submit.datalistWidget'+this.input.id);
416
- }
417
- this.input.removeAttribute('aria-haspopup');
418
- if(autocomplete === undefined){
419
- this.input.removeAttribute('autocomplete');
420
- } else {
421
- $(this.input).attr('autocomplete', autocomplete);
422
- }
423
- },
424
- _resetListCached: function(e){
425
- var that = this;
426
- var forceShow;
427
- this.needsUpdate = true;
428
- this.lastUpdatedValue = false;
429
- this.lastUnfoundValue = '';
430
-
431
- if(!this.updateTimer){
432
- if(window.QUnit || (forceShow = (e && document.activeElement == that.input))){
433
- that.updateListOptions(forceShow);
434
- } else {
435
- webshims.ready('WINDOWLOAD', function(){
436
- that.updateTimer = setTimeout(function(){
437
- that.updateListOptions();
438
- that = null;
439
- listidIndex = 1;
440
- }, 200 + (100 * listidIndex));
441
- });
442
- }
443
- }
444
- },
445
- updateListOptions: function(_forceShow){
446
- this.needsUpdate = false;
447
- clearTimeout(this.updateTimer);
448
- this.updateTimer = false;
449
- this.shadowList
450
- .css({
451
- fontSize: $.css(this.input, 'fontSize'),
452
- fontFamily: $.css(this.input, 'fontFamily')
453
- })
454
- ;
455
- this.searchStart = formsCFG.customDatalist && $(this.input).hasClass('search-start');
456
-
457
- var list = [];
458
-
459
- var values = [];
460
- var allOptions = [];
461
- var rElem, rItem, rOptions, rI, rLen, item;
462
- for(rOptions = $.prop(this.datalist, 'options'), rI = 0, rLen = rOptions.length; rI < rLen; rI++){
463
- rElem = rOptions[rI];
464
- if(rElem.disabled){return;}
465
- rItem = {
466
- value: $(rElem).val() || '',
467
- text: $.trim($.attr(rElem, 'label') || getText(rElem)),
468
- className: rElem.className || '',
469
- style: $.attr(rElem, 'style') || ''
470
- };
471
- if(!rItem.text){
472
- rItem.text = rItem.value;
473
- } else if(rItem.text != rItem.value){
474
- rItem.className += ' different-label-value';
475
- }
476
- values[rI] = rItem.value;
477
- allOptions[rI] = rItem;
478
- }
479
-
480
- if(!this.storedOptions){
481
- this.storedOptions = ($(this.input).hasClass('no-datalist-cache') || this._autocomplete == 'off') ? [] : getStoredOptions((this.input.name || this.input.id) + $.prop(this.input, 'type'));
482
- }
483
-
484
- this.storedOptions.forEach(function(val, i){
485
- if(values.indexOf(val) == -1){
486
- allOptions.push({value: val, text: val, className: 'stored-suggest', style: ''});
487
- }
488
- });
489
-
490
- for(rI = 0, rLen = allOptions.length; rI < rLen; rI++){
491
- item = allOptions[rI];
492
- list[rI] = '<li class="'+ item.className +'" style="'+ item.style +'" tabindex="-1" role="listitem"><span class="option-label">'+ item.text +'</span> <span class="option-value">'+item.value+'</span></li>';
493
- }
494
-
495
- this.arrayOptions = allOptions;
496
- this.shadowList.html('<div class="datalist-outer-box"><div class="datalist-box"><ul role="list">'+ list.join("\n") +'</ul></div></div>');
497
-
498
- if($.fn.bgIframe && lteie6){
499
- this.shadowList.bgIframe();
500
- }
501
-
502
- if(_forceShow || this.isListVisible){
503
- this.showHideOptions();
504
- }
505
- },
506
- showHideOptions: function(_fromShowList){
507
- var value = $.prop(this.input, 'value').toLowerCase();
508
- //first check prevent infinite loop, second creates simple lazy optimization
509
- if(value === this.lastUpdatedValue || (this.lastUnfoundValue && value.indexOf(this.lastUnfoundValue) === 0)){
510
- return;
511
- }
512
-
513
- this.lastUpdatedValue = value;
514
- var found = false;
515
- var startSearch = this.searchStart;
516
- var lis = $('li', this.shadowList);
517
- if(value){
518
- this.arrayOptions.forEach(function(item, i){
519
- var search;
520
- if(!('lowerText' in item)){
521
- if(item.text != item.value){
522
- item.lowerText = item.value.toLowerCase() + item.text.toLowerCase();
523
- } else {
524
- item.lowerText = item.text.toLowerCase();
525
- }
526
- }
527
- search = item.lowerText.indexOf(value);
528
- search = startSearch ? !search : search !== -1;
529
- if(search){
530
- $(lis[i]).removeClass('hidden-item');
531
- found = true;
532
- } else {
533
- $(lis[i]).addClass('hidden-item');
534
- }
535
- });
536
- } else if(lis.length) {
537
- lis.removeClass('hidden-item');
538
- found = true;
539
- }
540
-
541
- this.hasViewableData = found;
542
- if(!_fromShowList && found){
543
- this.showList();
544
- }
545
- if(!found){
546
- this.lastUnfoundValue = value;
547
- this.hideList();
548
- }
549
- },
550
- setPos: function(){
551
- this.shadowList.css({marginTop: 0, marginLeft: 0, marginRight: 0, marginBottom: 0});
552
- var css = (formsCFG.positionDatalist) ? $(this.input).position() : webshims.getRelOffset(this.shadowList, this.input);
553
- css.top += $(this.input).outerHeight();
554
- css.width = $(this.input).outerWidth() - (parseInt(this.shadowList.css('borderLeftWidth'), 10) || 0) - (parseInt(this.shadowList.css('borderRightWidth'), 10) || 0);
555
- this.shadowList.css({marginTop: '', marginLeft: '', marginRight: '', marginBottom: ''}).css(css);
556
- return css;
557
- },
558
- showList: function(){
559
- if(this.isListVisible){return false;}
560
- if(this.needsUpdate){
561
- this.updateListOptions();
562
- }
563
- this.showHideOptions(true);
564
- if(!this.hasViewableData){return false;}
565
- this.isListVisible = true;
566
- var that = this;
567
-
568
- that.setPos();
569
- that.shadowList.addClass('datalist-visible').find('li.active-item').removeClass('active-item');
570
-
571
- $(window).unbind('.datalist'+that.id);
572
- $(document)
573
- .unbind('.datalist'+that.id)
574
- .bind('mousedown.datalist'+that.id +' focusin.datalist'+that.id, function(e){
575
- if(e.target === that.input || that.shadowList[0] === e.target || $.contains( that.shadowList[0], e.target )){
576
- clearTimeout(that.hideTimer);
577
- setTimeout(function(){
578
- clearTimeout(that.hideTimer);
579
- }, 9);
580
- } else {
581
- that.timedHide();
582
- }
583
- })
584
- .bind('updateshadowdom.datalist'+that.id, function(){
585
- that.setPos();
586
- })
587
- ;
588
- return true;
589
- },
590
- hideList: function(){
591
- if(!this.isListVisible){return false;}
592
- var that = this;
593
- var triggerChange = function(e){
594
- if(that.changedValue){
595
- $(that.input).trigger('change');
596
- }
597
- that.changedValue = false;
598
- };
599
-
600
- that.shadowList.removeClass('datalist-visible list-item-active');
601
- that.index = -1;
602
- that.isListVisible = false;
603
- if(that.changedValue){
604
- that.triggeredByDatalist = true;
605
- webshims.triggerInlineForm && webshims.triggerInlineForm(that.input, 'input');
606
- if($(that.input).is(':focus')){
607
- $(that.input).one('blur', triggerChange);
608
- } else {
609
- triggerChange();
610
- }
611
- that.triggeredByDatalist = false;
612
- }
613
- $(document).unbind('.datalist'+that.id);
614
- $(window)
615
- .unbind('.datalist'+that.id)
616
- .one('resize.datalist'+that.id, function(){
617
- that.shadowList.css({top: 0, left: 0});
618
- })
619
- ;
620
- return true;
621
- },
622
- scrollIntoView: function(elem){
623
- var ul = $('ul', this.shadowList);
624
- var div = $('div.datalist-box', this.shadowList);
625
- var elemPos = elem.position();
626
- var containerHeight;
627
- elemPos.top -= (parseInt(ul.css('paddingTop'), 10) || 0) + (parseInt(ul.css('marginTop'), 10) || 0) + (parseInt(ul.css('borderTopWidth'), 10) || 0);
628
- if(elemPos.top < 0){
629
- div.scrollTop( div.scrollTop() + elemPos.top - 2);
630
- return;
631
- }
632
- elemPos.top += elem.outerHeight();
633
- containerHeight = div.height();
634
- if(elemPos.top > containerHeight){
635
- div.scrollTop( div.scrollTop() + (elemPos.top - containerHeight) + 2);
636
- }
637
- },
638
- changeValue: function(activeItem){
639
- if(!activeItem[0]){return;}
640
- var newValue = $('span.option-value', activeItem).text();
641
- var oldValue = $.prop(this.input, 'value');
642
- if(newValue != oldValue){
643
- $(this.input)
644
- .prop('value', newValue)
645
- .triggerHandler('updateInput')
646
- ;
647
- this.changedValue = true;
648
- }
649
- },
650
- markItem: function(index, doValue, items){
651
- var activeItem;
652
- var goesUp;
653
-
654
- items = items || $('li:not(.hidden-item)', this.shadowList);
655
- if(!items.length){return;}
656
- if(index < 0){
657
- index = items.length - 1;
658
- } else if(index >= items.length){
659
- index = 0;
660
- }
661
- items.removeClass('active-item');
662
- this.shadowList.addClass('list-item-active');
663
- activeItem = items.filter(':eq('+ index +')').addClass('active-item');
664
-
665
- if(doValue){
666
- this.changeValue(activeItem);
667
- this.scrollIntoView(activeItem);
668
- }
669
- this.index = index;
670
- }
671
- };
672
-
673
- //init datalist update
674
- initializeDatalist();
675
- })();
676
-
677
- });jQuery.webshims.register('form-extend', function($, webshims, window, doc, undefined, options){
678
- "use strict";
679
- var Modernizr = window.Modernizr;
680
- var modernizrInputTypes = Modernizr.inputtypes;
681
- if(!Modernizr.formvalidation || webshims.bugs.bustedValidity){return;}
682
- var typeModels = webshims.inputTypes;
683
- var validityRules = {};
684
-
685
- webshims.addInputType = function(type, obj){
686
- typeModels[type] = obj;
687
- };
688
-
689
- webshims.addValidityRule = function(type, fn){
690
- validityRules[type] = fn;
691
- };
692
-
693
- webshims.addValidityRule('typeMismatch',function (input, val, cache, validityState){
694
- if(val === ''){return false;}
695
- var ret = validityState.typeMismatch;
696
- if(!('type' in cache)){
697
- cache.type = (input[0].getAttribute('type') || '').toLowerCase();
698
- }
699
-
700
- if(typeModels[cache.type] && typeModels[cache.type].mismatch){
701
- ret = typeModels[cache.type].mismatch(val, input);
702
- }
703
- return ret;
704
- });
705
-
706
- var overrideNativeMessages = options.overrideMessages;
707
-
708
- var overrideValidity = (!modernizrInputTypes.number || !modernizrInputTypes.time || !modernizrInputTypes.range || overrideNativeMessages);
709
- var validityProps = ['customError','typeMismatch','rangeUnderflow','rangeOverflow','stepMismatch','tooLong','patternMismatch','valueMissing','valid'];
710
-
711
- var validityChanger = (overrideNativeMessages)? ['value', 'checked'] : ['value'];
712
- var validityElements = [];
713
- var testValidity = function(elem, init){
714
- if(!elem){return;}
715
- var type = (elem.getAttribute && elem.getAttribute('type') || elem.type || '').toLowerCase();
716
-
717
- if(!overrideNativeMessages && !typeModels[type]){
718
- return;
719
- }
720
-
721
- if(overrideNativeMessages && !init && type == 'radio' && elem.name){
722
- $(doc.getElementsByName( elem.name )).each(function(){
723
- $.prop(this, 'validity');
724
- });
725
- } else {
726
- $.prop(elem, 'validity');
727
- }
728
- };
729
-
730
- var oldSetCustomValidity = {};
731
- ['input', 'textarea', 'select'].forEach(function(name){
732
- var desc = webshims.defineNodeNameProperty(name, 'setCustomValidity', {
733
- prop: {
734
- value: function(error){
735
- error = error+'';
736
- var elem = (name == 'input') ? $(this).getNativeElement()[0] : this;
737
- desc.prop._supvalue.call(elem, error);
738
-
739
- if(webshims.bugs.validationMessage){
740
- webshims.data(elem, 'customvalidationMessage', error);
741
- }
742
- if(overrideValidity){
743
- webshims.data(elem, 'hasCustomError', !!(error));
744
- testValidity(elem);
745
- }
746
- }
747
- }
748
- });
749
- oldSetCustomValidity[name] = desc.prop._supvalue;
750
- });
751
-
752
-
753
- if(overrideValidity || overrideNativeMessages){
754
- validityChanger.push('min');
755
- validityChanger.push('max');
756
- validityChanger.push('step');
757
- validityElements.push('input');
758
- }
759
- if(overrideNativeMessages){
760
- validityChanger.push('required');
761
- validityChanger.push('pattern');
762
- validityElements.push('select');
763
- validityElements.push('textarea');
764
- }
765
-
766
- if(overrideValidity){
767
- var stopValidity;
768
- validityElements.forEach(function(nodeName){
769
-
770
- var oldDesc = webshims.defineNodeNameProperty(nodeName, 'validity', {
771
- prop: {
772
- get: function(){
773
- if(stopValidity){return;}
774
- var elem = (nodeName == 'input') ? $(this).getNativeElement()[0] : this;
775
-
776
- var validity = oldDesc.prop._supget.call(elem);
777
-
778
- if(!validity){
779
- return validity;
780
- }
781
- var validityState = {};
782
- validityProps.forEach(function(prop){
783
- validityState[prop] = validity[prop];
784
- });
785
-
786
- if( !$.prop(elem, 'willValidate') ){
787
- return validityState;
788
- }
789
- stopValidity = true;
790
- var jElm = $(elem),
791
- cache = {type: (elem.getAttribute && elem.getAttribute('type') || '').toLowerCase(), nodeName: (elem.nodeName || '').toLowerCase()},
792
- val = jElm.val(),
793
- customError = !!(webshims.data(elem, 'hasCustomError')),
794
- setCustomMessage
795
- ;
796
- stopValidity = false;
797
- validityState.customError = customError;
798
-
799
- if( validityState.valid && validityState.customError ){
800
- validityState.valid = false;
801
- } else if(!validityState.valid) {
802
- var allFalse = true;
803
- $.each(validityState, function(name, prop){
804
- if(prop){
805
- allFalse = false;
806
- return false;
807
- }
808
- });
809
-
810
- if(allFalse){
811
- validityState.valid = true;
812
- }
813
-
814
- }
815
-
816
- $.each(validityRules, function(rule, fn){
817
- validityState[rule] = fn(jElm, val, cache, validityState);
818
- if( validityState[rule] && (validityState.valid || !setCustomMessage) && (overrideNativeMessages || (typeModels[cache.type] && typeModels[cache.type].mismatch)) ) {
819
- oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, rule));
820
- validityState.valid = false;
821
- setCustomMessage = true;
822
- }
823
- });
824
- if(validityState.valid){
825
- oldSetCustomValidity[nodeName].call(elem, '');
826
- webshims.data(elem, 'hasCustomError', false);
827
- } else if(overrideNativeMessages && !setCustomMessage && !customError){
828
- $.each(validityState, function(name, prop){
829
- if(name !== 'valid' && prop){
830
- oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, name));
831
- return false;
832
- }
833
- });
834
- }
835
- return validityState;
836
- },
837
- writeable: false
838
-
839
- }
840
- });
841
- });
842
-
843
- validityChanger.forEach(function(prop){
844
- webshims.onNodeNamesPropertyModify(validityElements, prop, function(s){
845
- testValidity(this);
846
- });
847
- });
848
-
849
- if(doc.addEventListener){
850
- var inputThrottle;
851
- var testPassValidity = function(e){
852
- if(!('form' in e.target)){return;}
853
- var form = e.target.form;
854
- clearTimeout(inputThrottle);
855
- testValidity(e.target);
856
- if(form && overrideNativeMessages){
857
- $('input', form).each(function(){
858
- if(this.type == 'password'){
859
- testValidity(this);
860
- }
861
- });
862
- }
863
- };
864
-
865
- doc.addEventListener('change', testPassValidity, true);
866
-
867
- if(overrideNativeMessages){
868
- doc.addEventListener('blur', testPassValidity, true);
869
- doc.addEventListener('keydown', function(e){
870
- if(e.keyCode != 13){return;}
871
- testPassValidity(e);
872
- }, true);
873
- }
874
-
875
- doc.addEventListener('input', function(e){
876
- clearTimeout(inputThrottle);
877
- inputThrottle = setTimeout(function(){
878
- testValidity(e.target);
879
- }, 290);
880
- }, true);
881
- }
882
-
883
- var validityElementsSel = validityElements.join(',');
884
-
885
- webshims.addReady(function(context, elem){
886
- $(validityElementsSel, context).add(elem.filter(validityElementsSel)).each(function(){
887
- $.prop(this, 'validity');
888
- });
889
- });
890
-
891
-
892
- if(overrideNativeMessages){
893
- webshims.ready('DOM form-message', function(){
894
- webshims.activeLang({
895
- register: 'form-core',
896
- callback: function(){
897
- $('input, select, textarea')
898
- .getNativeElement()
899
- .each(function(){
900
- if(webshims.data(this, 'hasCustomError')){return;}
901
- var elem = this;
902
- var validity = $.prop(elem, 'validity') || {valid: true};
903
- var nodeName;
904
- if(validity.valid){return;}
905
- nodeName = (elem.nodeName || '').toLowerCase();
906
- $.each(validity, function(name, prop){
907
- if(name !== 'valid' && prop){
908
- oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, name));
909
- return false;
910
- }
911
- });
912
- })
913
- ;
914
- }
915
- });
916
- });
917
- }
918
-
919
- } //end: overrideValidity
920
-
921
- webshims.defineNodeNameProperty('input', 'type', {
922
- prop: {
923
- get: function(){
924
- var elem = this;
925
- var type = (elem.getAttribute('type') || '').toLowerCase();
926
- return (webshims.inputTypes[type]) ? type : elem.type;
927
- }
928
- }
929
- });
930
-
931
-
932
- });jQuery.webshims.register('form-number-date-api', function($, webshims, window, document, undefined){
933
- "use strict";
934
-
935
- //ToDo
936
- if(!webshims.getStep){
937
- webshims.getStep = function(elem, type){
938
- var step = $.attr(elem, 'step');
939
- if(step === 'any'){
940
- return step;
941
- }
942
- type = type || getType(elem);
943
- if(!typeModels[type] || !typeModels[type].step){
944
- return step;
945
- }
946
- step = typeProtos.number.asNumber(step);
947
- return ((!isNaN(step) && step > 0) ? step : typeModels[type].step) * typeModels[type].stepScaleFactor;
948
- };
949
- }
950
- if(!webshims.addMinMaxNumberToCache){
951
- webshims.addMinMaxNumberToCache = function(attr, elem, cache){
952
- if (!(attr+'AsNumber' in cache)) {
953
- cache[attr+'AsNumber'] = typeModels[cache.type].asNumber(elem.attr(attr));
954
- if(isNaN(cache[attr+'AsNumber']) && (attr+'Default' in typeModels[cache.type])){
955
- cache[attr+'AsNumber'] = typeModels[cache.type][attr+'Default'];
956
- }
957
- }
958
- };
959
- }
960
-
961
- var nan = parseInt('NaN', 10),
962
- doc = document,
963
- typeModels = webshims.inputTypes,
964
- isNumber = function(string){
965
- return (typeof string == 'number' || (string && string == string * 1));
966
- },
967
- supportsType = function(type){
968
- return ($('<input type="'+type+'" />').prop('type') === type);
969
- },
970
- getType = function(elem){
971
- return (elem.getAttribute('type') || '').toLowerCase();
972
- },
973
- isDateTimePart = function(string){
974
- return (isNumber(string) || (string && string == '0' + (string * 1)));
975
- },
976
- addMinMaxNumberToCache = webshims.addMinMaxNumberToCache,
977
- addleadingZero = function(val, len){
978
- val = ''+val;
979
- len = len - val.length;
980
- for(var i = 0; i < len; i++){
981
- val = '0'+val;
982
- }
983
- return val;
984
- },
985
- EPS = 1e-7,
986
- typeBugs = webshims.bugs.valueAsNumberSet || webshims.bugs.bustedValidity
987
- ;
988
-
989
- webshims.addValidityRule('stepMismatch', function(input, val, cache, validityState){
990
- if(val === ''){return false;}
991
- if(!('type' in cache)){
992
- cache.type = getType(input[0]);
993
- }
994
- //stepmismatch with date is computable, but it would be a typeMismatch (performance)
995
- if(cache.type == 'date'){
996
- return false;
997
- }
998
- var ret = (validityState || {}).stepMismatch, base;
999
- if(typeModels[cache.type] && typeModels[cache.type].step){
1000
- if( !('step' in cache) ){
1001
- cache.step = webshims.getStep(input[0], cache.type);
1002
- }
1003
-
1004
- if(cache.step == 'any'){return false;}
1005
-
1006
- if(!('valueAsNumber' in cache)){
1007
- cache.valueAsNumber = typeModels[cache.type].asNumber( val );
1008
- }
1009
- if(isNaN(cache.valueAsNumber)){return false;}
1010
-
1011
- addMinMaxNumberToCache('min', input, cache);
1012
- base = cache.minAsNumber;
1013
- if(isNaN(base)){
1014
- base = typeModels[cache.type].stepBase || 0;
1015
- }
1016
-
1017
- ret = Math.abs((cache.valueAsNumber - base) % cache.step);
1018
-
1019
- ret = !( ret <= EPS || Math.abs(ret - cache.step) <= EPS );
1020
- }
1021
- return ret;
1022
- });
1023
-
1024
-
1025
-
1026
- [{name: 'rangeOverflow', attr: 'max', factor: 1}, {name: 'rangeUnderflow', attr: 'min', factor: -1}].forEach(function(data, i){
1027
- webshims.addValidityRule(data.name, function(input, val, cache, validityState) {
1028
- var ret = (validityState || {})[data.name] || false;
1029
- if(val === ''){return ret;}
1030
- if (!('type' in cache)) {
1031
- cache.type = getType(input[0]);
1032
- }
1033
- if (typeModels[cache.type] && typeModels[cache.type].asNumber) {
1034
- if(!('valueAsNumber' in cache)){
1035
- cache.valueAsNumber = typeModels[cache.type].asNumber( val );
1036
- }
1037
- if(isNaN(cache.valueAsNumber)){
1038
- return false;
1039
- }
1040
-
1041
- addMinMaxNumberToCache(data.attr, input, cache);
1042
-
1043
- if(isNaN(cache[data.attr+'AsNumber'])){
1044
- return ret;
1045
- }
1046
- ret = ( cache[data.attr+'AsNumber'] * data.factor < cache.valueAsNumber * data.factor - EPS );
1047
- }
1048
- return ret;
1049
- });
1050
- });
1051
-
1052
- webshims.reflectProperties(['input'], ['max', 'min', 'step']);
1053
-
1054
-
1055
- //IDLs and methods, that aren't part of constrain validation, but strongly tight to it
1056
- var valueAsNumberDescriptor = webshims.defineNodeNameProperty('input', 'valueAsNumber', {
1057
- prop: {
1058
- get: function(){
1059
- var elem = this;
1060
- var type = getType(elem);
1061
- var ret = (typeModels[type] && typeModels[type].asNumber) ?
1062
- typeModels[type].asNumber($.prop(elem, 'value')) :
1063
- (valueAsNumberDescriptor.prop._supget && valueAsNumberDescriptor.prop._supget.apply(elem, arguments));
1064
- if(ret == null){
1065
- ret = nan;
1066
- }
1067
- return ret;
1068
- },
1069
- set: function(val){
1070
- var elem = this;
1071
- var type = getType(elem);
1072
- if(typeModels[type] && typeModels[type].numberToString){
1073
- //is NaN a number?
1074
- if(isNaN(val)){
1075
- $.prop(elem, 'value', '');
1076
- return;
1077
- }
1078
- var set = typeModels[type].numberToString(val);
1079
- if(set !== false){
1080
- $.prop(elem, 'value', set);
1081
- } else {
1082
- webshims.warn('INVALID_STATE_ERR: DOM Exception 11');
1083
- }
1084
- } else {
1085
- valueAsNumberDescriptor.prop._supset && valueAsNumberDescriptor.prop._supset.apply(elem, arguments);
1086
- }
1087
- }
1088
- }
1089
- });
1090
-
1091
- var valueAsDateDescriptor = webshims.defineNodeNameProperty('input', 'valueAsDate', {
1092
- prop: {
1093
- get: function(){
1094
- var elem = this;
1095
- var type = getType(elem);
1096
- return (typeModels[type] && typeModels[type].asDate && !typeModels[type].noAsDate) ?
1097
- typeModels[type].asDate($.prop(elem, 'value')) :
1098
- valueAsDateDescriptor.prop._supget && valueAsDateDescriptor.prop._supget.call(elem) || null;
1099
- },
1100
- set: function(value){
1101
- var elem = this;
1102
- var type = getType(elem);
1103
- if(typeModels[type] && typeModels[type].dateToString && !typeModels[type].noAsDate){
1104
-
1105
- if(value === null){
1106
- $.prop(elem, 'value', '');
1107
- return '';
1108
- }
1109
- var set = typeModels[type].dateToString(value);
1110
- if(set !== false){
1111
- $.prop(elem, 'value', set);
1112
- return set;
1113
- } else {
1114
- webshims.warn('INVALID_STATE_ERR: DOM Exception 11');
1115
- }
1116
- } else {
1117
- return valueAsDateDescriptor.prop._supset && valueAsDateDescriptor.prop._supset.apply(elem, arguments) || null;
1118
- }
1119
- }
1120
- }
1121
- });
1122
-
1123
- var typeProtos = {
1124
-
1125
- number: {
1126
- mismatch: function(val){
1127
- return !(isNumber(val));
1128
- },
1129
- step: 1,
1130
- //stepBase: 0, 0 = default
1131
- stepScaleFactor: 1,
1132
- asNumber: function(str){
1133
- return (isNumber(str)) ? str * 1 : nan;
1134
- },
1135
- numberToString: function(num){
1136
- return (isNumber(num)) ? num : false;
1137
- }
1138
- },
1139
-
1140
- range: {
1141
- minDefault: 0,
1142
- maxDefault: 100
1143
- },
1144
-
1145
- date: {
1146
- mismatch: function(val){
1147
- if(!val || !val.split || !(/\d$/.test(val))){return true;}
1148
- var valA = val.split(/\u002D/);
1149
- if(valA.length !== 3){return true;}
1150
- var ret = false;
1151
- $.each(valA, function(i, part){
1152
- if(!isDateTimePart(part)){
1153
- ret = true;
1154
- return false;
1155
- }
1156
- });
1157
- if(ret){return ret;}
1158
- if(valA[0].length !== 4 || valA[1].length != 2 || valA[1] > 12 || valA[2].length != 2 || valA[2] > 33){
1159
- ret = true;
1160
- }
1161
- return (val !== this.dateToString( this.asDate(val, true) ) );
1162
- },
1163
- step: 1,
1164
- //stepBase: 0, 0 = default
1165
- stepScaleFactor: 86400000,
1166
- asDate: function(val, _noMismatch){
1167
- if(!_noMismatch && this.mismatch(val)){
1168
- return null;
1169
- }
1170
- return new Date(this.asNumber(val, true));
1171
- },
1172
- asNumber: function(str, _noMismatch){
1173
- var ret = nan;
1174
- if(_noMismatch || !this.mismatch(str)){
1175
- str = str.split(/\u002D/);
1176
- ret = Date.UTC(str[0], str[1] - 1, str[2]);
1177
- }
1178
- return ret;
1179
- },
1180
- numberToString: function(num){
1181
- return (isNumber(num)) ? this.dateToString(new Date( num * 1)) : false;
1182
- },
1183
- dateToString: function(date){
1184
- return (date && date.getFullYear) ? date.getUTCFullYear() +'-'+ addleadingZero(date.getUTCMonth()+1, 2) +'-'+ addleadingZero(date.getUTCDate(), 2) : false;
1185
- }
1186
- },
1187
- time: {
1188
- mismatch: function(val, _getParsed){
1189
- if(!val || !val.split || !(/\d$/.test(val))){return true;}
1190
- val = val.split(/\u003A/);
1191
- if(val.length < 2 || val.length > 3){return true;}
1192
- var ret = false,
1193
- sFraction;
1194
- if(val[2]){
1195
- val[2] = val[2].split(/\u002E/);
1196
- sFraction = parseInt(val[2][1], 10);
1197
- val[2] = val[2][0];
1198
- }
1199
- $.each(val, function(i, part){
1200
- if(!isDateTimePart(part) || part.length !== 2){
1201
- ret = true;
1202
- return false;
1203
- }
1204
- });
1205
- if(ret){return true;}
1206
- if(val[0] > 23 || val[0] < 0 || val[1] > 59 || val[1] < 0){
1207
- return true;
1208
- }
1209
- if(val[2] && (val[2] > 59 || val[2] < 0 )){
1210
- return true;
1211
- }
1212
- if(sFraction && isNaN(sFraction)){
1213
- return true;
1214
- }
1215
- if(sFraction){
1216
- if(sFraction < 100){
1217
- sFraction *= 100;
1218
- } else if(sFraction < 10){
1219
- sFraction *= 10;
1220
- }
1221
- }
1222
- return (_getParsed === true) ? [val, sFraction] : false;
1223
- },
1224
- step: 60,
1225
- stepBase: 0,
1226
- stepScaleFactor: 1000,
1227
- asDate: function(val){
1228
- val = new Date(this.asNumber(val));
1229
- return (isNaN(val)) ? null : val;
1230
- },
1231
- asNumber: function(val){
1232
- var ret = nan;
1233
- val = this.mismatch(val, true);
1234
- if(val !== true){
1235
- ret = Date.UTC('1970', 0, 1, val[0][0], val[0][1], val[0][2] || 0);
1236
- if(val[1]){
1237
- ret += val[1];
1238
- }
1239
- }
1240
- return ret;
1241
- },
1242
- dateToString: function(date){
1243
- if(date && date.getUTCHours){
1244
- var str = addleadingZero(date.getUTCHours(), 2) +':'+ addleadingZero(date.getUTCMinutes(), 2),
1245
- tmp = date.getSeconds()
1246
- ;
1247
- if(tmp != "0"){
1248
- str += ':'+ addleadingZero(tmp, 2);
1249
- }
1250
- tmp = date.getUTCMilliseconds();
1251
- if(tmp != "0"){
1252
- str += '.'+ addleadingZero(tmp, 3);
1253
- }
1254
- return str;
1255
- } else {
1256
- return false;
1257
- }
1258
- }
1259
- }
1260
- // ,'datetime-local': {
1261
- // mismatch: function(val, _getParsed){
1262
- // if(!val || !val.split || (val+'special').split(/\u0054/).length !== 2){return true;}
1263
- // val = val.split(/\u0054/);
1264
- // return ( typeProtos.date.mismatch(val[0]) || typeProtos.time.mismatch(val[1], _getParsed) );
1265
- // },
1266
- // noAsDate: true,
1267
- // asDate: function(val){
1268
- // val = new Date(this.asNumber(val));
1269
- //
1270
- // return (isNaN(val)) ? null : val;
1271
- // },
1272
- // asNumber: function(val){
1273
- // var ret = nan;
1274
- // var time = this.mismatch(val, true);
1275
- // if(time !== true){
1276
- // val = val.split(/\u0054/)[0].split(/\u002D/);
1277
- //
1278
- // ret = Date.UTC(val[0], val[1] - 1, val[2], time[0][0], time[0][1], time[0][2] || 0);
1279
- // if(time[1]){
1280
- // ret += time[1];
1281
- // }
1282
- // }
1283
- // return ret;
1284
- // },
1285
- // dateToString: function(date, _getParsed){
1286
- // return typeProtos.date.dateToString(date) +'T'+ typeProtos.time.dateToString(date, _getParsed);
1287
- // }
1288
- // }
1289
- };
1290
-
1291
- if(typeBugs || !supportsType('range') || !supportsType('time')){
1292
- typeProtos.range = $.extend({}, typeProtos.number, typeProtos.range);
1293
- typeProtos.time = $.extend({}, typeProtos.date, typeProtos.time);
1294
- // typeProtos['datetime-local'] = $.extend({}, typeProtos.date, typeProtos.time, typeProtos['datetime-local']);
1295
- }
1296
-
1297
- if(typeBugs || !supportsType('number')){
1298
- webshims.addInputType('number', typeProtos.number);
1299
- }
1300
-
1301
- if(typeBugs || !supportsType('range')){
1302
- webshims.addInputType('range', typeProtos.range);
1303
- }
1304
- if(typeBugs || !supportsType('date')){
1305
- webshims.addInputType('date', typeProtos.date);
1306
- }
1307
- if(typeBugs || !supportsType('time')){
1308
- webshims.addInputType('time', typeProtos.time);
1309
- }
1310
-
1311
- // if(typeBugs || !supportsType('datetime-local')){
1312
- // webshims.addInputType('datetime-local', typeProtos['datetime-local']);
1313
- // }
1314
-
1
+ jQuery.webshims.register('form-datalist', function($, webshims, window, document, undefined){
2
+ "use strict";
3
+ var doc = document;
4
+
5
+ /*
6
+ * implement propType "element" currently only used for list-attribute (will be moved to dom-extend, if needed)
7
+ */
8
+ webshims.propTypes.element = function(descs){
9
+ webshims.createPropDefault(descs, 'attr');
10
+ if(descs.prop){return;}
11
+ descs.prop = {
12
+ get: function(){
13
+ var elem = descs.attr.get.call(this);
14
+ if(elem){
15
+ elem = document.getElementById(elem);
16
+ if(elem && descs.propNodeName && !$.nodeName(elem, descs.propNodeName)){
17
+ elem = null;
18
+ }
19
+ }
20
+ return elem || null;
21
+ },
22
+ writeable: false
23
+ };
24
+ };
25
+
26
+
27
+ /*
28
+ * Implements datalist element and list attribute
29
+ */
30
+
31
+ (function(){
32
+ var formsCFG = $.webshims.cfg.forms;
33
+ var listSupport = Modernizr.input.list;
34
+ if(listSupport && !formsCFG.customDatalist){return;}
35
+
36
+ var initializeDatalist = function(){
37
+
38
+
39
+ if(!listSupport){
40
+ webshims.defineNodeNameProperty('datalist', 'options', {
41
+ prop: {
42
+ writeable: false,
43
+ get: function(){
44
+ var elem = this;
45
+ var select = $('select', elem);
46
+ var options;
47
+ if(select[0]){
48
+ options = select[0].options;
49
+ } else {
50
+ options = $('option', elem).get();
51
+ if(options.length){
52
+ webshims.warn('you should wrap your option-elements for a datalist in a select element to support IE and other old browsers.');
53
+ }
54
+ }
55
+ return options;
56
+ }
57
+ }
58
+ });
59
+ }
60
+
61
+ var inputListProto = {
62
+ //override autocomplete
63
+ autocomplete: {
64
+ attr: {
65
+ get: function(){
66
+ var elem = this;
67
+ var data = $.data(elem, 'datalistWidget');
68
+ if(data){
69
+ return data._autocomplete;
70
+ }
71
+ return ('autocomplete' in elem) ? elem.autocomplete : elem.getAttribute('autocomplete');
72
+ },
73
+ set: function(value){
74
+ var elem = this;
75
+ var data = $.data(elem, 'datalistWidget');
76
+ if(data){
77
+ data._autocomplete = value;
78
+ if(value == 'off'){
79
+ data.hideList();
80
+ }
81
+ } else {
82
+ if('autocomplete' in elem){
83
+ elem.autocomplete = value;
84
+ } else {
85
+ elem.setAttribute('autocomplete', value);
86
+ }
87
+ }
88
+ }
89
+ }
90
+ }
91
+ };
92
+
93
+ // if(formsCFG.customDatalist && (!listSupport || !('selectedOption') in $('<input />')[0])){
94
+ // //currently not supported x-browser (FF4 has not implemented and is not polyfilled )
95
+ // inputListProto.selectedOption = {
96
+ // prop: {
97
+ // writeable: false,
98
+ // get: function(){
99
+ // var elem = this;
100
+ // var list = $.prop(elem, 'list');
101
+ // var ret = null;
102
+ // var value, options;
103
+ // if(!list){return ret;}
104
+ // value = $.prop(elem, 'value');
105
+ // if(!value){return ret;}
106
+ // options = $.prop(list, 'options');
107
+ // if(!options.length){return ret;}
108
+ // $.each(options, function(i, option){
109
+ // if(value == $.prop(option, 'value')){
110
+ // ret = option;
111
+ // return false;
112
+ // }
113
+ // });
114
+ // return ret;
115
+ // }
116
+ // }
117
+ // };
118
+ // }
119
+
120
+ if(!listSupport){
121
+ inputListProto['list'] = {
122
+ attr: {
123
+ get: function(){
124
+ var val = webshims.contentAttr(this, 'list');
125
+ return (val == null) ? undefined : val;
126
+ },
127
+ set: function(value){
128
+ var elem = this;
129
+ webshims.contentAttr(elem, 'list', value);
130
+ webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
131
+ }
132
+ },
133
+ initAttr: true,
134
+ reflect: true,
135
+ propType: 'element',
136
+ propNodeName: 'datalist'
137
+ };
138
+ } else {
139
+ //options only return options, if option-elements are rooted: but this makes this part of HTML5 less backwards compatible
140
+ if(!($('<datalist><select><option></option></select></datalist>').prop('options') || []).length ){
141
+ webshims.defineNodeNameProperty('datalist', 'options', {
142
+ prop: {
143
+ writeable: false,
144
+ get: function(){
145
+ var options = this.options || [];
146
+ if(!options.length){
147
+ var elem = this;
148
+ var select = $('select', elem);
149
+ if(select[0] && select[0].options && select[0].options.length){
150
+ options = select[0].options;
151
+ }
152
+ }
153
+ return options;
154
+ }
155
+ }
156
+ });
157
+ }
158
+ inputListProto['list'] = {
159
+ attr: {
160
+ get: function(){
161
+ var val = webshims.contentAttr(this, 'list');
162
+ if(val != null){
163
+ this.removeAttribute('list');
164
+ } else {
165
+ val = $.data(this, 'datalistListAttr');
166
+ }
167
+
168
+ return (val == null) ? undefined : val;
169
+ },
170
+ set: function(value){
171
+ var elem = this;
172
+ $.data(elem, 'datalistListAttr', value);
173
+ webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
174
+ }
175
+ },
176
+ initAttr: true,
177
+ reflect: true,
178
+ propType: 'element',
179
+ propNodeName: 'datalist'
180
+ };
181
+ }
182
+
183
+
184
+ webshims.defineNodeNameProperties('input', inputListProto);
185
+
186
+ if($.event.customEvent){
187
+ $.event.customEvent.updateDatalist = true;
188
+ $.event.customEvent.updateInput = true;
189
+ $.event.customEvent.datalistselect = true;
190
+ }
191
+ webshims.addReady(function(context, contextElem){
192
+ contextElem
193
+ .filter('datalist > select, datalist, datalist > option, datalist > select > option')
194
+ .closest('datalist')
195
+ .triggerHandler('updateDatalist')
196
+ ;
197
+
198
+ });
199
+
200
+
201
+ };
202
+
203
+
204
+ /*
205
+ * ShadowList
206
+ */
207
+ var listidIndex = 0;
208
+
209
+ var noDatalistSupport = {
210
+ submit: 1,
211
+ button: 1,
212
+ reset: 1,
213
+ hidden: 1,
214
+
215
+ //ToDo
216
+ range: 1,
217
+ date: 1
218
+ };
219
+ var lteie6 = ($.browser.msie && parseInt($.browser.version, 10) < 7);
220
+ var globStoredOptions = {};
221
+ var getStoredOptions = function(name){
222
+ if(!name){return [];}
223
+ if(globStoredOptions[name]){
224
+ return globStoredOptions[name];
225
+ }
226
+ var data;
227
+ try {
228
+ data = JSON.parse(localStorage.getItem('storedDatalistOptions'+name));
229
+ } catch(e){}
230
+ globStoredOptions[name] = data || [];
231
+ return data || [];
232
+ };
233
+ var storeOptions = function(name, val){
234
+ if(!name){return;}
235
+ val = val || [];
236
+ try {
237
+ localStorage.setItem( 'storedDatalistOptions'+name, JSON.stringify(val) );
238
+ } catch(e){}
239
+ };
240
+
241
+ var getText = function(elem){
242
+ return (elem.textContent || elem.innerText || $.text([ elem ]) || '');
243
+ };
244
+
245
+ var shadowListProto = {
246
+ _create: function(opts){
247
+
248
+ if(noDatalistSupport[$.prop(opts.input, 'type')]){return;}
249
+ var datalist = opts.datalist;
250
+ var data = $.data(opts.input, 'datalistWidget');
251
+ if(datalist && data && data.datalist !== datalist){
252
+ data.datalist = datalist;
253
+ data.id = opts.id;
254
+
255
+ data.shadowList.prop('className', 'datalist-polyfill '+ (data.datalist.className || '') + ' '+ data.datalist.id +'-shadowdom');
256
+ if(formsCFG.positionDatalist){
257
+ data.shadowList.insertAfter(opts.input);
258
+ } else {
259
+ data.shadowList.appendTo('body');
260
+ }
261
+ $(data.datalist)
262
+ .off('updateDatalist.datalistWidget')
263
+ .on('updateDatalist.datalistWidget', $.proxy(data, '_resetListCached'))
264
+ ;
265
+ data._resetListCached();
266
+ return;
267
+ } else if(!datalist){
268
+ if(data){
269
+ data.destroy();
270
+ }
271
+ return;
272
+ } else if(data && data.datalist === datalist){
273
+ return;
274
+ }
275
+ listidIndex++;
276
+ var that = this;
277
+ this.hideList = $.proxy(that, 'hideList');
278
+ this.timedHide = function(){
279
+ clearTimeout(that.hideTimer);
280
+ that.hideTimer = setTimeout(that.hideList, 9);
281
+ };
282
+ this.datalist = datalist;
283
+ this.id = opts.id;
284
+ this.hasViewableData = true;
285
+ this._autocomplete = $.attr(opts.input, 'autocomplete');
286
+ $.data(opts.input, 'datalistWidget', this);
287
+ this.shadowList = $('<div class="datalist-polyfill '+ (this.datalist.className || '') + ' '+ this.datalist.id +'-shadowdom' +'" />');
288
+
289
+ if(formsCFG.positionDatalist || $(opts.input).hasClass('position-datalist')){
290
+ this.shadowList.insertAfter(opts.input);
291
+ } else {
292
+ this.shadowList.appendTo('body');
293
+ }
294
+
295
+ this.index = -1;
296
+ this.input = opts.input;
297
+ this.arrayOptions = [];
298
+
299
+ this.shadowList
300
+ .delegate('li', 'mouseenter.datalistWidget mousedown.datalistWidget click.datalistWidget', function(e){
301
+ var items = $('li:not(.hidden-item)', that.shadowList);
302
+ var select = (e.type == 'mousedown' || e.type == 'click');
303
+ that.markItem(items.index(e.currentTarget), select, items);
304
+ if(e.type == 'click'){
305
+ that.hideList();
306
+ if(formsCFG.customDatalist){
307
+ $(opts.input).trigger('datalistselect');
308
+ }
309
+ }
310
+ return (e.type != 'mousedown');
311
+ })
312
+ .on('focusout', this.timedHide)
313
+ ;
314
+
315
+ opts.input.setAttribute('autocomplete', 'off');
316
+
317
+ $(opts.input)
318
+ .attr({
319
+ //role: 'combobox',
320
+ 'aria-haspopup': 'true'
321
+ })
322
+ .on({
323
+ 'input.datalistWidget': function(){
324
+ if(!that.triggeredByDatalist){
325
+ that.changedValue = false;
326
+ that.showHideOptions();
327
+ }
328
+ },
329
+ 'keydown.datalistWidget': function(e){
330
+ var keyCode = e.keyCode;
331
+ var activeItem;
332
+ var items;
333
+ if(keyCode == 40 && !that.showList()){
334
+ that.markItem(that.index + 1, true);
335
+ return false;
336
+ }
337
+
338
+ if(!that.isListVisible){return;}
339
+
340
+
341
+ if(keyCode == 38){
342
+ that.markItem(that.index - 1, true);
343
+ return false;
344
+ }
345
+ if(!e.shiftKey && (keyCode == 33 || keyCode == 36)){
346
+ that.markItem(0, true);
347
+ return false;
348
+ }
349
+ if(!e.shiftKey && (keyCode == 34 || keyCode == 35)){
350
+ items = $('li:not(.hidden-item)', that.shadowList);
351
+ that.markItem(items.length - 1, true, items);
352
+ return false;
353
+ }
354
+ if(keyCode == 13 || keyCode == 27){
355
+ if (keyCode == 13){
356
+ activeItem = $('li.active-item:not(.hidden-item)', that.shadowList);
357
+ that.changeValue( $('li.active-item:not(.hidden-item)', that.shadowList) );
358
+ }
359
+ that.hideList();
360
+ if(formsCFG.customDatalist && activeItem && activeItem[0]){
361
+ $(opts.input).trigger('datalistselect');
362
+ }
363
+ return false;
364
+ }
365
+ },
366
+ 'focus.datalistWidget': function(){
367
+ if($(this).hasClass('list-focus')){
368
+ that.showList();
369
+ }
370
+ },
371
+ 'mousedown.datalistWidget': function(){
372
+ if($(this).is(':focus')){
373
+ that.showList();
374
+ }
375
+ },
376
+ 'blur.datalistWidget': this.timedHide
377
+ })
378
+ ;
379
+
380
+
381
+ $(this.datalist)
382
+ .off('updateDatalist.datalistWidget')
383
+ .on('updateDatalist.datalistWidget', $.proxy(this, '_resetListCached'))
384
+ ;
385
+
386
+ this._resetListCached();
387
+
388
+ if(opts.input.form && (opts.input.name || opts.input.id)){
389
+ $(opts.input.form).on('submit.datalistWidget'+opts.input.id, function(){
390
+ if(!$(opts.input).hasClass('no-datalist-cache') && that._autocomplete != 'off'){
391
+ var val = $.prop(opts.input, 'value');
392
+ var name = (opts.input.name || opts.input.id) + $.prop(opts.input, 'type');
393
+ if(!that.storedOptions){
394
+ that.storedOptions = getStoredOptions( name );
395
+ }
396
+ if(val && that.storedOptions.indexOf(val) == -1){
397
+ that.storedOptions.push(val);
398
+ storeOptions(name, that.storedOptions );
399
+ }
400
+ }
401
+ });
402
+ }
403
+ $(window).on('unload.datalist'+this.id+' beforeunload.datalist'+this.id, function(){
404
+ that.destroy();
405
+ });
406
+ },
407
+ destroy: function(){
408
+ var autocomplete = $.attr(this.input, 'autocomplete');
409
+ $(this.input)
410
+ .off('.datalistWidget')
411
+ .removeData('datalistWidget')
412
+ ;
413
+ this.shadowList.remove();
414
+ $(document).off('.datalist'+this.id);
415
+ $(window).off('.datalist'+this.id);
416
+ if(this.input.form && this.input.id){
417
+ $(this.input.form).off('submit.datalistWidget'+this.input.id);
418
+ }
419
+ this.input.removeAttribute('aria-haspopup');
420
+ if(autocomplete === undefined){
421
+ this.input.removeAttribute('autocomplete');
422
+ } else {
423
+ $(this.input).attr('autocomplete', autocomplete);
424
+ }
425
+ },
426
+ _resetListCached: function(e){
427
+ var that = this;
428
+ var forceShow;
429
+ this.needsUpdate = true;
430
+ this.lastUpdatedValue = false;
431
+ this.lastUnfoundValue = '';
432
+
433
+ if(!this.updateTimer){
434
+ if(window.QUnit || (forceShow = (e && document.activeElement == that.input))){
435
+ that.updateListOptions(forceShow);
436
+ } else {
437
+ webshims.ready('WINDOWLOAD', function(){
438
+ that.updateTimer = setTimeout(function(){
439
+ that.updateListOptions();
440
+ that = null;
441
+ listidIndex = 1;
442
+ }, 200 + (100 * listidIndex));
443
+ });
444
+ }
445
+ }
446
+ },
447
+ maskHTML: function(str){
448
+ return str.replace(/</g, '&lt;').replace(/>/g, '&gt;');
449
+ },
450
+ updateListOptions: function(_forceShow){
451
+ this.needsUpdate = false;
452
+ clearTimeout(this.updateTimer);
453
+ this.updateTimer = false;
454
+ this.shadowList
455
+ .css({
456
+ fontSize: $.css(this.input, 'fontSize'),
457
+ fontFamily: $.css(this.input, 'fontFamily')
458
+ })
459
+ ;
460
+ this.searchStart = formsCFG.customDatalist && $(this.input).hasClass('search-start');
461
+
462
+ var list = [];
463
+
464
+ var values = [];
465
+ var allOptions = [];
466
+ var rElem, rItem, rOptions, rI, rLen, item;
467
+ for(rOptions = $.prop(this.datalist, 'options'), rI = 0, rLen = rOptions.length; rI < rLen; rI++){
468
+ rElem = rOptions[rI];
469
+ if(rElem.disabled){return;}
470
+ rItem = {
471
+ value: $(rElem).val() || '',
472
+ text: $.trim($.attr(rElem, 'label') || getText(rElem)),
473
+ className: rElem.className || '',
474
+ style: $.attr(rElem, 'style') || ''
475
+ };
476
+ if(!rItem.text){
477
+ rItem.text = rItem.value;
478
+ } else if(rItem.text != rItem.value){
479
+ rItem.className += ' different-label-value';
480
+ }
481
+ values[rI] = rItem.value;
482
+ allOptions[rI] = rItem;
483
+ }
484
+
485
+ if(!this.storedOptions){
486
+ this.storedOptions = ($(this.input).hasClass('no-datalist-cache') || this._autocomplete == 'off') ? [] : getStoredOptions((this.input.name || this.input.id) + $.prop(this.input, 'type'));
487
+ }
488
+
489
+ this.storedOptions.forEach(function(val, i){
490
+ if(values.indexOf(val) == -1){
491
+ allOptions.push({value: val, text: val, className: 'stored-suggest', style: ''});
492
+ }
493
+ });
494
+
495
+ for(rI = 0, rLen = allOptions.length; rI < rLen; rI++){
496
+ item = allOptions[rI];
497
+ list[rI] = '<li class="'+ item.className +'" style="'+ item.style +'" tabindex="-1" role="listitem"><span class="option-label">'+ this.maskHTML(item.text) +'</span> <span class="option-value">'+ this.maskHTML(item.value) +'</span></li>';
498
+ }
499
+
500
+ this.arrayOptions = allOptions;
501
+ this.shadowList.html('<div class="datalist-outer-box"><div class="datalist-box"><ul role="list">'+ list.join("\n") +'</ul></div></div>');
502
+
503
+ if($.fn.bgIframe && lteie6){
504
+ this.shadowList.bgIframe();
505
+ }
506
+
507
+ if(_forceShow || this.isListVisible){
508
+ this.showHideOptions();
509
+ }
510
+ },
511
+ showHideOptions: function(_fromShowList){
512
+ var value = $.prop(this.input, 'value').toLowerCase();
513
+ //first check prevent infinite loop, second creates simple lazy optimization
514
+ if(value === this.lastUpdatedValue || (this.lastUnfoundValue && value.indexOf(this.lastUnfoundValue) === 0)){
515
+ return;
516
+ }
517
+
518
+ this.lastUpdatedValue = value;
519
+ var found = false;
520
+ var startSearch = this.searchStart;
521
+ var lis = $('li', this.shadowList);
522
+ if(value){
523
+ this.arrayOptions.forEach(function(item, i){
524
+ var search;
525
+ if(!('lowerText' in item)){
526
+ if(item.text != item.value){
527
+ item.lowerText = item.value.toLowerCase() + item.text.toLowerCase();
528
+ } else {
529
+ item.lowerText = item.text.toLowerCase();
530
+ }
531
+ }
532
+ search = item.lowerText.indexOf(value);
533
+ search = startSearch ? !search : search !== -1;
534
+ if(search){
535
+ $(lis[i]).removeClass('hidden-item');
536
+ found = true;
537
+ } else {
538
+ $(lis[i]).addClass('hidden-item');
539
+ }
540
+ });
541
+ } else if(lis.length) {
542
+ lis.removeClass('hidden-item');
543
+ found = true;
544
+ }
545
+
546
+ this.hasViewableData = found;
547
+ if(!_fromShowList && found){
548
+ this.showList();
549
+ }
550
+ if(!found){
551
+ this.lastUnfoundValue = value;
552
+ this.hideList();
553
+ }
554
+ },
555
+ setPos: function(){
556
+ this.shadowList.css({marginTop: 0, marginLeft: 0, marginRight: 0, marginBottom: 0});
557
+ var css = (formsCFG.positionDatalist) ? $(this.input).position() : webshims.getRelOffset(this.shadowList, this.input);
558
+ css.top += $(this.input).outerHeight();
559
+ css.width = $(this.input).outerWidth() - (parseInt(this.shadowList.css('borderLeftWidth'), 10) || 0) - (parseInt(this.shadowList.css('borderRightWidth'), 10) || 0);
560
+ this.shadowList.css({marginTop: '', marginLeft: '', marginRight: '', marginBottom: ''}).css(css);
561
+ return css;
562
+ },
563
+ showList: function(){
564
+ if(this.isListVisible){return false;}
565
+ if(this.needsUpdate){
566
+ this.updateListOptions();
567
+ }
568
+ this.showHideOptions(true);
569
+ if(!this.hasViewableData){return false;}
570
+ this.isListVisible = true;
571
+ var that = this;
572
+
573
+ that.setPos();
574
+ that.shadowList.addClass('datalist-visible').find('li.active-item').removeClass('active-item');
575
+
576
+ $(window).unbind('.datalist'+that.id);
577
+ $(document)
578
+ .off('.datalist'+that.id)
579
+ .on('mousedown.datalist'+that.id +' focusin.datalist'+that.id, function(e){
580
+ if(e.target === that.input || that.shadowList[0] === e.target || $.contains( that.shadowList[0], e.target )){
581
+ clearTimeout(that.hideTimer);
582
+ setTimeout(function(){
583
+ clearTimeout(that.hideTimer);
584
+ }, 9);
585
+ } else {
586
+ that.timedHide();
587
+ }
588
+ })
589
+ .on('updateshadowdom.datalist'+that.id, function(){
590
+ that.setPos();
591
+ })
592
+ ;
593
+ return true;
594
+ },
595
+ hideList: function(){
596
+ if(!this.isListVisible){return false;}
597
+ var that = this;
598
+ var triggerChange = function(e){
599
+ if(that.changedValue){
600
+ $(that.input).trigger('change');
601
+ }
602
+ that.changedValue = false;
603
+ };
604
+
605
+ that.shadowList.removeClass('datalist-visible list-item-active');
606
+ that.index = -1;
607
+ that.isListVisible = false;
608
+ if(that.changedValue){
609
+ that.triggeredByDatalist = true;
610
+ webshims.triggerInlineForm && webshims.triggerInlineForm(that.input, 'input');
611
+ if($(that.input).is(':focus')){
612
+ $(that.input).one('blur', triggerChange);
613
+ } else {
614
+ triggerChange();
615
+ }
616
+ that.triggeredByDatalist = false;
617
+ }
618
+ $(document).unbind('.datalist'+that.id);
619
+ $(window)
620
+ .off('.datalist'+that.id)
621
+ .one('resize.datalist'+that.id, function(){
622
+ that.shadowList.css({top: 0, left: 0});
623
+ })
624
+ ;
625
+ return true;
626
+ },
627
+ scrollIntoView: function(elem){
628
+ var ul = $('ul', this.shadowList);
629
+ var div = $('div.datalist-box', this.shadowList);
630
+ var elemPos = elem.position();
631
+ var containerHeight;
632
+ elemPos.top -= (parseInt(ul.css('paddingTop'), 10) || 0) + (parseInt(ul.css('marginTop'), 10) || 0) + (parseInt(ul.css('borderTopWidth'), 10) || 0);
633
+ if(elemPos.top < 0){
634
+ div.scrollTop( div.scrollTop() + elemPos.top - 2);
635
+ return;
636
+ }
637
+ elemPos.top += elem.outerHeight();
638
+ containerHeight = div.height();
639
+ if(elemPos.top > containerHeight){
640
+ div.scrollTop( div.scrollTop() + (elemPos.top - containerHeight) + 2);
641
+ }
642
+ },
643
+ changeValue: function(activeItem){
644
+ if(!activeItem[0]){return;}
645
+ var newValue = $('span.option-value', activeItem).text();
646
+ var oldValue = $.prop(this.input, 'value');
647
+ if(newValue != oldValue){
648
+ $(this.input)
649
+ .prop('value', newValue)
650
+ .triggerHandler('updateInput')
651
+ ;
652
+ this.changedValue = true;
653
+ }
654
+ },
655
+ markItem: function(index, doValue, items){
656
+ var activeItem;
657
+ var goesUp;
658
+
659
+ items = items || $('li:not(.hidden-item)', this.shadowList);
660
+ if(!items.length){return;}
661
+ if(index < 0){
662
+ index = items.length - 1;
663
+ } else if(index >= items.length){
664
+ index = 0;
665
+ }
666
+ items.removeClass('active-item');
667
+ this.shadowList.addClass('list-item-active');
668
+ activeItem = items.filter(':eq('+ index +')').addClass('active-item');
669
+
670
+ if(doValue){
671
+ this.changeValue(activeItem);
672
+ this.scrollIntoView(activeItem);
673
+ }
674
+ this.index = index;
675
+ }
676
+ };
677
+
678
+ //init datalist update
679
+ initializeDatalist();
680
+ })();
681
+
682
+ });jQuery.webshims.register('form-extend', function($, webshims, window, doc, undefined, options){
683
+ "use strict";
684
+ var Modernizr = window.Modernizr;
685
+ var modernizrInputTypes = Modernizr.inputtypes;
686
+ if(!Modernizr.formvalidation || webshims.bugs.bustedValidity){return;}
687
+ var typeModels = webshims.inputTypes;
688
+ var validityRules = {};
689
+
690
+ webshims.addInputType = function(type, obj){
691
+ typeModels[type] = obj;
692
+ };
693
+
694
+ webshims.addValidityRule = function(type, fn){
695
+ validityRules[type] = fn;
696
+ };
697
+
698
+ webshims.addValidityRule('typeMismatch',function (input, val, cache, validityState){
699
+ if(val === ''){return false;}
700
+ var ret = validityState.typeMismatch;
701
+ if(!('type' in cache)){
702
+ cache.type = (input[0].getAttribute('type') || '').toLowerCase();
703
+ }
704
+
705
+ if(typeModels[cache.type] && typeModels[cache.type].mismatch){
706
+ ret = typeModels[cache.type].mismatch(val, input);
707
+ }
708
+ return ret;
709
+ });
710
+
711
+ var overrideNativeMessages = options.overrideMessages;
712
+
713
+ var overrideValidity = (!modernizrInputTypes.number || !modernizrInputTypes.time || !modernizrInputTypes.range || overrideNativeMessages);
714
+ var validityProps = ['customError','typeMismatch','rangeUnderflow','rangeOverflow','stepMismatch','tooLong','patternMismatch','valueMissing','valid'];
715
+
716
+ var validityChanger = (overrideNativeMessages)? ['value', 'checked'] : ['value'];
717
+ var validityElements = [];
718
+ var testValidity = function(elem, init){
719
+ if(!elem){return;}
720
+ var type = (elem.getAttribute && elem.getAttribute('type') || elem.type || '').toLowerCase();
721
+
722
+ if(!overrideNativeMessages && !typeModels[type]){
723
+ return;
724
+ }
725
+
726
+ if(overrideNativeMessages && !init && type == 'radio' && elem.name){
727
+ $(doc.getElementsByName( elem.name )).each(function(){
728
+ $.prop(this, 'validity');
729
+ });
730
+ } else {
731
+ $.prop(elem, 'validity');
732
+ }
733
+ };
734
+
735
+ var oldSetCustomValidity = {};
736
+ ['input', 'textarea', 'select'].forEach(function(name){
737
+ var desc = webshims.defineNodeNameProperty(name, 'setCustomValidity', {
738
+ prop: {
739
+ value: function(error){
740
+ error = error+'';
741
+ var elem = (name == 'input') ? $(this).getNativeElement()[0] : this;
742
+ desc.prop._supvalue.call(elem, error);
743
+
744
+ if(webshims.bugs.validationMessage){
745
+ webshims.data(elem, 'customvalidationMessage', error);
746
+ }
747
+ if(overrideValidity){
748
+ webshims.data(elem, 'hasCustomError', !!(error));
749
+ testValidity(elem);
750
+ }
751
+ }
752
+ }
753
+ });
754
+ oldSetCustomValidity[name] = desc.prop._supvalue;
755
+ });
756
+
757
+
758
+ if(overrideValidity || overrideNativeMessages){
759
+ validityChanger.push('min');
760
+ validityChanger.push('max');
761
+ validityChanger.push('step');
762
+ validityElements.push('input');
763
+ }
764
+ if(overrideNativeMessages){
765
+ validityChanger.push('required');
766
+ validityChanger.push('pattern');
767
+ validityElements.push('select');
768
+ validityElements.push('textarea');
769
+ }
770
+
771
+ if(overrideValidity){
772
+ var stopValidity;
773
+ validityElements.forEach(function(nodeName){
774
+
775
+ var oldDesc = webshims.defineNodeNameProperty(nodeName, 'validity', {
776
+ prop: {
777
+ get: function(){
778
+ if(stopValidity){return;}
779
+ var elem = (nodeName == 'input') ? $(this).getNativeElement()[0] : this;
780
+
781
+ var validity = oldDesc.prop._supget.call(elem);
782
+
783
+ if(!validity){
784
+ return validity;
785
+ }
786
+ var validityState = {};
787
+ validityProps.forEach(function(prop){
788
+ validityState[prop] = validity[prop];
789
+ });
790
+
791
+ if( !$.prop(elem, 'willValidate') ){
792
+ return validityState;
793
+ }
794
+ stopValidity = true;
795
+ var jElm = $(elem),
796
+ cache = {type: (elem.getAttribute && elem.getAttribute('type') || '').toLowerCase(), nodeName: (elem.nodeName || '').toLowerCase()},
797
+ val = jElm.val(),
798
+ customError = !!(webshims.data(elem, 'hasCustomError')),
799
+ setCustomMessage
800
+ ;
801
+ stopValidity = false;
802
+ validityState.customError = customError;
803
+
804
+ if( validityState.valid && validityState.customError ){
805
+ validityState.valid = false;
806
+ } else if(!validityState.valid) {
807
+ var allFalse = true;
808
+ $.each(validityState, function(name, prop){
809
+ if(prop){
810
+ allFalse = false;
811
+ return false;
812
+ }
813
+ });
814
+
815
+ if(allFalse){
816
+ validityState.valid = true;
817
+ }
818
+
819
+ }
820
+
821
+ $.each(validityRules, function(rule, fn){
822
+ validityState[rule] = fn(jElm, val, cache, validityState);
823
+ if( validityState[rule] && (validityState.valid || !setCustomMessage) && (overrideNativeMessages || (typeModels[cache.type] && typeModels[cache.type].mismatch)) ) {
824
+ oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, rule));
825
+ validityState.valid = false;
826
+ setCustomMessage = true;
827
+ }
828
+ });
829
+ if(validityState.valid){
830
+ oldSetCustomValidity[nodeName].call(elem, '');
831
+ webshims.data(elem, 'hasCustomError', false);
832
+ } else if(overrideNativeMessages && !setCustomMessage && !customError){
833
+ $.each(validityState, function(name, prop){
834
+ if(name !== 'valid' && prop){
835
+ oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, name));
836
+ return false;
837
+ }
838
+ });
839
+ }
840
+ return validityState;
841
+ },
842
+ writeable: false
843
+
844
+ }
845
+ });
846
+ });
847
+
848
+ validityChanger.forEach(function(prop){
849
+ webshims.onNodeNamesPropertyModify(validityElements, prop, function(s){
850
+ testValidity(this);
851
+ });
852
+ });
853
+
854
+ if(doc.addEventListener){
855
+ var inputThrottle;
856
+ var testPassValidity = function(e){
857
+ if(!('form' in e.target)){return;}
858
+ var form = e.target.form;
859
+ clearTimeout(inputThrottle);
860
+ testValidity(e.target);
861
+ if(form && overrideNativeMessages){
862
+ $('input', form).each(function(){
863
+ if(this.type == 'password'){
864
+ testValidity(this);
865
+ }
866
+ });
867
+ }
868
+ };
869
+
870
+ doc.addEventListener('change', testPassValidity, true);
871
+
872
+ if(overrideNativeMessages){
873
+ doc.addEventListener('blur', testPassValidity, true);
874
+ doc.addEventListener('keydown', function(e){
875
+ if(e.keyCode != 13){return;}
876
+ testPassValidity(e);
877
+ }, true);
878
+ }
879
+
880
+ doc.addEventListener('input', function(e){
881
+ clearTimeout(inputThrottle);
882
+ inputThrottle = setTimeout(function(){
883
+ testValidity(e.target);
884
+ }, 290);
885
+ }, true);
886
+ }
887
+
888
+ var validityElementsSel = validityElements.join(',');
889
+
890
+ webshims.addReady(function(context, elem){
891
+ $(validityElementsSel, context).add(elem.filter(validityElementsSel)).each(function(){
892
+ $.prop(this, 'validity');
893
+ });
894
+ });
895
+
896
+
897
+ if(overrideNativeMessages){
898
+ webshims.ready('DOM form-message', function(){
899
+ webshims.activeLang({
900
+ register: 'form-core',
901
+ callback: function(){
902
+ $('input, select, textarea')
903
+ .getNativeElement()
904
+ .each(function(){
905
+ if(webshims.data(this, 'hasCustomError')){return;}
906
+ var elem = this;
907
+ var validity = $.prop(elem, 'validity') || {valid: true};
908
+ var nodeName;
909
+ if(validity.valid){return;}
910
+ nodeName = (elem.nodeName || '').toLowerCase();
911
+ $.each(validity, function(name, prop){
912
+ if(name !== 'valid' && prop){
913
+ oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, name));
914
+ return false;
915
+ }
916
+ });
917
+ })
918
+ ;
919
+ }
920
+ });
921
+ });
922
+ }
923
+
924
+ } //end: overrideValidity
925
+
926
+ webshims.defineNodeNameProperty('input', 'type', {
927
+ prop: {
928
+ get: function(){
929
+ var elem = this;
930
+ var type = (elem.getAttribute('type') || '').toLowerCase();
931
+ return (webshims.inputTypes[type]) ? type : elem.type;
932
+ }
933
+ }
934
+ });
935
+
936
+
937
+ });jQuery.webshims.register('form-number-date-api', function($, webshims, window, document, undefined){
938
+ "use strict";
939
+
940
+ //ToDo
941
+ if(!webshims.getStep){
942
+ webshims.getStep = function(elem, type){
943
+ var step = $.attr(elem, 'step');
944
+ if(step === 'any'){
945
+ return step;
946
+ }
947
+ type = type || getType(elem);
948
+ if(!typeModels[type] || !typeModels[type].step){
949
+ return step;
950
+ }
951
+ step = typeProtos.number.asNumber(step);
952
+ return ((!isNaN(step) && step > 0) ? step : typeModels[type].step) * typeModels[type].stepScaleFactor;
953
+ };
954
+ }
955
+ if(!webshims.addMinMaxNumberToCache){
956
+ webshims.addMinMaxNumberToCache = function(attr, elem, cache){
957
+ if (!(attr+'AsNumber' in cache)) {
958
+ cache[attr+'AsNumber'] = typeModels[cache.type].asNumber(elem.attr(attr));
959
+ if(isNaN(cache[attr+'AsNumber']) && (attr+'Default' in typeModels[cache.type])){
960
+ cache[attr+'AsNumber'] = typeModels[cache.type][attr+'Default'];
961
+ }
962
+ }
963
+ };
964
+ }
965
+
966
+ var nan = parseInt('NaN', 10),
967
+ doc = document,
968
+ typeModels = webshims.inputTypes,
969
+ isNumber = function(string){
970
+ return (typeof string == 'number' || (string && string == string * 1));
971
+ },
972
+ supportsType = function(type){
973
+ return ($('<input type="'+type+'" />').prop('type') === type);
974
+ },
975
+ getType = function(elem){
976
+ return (elem.getAttribute('type') || '').toLowerCase();
977
+ },
978
+ isDateTimePart = function(string){
979
+ return (isNumber(string) || (string && string == '0' + (string * 1)));
980
+ },
981
+ addMinMaxNumberToCache = webshims.addMinMaxNumberToCache,
982
+ addleadingZero = function(val, len){
983
+ val = ''+val;
984
+ len = len - val.length;
985
+ for(var i = 0; i < len; i++){
986
+ val = '0'+val;
987
+ }
988
+ return val;
989
+ },
990
+ EPS = 1e-7,
991
+ typeBugs = webshims.bugs.bustedValidity
992
+ ;
993
+
994
+ webshims.addValidityRule('stepMismatch', function(input, val, cache, validityState){
995
+ if(val === ''){return false;}
996
+ if(!('type' in cache)){
997
+ cache.type = getType(input[0]);
998
+ }
999
+ //stepmismatch with date is computable, but it would be a typeMismatch (performance)
1000
+ if(cache.type == 'date'){
1001
+ return false;
1002
+ }
1003
+ var ret = (validityState || {}).stepMismatch, base;
1004
+ if(typeModels[cache.type] && typeModels[cache.type].step){
1005
+ if( !('step' in cache) ){
1006
+ cache.step = webshims.getStep(input[0], cache.type);
1007
+ }
1008
+
1009
+ if(cache.step == 'any'){return false;}
1010
+
1011
+ if(!('valueAsNumber' in cache)){
1012
+ cache.valueAsNumber = typeModels[cache.type].asNumber( val );
1013
+ }
1014
+ if(isNaN(cache.valueAsNumber)){return false;}
1015
+
1016
+ addMinMaxNumberToCache('min', input, cache);
1017
+ base = cache.minAsNumber;
1018
+ if(isNaN(base)){
1019
+ base = typeModels[cache.type].stepBase || 0;
1020
+ }
1021
+
1022
+ ret = Math.abs((cache.valueAsNumber - base) % cache.step);
1023
+
1024
+ ret = !( ret <= EPS || Math.abs(ret - cache.step) <= EPS );
1025
+ }
1026
+ return ret;
1027
+ });
1028
+
1029
+
1030
+
1031
+ [{name: 'rangeOverflow', attr: 'max', factor: 1}, {name: 'rangeUnderflow', attr: 'min', factor: -1}].forEach(function(data, i){
1032
+ webshims.addValidityRule(data.name, function(input, val, cache, validityState) {
1033
+ var ret = (validityState || {})[data.name] || false;
1034
+ if(val === ''){return ret;}
1035
+ if (!('type' in cache)) {
1036
+ cache.type = getType(input[0]);
1037
+ }
1038
+ if (typeModels[cache.type] && typeModels[cache.type].asNumber) {
1039
+ if(!('valueAsNumber' in cache)){
1040
+ cache.valueAsNumber = typeModels[cache.type].asNumber( val );
1041
+ }
1042
+ if(isNaN(cache.valueAsNumber)){
1043
+ return false;
1044
+ }
1045
+
1046
+ addMinMaxNumberToCache(data.attr, input, cache);
1047
+
1048
+ if(isNaN(cache[data.attr+'AsNumber'])){
1049
+ return ret;
1050
+ }
1051
+ ret = ( cache[data.attr+'AsNumber'] * data.factor < cache.valueAsNumber * data.factor - EPS );
1052
+ }
1053
+ return ret;
1054
+ });
1055
+ });
1056
+
1057
+ webshims.reflectProperties(['input'], ['max', 'min', 'step']);
1058
+
1059
+
1060
+ //IDLs and methods, that aren't part of constrain validation, but strongly tight to it
1061
+ var valueAsNumberDescriptor = webshims.defineNodeNameProperty('input', 'valueAsNumber', {
1062
+ prop: {
1063
+ get: function(){
1064
+ var elem = this;
1065
+ var type = getType(elem);
1066
+ var ret = (typeModels[type] && typeModels[type].asNumber) ?
1067
+ typeModels[type].asNumber($.prop(elem, 'value')) :
1068
+ (valueAsNumberDescriptor.prop._supget && valueAsNumberDescriptor.prop._supget.apply(elem, arguments));
1069
+ if(ret == null){
1070
+ ret = nan;
1071
+ }
1072
+ return ret;
1073
+ },
1074
+ set: function(val){
1075
+ var elem = this;
1076
+ var type = getType(elem);
1077
+ if(typeModels[type] && typeModels[type].numberToString){
1078
+ //is NaN a number?
1079
+ if(isNaN(val)){
1080
+ $.prop(elem, 'value', '');
1081
+ return;
1082
+ }
1083
+ var set = typeModels[type].numberToString(val);
1084
+ if(set !== false){
1085
+ $.prop(elem, 'value', set);
1086
+ } else {
1087
+ webshims.warn('INVALID_STATE_ERR: DOM Exception 11');
1088
+ }
1089
+ } else {
1090
+ valueAsNumberDescriptor.prop._supset && valueAsNumberDescriptor.prop._supset.apply(elem, arguments);
1091
+ }
1092
+ }
1093
+ }
1094
+ });
1095
+
1096
+ var valueAsDateDescriptor = webshims.defineNodeNameProperty('input', 'valueAsDate', {
1097
+ prop: {
1098
+ get: function(){
1099
+ var elem = this;
1100
+ var type = getType(elem);
1101
+ return (typeModels[type] && typeModels[type].asDate && !typeModels[type].noAsDate) ?
1102
+ typeModels[type].asDate($.prop(elem, 'value')) :
1103
+ valueAsDateDescriptor.prop._supget && valueAsDateDescriptor.prop._supget.call(elem) || null;
1104
+ },
1105
+ set: function(value){
1106
+ var elem = this;
1107
+ var type = getType(elem);
1108
+ if(typeModels[type] && typeModels[type].dateToString && !typeModels[type].noAsDate){
1109
+
1110
+ if(value === null){
1111
+ $.prop(elem, 'value', '');
1112
+ return '';
1113
+ }
1114
+ var set = typeModels[type].dateToString(value);
1115
+ if(set !== false){
1116
+ $.prop(elem, 'value', set);
1117
+ return set;
1118
+ } else {
1119
+ webshims.warn('INVALID_STATE_ERR: DOM Exception 11');
1120
+ }
1121
+ } else {
1122
+ return valueAsDateDescriptor.prop._supset && valueAsDateDescriptor.prop._supset.apply(elem, arguments) || null;
1123
+ }
1124
+ }
1125
+ }
1126
+ });
1127
+
1128
+ var typeProtos = {
1129
+
1130
+ number: {
1131
+ mismatch: function(val){
1132
+ return !(isNumber(val));
1133
+ },
1134
+ step: 1,
1135
+ //stepBase: 0, 0 = default
1136
+ stepScaleFactor: 1,
1137
+ asNumber: function(str){
1138
+ return (isNumber(str)) ? str * 1 : nan;
1139
+ },
1140
+ numberToString: function(num){
1141
+ return (isNumber(num)) ? num : false;
1142
+ }
1143
+ },
1144
+
1145
+ range: {
1146
+ minDefault: 0,
1147
+ maxDefault: 100
1148
+ },
1149
+
1150
+ date: {
1151
+ mismatch: function(val){
1152
+ if(!val || !val.split || !(/\d$/.test(val))){return true;}
1153
+ var valA = val.split(/\u002D/);
1154
+ if(valA.length !== 3){return true;}
1155
+ var ret = false;
1156
+ $.each(valA, function(i, part){
1157
+ if(!isDateTimePart(part)){
1158
+ ret = true;
1159
+ return false;
1160
+ }
1161
+ });
1162
+ if(ret){return ret;}
1163
+ if(valA[0].length !== 4 || valA[1].length != 2 || valA[1] > 12 || valA[2].length != 2 || valA[2] > 33){
1164
+ ret = true;
1165
+ }
1166
+ return (val !== this.dateToString( this.asDate(val, true) ) );
1167
+ },
1168
+ step: 1,
1169
+ //stepBase: 0, 0 = default
1170
+ stepScaleFactor: 86400000,
1171
+ asDate: function(val, _noMismatch){
1172
+ if(!_noMismatch && this.mismatch(val)){
1173
+ return null;
1174
+ }
1175
+ return new Date(this.asNumber(val, true));
1176
+ },
1177
+ asNumber: function(str, _noMismatch){
1178
+ var ret = nan;
1179
+ if(_noMismatch || !this.mismatch(str)){
1180
+ str = str.split(/\u002D/);
1181
+ ret = Date.UTC(str[0], str[1] - 1, str[2]);
1182
+ }
1183
+ return ret;
1184
+ },
1185
+ numberToString: function(num){
1186
+ return (isNumber(num)) ? this.dateToString(new Date( num * 1)) : false;
1187
+ },
1188
+ dateToString: function(date){
1189
+ return (date && date.getFullYear) ? date.getUTCFullYear() +'-'+ addleadingZero(date.getUTCMonth()+1, 2) +'-'+ addleadingZero(date.getUTCDate(), 2) : false;
1190
+ }
1191
+ },
1192
+ time: {
1193
+ mismatch: function(val, _getParsed){
1194
+ if(!val || !val.split || !(/\d$/.test(val))){return true;}
1195
+ val = val.split(/\u003A/);
1196
+ if(val.length < 2 || val.length > 3){return true;}
1197
+ var ret = false,
1198
+ sFraction;
1199
+ if(val[2]){
1200
+ val[2] = val[2].split(/\u002E/);
1201
+ sFraction = parseInt(val[2][1], 10);
1202
+ val[2] = val[2][0];
1203
+ }
1204
+ $.each(val, function(i, part){
1205
+ if(!isDateTimePart(part) || part.length !== 2){
1206
+ ret = true;
1207
+ return false;
1208
+ }
1209
+ });
1210
+ if(ret){return true;}
1211
+ if(val[0] > 23 || val[0] < 0 || val[1] > 59 || val[1] < 0){
1212
+ return true;
1213
+ }
1214
+ if(val[2] && (val[2] > 59 || val[2] < 0 )){
1215
+ return true;
1216
+ }
1217
+ if(sFraction && isNaN(sFraction)){
1218
+ return true;
1219
+ }
1220
+ if(sFraction){
1221
+ if(sFraction < 100){
1222
+ sFraction *= 100;
1223
+ } else if(sFraction < 10){
1224
+ sFraction *= 10;
1225
+ }
1226
+ }
1227
+ return (_getParsed === true) ? [val, sFraction] : false;
1228
+ },
1229
+ step: 60,
1230
+ stepBase: 0,
1231
+ stepScaleFactor: 1000,
1232
+ asDate: function(val){
1233
+ val = new Date(this.asNumber(val));
1234
+ return (isNaN(val)) ? null : val;
1235
+ },
1236
+ asNumber: function(val){
1237
+ var ret = nan;
1238
+ val = this.mismatch(val, true);
1239
+ if(val !== true){
1240
+ ret = Date.UTC('1970', 0, 1, val[0][0], val[0][1], val[0][2] || 0);
1241
+ if(val[1]){
1242
+ ret += val[1];
1243
+ }
1244
+ }
1245
+ return ret;
1246
+ },
1247
+ dateToString: function(date){
1248
+ if(date && date.getUTCHours){
1249
+ var str = addleadingZero(date.getUTCHours(), 2) +':'+ addleadingZero(date.getUTCMinutes(), 2),
1250
+ tmp = date.getSeconds()
1251
+ ;
1252
+ if(tmp != "0"){
1253
+ str += ':'+ addleadingZero(tmp, 2);
1254
+ }
1255
+ tmp = date.getUTCMilliseconds();
1256
+ if(tmp != "0"){
1257
+ str += '.'+ addleadingZero(tmp, 3);
1258
+ }
1259
+ return str;
1260
+ } else {
1261
+ return false;
1262
+ }
1263
+ }
1264
+ }
1265
+ // ,'datetime-local': {
1266
+ // mismatch: function(val, _getParsed){
1267
+ // if(!val || !val.split || (val+'special').split(/\u0054/).length !== 2){return true;}
1268
+ // val = val.split(/\u0054/);
1269
+ // return ( typeProtos.date.mismatch(val[0]) || typeProtos.time.mismatch(val[1], _getParsed) );
1270
+ // },
1271
+ // noAsDate: true,
1272
+ // asDate: function(val){
1273
+ // val = new Date(this.asNumber(val));
1274
+ //
1275
+ // return (isNaN(val)) ? null : val;
1276
+ // },
1277
+ // asNumber: function(val){
1278
+ // var ret = nan;
1279
+ // var time = this.mismatch(val, true);
1280
+ // if(time !== true){
1281
+ // val = val.split(/\u0054/)[0].split(/\u002D/);
1282
+ //
1283
+ // ret = Date.UTC(val[0], val[1] - 1, val[2], time[0][0], time[0][1], time[0][2] || 0);
1284
+ // if(time[1]){
1285
+ // ret += time[1];
1286
+ // }
1287
+ // }
1288
+ // return ret;
1289
+ // },
1290
+ // dateToString: function(date, _getParsed){
1291
+ // return typeProtos.date.dateToString(date) +'T'+ typeProtos.time.dateToString(date, _getParsed);
1292
+ // }
1293
+ // }
1294
+ };
1295
+
1296
+ if(typeBugs || !supportsType('range') || !supportsType('time')){
1297
+ typeProtos.range = $.extend({}, typeProtos.number, typeProtos.range);
1298
+ typeProtos.time = $.extend({}, typeProtos.date, typeProtos.time);
1299
+ // typeProtos['datetime-local'] = $.extend({}, typeProtos.date, typeProtos.time, typeProtos['datetime-local']);
1300
+ }
1301
+
1302
+ if(typeBugs || !supportsType('number')){
1303
+ webshims.addInputType('number', typeProtos.number);
1304
+ }
1305
+
1306
+ if(typeBugs || !supportsType('range')){
1307
+ webshims.addInputType('range', typeProtos.range);
1308
+ }
1309
+ if(typeBugs || !supportsType('date')){
1310
+ webshims.addInputType('date', typeProtos.date);
1311
+ }
1312
+ if(typeBugs || !supportsType('time')){
1313
+ webshims.addInputType('time', typeProtos.time);
1314
+ }
1315
+
1316
+ // if(typeBugs || !supportsType('datetime-local')){
1317
+ // webshims.addInputType('datetime-local', typeProtos['datetime-local']);
1318
+ // }
1319
+
1315
1320
  });/* number-date-ui */
1316
1321
  /* https://github.com/aFarkas/webshim/issues#issue/23 */
1317
1322
  jQuery.webshims.register('form-number-date-ui', function($, webshims, window, document, undefined, options){
@@ -1425,15 +1430,15 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
1425
1430
 
1426
1431
  replaceInputUI.common = function(orig, shim, methods){
1427
1432
  if(Modernizr.formvalidation){
1428
- orig.bind('firstinvalid', function(e){
1433
+ orig.on('firstinvalid', function(e){
1429
1434
  if(!webshims.fromSubmit && isCheckValidity){return;}
1430
- orig.unbind('invalid.replacedwidgetbubble').bind('invalid.replacedwidgetbubble', function(evt){
1435
+ orig.off('invalid.replacedwidgetbubble').on('invalid.replacedwidgetbubble', function(evt){
1431
1436
  if(!e.isInvalidUIPrevented() && !evt.isDefaultPrevented()){
1432
1437
  webshims.validityAlert.showFor( e.target );
1433
1438
  e.preventDefault();
1434
1439
  evt.preventDefault();
1435
1440
  }
1436
- orig.unbind('invalid.replacedwidgetbubble');
1441
+ orig.off('invalid.replacedwidgetbubble');
1437
1442
  });
1438
1443
  });
1439
1444
  }
@@ -1466,7 +1471,7 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
1466
1471
  orig.after(shim);
1467
1472
 
1468
1473
  if(orig[0].form){
1469
- $(orig[0].form).bind('reset', function(e){
1474
+ $(orig[0].form).on('reset', function(e){
1470
1475
  if(e.originalEvent && !e.isDefaultPrevented()){
1471
1476
  setTimeout(function(){orig.prop( 'value', orig.prop('value') );}, 0);
1472
1477
  }
@@ -1475,7 +1480,7 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
1475
1480
 
1476
1481
  if(label[0]){
1477
1482
  shim.getShadowFocusElement().attr('aria-labelledby', webshims.getID(label));
1478
- label.bind('click', function(){
1483
+ label.on('click', function(){
1479
1484
  orig.getShadowFocusElement().focus();
1480
1485
  return false;
1481
1486
  });
@@ -1514,16 +1519,18 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
1514
1519
  focusedOut = false;
1515
1520
  };
1516
1521
  var data = datePicker
1517
- .bind('focusin', function(){
1518
- resetFocusHandler();
1519
- data.dpDiv.unbind('mousedown.webshimsmousedownhandler').bind('mousedown.webshimsmousedownhandler', function(){
1520
- stopFocusout = true;
1521
- });
1522
- })
1523
- .bind('focusout blur', function(e){
1524
- if(stopFocusout){
1525
- focusedOut = true;
1526
- e.stopImmediatePropagation();
1522
+ .on({
1523
+ focusin: function(){
1524
+ resetFocusHandler();
1525
+ data.dpDiv.unbind('mousedown.webshimsmousedownhandler').bind('mousedown.webshimsmousedownhandler', function(){
1526
+ stopFocusout = true;
1527
+ });
1528
+ },
1529
+ 'focusout blur': function(e){
1530
+ if(stopFocusout){
1531
+ focusedOut = true;
1532
+ e.stopImmediatePropagation();
1533
+ }
1527
1534
  }
1528
1535
  })
1529
1536
  .datepicker($.extend({
@@ -1537,7 +1544,7 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
1537
1544
  }
1538
1545
  }
1539
1546
  }, defaultDatepicker, options.datepicker, elem.data('datepicker')))
1540
- .bind('change', change)
1547
+ .on('change', change)
1541
1548
  .data('datepicker')
1542
1549
  ;
1543
1550
  data.dpDiv.addClass('input-date-datepicker-control');
@@ -1739,7 +1746,7 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
1739
1746
  data = configureDatePicker(elem, date, change);
1740
1747
 
1741
1748
  $(elem)
1742
- .bind('updateshadowdom', function(){
1749
+ .on('updateshadowdom', function(){
1743
1750
  if (data.trigger[0]) {
1744
1751
  elem.css({display: ''});
1745
1752
  if(elem[0].offsetWidth || elem[0].offsetHeight){
@@ -1829,7 +1836,7 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
1829
1836
 
1830
1837
 
1831
1838
  elem
1832
- .bind('updateshadowdom', function(){
1839
+ .on('updateshadowdom', function(){
1833
1840
  elem.css({display: ''});
1834
1841
  if (elem[0].offsetWidth || elem[0].offsetHeight) {
1835
1842
  var attr = getDimensions(elem);
@@ -1846,11 +1853,16 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
1846
1853
  ;
1847
1854
 
1848
1855
 
1849
- range.slider($.extend(true, {}, options.slider, elem.data('slider'))).bind('slide', change).bind('slidechange', function(e){
1850
- if(e.originalEvent){
1851
- triggerInlineForm(elem[0], 'change');
1852
- }
1853
- });
1856
+ range.slider($.extend(true, {}, options.slider, elem.data('slider')))
1857
+ .on({
1858
+ slide: change,
1859
+ slidechange: function(e){
1860
+ if(e.originalEvent){
1861
+ triggerInlineForm(elem[0], 'change');
1862
+ }
1863
+ }
1864
+ })
1865
+ ;
1854
1866
 
1855
1867
  ['disabled', 'min', 'max', 'step', 'value'].forEach(function(name){
1856
1868
  var val = elem.prop(name);
@@ -1905,7 +1917,7 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
1905
1917
  };
1906
1918
  }
1907
1919
 
1908
- if(!webshims.bugs.valueAsNumberSet && (options.replaceUI || !Modernizr.inputtypes.date /*|| !Modernizr.inputtypes["datetime-local"]*/ || !Modernizr.inputtypes.range)){
1920
+ if(options.replaceUI || !Modernizr.inputtypes.date /*|| !Modernizr.inputtypes["datetime-local"]*/ || !Modernizr.inputtypes.range){
1909
1921
  var reflectFn = function(val){
1910
1922
  if(webshims.data(this, 'hasShadow')){
1911
1923
  $.prop(this, 'value', $.prop(this, 'value'));
@@ -1956,7 +1968,7 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
1956
1968
  $(document).unbind('jquery-uiReady.langchange input-widgetsReady.langchange');
1957
1969
  };
1958
1970
 
1959
- $(document).bind('jquery-uiReady.langchange input-widgetsReady.langchange', getDefaults);
1971
+ $(document).on('jquery-uiReady.langchange input-widgetsReady.langchange', getDefaults);
1960
1972
  getDefaults();
1961
1973
 
1962
1974
  //implement set/arrow controls
@@ -2078,7 +2090,7 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
2078
2090
 
2079
2091
  function init(){
2080
2092
  blockChangeValue = $(elem)
2081
- .bind({
2093
+ .on({
2082
2094
  'change.stepcontrol focus.stepcontrol': function(e){
2083
2095
  if(!blockBlurChange || e.type != 'focus'){
2084
2096
  blockChangeValue = $.prop(elem, 'value');
@@ -2117,19 +2129,21 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
2117
2129
  var uiEvents = changeInput(elem, type);
2118
2130
  var controls = $('<span class="step-controls" unselectable="on"><span class="step-up" /><span class="step-down" /></span>')
2119
2131
  .insertAfter(elem)
2120
- .bind('selectstart dragstart', function(){return false;})
2121
- .bind('mousedown mousepress', function(e){
2122
- if(!$(e.target).hasClass('step-controls')){
2123
- uiEvents.step(($(e.target).hasClass('step-up')) ? 1 : -1);
2124
- }
2125
- uiEvents.setFocus();
2126
- return false;
2127
- })
2128
- .bind('mousepressstart mousepressend', function(e){
2129
- if(e.type == 'mousepressend'){
2130
- uiEvents.triggerChange();
2132
+ .on({
2133
+ 'selectstart dragstart': function(){return false;},
2134
+ 'mousedown mousepress': function(e){
2135
+ if(!$(e.target).hasClass('step-controls')){
2136
+ uiEvents.step(($(e.target).hasClass('step-up')) ? 1 : -1);
2137
+ }
2138
+ uiEvents.setFocus();
2139
+ return false;
2140
+ },
2141
+ 'mousepressstart mousepressend': function(e){
2142
+ if(e.type == 'mousepressend'){
2143
+ uiEvents.triggerChange();
2144
+ }
2145
+ $(e.target)[e.type == 'mousepressstart' ? 'addClass' : 'removeClass']('mousepress-ui');
2131
2146
  }
2132
- $(e.target)[e.type == 'mousepressstart' ? 'addClass' : 'removeClass']('mousepress-ui');
2133
2147
  })
2134
2148
  ;
2135
2149
  var mwheelUpDown = function(e, d){
@@ -2147,13 +2161,13 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
2147
2161
  autocomplete: 'off',
2148
2162
  role: 'spinbutton'
2149
2163
  })
2150
- .bind('keyup', function(e){
2164
+ .on('keyup', function(e){
2151
2165
  var step = stepKeys[e.keyCode];
2152
2166
  if(step){
2153
2167
  uiEvents.triggerChange(step);
2154
2168
  }
2155
2169
  })
2156
- .bind(($.browser.msie) ? 'keydown' : 'keypress', function(e){
2170
+ .on(($.browser.msie) ? 'keydown' : 'keypress', function(e){
2157
2171
  var step = stepKeys[e.keyCode];
2158
2172
  if(step){
2159
2173
  uiEvents.step(step);
@@ -2163,7 +2177,7 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
2163
2177
  ;
2164
2178
 
2165
2179
  if(allowedChars[type]){
2166
- jElm.bind('keypress', (function(){
2180
+ jElm.on('keypress', (function(){
2167
2181
  var chars = allowedChars[type];
2168
2182
  return function(event){
2169
2183
  var chr = String.fromCharCode(event.charCode == null ? event.keyCode : event.charCode);
@@ -2173,13 +2187,15 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
2173
2187
  }
2174
2188
 
2175
2189
  jElm
2176
- .bind('focus', function(){
2177
- jElm.add(controls).unbind('.mwhellwebshims')
2178
- .bind('mousewheel.mwhellwebshims', mwheelUpDown)
2179
- ;
2180
- })
2181
- .bind('blur', function(){
2182
- $(elem).add(controls).unbind('.mwhellwebshims');
2190
+ .on({
2191
+ focus: function(){
2192
+ jElm.add(controls).off('.mwhellwebshims')
2193
+ .on('mousewheel.mwhellwebshims', mwheelUpDown)
2194
+ ;
2195
+ },
2196
+ blur: function(){
2197
+ $(elem).add(controls).off('.mwhellwebshims');
2198
+ }
2183
2199
  })
2184
2200
  ;
2185
2201
 
@@ -2187,7 +2203,7 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
2187
2203
  if(options.calculateWidth){
2188
2204
  var init;
2189
2205
  jElm
2190
- .bind('updateshadowdom', function(){
2206
+ .on('updateshadowdom', function(){
2191
2207
  if(!init && (elem.offsetWidth || elem.offsetHeight)){
2192
2208
  init = true;
2193
2209
  adjustInputWithBtn(jElm, controls);
@@ -2204,7 +2220,7 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
2204
2220
 
2205
2221
 
2206
2222
  webshims.addReady(function(context, elem){
2207
- $(document).bind('jquery-uiReady.initinputui input-widgetsReady.initinputui', function(e){
2223
+ $(document).on('jquery-uiReady.initinputui input-widgetsReady.initinputui', function(e){
2208
2224
  if($.datepicker || $.fn.slider){
2209
2225
  if($.datepicker && !defaultDatepicker.dateFormat){
2210
2226
  defaultDatepicker.dateFormat = $.datepicker._defaults.dateFormat;