webshims-rails 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/lib/webshims-rails/version.rb +2 -2
  2. data/vendor/assets/javascripts/webshims/extras/custom-validity.js +253 -253
  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/polyfiller.js +1 -1
  6. data/vendor/assets/javascripts/webshims/minified/shims/combos/10.js +1 -1
  7. data/vendor/assets/javascripts/webshims/minified/shims/combos/12.js +1 -1
  8. data/vendor/assets/javascripts/webshims/minified/shims/combos/16.js +1 -1
  9. data/vendor/assets/javascripts/webshims/minified/shims/combos/17.js +1 -1
  10. data/vendor/assets/javascripts/webshims/minified/shims/combos/19.js +1 -1
  11. data/vendor/assets/javascripts/webshims/minified/shims/combos/2.js +1 -1
  12. data/vendor/assets/javascripts/webshims/minified/shims/combos/20.js +1 -1
  13. data/vendor/assets/javascripts/webshims/minified/shims/combos/21.js +1 -1
  14. data/vendor/assets/javascripts/webshims/minified/shims/combos/22.js +1 -1
  15. data/vendor/assets/javascripts/webshims/minified/shims/combos/23.js +1 -1
  16. data/vendor/assets/javascripts/webshims/minified/shims/combos/24.js +1 -1
  17. data/vendor/assets/javascripts/webshims/minified/shims/combos/25.js +1 -1
  18. data/vendor/assets/javascripts/webshims/minified/shims/combos/26.js +1 -1
  19. data/vendor/assets/javascripts/webshims/minified/shims/combos/27.js +1 -1
  20. data/vendor/assets/javascripts/webshims/minified/shims/combos/3.js +1 -1
  21. data/vendor/assets/javascripts/webshims/minified/shims/combos/4.js +1 -1
  22. data/vendor/assets/javascripts/webshims/minified/shims/combos/5.js +1 -1
  23. data/vendor/assets/javascripts/webshims/minified/shims/combos/59.js +1 -1
  24. data/vendor/assets/javascripts/webshims/minified/shims/combos/8.js +1 -1
  25. data/vendor/assets/javascripts/webshims/minified/shims/combos/9.js +1 -1
  26. data/vendor/assets/javascripts/webshims/minified/shims/form-core.js +1 -1
  27. data/vendor/assets/javascripts/webshims/minified/shims/form-message.js +1 -1
  28. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-de.txt +33 -33
  29. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-en.txt +34 -34
  30. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-core.js +1 -1
  31. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-jaris.js +1 -1
  32. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-swf.js +1 -1
  33. data/vendor/assets/javascripts/webshims/minified/shims/swf/JarisFLVPlayer.swf +0 -0
  34. data/vendor/assets/javascripts/webshims/polyfiller.js +1188 -1188
  35. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/README +82 -82
  36. data/vendor/assets/javascripts/webshims/shims/combos/1.js +1752 -1752
  37. data/vendor/assets/javascripts/webshims/shims/combos/10.js +3310 -3311
  38. data/vendor/assets/javascripts/webshims/shims/combos/11.js +1631 -1631
  39. data/vendor/assets/javascripts/webshims/shims/combos/12.js +1695 -1696
  40. data/vendor/assets/javascripts/webshims/shims/combos/13.js +1098 -1098
  41. data/vendor/assets/javascripts/webshims/shims/combos/14.js +477 -477
  42. data/vendor/assets/javascripts/webshims/shims/combos/15.js +317 -317
  43. data/vendor/assets/javascripts/webshims/shims/combos/16.js +2177 -2154
  44. data/vendor/assets/javascripts/webshims/shims/combos/17.js +2354 -2319
  45. data/vendor/assets/javascripts/webshims/shims/combos/18.js +1322 -1322
  46. data/vendor/assets/javascripts/webshims/shims/combos/19.js +2262 -2238
  47. data/vendor/assets/javascripts/webshims/shims/combos/2.js +2376 -2340
  48. data/vendor/assets/javascripts/webshims/shims/combos/20.js +1557 -1558
  49. data/vendor/assets/javascripts/webshims/shims/combos/21.js +1745 -1733
  50. data/vendor/assets/javascripts/webshims/shims/combos/22.js +2360 -2361
  51. data/vendor/assets/javascripts/webshims/shims/combos/23.js +2342 -2331
  52. data/vendor/assets/javascripts/webshims/shims/combos/24.js +2859 -2836
  53. data/vendor/assets/javascripts/webshims/shims/combos/25.js +1547 -1548
  54. data/vendor/assets/javascripts/webshims/shims/combos/26.js +2178 -2155
  55. data/vendor/assets/javascripts/webshims/shims/combos/27.js +3311 -3312
  56. data/vendor/assets/javascripts/webshims/shims/combos/3.js +3058 -3022
  57. data/vendor/assets/javascripts/webshims/shims/combos/4.js +807 -771
  58. data/vendor/assets/javascripts/webshims/shims/combos/5.js +1063 -1027
  59. data/vendor/assets/javascripts/webshims/shims/combos/59.js +1745 -1709
  60. data/vendor/assets/javascripts/webshims/shims/combos/6.js +384 -384
  61. data/vendor/assets/javascripts/webshims/shims/combos/7.js +640 -640
  62. data/vendor/assets/javascripts/webshims/shims/combos/8.js +1546 -1547
  63. data/vendor/assets/javascripts/webshims/shims/combos/9.js +2507 -2508
  64. data/vendor/assets/javascripts/webshims/shims/details.js +148 -148
  65. data/vendor/assets/javascripts/webshims/shims/dom-extend.js +949 -949
  66. data/vendor/assets/javascripts/webshims/shims/es5.js +802 -802
  67. data/vendor/assets/javascripts/webshims/shims/excanvas.js +924 -924
  68. data/vendor/assets/javascripts/webshims/shims/form-core.js +630 -606
  69. data/vendor/assets/javascripts/webshims/shims/form-datalist.js +681 -681
  70. data/vendor/assets/javascripts/webshims/shims/form-message.js +176 -164
  71. data/vendor/assets/javascripts/webshims/shims/form-native-extend.js +255 -255
  72. data/vendor/assets/javascripts/webshims/shims/form-number-date-api.js +383 -383
  73. data/vendor/assets/javascripts/webshims/shims/form-shim-extend.js +1568 -1568
  74. data/vendor/assets/javascripts/webshims/shims/geolocation.js +168 -168
  75. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ar.js +32 -32
  76. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ch-ZN.js +32 -32
  77. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-de.txt +33 -33
  78. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-el.js +32 -32
  79. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-en.txt +34 -34
  80. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-es.js +31 -31
  81. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-fr.js +32 -32
  82. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-he.js +32 -32
  83. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-hi.js +32 -32
  84. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-hu.js +32 -32
  85. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-it.js +32 -32
  86. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ja.js +32 -32
  87. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-nl.js +32 -32
  88. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-pt-PT.js +32 -32
  89. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ru.js +31 -31
  90. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-sv.js +32 -32
  91. data/vendor/assets/javascripts/webshims/shims/json-storage.js +308 -308
  92. data/vendor/assets/javascripts/webshims/shims/mediaelement-core.js +596 -597
  93. data/vendor/assets/javascripts/webshims/shims/mediaelement-jaris.js +891 -891
  94. data/vendor/assets/javascripts/webshims/shims/mediaelement-native-fix.js +98 -98
  95. data/vendor/assets/javascripts/webshims/shims/mediaelement-swf.js +960 -960
  96. data/vendor/assets/javascripts/webshims/shims/mediaelement-yt.js +543 -543
  97. data/vendor/assets/javascripts/webshims/shims/styles/shim.css +697 -697
  98. data/vendor/assets/javascripts/webshims/shims/swf/JarisFLVPlayer.swf +0 -0
  99. metadata +2 -4
  100. data/vendor/assets/javascripts/webshims/minified/shims/range-ui.js +0 -1
  101. data/vendor/assets/javascripts/webshims/shims/range-ui.js +0 -66
@@ -1,643 +1,643 @@
1
- jQuery.webshims.register('form-native-extend', function($, webshims, window, doc, undefined, options){
2
- "use strict";
3
- var Modernizr = window.Modernizr;
4
- var modernizrInputTypes = Modernizr.inputtypes;
5
- if(!Modernizr.formvalidation || webshims.bugs.bustedValidity){return;}
6
- var typeModels = webshims.inputTypes;
7
- var validityRules = {};
8
-
9
- webshims.addInputType = function(type, obj){
10
- typeModels[type] = obj;
11
- };
12
-
13
- webshims.addValidityRule = function(type, fn){
14
- validityRules[type] = fn;
15
- };
16
-
17
- webshims.addValidityRule('typeMismatch',function (input, val, cache, validityState){
18
- if(val === ''){return false;}
19
- var ret = validityState.typeMismatch;
20
- if(!('type' in cache)){
21
- cache.type = (input[0].getAttribute('type') || '').toLowerCase();
22
- }
23
-
24
- if(typeModels[cache.type] && typeModels[cache.type].mismatch){
25
- ret = typeModels[cache.type].mismatch(val, input);
26
- }
27
- return ret;
28
- });
29
-
30
- var overrideNativeMessages = options.overrideMessages;
31
-
32
- var overrideValidity = (!modernizrInputTypes.number || !modernizrInputTypes.time || !modernizrInputTypes.range || overrideNativeMessages);
33
- var validityProps = ['customError','typeMismatch','rangeUnderflow','rangeOverflow','stepMismatch','tooLong','patternMismatch','valueMissing','valid'];
34
-
35
- var validityChanger = (overrideNativeMessages)? ['value', 'checked'] : ['value'];
36
- var validityElements = [];
37
- var testValidity = function(elem, init){
38
- if(!elem){return;}
39
- var type = (elem.getAttribute && elem.getAttribute('type') || elem.type || '').toLowerCase();
40
-
41
- if(!overrideNativeMessages && !typeModels[type]){
42
- return;
43
- }
44
-
45
- if(overrideNativeMessages && !init && type == 'radio' && elem.name){
46
- $(doc.getElementsByName( elem.name )).each(function(){
47
- $.prop(this, 'validity');
48
- });
49
- } else {
50
- $.prop(elem, 'validity');
51
- }
52
- };
53
-
54
- var oldSetCustomValidity = {};
55
- ['input', 'textarea', 'select'].forEach(function(name){
56
- var desc = webshims.defineNodeNameProperty(name, 'setCustomValidity', {
57
- prop: {
58
- value: function(error){
59
- error = error+'';
60
- var elem = (name == 'input') ? $(this).getNativeElement()[0] : this;
61
- desc.prop._supvalue.call(elem, error);
62
-
63
- if(webshims.bugs.validationMessage){
64
- webshims.data(elem, 'customvalidationMessage', error);
65
- }
66
- if(overrideValidity){
67
- webshims.data(elem, 'hasCustomError', !!(error));
68
- testValidity(elem);
69
- }
70
- }
71
- }
72
- });
73
- oldSetCustomValidity[name] = desc.prop._supvalue;
74
- });
75
-
76
-
77
- if(overrideValidity || overrideNativeMessages){
78
- validityChanger.push('min');
79
- validityChanger.push('max');
80
- validityChanger.push('step');
81
- validityElements.push('input');
82
- }
83
- if(overrideNativeMessages){
84
- validityChanger.push('required');
85
- validityChanger.push('pattern');
86
- validityElements.push('select');
87
- validityElements.push('textarea');
88
- }
89
-
90
- if(overrideValidity){
91
- var stopValidity;
92
- validityElements.forEach(function(nodeName){
93
-
94
- var oldDesc = webshims.defineNodeNameProperty(nodeName, 'validity', {
95
- prop: {
96
- get: function(){
97
- if(stopValidity){return;}
98
- var elem = (nodeName == 'input') ? $(this).getNativeElement()[0] : this;
99
-
100
- var validity = oldDesc.prop._supget.call(elem);
101
-
102
- if(!validity){
103
- return validity;
104
- }
105
- var validityState = {};
106
- validityProps.forEach(function(prop){
107
- validityState[prop] = validity[prop];
108
- });
109
-
110
- if( !$.prop(elem, 'willValidate') ){
111
- return validityState;
112
- }
113
- stopValidity = true;
114
- var jElm = $(elem),
115
- cache = {type: (elem.getAttribute && elem.getAttribute('type') || '').toLowerCase(), nodeName: (elem.nodeName || '').toLowerCase()},
116
- val = jElm.val(),
117
- customError = !!(webshims.data(elem, 'hasCustomError')),
118
- setCustomMessage
119
- ;
120
- stopValidity = false;
121
- validityState.customError = customError;
122
-
123
- if( validityState.valid && validityState.customError ){
124
- validityState.valid = false;
125
- } else if(!validityState.valid) {
126
- var allFalse = true;
127
- $.each(validityState, function(name, prop){
128
- if(prop){
129
- allFalse = false;
130
- return false;
131
- }
132
- });
133
-
134
- if(allFalse){
135
- validityState.valid = true;
136
- }
137
-
138
- }
139
-
140
- $.each(validityRules, function(rule, fn){
141
- validityState[rule] = fn(jElm, val, cache, validityState);
142
- if( validityState[rule] && (validityState.valid || !setCustomMessage) && (overrideNativeMessages || (typeModels[cache.type] && typeModels[cache.type].mismatch)) ) {
143
- oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, rule));
144
- validityState.valid = false;
145
- setCustomMessage = true;
146
- }
147
- });
148
- if(validityState.valid){
149
- oldSetCustomValidity[nodeName].call(elem, '');
150
- webshims.data(elem, 'hasCustomError', false);
151
- } else if(overrideNativeMessages && !setCustomMessage && !customError){
152
- $.each(validityState, function(name, prop){
153
- if(name !== 'valid' && prop){
154
- oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, name));
155
- return false;
156
- }
157
- });
158
- }
159
- return validityState;
160
- },
161
- writeable: false
162
-
163
- }
164
- });
165
- });
166
-
167
- validityChanger.forEach(function(prop){
168
- webshims.onNodeNamesPropertyModify(validityElements, prop, function(s){
169
- testValidity(this);
170
- });
171
- });
172
-
173
- if(doc.addEventListener){
174
- var inputThrottle;
175
- var testPassValidity = function(e){
176
- if(!('form' in e.target)){return;}
177
- var form = e.target.form;
178
- clearTimeout(inputThrottle);
179
- testValidity(e.target);
180
- if(form && overrideNativeMessages){
181
- $('input', form).each(function(){
182
- if(this.type == 'password'){
183
- testValidity(this);
184
- }
185
- });
186
- }
187
- };
188
-
189
- doc.addEventListener('change', testPassValidity, true);
190
-
191
- if(overrideNativeMessages){
192
- doc.addEventListener('blur', testPassValidity, true);
193
- doc.addEventListener('keydown', function(e){
194
- if(e.keyCode != 13){return;}
195
- testPassValidity(e);
196
- }, true);
197
- }
198
-
199
- doc.addEventListener('input', function(e){
200
- clearTimeout(inputThrottle);
201
- inputThrottle = setTimeout(function(){
202
- testValidity(e.target);
203
- }, 290);
204
- }, true);
205
- }
206
-
207
- var validityElementsSel = validityElements.join(',');
208
-
209
- webshims.addReady(function(context, elem){
210
- $(validityElementsSel, context).add(elem.filter(validityElementsSel)).each(function(){
211
- $.prop(this, 'validity');
212
- });
213
- });
214
-
215
-
216
- if(overrideNativeMessages){
217
- webshims.ready('DOM form-message', function(){
218
- webshims.activeLang({
219
- register: 'form-core',
220
- callback: function(){
221
- $('input, select, textarea')
222
- .getNativeElement()
223
- .each(function(){
224
- if(webshims.data(this, 'hasCustomError')){return;}
225
- var elem = this;
226
- var validity = $.prop(elem, 'validity') || {valid: true};
227
- var nodeName;
228
- if(validity.valid){return;}
229
- nodeName = (elem.nodeName || '').toLowerCase();
230
- $.each(validity, function(name, prop){
231
- if(name !== 'valid' && prop){
232
- oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, name));
233
- return false;
234
- }
235
- });
236
- })
237
- ;
238
- }
239
- });
240
- });
241
- }
242
-
243
- } //end: overrideValidity
244
-
245
- webshims.defineNodeNameProperty('input', 'type', {
246
- prop: {
247
- get: function(){
248
- var elem = this;
249
- var type = (elem.getAttribute('type') || '').toLowerCase();
250
- return (webshims.inputTypes[type]) ? type : elem.type;
251
- }
252
- }
253
- });
254
-
255
-
256
- });
257
- jQuery.webshims.register('form-number-date-api', function($, webshims, window, document, undefined){
258
- "use strict";
259
-
260
- //ToDo
261
- if(!webshims.getStep){
262
- webshims.getStep = function(elem, type){
263
- var step = $.attr(elem, 'step');
264
- if(step === 'any'){
265
- return step;
266
- }
267
- type = type || getType(elem);
268
- if(!typeModels[type] || !typeModels[type].step){
269
- return step;
270
- }
271
- step = typeProtos.number.asNumber(step);
272
- return ((!isNaN(step) && step > 0) ? step : typeModels[type].step) * typeModels[type].stepScaleFactor;
273
- };
274
- }
275
- if(!webshims.addMinMaxNumberToCache){
276
- webshims.addMinMaxNumberToCache = function(attr, elem, cache){
277
- if (!(attr+'AsNumber' in cache)) {
278
- cache[attr+'AsNumber'] = typeModels[cache.type].asNumber(elem.attr(attr));
279
- if(isNaN(cache[attr+'AsNumber']) && (attr+'Default' in typeModels[cache.type])){
280
- cache[attr+'AsNumber'] = typeModels[cache.type][attr+'Default'];
281
- }
282
- }
283
- };
284
- }
285
-
286
- var nan = parseInt('NaN', 10),
287
- doc = document,
288
- typeModels = webshims.inputTypes,
289
- isNumber = function(string){
290
- return (typeof string == 'number' || (string && string == string * 1));
291
- },
292
- supportsType = function(type){
293
- return ($('<input type="'+type+'" />').prop('type') === type);
294
- },
295
- getType = function(elem){
296
- return (elem.getAttribute('type') || '').toLowerCase();
297
- },
298
- isDateTimePart = function(string){
299
- return (isNumber(string) || (string && string == '0' + (string * 1)));
300
- },
301
- addMinMaxNumberToCache = webshims.addMinMaxNumberToCache,
302
- addleadingZero = function(val, len){
303
- val = ''+val;
304
- len = len - val.length;
305
- for(var i = 0; i < len; i++){
306
- val = '0'+val;
307
- }
308
- return val;
309
- },
310
- EPS = 1e-7,
311
- typeBugs = webshims.bugs.bustedValidity
312
- ;
313
-
314
- webshims.addValidityRule('stepMismatch', function(input, val, cache, validityState){
315
- if(val === ''){return false;}
316
- if(!('type' in cache)){
317
- cache.type = getType(input[0]);
318
- }
319
- //stepmismatch with date is computable, but it would be a typeMismatch (performance)
320
- if(cache.type == 'date'){
321
- return false;
322
- }
323
- var ret = (validityState || {}).stepMismatch, base;
324
- if(typeModels[cache.type] && typeModels[cache.type].step){
325
- if( !('step' in cache) ){
326
- cache.step = webshims.getStep(input[0], cache.type);
327
- }
328
-
329
- if(cache.step == 'any'){return false;}
330
-
331
- if(!('valueAsNumber' in cache)){
332
- cache.valueAsNumber = typeModels[cache.type].asNumber( val );
333
- }
334
- if(isNaN(cache.valueAsNumber)){return false;}
335
-
336
- addMinMaxNumberToCache('min', input, cache);
337
- base = cache.minAsNumber;
338
- if(isNaN(base)){
339
- base = typeModels[cache.type].stepBase || 0;
340
- }
341
-
342
- ret = Math.abs((cache.valueAsNumber - base) % cache.step);
343
-
344
- ret = !( ret <= EPS || Math.abs(ret - cache.step) <= EPS );
345
- }
346
- return ret;
347
- });
348
-
349
-
350
-
351
- [{name: 'rangeOverflow', attr: 'max', factor: 1}, {name: 'rangeUnderflow', attr: 'min', factor: -1}].forEach(function(data, i){
352
- webshims.addValidityRule(data.name, function(input, val, cache, validityState) {
353
- var ret = (validityState || {})[data.name] || false;
354
- if(val === ''){return ret;}
355
- if (!('type' in cache)) {
356
- cache.type = getType(input[0]);
357
- }
358
- if (typeModels[cache.type] && typeModels[cache.type].asNumber) {
359
- if(!('valueAsNumber' in cache)){
360
- cache.valueAsNumber = typeModels[cache.type].asNumber( val );
361
- }
362
- if(isNaN(cache.valueAsNumber)){
363
- return false;
364
- }
365
-
366
- addMinMaxNumberToCache(data.attr, input, cache);
367
-
368
- if(isNaN(cache[data.attr+'AsNumber'])){
369
- return ret;
370
- }
371
- ret = ( cache[data.attr+'AsNumber'] * data.factor < cache.valueAsNumber * data.factor - EPS );
372
- }
373
- return ret;
374
- });
375
- });
376
-
377
- webshims.reflectProperties(['input'], ['max', 'min', 'step']);
378
-
379
-
380
- //IDLs and methods, that aren't part of constrain validation, but strongly tight to it
381
- var valueAsNumberDescriptor = webshims.defineNodeNameProperty('input', 'valueAsNumber', {
382
- prop: {
383
- get: function(){
384
- var elem = this;
385
- var type = getType(elem);
386
- var ret = (typeModels[type] && typeModels[type].asNumber) ?
387
- typeModels[type].asNumber($.prop(elem, 'value')) :
388
- (valueAsNumberDescriptor.prop._supget && valueAsNumberDescriptor.prop._supget.apply(elem, arguments));
389
- if(ret == null){
390
- ret = nan;
391
- }
392
- return ret;
393
- },
394
- set: function(val){
395
- var elem = this;
396
- var type = getType(elem);
397
- if(typeModels[type] && typeModels[type].numberToString){
398
- //is NaN a number?
399
- if(isNaN(val)){
400
- $.prop(elem, 'value', '');
401
- return;
402
- }
403
- var set = typeModels[type].numberToString(val);
404
- if(set !== false){
405
- $.prop(elem, 'value', set);
406
- } else {
407
- webshims.warn('INVALID_STATE_ERR: DOM Exception 11');
408
- }
409
- } else {
410
- valueAsNumberDescriptor.prop._supset && valueAsNumberDescriptor.prop._supset.apply(elem, arguments);
411
- }
412
- }
413
- }
414
- });
415
-
416
- var valueAsDateDescriptor = webshims.defineNodeNameProperty('input', 'valueAsDate', {
417
- prop: {
418
- get: function(){
419
- var elem = this;
420
- var type = getType(elem);
421
- return (typeModels[type] && typeModels[type].asDate && !typeModels[type].noAsDate) ?
422
- typeModels[type].asDate($.prop(elem, 'value')) :
423
- valueAsDateDescriptor.prop._supget && valueAsDateDescriptor.prop._supget.call(elem) || null;
424
- },
425
- set: function(value){
426
- var elem = this;
427
- var type = getType(elem);
428
- if(typeModels[type] && typeModels[type].dateToString && !typeModels[type].noAsDate){
429
-
430
- if(value === null){
431
- $.prop(elem, 'value', '');
432
- return '';
433
- }
434
- var set = typeModels[type].dateToString(value);
435
- if(set !== false){
436
- $.prop(elem, 'value', set);
437
- return set;
438
- } else {
439
- webshims.warn('INVALID_STATE_ERR: DOM Exception 11');
440
- }
441
- } else {
442
- return valueAsDateDescriptor.prop._supset && valueAsDateDescriptor.prop._supset.apply(elem, arguments) || null;
443
- }
444
- }
445
- }
446
- });
447
-
448
- var typeProtos = {
449
-
450
- number: {
451
- mismatch: function(val){
452
- return !(isNumber(val));
453
- },
454
- step: 1,
455
- //stepBase: 0, 0 = default
456
- stepScaleFactor: 1,
457
- asNumber: function(str){
458
- return (isNumber(str)) ? str * 1 : nan;
459
- },
460
- numberToString: function(num){
461
- return (isNumber(num)) ? num : false;
462
- }
463
- },
464
-
465
- range: {
466
- minDefault: 0,
467
- maxDefault: 100
468
- },
469
-
470
- date: {
471
- mismatch: function(val){
472
- if(!val || !val.split || !(/\d$/.test(val))){return true;}
473
- var valA = val.split(/\u002D/);
474
- if(valA.length !== 3){return true;}
475
- var ret = false;
476
- $.each(valA, function(i, part){
477
- if(!isDateTimePart(part)){
478
- ret = true;
479
- return false;
480
- }
481
- });
482
- if(ret){return ret;}
483
- if(valA[0].length !== 4 || valA[1].length != 2 || valA[1] > 12 || valA[2].length != 2 || valA[2] > 33){
484
- ret = true;
485
- }
486
- return (val !== this.dateToString( this.asDate(val, true) ) );
487
- },
488
- step: 1,
489
- //stepBase: 0, 0 = default
490
- stepScaleFactor: 86400000,
491
- asDate: function(val, _noMismatch){
492
- if(!_noMismatch && this.mismatch(val)){
493
- return null;
494
- }
495
- return new Date(this.asNumber(val, true));
496
- },
497
- asNumber: function(str, _noMismatch){
498
- var ret = nan;
499
- if(_noMismatch || !this.mismatch(str)){
500
- str = str.split(/\u002D/);
501
- ret = Date.UTC(str[0], str[1] - 1, str[2]);
502
- }
503
- return ret;
504
- },
505
- numberToString: function(num){
506
- return (isNumber(num)) ? this.dateToString(new Date( num * 1)) : false;
507
- },
508
- dateToString: function(date){
509
- return (date && date.getFullYear) ? date.getUTCFullYear() +'-'+ addleadingZero(date.getUTCMonth()+1, 2) +'-'+ addleadingZero(date.getUTCDate(), 2) : false;
510
- }
511
- },
512
- time: {
513
- mismatch: function(val, _getParsed){
514
- if(!val || !val.split || !(/\d$/.test(val))){return true;}
515
- val = val.split(/\u003A/);
516
- if(val.length < 2 || val.length > 3){return true;}
517
- var ret = false,
518
- sFraction;
519
- if(val[2]){
520
- val[2] = val[2].split(/\u002E/);
521
- sFraction = parseInt(val[2][1], 10);
522
- val[2] = val[2][0];
523
- }
524
- $.each(val, function(i, part){
525
- if(!isDateTimePart(part) || part.length !== 2){
526
- ret = true;
527
- return false;
528
- }
529
- });
530
- if(ret){return true;}
531
- if(val[0] > 23 || val[0] < 0 || val[1] > 59 || val[1] < 0){
532
- return true;
533
- }
534
- if(val[2] && (val[2] > 59 || val[2] < 0 )){
535
- return true;
536
- }
537
- if(sFraction && isNaN(sFraction)){
538
- return true;
539
- }
540
- if(sFraction){
541
- if(sFraction < 100){
542
- sFraction *= 100;
543
- } else if(sFraction < 10){
544
- sFraction *= 10;
545
- }
546
- }
547
- return (_getParsed === true) ? [val, sFraction] : false;
548
- },
549
- step: 60,
550
- stepBase: 0,
551
- stepScaleFactor: 1000,
552
- asDate: function(val){
553
- val = new Date(this.asNumber(val));
554
- return (isNaN(val)) ? null : val;
555
- },
556
- asNumber: function(val){
557
- var ret = nan;
558
- val = this.mismatch(val, true);
559
- if(val !== true){
560
- ret = Date.UTC('1970', 0, 1, val[0][0], val[0][1], val[0][2] || 0);
561
- if(val[1]){
562
- ret += val[1];
563
- }
564
- }
565
- return ret;
566
- },
567
- dateToString: function(date){
568
- if(date && date.getUTCHours){
569
- var str = addleadingZero(date.getUTCHours(), 2) +':'+ addleadingZero(date.getUTCMinutes(), 2),
570
- tmp = date.getSeconds()
571
- ;
572
- if(tmp != "0"){
573
- str += ':'+ addleadingZero(tmp, 2);
574
- }
575
- tmp = date.getUTCMilliseconds();
576
- if(tmp != "0"){
577
- str += '.'+ addleadingZero(tmp, 3);
578
- }
579
- return str;
580
- } else {
581
- return false;
582
- }
583
- }
584
- }
585
- // ,'datetime-local': {
586
- // mismatch: function(val, _getParsed){
587
- // if(!val || !val.split || (val+'special').split(/\u0054/).length !== 2){return true;}
588
- // val = val.split(/\u0054/);
589
- // return ( typeProtos.date.mismatch(val[0]) || typeProtos.time.mismatch(val[1], _getParsed) );
590
- // },
591
- // noAsDate: true,
592
- // asDate: function(val){
593
- // val = new Date(this.asNumber(val));
594
- //
595
- // return (isNaN(val)) ? null : val;
596
- // },
597
- // asNumber: function(val){
598
- // var ret = nan;
599
- // var time = this.mismatch(val, true);
600
- // if(time !== true){
601
- // val = val.split(/\u0054/)[0].split(/\u002D/);
602
- //
603
- // ret = Date.UTC(val[0], val[1] - 1, val[2], time[0][0], time[0][1], time[0][2] || 0);
604
- // if(time[1]){
605
- // ret += time[1];
606
- // }
607
- // }
608
- // return ret;
609
- // },
610
- // dateToString: function(date, _getParsed){
611
- // return typeProtos.date.dateToString(date) +'T'+ typeProtos.time.dateToString(date, _getParsed);
612
- // }
613
- // }
614
- };
615
-
616
- if(typeBugs || !supportsType('range') || !supportsType('time')){
617
- typeProtos.range = $.extend({}, typeProtos.number, typeProtos.range);
618
- typeProtos.time = $.extend({}, typeProtos.date, typeProtos.time);
619
- // typeProtos['datetime-local'] = $.extend({}, typeProtos.date, typeProtos.time, typeProtos['datetime-local']);
620
- }
621
-
622
- if(typeBugs || !supportsType('number')){
623
- webshims.addInputType('number', typeProtos.number);
624
- }
625
-
626
- if(typeBugs || !supportsType('range')){
627
- webshims.addInputType('range', typeProtos.range);
628
- }
629
- if(typeBugs || !supportsType('date')){
630
- webshims.addInputType('date', typeProtos.date);
631
- }
632
- if(typeBugs || !supportsType('time')){
633
- webshims.addInputType('time', typeProtos.time);
634
- }
635
-
636
- // if(typeBugs || !supportsType('datetime-local')){
637
- // webshims.addInputType('datetime-local', typeProtos['datetime-local']);
638
- // }
639
-
640
- });
1
+ jQuery.webshims.register('form-native-extend', function($, webshims, window, doc, undefined, options){
2
+ "use strict";
3
+ var Modernizr = window.Modernizr;
4
+ var modernizrInputTypes = Modernizr.inputtypes;
5
+ if(!Modernizr.formvalidation || webshims.bugs.bustedValidity){return;}
6
+ var typeModels = webshims.inputTypes;
7
+ var validityRules = {};
8
+
9
+ webshims.addInputType = function(type, obj){
10
+ typeModels[type] = obj;
11
+ };
12
+
13
+ webshims.addValidityRule = function(type, fn){
14
+ validityRules[type] = fn;
15
+ };
16
+
17
+ webshims.addValidityRule('typeMismatch',function (input, val, cache, validityState){
18
+ if(val === ''){return false;}
19
+ var ret = validityState.typeMismatch;
20
+ if(!('type' in cache)){
21
+ cache.type = (input[0].getAttribute('type') || '').toLowerCase();
22
+ }
23
+
24
+ if(typeModels[cache.type] && typeModels[cache.type].mismatch){
25
+ ret = typeModels[cache.type].mismatch(val, input);
26
+ }
27
+ return ret;
28
+ });
29
+
30
+ var overrideNativeMessages = options.overrideMessages;
31
+
32
+ var overrideValidity = (!modernizrInputTypes.number || !modernizrInputTypes.time || !modernizrInputTypes.range || overrideNativeMessages);
33
+ var validityProps = ['customError','typeMismatch','rangeUnderflow','rangeOverflow','stepMismatch','tooLong','patternMismatch','valueMissing','valid'];
34
+
35
+ var validityChanger = (overrideNativeMessages)? ['value', 'checked'] : ['value'];
36
+ var validityElements = [];
37
+ var testValidity = function(elem, init){
38
+ if(!elem){return;}
39
+ var type = (elem.getAttribute && elem.getAttribute('type') || elem.type || '').toLowerCase();
40
+
41
+ if(!overrideNativeMessages && !typeModels[type]){
42
+ return;
43
+ }
44
+
45
+ if(overrideNativeMessages && !init && type == 'radio' && elem.name){
46
+ $(doc.getElementsByName( elem.name )).each(function(){
47
+ $.prop(this, 'validity');
48
+ });
49
+ } else {
50
+ $.prop(elem, 'validity');
51
+ }
52
+ };
53
+
54
+ var oldSetCustomValidity = {};
55
+ ['input', 'textarea', 'select'].forEach(function(name){
56
+ var desc = webshims.defineNodeNameProperty(name, 'setCustomValidity', {
57
+ prop: {
58
+ value: function(error){
59
+ error = error+'';
60
+ var elem = (name == 'input') ? $(this).getNativeElement()[0] : this;
61
+ desc.prop._supvalue.call(elem, error);
62
+
63
+ if(webshims.bugs.validationMessage){
64
+ webshims.data(elem, 'customvalidationMessage', error);
65
+ }
66
+ if(overrideValidity){
67
+ webshims.data(elem, 'hasCustomError', !!(error));
68
+ testValidity(elem);
69
+ }
70
+ }
71
+ }
72
+ });
73
+ oldSetCustomValidity[name] = desc.prop._supvalue;
74
+ });
75
+
76
+
77
+ if(overrideValidity || overrideNativeMessages){
78
+ validityChanger.push('min');
79
+ validityChanger.push('max');
80
+ validityChanger.push('step');
81
+ validityElements.push('input');
82
+ }
83
+ if(overrideNativeMessages){
84
+ validityChanger.push('required');
85
+ validityChanger.push('pattern');
86
+ validityElements.push('select');
87
+ validityElements.push('textarea');
88
+ }
89
+
90
+ if(overrideValidity){
91
+ var stopValidity;
92
+ validityElements.forEach(function(nodeName){
93
+
94
+ var oldDesc = webshims.defineNodeNameProperty(nodeName, 'validity', {
95
+ prop: {
96
+ get: function(){
97
+ if(stopValidity){return;}
98
+ var elem = (nodeName == 'input') ? $(this).getNativeElement()[0] : this;
99
+
100
+ var validity = oldDesc.prop._supget.call(elem);
101
+
102
+ if(!validity){
103
+ return validity;
104
+ }
105
+ var validityState = {};
106
+ validityProps.forEach(function(prop){
107
+ validityState[prop] = validity[prop];
108
+ });
109
+
110
+ if( !$.prop(elem, 'willValidate') ){
111
+ return validityState;
112
+ }
113
+ stopValidity = true;
114
+ var jElm = $(elem),
115
+ cache = {type: (elem.getAttribute && elem.getAttribute('type') || '').toLowerCase(), nodeName: (elem.nodeName || '').toLowerCase()},
116
+ val = jElm.val(),
117
+ customError = !!(webshims.data(elem, 'hasCustomError')),
118
+ setCustomMessage
119
+ ;
120
+ stopValidity = false;
121
+ validityState.customError = customError;
122
+
123
+ if( validityState.valid && validityState.customError ){
124
+ validityState.valid = false;
125
+ } else if(!validityState.valid) {
126
+ var allFalse = true;
127
+ $.each(validityState, function(name, prop){
128
+ if(prop){
129
+ allFalse = false;
130
+ return false;
131
+ }
132
+ });
133
+
134
+ if(allFalse){
135
+ validityState.valid = true;
136
+ }
137
+
138
+ }
139
+
140
+ $.each(validityRules, function(rule, fn){
141
+ validityState[rule] = fn(jElm, val, cache, validityState);
142
+ if( validityState[rule] && (validityState.valid || !setCustomMessage) && (overrideNativeMessages || (typeModels[cache.type] && typeModels[cache.type].mismatch)) ) {
143
+ oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, rule));
144
+ validityState.valid = false;
145
+ setCustomMessage = true;
146
+ }
147
+ });
148
+ if(validityState.valid){
149
+ oldSetCustomValidity[nodeName].call(elem, '');
150
+ webshims.data(elem, 'hasCustomError', false);
151
+ } else if(overrideNativeMessages && !setCustomMessage && !customError){
152
+ $.each(validityState, function(name, prop){
153
+ if(name !== 'valid' && prop){
154
+ oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, name));
155
+ return false;
156
+ }
157
+ });
158
+ }
159
+ return validityState;
160
+ },
161
+ writeable: false
162
+
163
+ }
164
+ });
165
+ });
166
+
167
+ validityChanger.forEach(function(prop){
168
+ webshims.onNodeNamesPropertyModify(validityElements, prop, function(s){
169
+ testValidity(this);
170
+ });
171
+ });
172
+
173
+ if(doc.addEventListener){
174
+ var inputThrottle;
175
+ var testPassValidity = function(e){
176
+ if(!('form' in e.target)){return;}
177
+ var form = e.target.form;
178
+ clearTimeout(inputThrottle);
179
+ testValidity(e.target);
180
+ if(form && overrideNativeMessages){
181
+ $('input', form).each(function(){
182
+ if(this.type == 'password'){
183
+ testValidity(this);
184
+ }
185
+ });
186
+ }
187
+ };
188
+
189
+ doc.addEventListener('change', testPassValidity, true);
190
+
191
+ if(overrideNativeMessages){
192
+ doc.addEventListener('blur', testPassValidity, true);
193
+ doc.addEventListener('keydown', function(e){
194
+ if(e.keyCode != 13){return;}
195
+ testPassValidity(e);
196
+ }, true);
197
+ }
198
+
199
+ doc.addEventListener('input', function(e){
200
+ clearTimeout(inputThrottle);
201
+ inputThrottle = setTimeout(function(){
202
+ testValidity(e.target);
203
+ }, 290);
204
+ }, true);
205
+ }
206
+
207
+ var validityElementsSel = validityElements.join(',');
208
+
209
+ webshims.addReady(function(context, elem){
210
+ $(validityElementsSel, context).add(elem.filter(validityElementsSel)).each(function(){
211
+ $.prop(this, 'validity');
212
+ });
213
+ });
214
+
215
+
216
+ if(overrideNativeMessages){
217
+ webshims.ready('DOM form-message', function(){
218
+ webshims.activeLang({
219
+ register: 'form-core',
220
+ callback: function(){
221
+ $('input, select, textarea')
222
+ .getNativeElement()
223
+ .each(function(){
224
+ if(webshims.data(this, 'hasCustomError')){return;}
225
+ var elem = this;
226
+ var validity = $.prop(elem, 'validity') || {valid: true};
227
+ var nodeName;
228
+ if(validity.valid){return;}
229
+ nodeName = (elem.nodeName || '').toLowerCase();
230
+ $.each(validity, function(name, prop){
231
+ if(name !== 'valid' && prop){
232
+ oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, name));
233
+ return false;
234
+ }
235
+ });
236
+ })
237
+ ;
238
+ }
239
+ });
240
+ });
241
+ }
242
+
243
+ } //end: overrideValidity
244
+
245
+ webshims.defineNodeNameProperty('input', 'type', {
246
+ prop: {
247
+ get: function(){
248
+ var elem = this;
249
+ var type = (elem.getAttribute('type') || '').toLowerCase();
250
+ return (webshims.inputTypes[type]) ? type : elem.type;
251
+ }
252
+ }
253
+ });
254
+
255
+
256
+ });
257
+ jQuery.webshims.register('form-number-date-api', function($, webshims, window, document, undefined){
258
+ "use strict";
259
+
260
+ //ToDo
261
+ if(!webshims.getStep){
262
+ webshims.getStep = function(elem, type){
263
+ var step = $.attr(elem, 'step');
264
+ if(step === 'any'){
265
+ return step;
266
+ }
267
+ type = type || getType(elem);
268
+ if(!typeModels[type] || !typeModels[type].step){
269
+ return step;
270
+ }
271
+ step = typeProtos.number.asNumber(step);
272
+ return ((!isNaN(step) && step > 0) ? step : typeModels[type].step) * typeModels[type].stepScaleFactor;
273
+ };
274
+ }
275
+ if(!webshims.addMinMaxNumberToCache){
276
+ webshims.addMinMaxNumberToCache = function(attr, elem, cache){
277
+ if (!(attr+'AsNumber' in cache)) {
278
+ cache[attr+'AsNumber'] = typeModels[cache.type].asNumber(elem.attr(attr));
279
+ if(isNaN(cache[attr+'AsNumber']) && (attr+'Default' in typeModels[cache.type])){
280
+ cache[attr+'AsNumber'] = typeModels[cache.type][attr+'Default'];
281
+ }
282
+ }
283
+ };
284
+ }
285
+
286
+ var nan = parseInt('NaN', 10),
287
+ doc = document,
288
+ typeModels = webshims.inputTypes,
289
+ isNumber = function(string){
290
+ return (typeof string == 'number' || (string && string == string * 1));
291
+ },
292
+ supportsType = function(type){
293
+ return ($('<input type="'+type+'" />').prop('type') === type);
294
+ },
295
+ getType = function(elem){
296
+ return (elem.getAttribute('type') || '').toLowerCase();
297
+ },
298
+ isDateTimePart = function(string){
299
+ return (isNumber(string) || (string && string == '0' + (string * 1)));
300
+ },
301
+ addMinMaxNumberToCache = webshims.addMinMaxNumberToCache,
302
+ addleadingZero = function(val, len){
303
+ val = ''+val;
304
+ len = len - val.length;
305
+ for(var i = 0; i < len; i++){
306
+ val = '0'+val;
307
+ }
308
+ return val;
309
+ },
310
+ EPS = 1e-7,
311
+ typeBugs = webshims.bugs.bustedValidity
312
+ ;
313
+
314
+ webshims.addValidityRule('stepMismatch', function(input, val, cache, validityState){
315
+ if(val === ''){return false;}
316
+ if(!('type' in cache)){
317
+ cache.type = getType(input[0]);
318
+ }
319
+ //stepmismatch with date is computable, but it would be a typeMismatch (performance)
320
+ if(cache.type == 'date'){
321
+ return false;
322
+ }
323
+ var ret = (validityState || {}).stepMismatch, base;
324
+ if(typeModels[cache.type] && typeModels[cache.type].step){
325
+ if( !('step' in cache) ){
326
+ cache.step = webshims.getStep(input[0], cache.type);
327
+ }
328
+
329
+ if(cache.step == 'any'){return false;}
330
+
331
+ if(!('valueAsNumber' in cache)){
332
+ cache.valueAsNumber = typeModels[cache.type].asNumber( val );
333
+ }
334
+ if(isNaN(cache.valueAsNumber)){return false;}
335
+
336
+ addMinMaxNumberToCache('min', input, cache);
337
+ base = cache.minAsNumber;
338
+ if(isNaN(base)){
339
+ base = typeModels[cache.type].stepBase || 0;
340
+ }
341
+
342
+ ret = Math.abs((cache.valueAsNumber - base) % cache.step);
343
+
344
+ ret = !( ret <= EPS || Math.abs(ret - cache.step) <= EPS );
345
+ }
346
+ return ret;
347
+ });
348
+
349
+
350
+
351
+ [{name: 'rangeOverflow', attr: 'max', factor: 1}, {name: 'rangeUnderflow', attr: 'min', factor: -1}].forEach(function(data, i){
352
+ webshims.addValidityRule(data.name, function(input, val, cache, validityState) {
353
+ var ret = (validityState || {})[data.name] || false;
354
+ if(val === ''){return ret;}
355
+ if (!('type' in cache)) {
356
+ cache.type = getType(input[0]);
357
+ }
358
+ if (typeModels[cache.type] && typeModels[cache.type].asNumber) {
359
+ if(!('valueAsNumber' in cache)){
360
+ cache.valueAsNumber = typeModels[cache.type].asNumber( val );
361
+ }
362
+ if(isNaN(cache.valueAsNumber)){
363
+ return false;
364
+ }
365
+
366
+ addMinMaxNumberToCache(data.attr, input, cache);
367
+
368
+ if(isNaN(cache[data.attr+'AsNumber'])){
369
+ return ret;
370
+ }
371
+ ret = ( cache[data.attr+'AsNumber'] * data.factor < cache.valueAsNumber * data.factor - EPS );
372
+ }
373
+ return ret;
374
+ });
375
+ });
376
+
377
+ webshims.reflectProperties(['input'], ['max', 'min', 'step']);
378
+
379
+
380
+ //IDLs and methods, that aren't part of constrain validation, but strongly tight to it
381
+ var valueAsNumberDescriptor = webshims.defineNodeNameProperty('input', 'valueAsNumber', {
382
+ prop: {
383
+ get: function(){
384
+ var elem = this;
385
+ var type = getType(elem);
386
+ var ret = (typeModels[type] && typeModels[type].asNumber) ?
387
+ typeModels[type].asNumber($.prop(elem, 'value')) :
388
+ (valueAsNumberDescriptor.prop._supget && valueAsNumberDescriptor.prop._supget.apply(elem, arguments));
389
+ if(ret == null){
390
+ ret = nan;
391
+ }
392
+ return ret;
393
+ },
394
+ set: function(val){
395
+ var elem = this;
396
+ var type = getType(elem);
397
+ if(typeModels[type] && typeModels[type].numberToString){
398
+ //is NaN a number?
399
+ if(isNaN(val)){
400
+ $.prop(elem, 'value', '');
401
+ return;
402
+ }
403
+ var set = typeModels[type].numberToString(val);
404
+ if(set !== false){
405
+ $.prop(elem, 'value', set);
406
+ } else {
407
+ webshims.warn('INVALID_STATE_ERR: DOM Exception 11');
408
+ }
409
+ } else {
410
+ valueAsNumberDescriptor.prop._supset && valueAsNumberDescriptor.prop._supset.apply(elem, arguments);
411
+ }
412
+ }
413
+ }
414
+ });
415
+
416
+ var valueAsDateDescriptor = webshims.defineNodeNameProperty('input', 'valueAsDate', {
417
+ prop: {
418
+ get: function(){
419
+ var elem = this;
420
+ var type = getType(elem);
421
+ return (typeModels[type] && typeModels[type].asDate && !typeModels[type].noAsDate) ?
422
+ typeModels[type].asDate($.prop(elem, 'value')) :
423
+ valueAsDateDescriptor.prop._supget && valueAsDateDescriptor.prop._supget.call(elem) || null;
424
+ },
425
+ set: function(value){
426
+ var elem = this;
427
+ var type = getType(elem);
428
+ if(typeModels[type] && typeModels[type].dateToString && !typeModels[type].noAsDate){
429
+
430
+ if(value === null){
431
+ $.prop(elem, 'value', '');
432
+ return '';
433
+ }
434
+ var set = typeModels[type].dateToString(value);
435
+ if(set !== false){
436
+ $.prop(elem, 'value', set);
437
+ return set;
438
+ } else {
439
+ webshims.warn('INVALID_STATE_ERR: DOM Exception 11');
440
+ }
441
+ } else {
442
+ return valueAsDateDescriptor.prop._supset && valueAsDateDescriptor.prop._supset.apply(elem, arguments) || null;
443
+ }
444
+ }
445
+ }
446
+ });
447
+
448
+ var typeProtos = {
449
+
450
+ number: {
451
+ mismatch: function(val){
452
+ return !(isNumber(val));
453
+ },
454
+ step: 1,
455
+ //stepBase: 0, 0 = default
456
+ stepScaleFactor: 1,
457
+ asNumber: function(str){
458
+ return (isNumber(str)) ? str * 1 : nan;
459
+ },
460
+ numberToString: function(num){
461
+ return (isNumber(num)) ? num : false;
462
+ }
463
+ },
464
+
465
+ range: {
466
+ minDefault: 0,
467
+ maxDefault: 100
468
+ },
469
+
470
+ date: {
471
+ mismatch: function(val){
472
+ if(!val || !val.split || !(/\d$/.test(val))){return true;}
473
+ var valA = val.split(/\u002D/);
474
+ if(valA.length !== 3){return true;}
475
+ var ret = false;
476
+ $.each(valA, function(i, part){
477
+ if(!isDateTimePart(part)){
478
+ ret = true;
479
+ return false;
480
+ }
481
+ });
482
+ if(ret){return ret;}
483
+ if(valA[0].length !== 4 || valA[1].length != 2 || valA[1] > 12 || valA[2].length != 2 || valA[2] > 33){
484
+ ret = true;
485
+ }
486
+ return (val !== this.dateToString( this.asDate(val, true) ) );
487
+ },
488
+ step: 1,
489
+ //stepBase: 0, 0 = default
490
+ stepScaleFactor: 86400000,
491
+ asDate: function(val, _noMismatch){
492
+ if(!_noMismatch && this.mismatch(val)){
493
+ return null;
494
+ }
495
+ return new Date(this.asNumber(val, true));
496
+ },
497
+ asNumber: function(str, _noMismatch){
498
+ var ret = nan;
499
+ if(_noMismatch || !this.mismatch(str)){
500
+ str = str.split(/\u002D/);
501
+ ret = Date.UTC(str[0], str[1] - 1, str[2]);
502
+ }
503
+ return ret;
504
+ },
505
+ numberToString: function(num){
506
+ return (isNumber(num)) ? this.dateToString(new Date( num * 1)) : false;
507
+ },
508
+ dateToString: function(date){
509
+ return (date && date.getFullYear) ? date.getUTCFullYear() +'-'+ addleadingZero(date.getUTCMonth()+1, 2) +'-'+ addleadingZero(date.getUTCDate(), 2) : false;
510
+ }
511
+ },
512
+ time: {
513
+ mismatch: function(val, _getParsed){
514
+ if(!val || !val.split || !(/\d$/.test(val))){return true;}
515
+ val = val.split(/\u003A/);
516
+ if(val.length < 2 || val.length > 3){return true;}
517
+ var ret = false,
518
+ sFraction;
519
+ if(val[2]){
520
+ val[2] = val[2].split(/\u002E/);
521
+ sFraction = parseInt(val[2][1], 10);
522
+ val[2] = val[2][0];
523
+ }
524
+ $.each(val, function(i, part){
525
+ if(!isDateTimePart(part) || part.length !== 2){
526
+ ret = true;
527
+ return false;
528
+ }
529
+ });
530
+ if(ret){return true;}
531
+ if(val[0] > 23 || val[0] < 0 || val[1] > 59 || val[1] < 0){
532
+ return true;
533
+ }
534
+ if(val[2] && (val[2] > 59 || val[2] < 0 )){
535
+ return true;
536
+ }
537
+ if(sFraction && isNaN(sFraction)){
538
+ return true;
539
+ }
540
+ if(sFraction){
541
+ if(sFraction < 100){
542
+ sFraction *= 100;
543
+ } else if(sFraction < 10){
544
+ sFraction *= 10;
545
+ }
546
+ }
547
+ return (_getParsed === true) ? [val, sFraction] : false;
548
+ },
549
+ step: 60,
550
+ stepBase: 0,
551
+ stepScaleFactor: 1000,
552
+ asDate: function(val){
553
+ val = new Date(this.asNumber(val));
554
+ return (isNaN(val)) ? null : val;
555
+ },
556
+ asNumber: function(val){
557
+ var ret = nan;
558
+ val = this.mismatch(val, true);
559
+ if(val !== true){
560
+ ret = Date.UTC('1970', 0, 1, val[0][0], val[0][1], val[0][2] || 0);
561
+ if(val[1]){
562
+ ret += val[1];
563
+ }
564
+ }
565
+ return ret;
566
+ },
567
+ dateToString: function(date){
568
+ if(date && date.getUTCHours){
569
+ var str = addleadingZero(date.getUTCHours(), 2) +':'+ addleadingZero(date.getUTCMinutes(), 2),
570
+ tmp = date.getSeconds()
571
+ ;
572
+ if(tmp != "0"){
573
+ str += ':'+ addleadingZero(tmp, 2);
574
+ }
575
+ tmp = date.getUTCMilliseconds();
576
+ if(tmp != "0"){
577
+ str += '.'+ addleadingZero(tmp, 3);
578
+ }
579
+ return str;
580
+ } else {
581
+ return false;
582
+ }
583
+ }
584
+ }
585
+ // ,'datetime-local': {
586
+ // mismatch: function(val, _getParsed){
587
+ // if(!val || !val.split || (val+'special').split(/\u0054/).length !== 2){return true;}
588
+ // val = val.split(/\u0054/);
589
+ // return ( typeProtos.date.mismatch(val[0]) || typeProtos.time.mismatch(val[1], _getParsed) );
590
+ // },
591
+ // noAsDate: true,
592
+ // asDate: function(val){
593
+ // val = new Date(this.asNumber(val));
594
+ //
595
+ // return (isNaN(val)) ? null : val;
596
+ // },
597
+ // asNumber: function(val){
598
+ // var ret = nan;
599
+ // var time = this.mismatch(val, true);
600
+ // if(time !== true){
601
+ // val = val.split(/\u0054/)[0].split(/\u002D/);
602
+ //
603
+ // ret = Date.UTC(val[0], val[1] - 1, val[2], time[0][0], time[0][1], time[0][2] || 0);
604
+ // if(time[1]){
605
+ // ret += time[1];
606
+ // }
607
+ // }
608
+ // return ret;
609
+ // },
610
+ // dateToString: function(date, _getParsed){
611
+ // return typeProtos.date.dateToString(date) +'T'+ typeProtos.time.dateToString(date, _getParsed);
612
+ // }
613
+ // }
614
+ };
615
+
616
+ if(typeBugs || !supportsType('range') || !supportsType('time')){
617
+ typeProtos.range = $.extend({}, typeProtos.number, typeProtos.range);
618
+ typeProtos.time = $.extend({}, typeProtos.date, typeProtos.time);
619
+ // typeProtos['datetime-local'] = $.extend({}, typeProtos.date, typeProtos.time, typeProtos['datetime-local']);
620
+ }
621
+
622
+ if(typeBugs || !supportsType('number')){
623
+ webshims.addInputType('number', typeProtos.number);
624
+ }
625
+
626
+ if(typeBugs || !supportsType('range')){
627
+ webshims.addInputType('range', typeProtos.range);
628
+ }
629
+ if(typeBugs || !supportsType('date')){
630
+ webshims.addInputType('date', typeProtos.date);
631
+ }
632
+ if(typeBugs || !supportsType('time')){
633
+ webshims.addInputType('time', typeProtos.time);
634
+ }
635
+
636
+ // if(typeBugs || !supportsType('datetime-local')){
637
+ // webshims.addInputType('datetime-local', typeProtos['datetime-local']);
638
+ // }
639
+
640
+ });
641
641
  /* number-date-ui */
642
642
  /* https://github.com/aFarkas/webshim/issues#issue/23 */
643
643
  jQuery.webshims.register('form-number-date-ui', function($, webshims, window, document, undefined, options){
@@ -1558,686 +1558,686 @@ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, do
1558
1558
 
1559
1559
  });
1560
1560
 
1561
-
1562
- jQuery.webshims.register('form-datalist', function($, webshims, window, document, undefined){
1563
- "use strict";
1564
- var doc = document;
1565
-
1566
- /*
1567
- * implement propType "element" currently only used for list-attribute (will be moved to dom-extend, if needed)
1568
- */
1569
- webshims.propTypes.element = function(descs){
1570
- webshims.createPropDefault(descs, 'attr');
1571
- if(descs.prop){return;}
1572
- descs.prop = {
1573
- get: function(){
1574
- var elem = descs.attr.get.call(this);
1575
- if(elem){
1576
- elem = document.getElementById(elem);
1577
- if(elem && descs.propNodeName && !$.nodeName(elem, descs.propNodeName)){
1578
- elem = null;
1579
- }
1580
- }
1581
- return elem || null;
1582
- },
1583
- writeable: false
1584
- };
1585
- };
1586
-
1587
-
1588
- /*
1589
- * Implements datalist element and list attribute
1590
- */
1591
-
1592
- (function(){
1593
- var formsCFG = $.webshims.cfg.forms;
1594
- var listSupport = Modernizr.input.list;
1595
- if(listSupport && !formsCFG.customDatalist){return;}
1596
-
1597
- var initializeDatalist = function(){
1598
-
1599
-
1600
- if(!listSupport){
1601
- webshims.defineNodeNameProperty('datalist', 'options', {
1602
- prop: {
1603
- writeable: false,
1604
- get: function(){
1605
- var elem = this;
1606
- var select = $('select', elem);
1607
- var options;
1608
- if(select[0]){
1609
- options = select[0].options;
1610
- } else {
1611
- options = $('option', elem).get();
1612
- if(options.length){
1613
- webshims.warn('you should wrap your option-elements for a datalist in a select element to support IE and other old browsers.');
1614
- }
1615
- }
1616
- return options;
1617
- }
1618
- }
1619
- });
1620
- }
1621
-
1622
- var inputListProto = {
1623
- //override autocomplete
1624
- autocomplete: {
1625
- attr: {
1626
- get: function(){
1627
- var elem = this;
1628
- var data = $.data(elem, 'datalistWidget');
1629
- if(data){
1630
- return data._autocomplete;
1631
- }
1632
- return ('autocomplete' in elem) ? elem.autocomplete : elem.getAttribute('autocomplete');
1633
- },
1634
- set: function(value){
1635
- var elem = this;
1636
- var data = $.data(elem, 'datalistWidget');
1637
- if(data){
1638
- data._autocomplete = value;
1639
- if(value == 'off'){
1640
- data.hideList();
1641
- }
1642
- } else {
1643
- if('autocomplete' in elem){
1644
- elem.autocomplete = value;
1645
- } else {
1646
- elem.setAttribute('autocomplete', value);
1647
- }
1648
- }
1649
- }
1650
- }
1651
- }
1652
- };
1653
-
1654
- // if(formsCFG.customDatalist && (!listSupport || !('selectedOption') in $('<input />')[0])){
1655
- // //currently not supported x-browser (FF4 has not implemented and is not polyfilled )
1656
- // inputListProto.selectedOption = {
1657
- // prop: {
1658
- // writeable: false,
1659
- // get: function(){
1660
- // var elem = this;
1661
- // var list = $.prop(elem, 'list');
1662
- // var ret = null;
1663
- // var value, options;
1664
- // if(!list){return ret;}
1665
- // value = $.prop(elem, 'value');
1666
- // if(!value){return ret;}
1667
- // options = $.prop(list, 'options');
1668
- // if(!options.length){return ret;}
1669
- // $.each(options, function(i, option){
1670
- // if(value == $.prop(option, 'value')){
1671
- // ret = option;
1672
- // return false;
1673
- // }
1674
- // });
1675
- // return ret;
1676
- // }
1677
- // }
1678
- // };
1679
- // }
1680
-
1681
- if(!listSupport){
1682
- inputListProto['list'] = {
1683
- attr: {
1684
- get: function(){
1685
- var val = webshims.contentAttr(this, 'list');
1686
- return (val == null) ? undefined : val;
1687
- },
1688
- set: function(value){
1689
- var elem = this;
1690
- webshims.contentAttr(elem, 'list', value);
1691
- webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
1692
- }
1693
- },
1694
- initAttr: true,
1695
- reflect: true,
1696
- propType: 'element',
1697
- propNodeName: 'datalist'
1698
- };
1699
- } else {
1700
- //options only return options, if option-elements are rooted: but this makes this part of HTML5 less backwards compatible
1701
- if(!($('<datalist><select><option></option></select></datalist>').prop('options') || []).length ){
1702
- webshims.defineNodeNameProperty('datalist', 'options', {
1703
- prop: {
1704
- writeable: false,
1705
- get: function(){
1706
- var options = this.options || [];
1707
- if(!options.length){
1708
- var elem = this;
1709
- var select = $('select', elem);
1710
- if(select[0] && select[0].options && select[0].options.length){
1711
- options = select[0].options;
1712
- }
1713
- }
1714
- return options;
1715
- }
1716
- }
1717
- });
1718
- }
1719
- inputListProto['list'] = {
1720
- attr: {
1721
- get: function(){
1722
- var val = webshims.contentAttr(this, 'list');
1723
- if(val != null){
1724
- this.removeAttribute('list');
1725
- } else {
1726
- val = $.data(this, 'datalistListAttr');
1727
- }
1728
-
1729
- return (val == null) ? undefined : val;
1730
- },
1731
- set: function(value){
1732
- var elem = this;
1733
- $.data(elem, 'datalistListAttr', value);
1734
- webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
1735
- }
1736
- },
1737
- initAttr: true,
1738
- reflect: true,
1739
- propType: 'element',
1740
- propNodeName: 'datalist'
1741
- };
1742
- }
1743
-
1744
-
1745
- webshims.defineNodeNameProperties('input', inputListProto);
1746
-
1747
- if($.event.customEvent){
1748
- $.event.customEvent.updateDatalist = true;
1749
- $.event.customEvent.updateInput = true;
1750
- $.event.customEvent.datalistselect = true;
1751
- }
1752
- webshims.addReady(function(context, contextElem){
1753
- contextElem
1754
- .filter('datalist > select, datalist, datalist > option, datalist > select > option')
1755
- .closest('datalist')
1756
- .triggerHandler('updateDatalist')
1757
- ;
1758
-
1759
- });
1760
-
1761
-
1762
- };
1763
-
1764
-
1765
- /*
1766
- * ShadowList
1767
- */
1768
- var listidIndex = 0;
1769
-
1770
- var noDatalistSupport = {
1771
- submit: 1,
1772
- button: 1,
1773
- reset: 1,
1774
- hidden: 1,
1775
-
1776
- //ToDo
1777
- range: 1,
1778
- date: 1
1779
- };
1780
- var lteie6 = ($.browser.msie && parseInt($.browser.version, 10) < 7);
1781
- var globStoredOptions = {};
1782
- var getStoredOptions = function(name){
1783
- if(!name){return [];}
1784
- if(globStoredOptions[name]){
1785
- return globStoredOptions[name];
1786
- }
1787
- var data;
1788
- try {
1789
- data = JSON.parse(localStorage.getItem('storedDatalistOptions'+name));
1790
- } catch(e){}
1791
- globStoredOptions[name] = data || [];
1792
- return data || [];
1793
- };
1794
- var storeOptions = function(name, val){
1795
- if(!name){return;}
1796
- val = val || [];
1797
- try {
1798
- localStorage.setItem( 'storedDatalistOptions'+name, JSON.stringify(val) );
1799
- } catch(e){}
1800
- };
1801
-
1802
- var getText = function(elem){
1803
- return (elem.textContent || elem.innerText || $.text([ elem ]) || '');
1804
- };
1805
-
1806
- var shadowListProto = {
1807
- _create: function(opts){
1808
-
1809
- if(noDatalistSupport[$.prop(opts.input, 'type')]){return;}
1810
- var datalist = opts.datalist;
1811
- var data = $.data(opts.input, 'datalistWidget');
1812
- if(datalist && data && data.datalist !== datalist){
1813
- data.datalist = datalist;
1814
- data.id = opts.id;
1815
-
1816
- data.shadowList.prop('className', 'datalist-polyfill '+ (data.datalist.className || '') + ' '+ data.datalist.id +'-shadowdom');
1817
- if(formsCFG.positionDatalist){
1818
- data.shadowList.insertAfter(opts.input);
1819
- } else {
1820
- data.shadowList.appendTo('body');
1821
- }
1822
- $(data.datalist)
1823
- .off('updateDatalist.datalistWidget')
1824
- .on('updateDatalist.datalistWidget', $.proxy(data, '_resetListCached'))
1825
- ;
1826
- data._resetListCached();
1827
- return;
1828
- } else if(!datalist){
1829
- if(data){
1830
- data.destroy();
1831
- }
1832
- return;
1833
- } else if(data && data.datalist === datalist){
1834
- return;
1835
- }
1836
- listidIndex++;
1837
- var that = this;
1838
- this.hideList = $.proxy(that, 'hideList');
1839
- this.timedHide = function(){
1840
- clearTimeout(that.hideTimer);
1841
- that.hideTimer = setTimeout(that.hideList, 9);
1842
- };
1843
- this.datalist = datalist;
1844
- this.id = opts.id;
1845
- this.hasViewableData = true;
1846
- this._autocomplete = $.attr(opts.input, 'autocomplete');
1847
- $.data(opts.input, 'datalistWidget', this);
1848
- this.shadowList = $('<div class="datalist-polyfill '+ (this.datalist.className || '') + ' '+ this.datalist.id +'-shadowdom' +'" />');
1849
-
1850
- if(formsCFG.positionDatalist || $(opts.input).hasClass('position-datalist')){
1851
- this.shadowList.insertAfter(opts.input);
1852
- } else {
1853
- this.shadowList.appendTo('body');
1854
- }
1855
-
1856
- this.index = -1;
1857
- this.input = opts.input;
1858
- this.arrayOptions = [];
1859
-
1860
- this.shadowList
1861
- .delegate('li', 'mouseenter.datalistWidget mousedown.datalistWidget click.datalistWidget', function(e){
1862
- var items = $('li:not(.hidden-item)', that.shadowList);
1863
- var select = (e.type == 'mousedown' || e.type == 'click');
1864
- that.markItem(items.index(e.currentTarget), select, items);
1865
- if(e.type == 'click'){
1866
- that.hideList();
1867
- if(formsCFG.customDatalist){
1868
- $(opts.input).trigger('datalistselect');
1869
- }
1870
- }
1871
- return (e.type != 'mousedown');
1872
- })
1873
- .on('focusout', this.timedHide)
1874
- ;
1875
-
1876
- opts.input.setAttribute('autocomplete', 'off');
1877
-
1878
- $(opts.input)
1879
- .attr({
1880
- //role: 'combobox',
1881
- 'aria-haspopup': 'true'
1882
- })
1883
- .on({
1884
- 'input.datalistWidget': function(){
1885
- if(!that.triggeredByDatalist){
1886
- that.changedValue = false;
1887
- that.showHideOptions();
1888
- }
1889
- },
1890
- 'keydown.datalistWidget': function(e){
1891
- var keyCode = e.keyCode;
1892
- var activeItem;
1893
- var items;
1894
- if(keyCode == 40 && !that.showList()){
1895
- that.markItem(that.index + 1, true);
1896
- return false;
1897
- }
1898
-
1899
- if(!that.isListVisible){return;}
1900
-
1901
-
1902
- if(keyCode == 38){
1903
- that.markItem(that.index - 1, true);
1904
- return false;
1905
- }
1906
- if(!e.shiftKey && (keyCode == 33 || keyCode == 36)){
1907
- that.markItem(0, true);
1908
- return false;
1909
- }
1910
- if(!e.shiftKey && (keyCode == 34 || keyCode == 35)){
1911
- items = $('li:not(.hidden-item)', that.shadowList);
1912
- that.markItem(items.length - 1, true, items);
1913
- return false;
1914
- }
1915
- if(keyCode == 13 || keyCode == 27){
1916
- if (keyCode == 13){
1917
- activeItem = $('li.active-item:not(.hidden-item)', that.shadowList);
1918
- that.changeValue( $('li.active-item:not(.hidden-item)', that.shadowList) );
1919
- }
1920
- that.hideList();
1921
- if(formsCFG.customDatalist && activeItem && activeItem[0]){
1922
- $(opts.input).trigger('datalistselect');
1923
- }
1924
- return false;
1925
- }
1926
- },
1927
- 'focus.datalistWidget': function(){
1928
- if($(this).hasClass('list-focus')){
1929
- that.showList();
1930
- }
1931
- },
1932
- 'mousedown.datalistWidget': function(){
1933
- if($(this).is(':focus')){
1934
- that.showList();
1935
- }
1936
- },
1937
- 'blur.datalistWidget': this.timedHide
1938
- })
1939
- ;
1940
-
1941
-
1942
- $(this.datalist)
1943
- .off('updateDatalist.datalistWidget')
1944
- .on('updateDatalist.datalistWidget', $.proxy(this, '_resetListCached'))
1945
- ;
1946
-
1947
- this._resetListCached();
1948
-
1949
- if(opts.input.form && (opts.input.name || opts.input.id)){
1950
- $(opts.input.form).on('submit.datalistWidget'+opts.input.id, function(){
1951
- if(!$(opts.input).hasClass('no-datalist-cache') && that._autocomplete != 'off'){
1952
- var val = $.prop(opts.input, 'value');
1953
- var name = (opts.input.name || opts.input.id) + $.prop(opts.input, 'type');
1954
- if(!that.storedOptions){
1955
- that.storedOptions = getStoredOptions( name );
1956
- }
1957
- if(val && that.storedOptions.indexOf(val) == -1){
1958
- that.storedOptions.push(val);
1959
- storeOptions(name, that.storedOptions );
1960
- }
1961
- }
1962
- });
1963
- }
1964
- $(window).on('unload.datalist'+this.id+' beforeunload.datalist'+this.id, function(){
1965
- that.destroy();
1966
- });
1967
- },
1968
- destroy: function(){
1969
- var autocomplete = $.attr(this.input, 'autocomplete');
1970
- $(this.input)
1971
- .off('.datalistWidget')
1972
- .removeData('datalistWidget')
1973
- ;
1974
- this.shadowList.remove();
1975
- $(document).off('.datalist'+this.id);
1976
- $(window).off('.datalist'+this.id);
1977
- if(this.input.form && this.input.id){
1978
- $(this.input.form).off('submit.datalistWidget'+this.input.id);
1979
- }
1980
- this.input.removeAttribute('aria-haspopup');
1981
- if(autocomplete === undefined){
1982
- this.input.removeAttribute('autocomplete');
1983
- } else {
1984
- $(this.input).attr('autocomplete', autocomplete);
1985
- }
1986
- },
1987
- _resetListCached: function(e){
1988
- var that = this;
1989
- var forceShow;
1990
- this.needsUpdate = true;
1991
- this.lastUpdatedValue = false;
1992
- this.lastUnfoundValue = '';
1993
-
1994
- if(!this.updateTimer){
1995
- if(window.QUnit || (forceShow = (e && document.activeElement == that.input))){
1996
- that.updateListOptions(forceShow);
1997
- } else {
1998
- webshims.ready('WINDOWLOAD', function(){
1999
- that.updateTimer = setTimeout(function(){
2000
- that.updateListOptions();
2001
- that = null;
2002
- listidIndex = 1;
2003
- }, 200 + (100 * listidIndex));
2004
- });
2005
- }
2006
- }
2007
- },
2008
- maskHTML: function(str){
2009
- return str.replace(/</g, '&lt;').replace(/>/g, '&gt;');
2010
- },
2011
- updateListOptions: function(_forceShow){
2012
- this.needsUpdate = false;
2013
- clearTimeout(this.updateTimer);
2014
- this.updateTimer = false;
2015
- this.shadowList
2016
- .css({
2017
- fontSize: $.css(this.input, 'fontSize'),
2018
- fontFamily: $.css(this.input, 'fontFamily')
2019
- })
2020
- ;
2021
- this.searchStart = formsCFG.customDatalist && $(this.input).hasClass('search-start');
2022
-
2023
- var list = [];
2024
-
2025
- var values = [];
2026
- var allOptions = [];
2027
- var rElem, rItem, rOptions, rI, rLen, item;
2028
- for(rOptions = $.prop(this.datalist, 'options'), rI = 0, rLen = rOptions.length; rI < rLen; rI++){
2029
- rElem = rOptions[rI];
2030
- if(rElem.disabled){return;}
2031
- rItem = {
2032
- value: $(rElem).val() || '',
2033
- text: $.trim($.attr(rElem, 'label') || getText(rElem)),
2034
- className: rElem.className || '',
2035
- style: $.attr(rElem, 'style') || ''
2036
- };
2037
- if(!rItem.text){
2038
- rItem.text = rItem.value;
2039
- } else if(rItem.text != rItem.value){
2040
- rItem.className += ' different-label-value';
2041
- }
2042
- values[rI] = rItem.value;
2043
- allOptions[rI] = rItem;
2044
- }
2045
-
2046
- if(!this.storedOptions){
2047
- this.storedOptions = ($(this.input).hasClass('no-datalist-cache') || this._autocomplete == 'off') ? [] : getStoredOptions((this.input.name || this.input.id) + $.prop(this.input, 'type'));
2048
- }
2049
-
2050
- this.storedOptions.forEach(function(val, i){
2051
- if(values.indexOf(val) == -1){
2052
- allOptions.push({value: val, text: val, className: 'stored-suggest', style: ''});
2053
- }
2054
- });
2055
-
2056
- for(rI = 0, rLen = allOptions.length; rI < rLen; rI++){
2057
- item = allOptions[rI];
2058
- 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>';
2059
- }
2060
-
2061
- this.arrayOptions = allOptions;
2062
- this.shadowList.html('<div class="datalist-outer-box"><div class="datalist-box"><ul role="list">'+ list.join("\n") +'</ul></div></div>');
2063
-
2064
- if($.fn.bgIframe && lteie6){
2065
- this.shadowList.bgIframe();
2066
- }
2067
-
2068
- if(_forceShow || this.isListVisible){
2069
- this.showHideOptions();
2070
- }
2071
- },
2072
- showHideOptions: function(_fromShowList){
2073
- var value = $.prop(this.input, 'value').toLowerCase();
2074
- //first check prevent infinite loop, second creates simple lazy optimization
2075
- if(value === this.lastUpdatedValue || (this.lastUnfoundValue && value.indexOf(this.lastUnfoundValue) === 0)){
2076
- return;
2077
- }
2078
-
2079
- this.lastUpdatedValue = value;
2080
- var found = false;
2081
- var startSearch = this.searchStart;
2082
- var lis = $('li', this.shadowList);
2083
- if(value){
2084
- this.arrayOptions.forEach(function(item, i){
2085
- var search;
2086
- if(!('lowerText' in item)){
2087
- if(item.text != item.value){
2088
- item.lowerText = item.value.toLowerCase() + item.text.toLowerCase();
2089
- } else {
2090
- item.lowerText = item.text.toLowerCase();
2091
- }
2092
- }
2093
- search = item.lowerText.indexOf(value);
2094
- search = startSearch ? !search : search !== -1;
2095
- if(search){
2096
- $(lis[i]).removeClass('hidden-item');
2097
- found = true;
2098
- } else {
2099
- $(lis[i]).addClass('hidden-item');
2100
- }
2101
- });
2102
- } else if(lis.length) {
2103
- lis.removeClass('hidden-item');
2104
- found = true;
2105
- }
2106
-
2107
- this.hasViewableData = found;
2108
- if(!_fromShowList && found){
2109
- this.showList();
2110
- }
2111
- if(!found){
2112
- this.lastUnfoundValue = value;
2113
- this.hideList();
2114
- }
2115
- },
2116
- setPos: function(){
2117
- this.shadowList.css({marginTop: 0, marginLeft: 0, marginRight: 0, marginBottom: 0});
2118
- var css = (formsCFG.positionDatalist) ? $(this.input).position() : webshims.getRelOffset(this.shadowList, this.input);
2119
- css.top += $(this.input).outerHeight();
2120
- css.width = $(this.input).outerWidth() - (parseInt(this.shadowList.css('borderLeftWidth'), 10) || 0) - (parseInt(this.shadowList.css('borderRightWidth'), 10) || 0);
2121
- this.shadowList.css({marginTop: '', marginLeft: '', marginRight: '', marginBottom: ''}).css(css);
2122
- return css;
2123
- },
2124
- showList: function(){
2125
- if(this.isListVisible){return false;}
2126
- if(this.needsUpdate){
2127
- this.updateListOptions();
2128
- }
2129
- this.showHideOptions(true);
2130
- if(!this.hasViewableData){return false;}
2131
- this.isListVisible = true;
2132
- var that = this;
2133
-
2134
- that.setPos();
2135
- that.shadowList.addClass('datalist-visible').find('li.active-item').removeClass('active-item');
2136
-
2137
- $(window).unbind('.datalist'+that.id);
2138
- $(document)
2139
- .off('.datalist'+that.id)
2140
- .on('mousedown.datalist'+that.id +' focusin.datalist'+that.id, function(e){
2141
- if(e.target === that.input || that.shadowList[0] === e.target || $.contains( that.shadowList[0], e.target )){
2142
- clearTimeout(that.hideTimer);
2143
- setTimeout(function(){
2144
- clearTimeout(that.hideTimer);
2145
- }, 9);
2146
- } else {
2147
- that.timedHide();
2148
- }
2149
- })
2150
- .on('updateshadowdom.datalist'+that.id, function(){
2151
- that.setPos();
2152
- })
2153
- ;
2154
- return true;
2155
- },
2156
- hideList: function(){
2157
- if(!this.isListVisible){return false;}
2158
- var that = this;
2159
- var triggerChange = function(e){
2160
- if(that.changedValue){
2161
- $(that.input).trigger('change');
2162
- }
2163
- that.changedValue = false;
2164
- };
2165
-
2166
- that.shadowList.removeClass('datalist-visible list-item-active');
2167
- that.index = -1;
2168
- that.isListVisible = false;
2169
- if(that.changedValue){
2170
- that.triggeredByDatalist = true;
2171
- webshims.triggerInlineForm && webshims.triggerInlineForm(that.input, 'input');
2172
- if($(that.input).is(':focus')){
2173
- $(that.input).one('blur', triggerChange);
2174
- } else {
2175
- triggerChange();
2176
- }
2177
- that.triggeredByDatalist = false;
2178
- }
2179
- $(document).unbind('.datalist'+that.id);
2180
- $(window)
2181
- .off('.datalist'+that.id)
2182
- .one('resize.datalist'+that.id, function(){
2183
- that.shadowList.css({top: 0, left: 0});
2184
- })
2185
- ;
2186
- return true;
2187
- },
2188
- scrollIntoView: function(elem){
2189
- var ul = $('ul', this.shadowList);
2190
- var div = $('div.datalist-box', this.shadowList);
2191
- var elemPos = elem.position();
2192
- var containerHeight;
2193
- elemPos.top -= (parseInt(ul.css('paddingTop'), 10) || 0) + (parseInt(ul.css('marginTop'), 10) || 0) + (parseInt(ul.css('borderTopWidth'), 10) || 0);
2194
- if(elemPos.top < 0){
2195
- div.scrollTop( div.scrollTop() + elemPos.top - 2);
2196
- return;
2197
- }
2198
- elemPos.top += elem.outerHeight();
2199
- containerHeight = div.height();
2200
- if(elemPos.top > containerHeight){
2201
- div.scrollTop( div.scrollTop() + (elemPos.top - containerHeight) + 2);
2202
- }
2203
- },
2204
- changeValue: function(activeItem){
2205
- if(!activeItem[0]){return;}
2206
- var newValue = $('span.option-value', activeItem).text();
2207
- var oldValue = $.prop(this.input, 'value');
2208
- if(newValue != oldValue){
2209
- $(this.input)
2210
- .prop('value', newValue)
2211
- .triggerHandler('updateInput')
2212
- ;
2213
- this.changedValue = true;
2214
- }
2215
- },
2216
- markItem: function(index, doValue, items){
2217
- var activeItem;
2218
- var goesUp;
2219
-
2220
- items = items || $('li:not(.hidden-item)', this.shadowList);
2221
- if(!items.length){return;}
2222
- if(index < 0){
2223
- index = items.length - 1;
2224
- } else if(index >= items.length){
2225
- index = 0;
2226
- }
2227
- items.removeClass('active-item');
2228
- this.shadowList.addClass('list-item-active');
2229
- activeItem = items.filter(':eq('+ index +')').addClass('active-item');
2230
-
2231
- if(doValue){
2232
- this.changeValue(activeItem);
2233
- this.scrollIntoView(activeItem);
2234
- }
2235
- this.index = index;
2236
- }
2237
- };
2238
-
2239
- //init datalist update
2240
- initializeDatalist();
2241
- })();
2242
-
1561
+
1562
+ jQuery.webshims.register('form-datalist', function($, webshims, window, document, undefined){
1563
+ "use strict";
1564
+ var doc = document;
1565
+
1566
+ /*
1567
+ * implement propType "element" currently only used for list-attribute (will be moved to dom-extend, if needed)
1568
+ */
1569
+ webshims.propTypes.element = function(descs){
1570
+ webshims.createPropDefault(descs, 'attr');
1571
+ if(descs.prop){return;}
1572
+ descs.prop = {
1573
+ get: function(){
1574
+ var elem = descs.attr.get.call(this);
1575
+ if(elem){
1576
+ elem = document.getElementById(elem);
1577
+ if(elem && descs.propNodeName && !$.nodeName(elem, descs.propNodeName)){
1578
+ elem = null;
1579
+ }
1580
+ }
1581
+ return elem || null;
1582
+ },
1583
+ writeable: false
1584
+ };
1585
+ };
1586
+
1587
+
1588
+ /*
1589
+ * Implements datalist element and list attribute
1590
+ */
1591
+
1592
+ (function(){
1593
+ var formsCFG = $.webshims.cfg.forms;
1594
+ var listSupport = Modernizr.input.list;
1595
+ if(listSupport && !formsCFG.customDatalist){return;}
1596
+
1597
+ var initializeDatalist = function(){
1598
+
1599
+
1600
+ if(!listSupport){
1601
+ webshims.defineNodeNameProperty('datalist', 'options', {
1602
+ prop: {
1603
+ writeable: false,
1604
+ get: function(){
1605
+ var elem = this;
1606
+ var select = $('select', elem);
1607
+ var options;
1608
+ if(select[0]){
1609
+ options = select[0].options;
1610
+ } else {
1611
+ options = $('option', elem).get();
1612
+ if(options.length){
1613
+ webshims.warn('you should wrap your option-elements for a datalist in a select element to support IE and other old browsers.');
1614
+ }
1615
+ }
1616
+ return options;
1617
+ }
1618
+ }
1619
+ });
1620
+ }
1621
+
1622
+ var inputListProto = {
1623
+ //override autocomplete
1624
+ autocomplete: {
1625
+ attr: {
1626
+ get: function(){
1627
+ var elem = this;
1628
+ var data = $.data(elem, 'datalistWidget');
1629
+ if(data){
1630
+ return data._autocomplete;
1631
+ }
1632
+ return ('autocomplete' in elem) ? elem.autocomplete : elem.getAttribute('autocomplete');
1633
+ },
1634
+ set: function(value){
1635
+ var elem = this;
1636
+ var data = $.data(elem, 'datalistWidget');
1637
+ if(data){
1638
+ data._autocomplete = value;
1639
+ if(value == 'off'){
1640
+ data.hideList();
1641
+ }
1642
+ } else {
1643
+ if('autocomplete' in elem){
1644
+ elem.autocomplete = value;
1645
+ } else {
1646
+ elem.setAttribute('autocomplete', value);
1647
+ }
1648
+ }
1649
+ }
1650
+ }
1651
+ }
1652
+ };
1653
+
1654
+ // if(formsCFG.customDatalist && (!listSupport || !('selectedOption') in $('<input />')[0])){
1655
+ // //currently not supported x-browser (FF4 has not implemented and is not polyfilled )
1656
+ // inputListProto.selectedOption = {
1657
+ // prop: {
1658
+ // writeable: false,
1659
+ // get: function(){
1660
+ // var elem = this;
1661
+ // var list = $.prop(elem, 'list');
1662
+ // var ret = null;
1663
+ // var value, options;
1664
+ // if(!list){return ret;}
1665
+ // value = $.prop(elem, 'value');
1666
+ // if(!value){return ret;}
1667
+ // options = $.prop(list, 'options');
1668
+ // if(!options.length){return ret;}
1669
+ // $.each(options, function(i, option){
1670
+ // if(value == $.prop(option, 'value')){
1671
+ // ret = option;
1672
+ // return false;
1673
+ // }
1674
+ // });
1675
+ // return ret;
1676
+ // }
1677
+ // }
1678
+ // };
1679
+ // }
1680
+
1681
+ if(!listSupport){
1682
+ inputListProto['list'] = {
1683
+ attr: {
1684
+ get: function(){
1685
+ var val = webshims.contentAttr(this, 'list');
1686
+ return (val == null) ? undefined : val;
1687
+ },
1688
+ set: function(value){
1689
+ var elem = this;
1690
+ webshims.contentAttr(elem, 'list', value);
1691
+ webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
1692
+ }
1693
+ },
1694
+ initAttr: true,
1695
+ reflect: true,
1696
+ propType: 'element',
1697
+ propNodeName: 'datalist'
1698
+ };
1699
+ } else {
1700
+ //options only return options, if option-elements are rooted: but this makes this part of HTML5 less backwards compatible
1701
+ if(!($('<datalist><select><option></option></select></datalist>').prop('options') || []).length ){
1702
+ webshims.defineNodeNameProperty('datalist', 'options', {
1703
+ prop: {
1704
+ writeable: false,
1705
+ get: function(){
1706
+ var options = this.options || [];
1707
+ if(!options.length){
1708
+ var elem = this;
1709
+ var select = $('select', elem);
1710
+ if(select[0] && select[0].options && select[0].options.length){
1711
+ options = select[0].options;
1712
+ }
1713
+ }
1714
+ return options;
1715
+ }
1716
+ }
1717
+ });
1718
+ }
1719
+ inputListProto['list'] = {
1720
+ attr: {
1721
+ get: function(){
1722
+ var val = webshims.contentAttr(this, 'list');
1723
+ if(val != null){
1724
+ this.removeAttribute('list');
1725
+ } else {
1726
+ val = $.data(this, 'datalistListAttr');
1727
+ }
1728
+
1729
+ return (val == null) ? undefined : val;
1730
+ },
1731
+ set: function(value){
1732
+ var elem = this;
1733
+ $.data(elem, 'datalistListAttr', value);
1734
+ webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
1735
+ }
1736
+ },
1737
+ initAttr: true,
1738
+ reflect: true,
1739
+ propType: 'element',
1740
+ propNodeName: 'datalist'
1741
+ };
1742
+ }
1743
+
1744
+
1745
+ webshims.defineNodeNameProperties('input', inputListProto);
1746
+
1747
+ if($.event.customEvent){
1748
+ $.event.customEvent.updateDatalist = true;
1749
+ $.event.customEvent.updateInput = true;
1750
+ $.event.customEvent.datalistselect = true;
1751
+ }
1752
+ webshims.addReady(function(context, contextElem){
1753
+ contextElem
1754
+ .filter('datalist > select, datalist, datalist > option, datalist > select > option')
1755
+ .closest('datalist')
1756
+ .triggerHandler('updateDatalist')
1757
+ ;
1758
+
1759
+ });
1760
+
1761
+
1762
+ };
1763
+
1764
+
1765
+ /*
1766
+ * ShadowList
1767
+ */
1768
+ var listidIndex = 0;
1769
+
1770
+ var noDatalistSupport = {
1771
+ submit: 1,
1772
+ button: 1,
1773
+ reset: 1,
1774
+ hidden: 1,
1775
+
1776
+ //ToDo
1777
+ range: 1,
1778
+ date: 1
1779
+ };
1780
+ var lteie6 = ($.browser.msie && parseInt($.browser.version, 10) < 7);
1781
+ var globStoredOptions = {};
1782
+ var getStoredOptions = function(name){
1783
+ if(!name){return [];}
1784
+ if(globStoredOptions[name]){
1785
+ return globStoredOptions[name];
1786
+ }
1787
+ var data;
1788
+ try {
1789
+ data = JSON.parse(localStorage.getItem('storedDatalistOptions'+name));
1790
+ } catch(e){}
1791
+ globStoredOptions[name] = data || [];
1792
+ return data || [];
1793
+ };
1794
+ var storeOptions = function(name, val){
1795
+ if(!name){return;}
1796
+ val = val || [];
1797
+ try {
1798
+ localStorage.setItem( 'storedDatalistOptions'+name, JSON.stringify(val) );
1799
+ } catch(e){}
1800
+ };
1801
+
1802
+ var getText = function(elem){
1803
+ return (elem.textContent || elem.innerText || $.text([ elem ]) || '');
1804
+ };
1805
+
1806
+ var shadowListProto = {
1807
+ _create: function(opts){
1808
+
1809
+ if(noDatalistSupport[$.prop(opts.input, 'type')]){return;}
1810
+ var datalist = opts.datalist;
1811
+ var data = $.data(opts.input, 'datalistWidget');
1812
+ if(datalist && data && data.datalist !== datalist){
1813
+ data.datalist = datalist;
1814
+ data.id = opts.id;
1815
+
1816
+ data.shadowList.prop('className', 'datalist-polyfill '+ (data.datalist.className || '') + ' '+ data.datalist.id +'-shadowdom');
1817
+ if(formsCFG.positionDatalist){
1818
+ data.shadowList.insertAfter(opts.input);
1819
+ } else {
1820
+ data.shadowList.appendTo('body');
1821
+ }
1822
+ $(data.datalist)
1823
+ .off('updateDatalist.datalistWidget')
1824
+ .on('updateDatalist.datalistWidget', $.proxy(data, '_resetListCached'))
1825
+ ;
1826
+ data._resetListCached();
1827
+ return;
1828
+ } else if(!datalist){
1829
+ if(data){
1830
+ data.destroy();
1831
+ }
1832
+ return;
1833
+ } else if(data && data.datalist === datalist){
1834
+ return;
1835
+ }
1836
+ listidIndex++;
1837
+ var that = this;
1838
+ this.hideList = $.proxy(that, 'hideList');
1839
+ this.timedHide = function(){
1840
+ clearTimeout(that.hideTimer);
1841
+ that.hideTimer = setTimeout(that.hideList, 9);
1842
+ };
1843
+ this.datalist = datalist;
1844
+ this.id = opts.id;
1845
+ this.hasViewableData = true;
1846
+ this._autocomplete = $.attr(opts.input, 'autocomplete');
1847
+ $.data(opts.input, 'datalistWidget', this);
1848
+ this.shadowList = $('<div class="datalist-polyfill '+ (this.datalist.className || '') + ' '+ this.datalist.id +'-shadowdom' +'" />');
1849
+
1850
+ if(formsCFG.positionDatalist || $(opts.input).hasClass('position-datalist')){
1851
+ this.shadowList.insertAfter(opts.input);
1852
+ } else {
1853
+ this.shadowList.appendTo('body');
1854
+ }
1855
+
1856
+ this.index = -1;
1857
+ this.input = opts.input;
1858
+ this.arrayOptions = [];
1859
+
1860
+ this.shadowList
1861
+ .delegate('li', 'mouseenter.datalistWidget mousedown.datalistWidget click.datalistWidget', function(e){
1862
+ var items = $('li:not(.hidden-item)', that.shadowList);
1863
+ var select = (e.type == 'mousedown' || e.type == 'click');
1864
+ that.markItem(items.index(e.currentTarget), select, items);
1865
+ if(e.type == 'click'){
1866
+ that.hideList();
1867
+ if(formsCFG.customDatalist){
1868
+ $(opts.input).trigger('datalistselect');
1869
+ }
1870
+ }
1871
+ return (e.type != 'mousedown');
1872
+ })
1873
+ .on('focusout', this.timedHide)
1874
+ ;
1875
+
1876
+ opts.input.setAttribute('autocomplete', 'off');
1877
+
1878
+ $(opts.input)
1879
+ .attr({
1880
+ //role: 'combobox',
1881
+ 'aria-haspopup': 'true'
1882
+ })
1883
+ .on({
1884
+ 'input.datalistWidget': function(){
1885
+ if(!that.triggeredByDatalist){
1886
+ that.changedValue = false;
1887
+ that.showHideOptions();
1888
+ }
1889
+ },
1890
+ 'keydown.datalistWidget': function(e){
1891
+ var keyCode = e.keyCode;
1892
+ var activeItem;
1893
+ var items;
1894
+ if(keyCode == 40 && !that.showList()){
1895
+ that.markItem(that.index + 1, true);
1896
+ return false;
1897
+ }
1898
+
1899
+ if(!that.isListVisible){return;}
1900
+
1901
+
1902
+ if(keyCode == 38){
1903
+ that.markItem(that.index - 1, true);
1904
+ return false;
1905
+ }
1906
+ if(!e.shiftKey && (keyCode == 33 || keyCode == 36)){
1907
+ that.markItem(0, true);
1908
+ return false;
1909
+ }
1910
+ if(!e.shiftKey && (keyCode == 34 || keyCode == 35)){
1911
+ items = $('li:not(.hidden-item)', that.shadowList);
1912
+ that.markItem(items.length - 1, true, items);
1913
+ return false;
1914
+ }
1915
+ if(keyCode == 13 || keyCode == 27){
1916
+ if (keyCode == 13){
1917
+ activeItem = $('li.active-item:not(.hidden-item)', that.shadowList);
1918
+ that.changeValue( $('li.active-item:not(.hidden-item)', that.shadowList) );
1919
+ }
1920
+ that.hideList();
1921
+ if(formsCFG.customDatalist && activeItem && activeItem[0]){
1922
+ $(opts.input).trigger('datalistselect');
1923
+ }
1924
+ return false;
1925
+ }
1926
+ },
1927
+ 'focus.datalistWidget': function(){
1928
+ if($(this).hasClass('list-focus')){
1929
+ that.showList();
1930
+ }
1931
+ },
1932
+ 'mousedown.datalistWidget': function(){
1933
+ if($(this).is(':focus')){
1934
+ that.showList();
1935
+ }
1936
+ },
1937
+ 'blur.datalistWidget': this.timedHide
1938
+ })
1939
+ ;
1940
+
1941
+
1942
+ $(this.datalist)
1943
+ .off('updateDatalist.datalistWidget')
1944
+ .on('updateDatalist.datalistWidget', $.proxy(this, '_resetListCached'))
1945
+ ;
1946
+
1947
+ this._resetListCached();
1948
+
1949
+ if(opts.input.form && (opts.input.name || opts.input.id)){
1950
+ $(opts.input.form).on('submit.datalistWidget'+opts.input.id, function(){
1951
+ if(!$(opts.input).hasClass('no-datalist-cache') && that._autocomplete != 'off'){
1952
+ var val = $.prop(opts.input, 'value');
1953
+ var name = (opts.input.name || opts.input.id) + $.prop(opts.input, 'type');
1954
+ if(!that.storedOptions){
1955
+ that.storedOptions = getStoredOptions( name );
1956
+ }
1957
+ if(val && that.storedOptions.indexOf(val) == -1){
1958
+ that.storedOptions.push(val);
1959
+ storeOptions(name, that.storedOptions );
1960
+ }
1961
+ }
1962
+ });
1963
+ }
1964
+ $(window).on('unload.datalist'+this.id+' beforeunload.datalist'+this.id, function(){
1965
+ that.destroy();
1966
+ });
1967
+ },
1968
+ destroy: function(){
1969
+ var autocomplete = $.attr(this.input, 'autocomplete');
1970
+ $(this.input)
1971
+ .off('.datalistWidget')
1972
+ .removeData('datalistWidget')
1973
+ ;
1974
+ this.shadowList.remove();
1975
+ $(document).off('.datalist'+this.id);
1976
+ $(window).off('.datalist'+this.id);
1977
+ if(this.input.form && this.input.id){
1978
+ $(this.input.form).off('submit.datalistWidget'+this.input.id);
1979
+ }
1980
+ this.input.removeAttribute('aria-haspopup');
1981
+ if(autocomplete === undefined){
1982
+ this.input.removeAttribute('autocomplete');
1983
+ } else {
1984
+ $(this.input).attr('autocomplete', autocomplete);
1985
+ }
1986
+ },
1987
+ _resetListCached: function(e){
1988
+ var that = this;
1989
+ var forceShow;
1990
+ this.needsUpdate = true;
1991
+ this.lastUpdatedValue = false;
1992
+ this.lastUnfoundValue = '';
1993
+
1994
+ if(!this.updateTimer){
1995
+ if(window.QUnit || (forceShow = (e && document.activeElement == that.input))){
1996
+ that.updateListOptions(forceShow);
1997
+ } else {
1998
+ webshims.ready('WINDOWLOAD', function(){
1999
+ that.updateTimer = setTimeout(function(){
2000
+ that.updateListOptions();
2001
+ that = null;
2002
+ listidIndex = 1;
2003
+ }, 200 + (100 * listidIndex));
2004
+ });
2005
+ }
2006
+ }
2007
+ },
2008
+ maskHTML: function(str){
2009
+ return str.replace(/</g, '&lt;').replace(/>/g, '&gt;');
2010
+ },
2011
+ updateListOptions: function(_forceShow){
2012
+ this.needsUpdate = false;
2013
+ clearTimeout(this.updateTimer);
2014
+ this.updateTimer = false;
2015
+ this.shadowList
2016
+ .css({
2017
+ fontSize: $.css(this.input, 'fontSize'),
2018
+ fontFamily: $.css(this.input, 'fontFamily')
2019
+ })
2020
+ ;
2021
+ this.searchStart = formsCFG.customDatalist && $(this.input).hasClass('search-start');
2022
+
2023
+ var list = [];
2024
+
2025
+ var values = [];
2026
+ var allOptions = [];
2027
+ var rElem, rItem, rOptions, rI, rLen, item;
2028
+ for(rOptions = $.prop(this.datalist, 'options'), rI = 0, rLen = rOptions.length; rI < rLen; rI++){
2029
+ rElem = rOptions[rI];
2030
+ if(rElem.disabled){return;}
2031
+ rItem = {
2032
+ value: $(rElem).val() || '',
2033
+ text: $.trim($.attr(rElem, 'label') || getText(rElem)),
2034
+ className: rElem.className || '',
2035
+ style: $.attr(rElem, 'style') || ''
2036
+ };
2037
+ if(!rItem.text){
2038
+ rItem.text = rItem.value;
2039
+ } else if(rItem.text != rItem.value){
2040
+ rItem.className += ' different-label-value';
2041
+ }
2042
+ values[rI] = rItem.value;
2043
+ allOptions[rI] = rItem;
2044
+ }
2045
+
2046
+ if(!this.storedOptions){
2047
+ this.storedOptions = ($(this.input).hasClass('no-datalist-cache') || this._autocomplete == 'off') ? [] : getStoredOptions((this.input.name || this.input.id) + $.prop(this.input, 'type'));
2048
+ }
2049
+
2050
+ this.storedOptions.forEach(function(val, i){
2051
+ if(values.indexOf(val) == -1){
2052
+ allOptions.push({value: val, text: val, className: 'stored-suggest', style: ''});
2053
+ }
2054
+ });
2055
+
2056
+ for(rI = 0, rLen = allOptions.length; rI < rLen; rI++){
2057
+ item = allOptions[rI];
2058
+ 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>';
2059
+ }
2060
+
2061
+ this.arrayOptions = allOptions;
2062
+ this.shadowList.html('<div class="datalist-outer-box"><div class="datalist-box"><ul role="list">'+ list.join("\n") +'</ul></div></div>');
2063
+
2064
+ if($.fn.bgIframe && lteie6){
2065
+ this.shadowList.bgIframe();
2066
+ }
2067
+
2068
+ if(_forceShow || this.isListVisible){
2069
+ this.showHideOptions();
2070
+ }
2071
+ },
2072
+ showHideOptions: function(_fromShowList){
2073
+ var value = $.prop(this.input, 'value').toLowerCase();
2074
+ //first check prevent infinite loop, second creates simple lazy optimization
2075
+ if(value === this.lastUpdatedValue || (this.lastUnfoundValue && value.indexOf(this.lastUnfoundValue) === 0)){
2076
+ return;
2077
+ }
2078
+
2079
+ this.lastUpdatedValue = value;
2080
+ var found = false;
2081
+ var startSearch = this.searchStart;
2082
+ var lis = $('li', this.shadowList);
2083
+ if(value){
2084
+ this.arrayOptions.forEach(function(item, i){
2085
+ var search;
2086
+ if(!('lowerText' in item)){
2087
+ if(item.text != item.value){
2088
+ item.lowerText = item.value.toLowerCase() + item.text.toLowerCase();
2089
+ } else {
2090
+ item.lowerText = item.text.toLowerCase();
2091
+ }
2092
+ }
2093
+ search = item.lowerText.indexOf(value);
2094
+ search = startSearch ? !search : search !== -1;
2095
+ if(search){
2096
+ $(lis[i]).removeClass('hidden-item');
2097
+ found = true;
2098
+ } else {
2099
+ $(lis[i]).addClass('hidden-item');
2100
+ }
2101
+ });
2102
+ } else if(lis.length) {
2103
+ lis.removeClass('hidden-item');
2104
+ found = true;
2105
+ }
2106
+
2107
+ this.hasViewableData = found;
2108
+ if(!_fromShowList && found){
2109
+ this.showList();
2110
+ }
2111
+ if(!found){
2112
+ this.lastUnfoundValue = value;
2113
+ this.hideList();
2114
+ }
2115
+ },
2116
+ setPos: function(){
2117
+ this.shadowList.css({marginTop: 0, marginLeft: 0, marginRight: 0, marginBottom: 0});
2118
+ var css = (formsCFG.positionDatalist) ? $(this.input).position() : webshims.getRelOffset(this.shadowList, this.input);
2119
+ css.top += $(this.input).outerHeight();
2120
+ css.width = $(this.input).outerWidth() - (parseInt(this.shadowList.css('borderLeftWidth'), 10) || 0) - (parseInt(this.shadowList.css('borderRightWidth'), 10) || 0);
2121
+ this.shadowList.css({marginTop: '', marginLeft: '', marginRight: '', marginBottom: ''}).css(css);
2122
+ return css;
2123
+ },
2124
+ showList: function(){
2125
+ if(this.isListVisible){return false;}
2126
+ if(this.needsUpdate){
2127
+ this.updateListOptions();
2128
+ }
2129
+ this.showHideOptions(true);
2130
+ if(!this.hasViewableData){return false;}
2131
+ this.isListVisible = true;
2132
+ var that = this;
2133
+
2134
+ that.setPos();
2135
+ that.shadowList.addClass('datalist-visible').find('li.active-item').removeClass('active-item');
2136
+
2137
+ $(window).unbind('.datalist'+that.id);
2138
+ $(document)
2139
+ .off('.datalist'+that.id)
2140
+ .on('mousedown.datalist'+that.id +' focusin.datalist'+that.id, function(e){
2141
+ if(e.target === that.input || that.shadowList[0] === e.target || $.contains( that.shadowList[0], e.target )){
2142
+ clearTimeout(that.hideTimer);
2143
+ setTimeout(function(){
2144
+ clearTimeout(that.hideTimer);
2145
+ }, 9);
2146
+ } else {
2147
+ that.timedHide();
2148
+ }
2149
+ })
2150
+ .on('updateshadowdom.datalist'+that.id, function(){
2151
+ that.setPos();
2152
+ })
2153
+ ;
2154
+ return true;
2155
+ },
2156
+ hideList: function(){
2157
+ if(!this.isListVisible){return false;}
2158
+ var that = this;
2159
+ var triggerChange = function(e){
2160
+ if(that.changedValue){
2161
+ $(that.input).trigger('change');
2162
+ }
2163
+ that.changedValue = false;
2164
+ };
2165
+
2166
+ that.shadowList.removeClass('datalist-visible list-item-active');
2167
+ that.index = -1;
2168
+ that.isListVisible = false;
2169
+ if(that.changedValue){
2170
+ that.triggeredByDatalist = true;
2171
+ webshims.triggerInlineForm && webshims.triggerInlineForm(that.input, 'input');
2172
+ if($(that.input).is(':focus')){
2173
+ $(that.input).one('blur', triggerChange);
2174
+ } else {
2175
+ triggerChange();
2176
+ }
2177
+ that.triggeredByDatalist = false;
2178
+ }
2179
+ $(document).unbind('.datalist'+that.id);
2180
+ $(window)
2181
+ .off('.datalist'+that.id)
2182
+ .one('resize.datalist'+that.id, function(){
2183
+ that.shadowList.css({top: 0, left: 0});
2184
+ })
2185
+ ;
2186
+ return true;
2187
+ },
2188
+ scrollIntoView: function(elem){
2189
+ var ul = $('ul', this.shadowList);
2190
+ var div = $('div.datalist-box', this.shadowList);
2191
+ var elemPos = elem.position();
2192
+ var containerHeight;
2193
+ elemPos.top -= (parseInt(ul.css('paddingTop'), 10) || 0) + (parseInt(ul.css('marginTop'), 10) || 0) + (parseInt(ul.css('borderTopWidth'), 10) || 0);
2194
+ if(elemPos.top < 0){
2195
+ div.scrollTop( div.scrollTop() + elemPos.top - 2);
2196
+ return;
2197
+ }
2198
+ elemPos.top += elem.outerHeight();
2199
+ containerHeight = div.height();
2200
+ if(elemPos.top > containerHeight){
2201
+ div.scrollTop( div.scrollTop() + (elemPos.top - containerHeight) + 2);
2202
+ }
2203
+ },
2204
+ changeValue: function(activeItem){
2205
+ if(!activeItem[0]){return;}
2206
+ var newValue = $('span.option-value', activeItem).text();
2207
+ var oldValue = $.prop(this.input, 'value');
2208
+ if(newValue != oldValue){
2209
+ $(this.input)
2210
+ .prop('value', newValue)
2211
+ .triggerHandler('updateInput')
2212
+ ;
2213
+ this.changedValue = true;
2214
+ }
2215
+ },
2216
+ markItem: function(index, doValue, items){
2217
+ var activeItem;
2218
+ var goesUp;
2219
+
2220
+ items = items || $('li:not(.hidden-item)', this.shadowList);
2221
+ if(!items.length){return;}
2222
+ if(index < 0){
2223
+ index = items.length - 1;
2224
+ } else if(index >= items.length){
2225
+ index = 0;
2226
+ }
2227
+ items.removeClass('active-item');
2228
+ this.shadowList.addClass('list-item-active');
2229
+ activeItem = items.filter(':eq('+ index +')').addClass('active-item');
2230
+
2231
+ if(doValue){
2232
+ this.changeValue(activeItem);
2233
+ this.scrollIntoView(activeItem);
2234
+ }
2235
+ this.index = index;
2236
+ }
2237
+ };
2238
+
2239
+ //init datalist update
2240
+ initializeDatalist();
2241
+ })();
2242
+
2243
2243
  });