webshims-rails 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/lib/webshims-rails/version.rb +2 -2
  2. data/vendor/assets/javascripts/webshims/extras/custom-validity.js +261 -261
  3. data/vendor/assets/javascripts/webshims/extras/modernizr-custom.js +534 -534
  4. data/vendor/assets/javascripts/webshims/extras/mousepress.js +60 -60
  5. data/vendor/assets/javascripts/webshims/minified/extras/custom-validity.js +1 -1
  6. data/vendor/assets/javascripts/webshims/minified/polyfiller.js +24 -24
  7. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/README +82 -82
  8. data/vendor/assets/javascripts/webshims/minified/shims/combos/1.js +35 -34
  9. data/vendor/assets/javascripts/webshims/minified/shims/combos/10.js +79 -82
  10. data/vendor/assets/javascripts/webshims/minified/shims/combos/11.js +45 -44
  11. data/vendor/assets/javascripts/webshims/minified/shims/combos/12.js +43 -42
  12. data/vendor/assets/javascripts/webshims/minified/shims/combos/13.js +28 -27
  13. data/vendor/assets/javascripts/webshims/minified/shims/combos/15.js +4 -4
  14. data/vendor/assets/javascripts/webshims/minified/shims/combos/16.js +57 -59
  15. data/vendor/assets/javascripts/webshims/minified/shims/combos/17.js +64 -66
  16. data/vendor/assets/javascripts/webshims/minified/shims/combos/18.js +53 -54
  17. data/vendor/assets/javascripts/webshims/minified/shims/combos/19.js +64 -66
  18. data/vendor/assets/javascripts/webshims/minified/shims/combos/2.js +72 -73
  19. data/vendor/assets/javascripts/webshims/minified/shims/combos/20.js +42 -46
  20. data/vendor/assets/javascripts/webshims/minified/shims/combos/21.js +52 -50
  21. data/vendor/assets/javascripts/webshims/minified/shims/combos/22.js +55 -59
  22. data/vendor/assets/javascripts/webshims/minified/shims/combos/23.js +66 -64
  23. data/vendor/assets/javascripts/webshims/minified/shims/combos/24.js +80 -82
  24. data/vendor/assets/javascripts/webshims/minified/shims/combos/25.js +60 -59
  25. data/vendor/assets/javascripts/webshims/minified/shims/combos/26.js +79 -81
  26. data/vendor/assets/javascripts/webshims/minified/shims/combos/27.js +101 -104
  27. data/vendor/assets/javascripts/webshims/minified/shims/combos/3.js +94 -95
  28. data/vendor/assets/javascripts/webshims/minified/shims/combos/4.js +26 -29
  29. data/vendor/assets/javascripts/webshims/minified/shims/combos/5.js +33 -36
  30. data/vendor/assets/javascripts/webshims/minified/shims/combos/59.js +51 -54
  31. data/vendor/assets/javascripts/webshims/minified/shims/combos/6.js +27 -28
  32. data/vendor/assets/javascripts/webshims/minified/shims/combos/7.js +27 -28
  33. data/vendor/assets/javascripts/webshims/minified/shims/combos/8.js +39 -38
  34. data/vendor/assets/javascripts/webshims/minified/shims/combos/9.js +65 -68
  35. data/vendor/assets/javascripts/webshims/minified/shims/details.js +4 -4
  36. data/vendor/assets/javascripts/webshims/minified/shims/dom-extend.js +23 -22
  37. data/vendor/assets/javascripts/webshims/minified/shims/form-core.js +19 -22
  38. data/vendor/assets/javascripts/webshims/minified/shims/form-datalist.js +14 -14
  39. data/vendor/assets/javascripts/webshims/minified/shims/form-number-date-api.js +9 -9
  40. data/vendor/assets/javascripts/webshims/minified/shims/form-number-date-ui.js +18 -19
  41. data/vendor/assets/javascripts/webshims/minified/shims/form-shim-extend.js +45 -43
  42. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-de.txt +33 -33
  43. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-en.txt +34 -34
  44. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-core.js +12 -12
  45. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-jaris.js +23 -0
  46. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-native-fix.js +1 -1
  47. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-swf.js +26 -30
  48. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-yt.js +3 -3
  49. data/vendor/assets/javascripts/webshims/minified/shims/styles/shim.css +689 -686
  50. data/vendor/assets/javascripts/webshims/minified/shims/swf/JarisFLVPlayer.swf +0 -0
  51. data/vendor/assets/javascripts/webshims/minified/shims/track-ui.js +9 -9
  52. data/vendor/assets/javascripts/webshims/minified/shims/track.js +21 -21
  53. data/vendor/assets/javascripts/webshims/polyfiller.js +1191 -1175
  54. data/vendor/assets/javascripts/webshims/shims/combos/1.js +1754 -1714
  55. data/vendor/assets/javascripts/webshims/shims/combos/10.js +3247 -3320
  56. data/vendor/assets/javascripts/webshims/shims/combos/11.js +1633 -1588
  57. data/vendor/assets/javascripts/webshims/shims/combos/12.js +1636 -1591
  58. data/vendor/assets/javascripts/webshims/shims/combos/13.js +1100 -1058
  59. data/vendor/assets/javascripts/webshims/shims/combos/14.js +476 -476
  60. data/vendor/assets/javascripts/webshims/shims/combos/15.js +316 -314
  61. data/vendor/assets/javascripts/webshims/shims/combos/16.js +2094 -2104
  62. data/vendor/assets/javascripts/webshims/shims/combos/17.js +2258 -2267
  63. data/vendor/assets/javascripts/webshims/shims/combos/18.js +1380 -1364
  64. data/vendor/assets/javascripts/webshims/shims/combos/19.js +2239 -2247
  65. data/vendor/assets/javascripts/webshims/shims/combos/2.js +2339 -2294
  66. data/vendor/assets/javascripts/webshims/shims/combos/20.js +1493 -1606
  67. data/vendor/assets/javascripts/webshims/shims/combos/21.js +1733 -1635
  68. data/vendor/assets/javascripts/webshims/shims/combos/22.js +2295 -2408
  69. data/vendor/assets/javascripts/webshims/shims/combos/23.js +2269 -2168
  70. data/vendor/assets/javascripts/webshims/shims/combos/24.js +2775 -2780
  71. data/vendor/assets/javascripts/webshims/shims/combos/25.js +1505 -1456
  72. data/vendor/assets/javascripts/webshims/shims/combos/26.js +2111 -2115
  73. data/vendor/assets/javascripts/webshims/shims/combos/27.js +3264 -3331
  74. data/vendor/assets/javascripts/webshims/shims/combos/3.js +3020 -2970
  75. data/vendor/assets/javascripts/webshims/shims/combos/4.js +770 -822
  76. data/vendor/assets/javascripts/webshims/shims/combos/5.js +1025 -1077
  77. data/vendor/assets/javascripts/webshims/shims/combos/59.js +1706 -1753
  78. data/vendor/assets/javascripts/webshims/shims/combos/6.js +444 -433
  79. data/vendor/assets/javascripts/webshims/shims/combos/7.js +699 -688
  80. data/vendor/assets/javascripts/webshims/shims/combos/8.js +1488 -1445
  81. data/vendor/assets/javascripts/webshims/shims/combos/9.js +2445 -2518
  82. data/vendor/assets/javascripts/webshims/shims/details.js +148 -146
  83. data/vendor/assets/javascripts/webshims/shims/dom-extend.js +952 -912
  84. data/vendor/assets/javascripts/webshims/shims/es5.js +802 -802
  85. data/vendor/assets/javascripts/webshims/shims/excanvas.js +924 -924
  86. data/vendor/assets/javascripts/webshims/shims/form-core.js +606 -659
  87. data/vendor/assets/javascripts/webshims/shims/form-datalist.js +681 -676
  88. data/vendor/assets/javascripts/webshims/shims/form-message.js +164 -163
  89. data/vendor/assets/javascripts/webshims/shims/form-native-extend.js +255 -255
  90. data/vendor/assets/javascripts/webshims/shims/form-number-date-api.js +383 -383
  91. data/vendor/assets/javascripts/webshims/shims/form-number-date-ui.js +61 -50
  92. data/vendor/assets/javascripts/webshims/shims/form-shim-extend.js +1569 -1472
  93. data/vendor/assets/javascripts/webshims/shims/geolocation.js +168 -168
  94. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ar.js +32 -32
  95. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ch-ZN.js +32 -32
  96. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-de.txt +33 -33
  97. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-el.js +32 -32
  98. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-en.txt +34 -34
  99. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-es.js +31 -31
  100. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-fr.js +32 -32
  101. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-he.js +32 -32
  102. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-hi.js +32 -32
  103. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-hu.js +32 -32
  104. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-it.js +32 -32
  105. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ja.js +32 -32
  106. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-nl.js +32 -32
  107. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-pt-PT.js +32 -32
  108. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ru.js +31 -31
  109. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-sv.js +32 -32
  110. data/vendor/assets/javascripts/webshims/shims/json-storage.js +308 -308
  111. data/vendor/assets/javascripts/webshims/shims/mediaelement-core.js +536 -533
  112. data/vendor/assets/javascripts/webshims/shims/mediaelement-jaris.js +861 -0
  113. data/vendor/assets/javascripts/webshims/shims/mediaelement-native-fix.js +98 -98
  114. data/vendor/assets/javascripts/webshims/shims/mediaelement-swf.js +957 -1073
  115. data/vendor/assets/javascripts/webshims/shims/mediaelement-yt.js +543 -543
  116. data/vendor/assets/javascripts/webshims/shims/styles/shim.css +689 -686
  117. data/vendor/assets/javascripts/webshims/shims/swf/JarisFLVPlayer.swf +0 -0
  118. data/vendor/assets/javascripts/webshims/shims/track-ui.js +9 -8
  119. data/vendor/assets/javascripts/webshims/shims/track.js +17 -11
  120. metadata +6 -6
  121. data/vendor/assets/javascripts/webshims/minified/shims/form-native-fix.js +0 -7
  122. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/README +0 -62
  123. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/README +0 -82
  124. data/vendor/assets/javascripts/webshims/shims/form-native-fix.js +0 -261
@@ -1,2248 +1,2240 @@
1
- //DOM-Extension helper
2
- jQuery.webshims.register('dom-extend', function($, webshims, window, document, undefined){
3
- "use strict";
4
- //shortcus
5
- var modules = webshims.modules;
6
- var listReg = /\s*,\s*/;
7
-
8
- //proxying attribute
9
- var olds = {};
10
- var havePolyfill = {};
11
- var extendedProps = {};
12
- var extendQ = {};
13
- var modifyProps = {};
14
-
15
- var oldVal = $.fn.val;
16
- var singleVal = function(elem, name, val, pass, _argless){
17
- return (_argless) ? oldVal.call($(elem)) : oldVal.call($(elem), val);
18
- };
19
- $.fn.val = function(val){
20
- var elem = this[0];
21
- if(arguments.length && val == null){
22
- val = '';
23
- }
24
- if(!arguments.length){
25
- if(!elem || elem.nodeType !== 1){return oldVal.call(this);}
26
- return $.prop(elem, 'value', val, 'val', true);
27
- }
28
- if($.isArray(val)){
29
- return oldVal.apply(this, arguments);
30
- }
31
- var isFunction = $.isFunction(val);
32
- return this.each(function(i){
33
- elem = this;
34
- if(elem.nodeType === 1){
35
- if(isFunction){
36
- var genVal = val.call( elem, i, $.prop(elem, 'value', undefined, 'val', true));
37
- if(genVal == null){
38
- genVal = '';
39
- }
40
- $.prop(elem, 'value', genVal, 'val') ;
41
- } else {
42
- $.prop(elem, 'value', val, 'val');
43
- }
44
- }
45
- });
46
- };
47
-
48
- var dataID = '_webshimsLib'+ (Math.round(Math.random() * 1000));
49
- var elementData = function(elem, key, val){
50
- elem = elem.jquery ? elem[0] : elem;
51
- if(!elem){return val || {};}
52
- var data = $.data(elem, dataID);
53
- if(val !== undefined){
54
- if(!data){
55
- data = $.data(elem, dataID, {});
56
- }
57
- if(key){
58
- data[key] = val;
59
- }
60
- }
61
-
62
- return key ? data && data[key] : data;
63
- };
64
-
65
-
66
- [{name: 'getNativeElement', prop: 'nativeElement'}, {name: 'getShadowElement', prop: 'shadowElement'}, {name: 'getShadowFocusElement', prop: 'shadowFocusElement'}].forEach(function(data){
67
- $.fn[data.name] = function(){
68
- return this.map(function(){
69
- var shadowData = elementData(this, 'shadowData');
70
- return shadowData && shadowData[data.prop] || this;
71
- });
72
- };
73
- });
74
-
75
-
76
- ['removeAttr', 'prop', 'attr'].forEach(function(type){
77
- olds[type] = $[type];
78
- $[type] = function(elem, name, value, pass, _argless){
79
- var isVal = (pass == 'val');
80
- var oldMethod = !isVal ? olds[type] : singleVal;
81
- if( !elem || !havePolyfill[name] || elem.nodeType !== 1 || (!isVal && pass && type == 'attr' && $.attrFn[name]) ){
82
- return oldMethod(elem, name, value, pass, _argless);
83
- }
84
-
85
- var nodeName = (elem.nodeName || '').toLowerCase();
86
- var desc = extendedProps[nodeName];
87
- var curType = (type == 'attr' && (value === false || value === null)) ? 'removeAttr' : type;
88
- var propMethod;
89
- var oldValMethod;
90
- var ret;
91
-
92
-
93
- if(!desc){
94
- desc = extendedProps['*'];
95
- }
96
- if(desc){
97
- desc = desc[name];
98
- }
99
-
100
- if(desc){
101
- propMethod = desc[curType];
102
- }
103
-
104
- if(propMethod){
105
- if(name == 'value'){
106
- oldValMethod = propMethod.isVal;
107
- propMethod.isVal = isVal;
108
- }
109
- if(curType === 'removeAttr'){
110
- return propMethod.value.call(elem);
111
- } else if(value === undefined){
112
- return (propMethod.get) ?
113
- propMethod.get.call(elem) :
114
- propMethod.value
115
- ;
116
- } else if(propMethod.set) {
117
- if(type == 'attr' && value === true){
118
- value = name;
119
- }
120
-
121
- ret = propMethod.set.call(elem, value);
122
- }
123
- if(name == 'value'){
124
- propMethod.isVal = oldValMethod;
125
- }
126
- } else {
127
- ret = oldMethod(elem, name, value, pass, _argless);
128
- }
129
- if((value !== undefined || curType === 'removeAttr') && modifyProps[nodeName] && modifyProps[nodeName][name]){
130
-
131
- var boolValue;
132
- if(curType == 'removeAttr'){
133
- boolValue = false;
134
- } else if(curType == 'prop'){
135
- boolValue = !!(value);
136
- } else {
137
- boolValue = true;
138
- }
139
-
140
- modifyProps[nodeName][name].forEach(function(fn){
141
- if(!fn.only || (fn.only = 'prop' && type == 'prop') || (fn.only == 'attr' && type != 'prop')){
142
- fn.call(elem, value, boolValue, (isVal) ? 'val' : curType, type);
143
- }
144
- });
145
- }
146
- return ret;
147
- };
148
-
149
- extendQ[type] = function(nodeName, prop, desc){
150
-
151
- if(!extendedProps[nodeName]){
152
- extendedProps[nodeName] = {};
153
- }
154
- if(!extendedProps[nodeName][prop]){
155
- extendedProps[nodeName][prop] = {};
156
- }
157
- var oldDesc = extendedProps[nodeName][prop][type];
158
- var getSup = function(propType, descriptor, oDesc){
159
- if(descriptor && descriptor[propType]){
160
- return descriptor[propType];
161
- }
162
- if(oDesc && oDesc[propType]){
163
- return oDesc[propType];
164
- }
165
- if(type == 'prop' && prop == 'value'){
166
- return function(value){
167
- var elem = this;
168
- return (desc.isVal) ?
169
- singleVal(elem, prop, value, false, (arguments.length === 0)) :
170
- olds[type](elem, prop, value)
171
- ;
172
- };
173
- }
174
- if(type == 'prop' && propType == 'value' && desc.value.apply){
175
- return function(value){
176
- var sup = olds[type](this, prop);
177
- if(sup && sup.apply){
178
- sup = sup.apply(this, arguments);
179
- }
180
- return sup;
181
- };
182
- }
183
- return function(value){
184
- return olds[type](this, prop, value);
185
- };
186
- };
187
- extendedProps[nodeName][prop][type] = desc;
188
- if(desc.value === undefined){
189
- if(!desc.set){
190
- desc.set = desc.writeable ?
191
- getSup('set', desc, oldDesc) :
192
- (webshims.cfg.useStrict && prop == 'prop') ?
193
- function(){throw(prop +' is readonly on '+ nodeName);} :
194
- $.noop
195
- ;
196
- }
197
- if(!desc.get){
198
- desc.get = getSup('get', desc, oldDesc);
199
- }
200
-
201
- }
202
-
203
- ['value', 'get', 'set'].forEach(function(descProp){
204
- if(desc[descProp]){
205
- desc['_sup'+descProp] = getSup(descProp, oldDesc);
206
- }
207
- });
208
- };
209
-
210
- });
211
-
212
- //see also: https://github.com/lojjic/PIE/issues/40 | https://prototype.lighthouseapp.com/projects/8886/tickets/1107-ie8-fatal-crash-when-prototypejs-is-loaded-with-rounded-cornershtc
213
- var isExtendNativeSave = (!$.browser.msie || parseInt($.browser.version, 10) > 8);
214
- var extendNativeValue = (function(){
215
- var UNKNOWN = webshims.getPrototypeOf(document.createElement('foobar'));
216
- var has = Object.prototype.hasOwnProperty;
217
- return function(nodeName, prop, desc){
218
- var elem = document.createElement(nodeName);
219
- var elemProto = webshims.getPrototypeOf(elem);
220
- if( isExtendNativeSave && elemProto && UNKNOWN !== elemProto && ( !elem[prop] || !has.call(elem, prop) ) ){
221
- var sup = elem[prop];
222
- desc._supvalue = function(){
223
- if(sup && sup.apply){
224
- return sup.apply(this, arguments);
225
- }
226
- return sup;
227
- };
228
- elemProto[prop] = desc.value;
229
- } else {
230
- desc._supvalue = function(){
231
- var data = elementData(this, 'propValue');
232
- if(data && data[prop] && data[prop].apply){
233
- return data[prop].apply(this, arguments);
234
- }
235
- return data && data[prop];
236
- };
237
- initProp.extendValue(nodeName, prop, desc.value);
238
- }
239
- desc.value._supvalue = desc._supvalue;
240
- };
241
- })();
242
-
243
- var initProp = (function(){
244
-
245
- var initProps = {};
246
-
247
- webshims.addReady(function(context, contextElem){
248
- var nodeNameCache = {};
249
- var getElementsByName = function(name){
250
- if(!nodeNameCache[name]){
251
- nodeNameCache[name] = $(context.getElementsByTagName(name));
252
- if(contextElem[0] && $.nodeName(contextElem[0], name)){
253
- nodeNameCache[name] = nodeNameCache[name].add(contextElem);
254
- }
255
- }
256
- };
257
-
258
-
259
- $.each(initProps, function(name, fns){
260
- getElementsByName(name);
261
- if(!fns || !fns.forEach){
262
- webshims.warn('Error: with '+ name +'-property. methods: '+ fns);
263
- return;
264
- }
265
- fns.forEach(function(fn){
266
- nodeNameCache[name].each(fn);
267
- });
268
- });
269
- nodeNameCache = null;
270
- });
271
-
272
- var tempCache;
273
- var emptyQ = $([]);
274
- var createNodeNameInit = function(nodeName, fn){
275
- if(!initProps[nodeName]){
276
- initProps[nodeName] = [fn];
277
- } else {
278
- initProps[nodeName].push(fn);
279
- }
280
- if($.isDOMReady){
281
- (tempCache || $( document.getElementsByTagName(nodeName) )).each(fn);
282
- }
283
- };
284
-
285
- var elementExtends = {};
286
- return {
287
- createTmpCache: function(nodeName){
288
- if($.isDOMReady){
289
- tempCache = tempCache || $( document.getElementsByTagName(nodeName) );
290
- }
291
- return tempCache || emptyQ;
292
- },
293
- flushTmpCache: function(){
294
- tempCache = null;
295
- },
296
- content: function(nodeName, prop){
297
- createNodeNameInit(nodeName, function(){
298
- var val = $.attr(this, prop);
299
- if(val != null){
300
- $.attr(this, prop, val);
301
- }
302
- });
303
- },
304
- createElement: function(nodeName, fn){
305
- createNodeNameInit(nodeName, fn);
306
- },
307
- extendValue: function(nodeName, prop, value){
308
- createNodeNameInit(nodeName, function(){
309
- $(this).each(function(){
310
- var data = elementData(this, 'propValue', {});
311
- data[prop] = this[prop];
312
- this[prop] = value;
313
- });
314
- });
315
- }
316
- };
317
- })();
318
-
319
- var createPropDefault = function(descs, removeType){
320
- if(descs.defaultValue === undefined){
321
- descs.defaultValue = '';
322
- }
323
- if(!descs.removeAttr){
324
- descs.removeAttr = {
325
- value: function(){
326
- descs[removeType || 'prop'].set.call(this, descs.defaultValue);
327
- descs.removeAttr._supvalue.call(this);
328
- }
329
- };
330
- }
331
- if(!descs.attr){
332
- descs.attr = {};
333
- }
334
- };
335
-
336
- $.extend(webshims, {
337
-
338
- getID: (function(){
339
- var ID = new Date().getTime();
340
- return function(elem){
341
- elem = $(elem);
342
- var id = elem.attr('id');
343
- if(!id){
344
- ID++;
345
- id = 'ID-'+ ID;
346
- elem.attr('id', id);
347
- }
348
- return id;
349
- };
350
- })(),
351
- extendUNDEFProp: function(obj, props){
352
- $.each(props, function(name, prop){
353
- if( !(name in obj) ){
354
- obj[name] = prop;
355
- }
356
- });
357
- },
358
- //http://www.w3.org/TR/html5/common-dom-interfaces.html#reflect
359
- createPropDefault: createPropDefault,
360
- data: elementData,
361
- moveToFirstEvent: (function(){
362
- var getData = $._data ? '_data' : 'data';
363
- return function(elem, eventType, bindType){
364
- var events = ($[getData](elem, 'events') || {})[eventType];
365
- var fn;
366
-
367
- if(events && events.length > 1){
368
- fn = events.pop();
369
- if(!bindType){
370
- bindType = 'bind';
371
- }
372
- if(bindType == 'bind' && events.delegateCount){
373
- events.splice( events.delegateCount, 0, fn);
374
- } else {
375
- events.unshift( fn );
376
- }
377
-
378
-
379
- }
380
- elem = null;
381
- };
382
- })(),
383
- addShadowDom: (function(){
384
- var resizeTimer;
385
- var lastHeight;
386
- var lastWidth;
387
- var handler;
388
- var docObserve = {
389
- init: false,
390
- start: function(){
391
- if(!this.init && document.body){
392
- this.init = true;
393
- this.height = $(document).height();
394
- this.width = $(document).width();
395
- setInterval(function(){
396
- var height = $(document).height();
397
- var width = $(document).width();
398
- if(height != docObserve.height || width != docObserve.width){
399
- docObserve.height = height;
400
- docObserve.width = width;
401
- handler({type: 'docresize'});
402
- }
403
- }, 600);
404
- }
405
- }
406
- };
407
-
408
- handler = function(e){
409
- clearTimeout(resizeTimer);
410
- resizeTimer = setTimeout(function(){
411
- if(e.type == 'resize'){
412
- var width = $(window).width();
413
- var height = $(window).width();
414
- if(height == lastHeight && width == lastWidth){
415
- return;
416
- }
417
- lastHeight = height;
418
- lastWidth = width;
419
- if(document.body){
420
- docObserve.height = $(document).height();
421
- docObserve.width = $(document).width();
422
- }
423
- }
424
- $.event.trigger('updateshadowdom');
425
- }, 40);
426
- };
427
- $(window).bind('resize', handler);
428
-
429
- $.event.customEvent.updateshadowdom = true;
430
-
431
- return function(nativeElem, shadowElem, opts){
432
- opts = opts || {};
433
- if(nativeElem.jquery){
434
- nativeElem = nativeElem[0];
435
- }
436
- if(shadowElem.jquery){
437
- shadowElem = shadowElem[0];
438
- }
439
- var nativeData = $.data(nativeElem, dataID) || $.data(nativeElem, dataID, {});
440
- var shadowData = $.data(shadowElem, dataID) || $.data(shadowElem, dataID, {});
441
- var shadowFocusElementData = {};
442
- if(!opts.shadowFocusElement){
443
- opts.shadowFocusElement = shadowElem;
444
- } else if(opts.shadowFocusElement){
445
- if(opts.shadowFocusElement.jquery){
446
- opts.shadowFocusElement = opts.shadowFocusElement[0];
447
- }
448
- shadowFocusElementData = $.data(opts.shadowFocusElement, dataID) || $.data(opts.shadowFocusElement, dataID, shadowFocusElementData);
449
- }
450
-
451
- nativeData.hasShadow = shadowElem;
452
- shadowFocusElementData.nativeElement = shadowData.nativeElement = nativeElem;
453
- shadowFocusElementData.shadowData = shadowData.shadowData = nativeData.shadowData = {
454
- nativeElement: nativeElem,
455
- shadowElement: shadowElem,
456
- shadowFocusElement: opts.shadowFocusElement
457
- };
458
- if(opts.shadowChilds){
459
- opts.shadowChilds.each(function(){
460
- elementData(this, 'shadowData', shadowData.shadowData);
461
- });
462
- }
463
-
464
- if(opts.data){
465
- shadowFocusElementData.shadowData.data = shadowData.shadowData.data = nativeData.shadowData.data = opts.data;
466
- }
467
- opts = null;
468
- webshims.ready('DOM', function(){
469
- docObserve.start();
470
- });
471
- }
472
- })(),
473
- propTypes: {
474
- standard: function(descs, name){
475
- createPropDefault(descs);
476
- if(descs.prop){return;}
477
- descs.prop = {
478
- set: function(val){
479
- descs.attr.set.call(this, ''+val);
480
- },
481
- get: function(){
482
- return descs.attr.get.call(this) || descs.defaultValue;
483
- }
484
- };
485
-
486
- },
487
- "boolean": function(descs, name){
488
-
489
- createPropDefault(descs);
490
- if(descs.prop){return;}
491
- descs.prop = {
492
- set: function(val){
493
- if(val){
494
- descs.attr.set.call(this, "");
495
- } else {
496
- descs.removeAttr.value.call(this);
497
- }
498
- },
499
- get: function(){
500
- return descs.attr.get.call(this) != null;
501
- }
502
- };
503
- },
504
- "src": (function(){
505
- var anchor = document.createElement('a');
506
- anchor.style.display = "none";
507
- return function(descs, name){
508
-
509
- createPropDefault(descs);
510
- if(descs.prop){return;}
511
- descs.prop = {
512
- set: function(val){
513
- descs.attr.set.call(this, val);
514
- },
515
- get: function(){
516
- var href = this.getAttribute(name);
517
- var ret;
518
- if(href == null){return '';}
519
-
520
- anchor.setAttribute('href', href+'' );
521
-
522
- if(!$.support.hrefNormalized){
523
- try {
524
- $(anchor).insertAfter(this);
525
- ret = anchor.getAttribute('href', 4);
526
- } catch(er){
527
- ret = anchor.getAttribute('href', 4);
528
- }
529
- $(anchor).detach();
530
- }
531
- return ret || anchor.href;
532
- }
533
- };
534
- };
535
- })(),
536
- enumarated: function(descs, name){
537
-
538
- createPropDefault(descs);
539
- if(descs.prop){return;}
540
- descs.prop = {
541
- set: function(val){
542
- descs.attr.set.call(this, val);
543
- },
544
- get: function(){
545
- var val = (descs.attr.get.call(this) || '').toLowerCase();
546
- if(!val || descs.limitedTo.indexOf(val) == -1){
547
- val = descs.defaultValue;
548
- }
549
- return val;
550
- }
551
- };
552
- }
553
-
554
- // ,unsignedLong: $.noop
555
- // ,"doubble": $.noop
556
- // ,"long": $.noop
557
- // ,tokenlist: $.noop
558
- // ,settableTokenlist: $.noop
559
- },
560
- reflectProperties: function(nodeNames, props){
561
- if(typeof props == 'string'){
562
- props = props.split(listReg);
563
- }
564
- props.forEach(function(prop){
565
- webshims.defineNodeNamesProperty(nodeNames, prop, {
566
- prop: {
567
- set: function(val){
568
- $.attr(this, prop, val);
569
- },
570
- get: function(){
571
- return $.attr(this, prop) || '';
572
- }
573
- }
574
- });
575
- });
576
- },
577
- defineNodeNameProperty: function(nodeName, prop, descs){
578
- havePolyfill[prop] = true;
579
-
580
- if(descs.reflect){
581
- webshims.propTypes[descs.propType || 'standard'](descs, prop);
582
- }
583
-
584
- ['prop', 'attr', 'removeAttr'].forEach(function(type){
585
- var desc = descs[type];
586
- if(desc){
587
- if(type === 'prop'){
588
- desc = $.extend({writeable: true}, desc);
589
- } else {
590
- desc = $.extend({}, desc, {writeable: true});
591
- }
592
-
593
- extendQ[type](nodeName, prop, desc);
594
- if(nodeName != '*' && webshims.cfg.extendNative && type == 'prop' && desc.value && $.isFunction(desc.value)){
595
- extendNativeValue(nodeName, prop, desc);
596
- }
597
- descs[type] = desc;
598
- }
599
- });
600
- if(descs.initAttr){
601
- initProp.content(nodeName, prop);
602
- }
603
- return descs;
604
- },
605
-
606
- defineNodeNameProperties: function(name, descs, propType, _noTmpCache){
607
- var olddesc;
608
- for(var prop in descs){
609
- if(!_noTmpCache && descs[prop].initAttr){
610
- initProp.createTmpCache(name);
611
- }
612
- if(propType){
613
- if(descs[prop][propType]){
614
- //webshims.log('override: '+ name +'['+prop +'] for '+ propType);
615
- } else {
616
- descs[prop][propType] = {};
617
- ['value', 'set', 'get'].forEach(function(copyProp){
618
- if(copyProp in descs[prop]){
619
- descs[prop][propType][copyProp] = descs[prop][copyProp];
620
- delete descs[prop][copyProp];
621
- }
622
- });
623
- }
624
- }
625
- descs[prop] = webshims.defineNodeNameProperty(name, prop, descs[prop]);
626
- }
627
- if(!_noTmpCache){
628
- initProp.flushTmpCache();
629
- }
630
- return descs;
631
- },
632
-
633
- createElement: function(nodeName, create, descs){
634
- var ret;
635
- if($.isFunction(create)){
636
- create = {
637
- after: create
638
- };
639
- }
640
- initProp.createTmpCache(nodeName);
641
- if(create.before){
642
- initProp.createElement(nodeName, create.before);
643
- }
644
- if(descs){
645
- ret = webshims.defineNodeNameProperties(nodeName, descs, false, true);
646
- }
647
- if(create.after){
648
- initProp.createElement(nodeName, create.after);
649
- }
650
- initProp.flushTmpCache();
651
- return ret;
652
- },
653
- onNodeNamesPropertyModify: function(nodeNames, props, desc, only){
654
- if(typeof nodeNames == 'string'){
655
- nodeNames = nodeNames.split(listReg);
656
- }
657
- if($.isFunction(desc)){
658
- desc = {set: desc};
659
- }
660
-
661
- nodeNames.forEach(function(name){
662
- if(!modifyProps[name]){
663
- modifyProps[name] = {};
664
- }
665
- if(typeof props == 'string'){
666
- props = props.split(listReg);
667
- }
668
- if(desc.initAttr){
669
- initProp.createTmpCache(name);
670
- }
671
- props.forEach(function(prop){
672
- if(!modifyProps[name][prop]){
673
- modifyProps[name][prop] = [];
674
- havePolyfill[prop] = true;
675
- }
676
- if(desc.set){
677
- if(only){
678
- desc.set.only = only;
679
- }
680
- modifyProps[name][prop].push(desc.set);
681
- }
682
-
683
- if(desc.initAttr){
684
- initProp.content(name, prop);
685
- }
686
- });
687
- initProp.flushTmpCache();
688
-
689
- });
690
- },
691
- defineNodeNamesBooleanProperty: function(elementNames, prop, descs){
692
- if(!descs){
693
- descs = {};
694
- }
695
- if($.isFunction(descs)){
696
- descs.set = descs;
697
- }
698
- webshims.defineNodeNamesProperty(elementNames, prop, {
699
- attr: {
700
- set: function(val){
701
- this.setAttribute(prop, val);
702
- if(descs.set){
703
- descs.set.call(this, true);
704
- }
705
- },
706
- get: function(){
707
- var ret = this.getAttribute(prop);
708
- return (ret == null) ? undefined : prop;
709
- }
710
- },
711
- removeAttr: {
712
- value: function(){
713
- this.removeAttribute(prop);
714
- if(descs.set){
715
- descs.set.call(this, false);
716
- }
717
- }
718
- },
719
- reflect: true,
720
- propType: 'boolean',
721
- initAttr: descs.initAttr || false
722
- });
723
- },
724
- contentAttr: function(elem, name, val){
725
- if(!elem.nodeName){return;}
726
- var attr;
727
- if(val === undefined){
728
- attr = (elem.attributes[name] || {});
729
- val = attr.specified ? attr.value : null;
730
- return (val == null) ? undefined : val;
731
- }
732
-
733
- if(typeof val == 'boolean'){
734
- if(!val){
735
- elem.removeAttribute(name);
736
- } else {
737
- elem.setAttribute(name, name);
738
- }
739
- } else {
740
- elem.setAttribute(name, val);
741
- }
742
- },
743
-
744
- // set current Lang:
745
- // - webshims.activeLang(lang:string);
746
- // get current lang
747
- // - webshims.activeLang();
748
- // get current lang
749
- // webshims.activeLang({
750
- // register: moduleName:string,
751
- // callback: callback:function
752
- // });
753
- // get/set including removeLang
754
- // - webshims.activeLang({
755
- // module: moduleName:string,
756
- // callback: callback:function,
757
- // langObj: languageObj:array/object
758
- // });
759
- activeLang: (function(){
760
- var callbacks = [];
761
- var registeredCallbacks = {};
762
- var currentLang;
763
- var shortLang;
764
- var notLocal = /:\/\/|^\.*\//;
765
- var loadRemoteLang = function(data, lang, options){
766
- var langSrc;
767
- if(lang && options && $.inArray(lang, options.availabeLangs || []) !== -1){
768
- data.loading = true;
769
- langSrc = options.langSrc;
770
- if(!notLocal.test(langSrc)){
771
- langSrc = webshims.cfg.basePath+langSrc;
772
- }
773
- webshims.loader.loadScript(langSrc+lang+'.js', function(){
774
- if(data.langObj[lang]){
775
- data.loading = false;
776
- callLang(data, true);
777
- } else {
778
- $(function(){
779
- if(data.langObj[lang]){
780
- callLang(data, true);
781
- }
782
- data.loading = false;
783
- });
784
- }
785
- });
786
- return true;
787
- }
788
- return false;
789
- };
790
- var callRegister = function(module){
791
- if(registeredCallbacks[module]){
792
- registeredCallbacks[module].forEach(function(data){
793
- data.callback();
794
- });
795
- }
796
- };
797
- var callLang = function(data, _noLoop){
798
- if(data.activeLang != currentLang && data.activeLang !== shortLang){
799
- var options = modules[data.module].options;
800
- if( data.langObj[currentLang] || (shortLang && data.langObj[shortLang]) ){
801
- data.activeLang = currentLang;
802
- data.callback(data.langObj[currentLang] || data.langObj[shortLang], currentLang);
803
- callRegister(data.module);
804
- } else if( !_noLoop &&
805
- !loadRemoteLang(data, currentLang, options) &&
806
- !loadRemoteLang(data, shortLang, options) &&
807
- data.langObj[''] && data.activeLang !== '' ) {
808
- data.activeLang = '';
809
- data.callback(data.langObj[''], currentLang);
810
- callRegister(data.module);
811
- }
812
- }
813
- };
814
-
815
-
816
- var activeLang = function(lang){
817
-
818
- if(typeof lang == 'string' && lang !== currentLang){
819
- currentLang = lang;
820
- shortLang = currentLang.split('-')[0];
821
- if(currentLang == shortLang){
822
- shortLang = false;
823
- }
824
- $.each(callbacks, function(i, data){
825
- callLang(data);
826
- });
827
- } else if(typeof lang == 'object'){
828
-
829
- if(lang.register){
830
- if(!registeredCallbacks[lang.register]){
831
- registeredCallbacks[lang.register] = [];
832
- }
833
- registeredCallbacks[lang.register].push(lang);
834
- lang.callback();
835
- } else {
836
- if(!lang.activeLang){
837
- lang.activeLang = '';
838
- }
839
- callbacks.push(lang);
840
- callLang(lang);
841
- }
842
- }
843
- return currentLang;
844
- };
845
-
846
- return activeLang;
847
- })()
848
- });
849
-
850
- $.each({
851
- defineNodeNamesProperty: 'defineNodeNameProperty',
852
- defineNodeNamesProperties: 'defineNodeNameProperties',
853
- createElements: 'createElement'
854
- }, function(name, baseMethod){
855
- webshims[name] = function(names, a, b, c){
856
- if(typeof names == 'string'){
857
- names = names.split(listReg);
858
- }
859
- var retDesc = {};
860
- names.forEach(function(nodeName){
861
- retDesc[nodeName] = webshims[baseMethod](nodeName, a, b, c);
862
- });
863
- return retDesc;
864
- };
865
- });
866
-
867
- webshims.isReady('webshimLocalization', true);
868
- });
869
- //html5a11y
870
- (function($, document){
871
- var browserVersion = $.webshims.browserVersion;
872
- if($.browser.mozilla && browserVersion > 5){return;}
873
- if (!$.browser.msie || (browserVersion < 12 && browserVersion > 7)) {
874
- var elemMappings = {
875
- article: "article",
876
- aside: "complementary",
877
- section: "region",
878
- nav: "navigation",
879
- address: "contentinfo"
880
- };
881
- var addRole = function(elem, role){
882
- var hasRole = elem.getAttribute('role');
883
- if (!hasRole) {
884
- elem.setAttribute('role', role);
885
- }
886
- };
887
-
888
- $.webshims.addReady(function(context, contextElem){
889
- $.each(elemMappings, function(name, role){
890
- var elems = $(name, context).add(contextElem.filter(name));
891
- for (var i = 0, len = elems.length; i < len; i++) {
892
- addRole(elems[i], role);
893
- }
894
- });
895
- if (context === document) {
896
- var header = document.getElementsByTagName('header')[0];
897
- var footers = document.getElementsByTagName('footer');
898
- var footerLen = footers.length;
899
- if (header && !$(header).closest('section, article')[0]) {
900
- addRole(header, 'banner');
901
- }
902
- if (!footerLen) {
903
- return;
904
- }
905
- var footer = footers[footerLen - 1];
906
- if (!$(footer).closest('section, article')[0]) {
907
- addRole(footer, 'contentinfo');
908
- }
909
- }
910
- });
911
- }
912
- })(jQuery, document);
913
- jQuery.webshims.register('form-datalist', function($, webshims, window, document, undefined){
914
- var doc = document;
915
-
916
- /*
917
- * implement propType "element" currently only used for list-attribute (will be moved to dom-extend, if needed)
918
- */
919
- webshims.propTypes.element = function(descs){
920
- webshims.createPropDefault(descs, 'attr');
921
- if(descs.prop){return;}
922
- descs.prop = {
923
- get: function(){
924
- var elem = descs.attr.get.call(this);
925
- if(elem){
926
- elem = document.getElementById(elem);
927
- if(elem && descs.propNodeName && !$.nodeName(elem, descs.propNodeName)){
928
- elem = null;
929
- }
930
- }
931
- return elem || null;
932
- },
933
- writeable: false
934
- };
935
- };
936
-
937
-
938
- /*
939
- * Implements datalist element and list attribute
940
- */
941
-
942
- (function(){
943
- var formsCFG = $.webshims.cfg.forms;
944
- var listSupport = Modernizr.input.list;
945
- if(listSupport && !formsCFG.customDatalist){return;}
946
-
947
- var initializeDatalist = function(){
948
-
949
-
950
- if(!listSupport){
951
- webshims.defineNodeNameProperty('datalist', 'options', {
952
- prop: {
953
- writeable: false,
954
- get: function(){
955
- var elem = this;
956
- var select = $('select', elem);
957
- var options;
958
- if(select[0]){
959
- options = select[0].options;
960
- } else {
961
- options = $('option', elem).get();
962
- if(options.length){
963
- webshims.warn('you should wrap your option-elements for a datalist in a select element to support IE and other old browsers.');
964
- }
965
- }
966
- return options;
967
- }
968
- }
969
- });
970
- }
971
-
972
- var inputListProto = {
973
- //override autocomplete
974
- autocomplete: {
975
- attr: {
976
- get: function(){
977
- var elem = this;
978
- var data = $.data(elem, 'datalistWidget');
979
- if(data){
980
- return data._autocomplete;
981
- }
982
- return ('autocomplete' in elem) ? elem.autocomplete : elem.getAttribute('autocomplete');
983
- },
984
- set: function(value){
985
- var elem = this;
986
- var data = $.data(elem, 'datalistWidget');
987
- if(data){
988
- data._autocomplete = value;
989
- if(value == 'off'){
990
- data.hideList();
991
- }
992
- } else {
993
- if('autocomplete' in elem){
994
- elem.autocomplete = value;
995
- } else {
996
- elem.setAttribute('autocomplete', value);
997
- }
998
- }
999
- }
1000
- }
1001
- }
1002
- };
1003
-
1004
- // if(formsCFG.customDatalist && (!listSupport || !('selectedOption') in $('<input />')[0])){
1005
- // //currently not supported x-browser (FF4 has not implemented and is not polyfilled )
1006
- // inputListProto.selectedOption = {
1007
- // prop: {
1008
- // writeable: false,
1009
- // get: function(){
1010
- // var elem = this;
1011
- // var list = $.prop(elem, 'list');
1012
- // var ret = null;
1013
- // var value, options;
1014
- // if(!list){return ret;}
1015
- // value = $.prop(elem, 'value');
1016
- // if(!value){return ret;}
1017
- // options = $.prop(list, 'options');
1018
- // if(!options.length){return ret;}
1019
- // $.each(options, function(i, option){
1020
- // if(value == $.prop(option, 'value')){
1021
- // ret = option;
1022
- // return false;
1023
- // }
1024
- // });
1025
- // return ret;
1026
- // }
1027
- // }
1028
- // };
1029
- // }
1030
-
1031
- if(!listSupport){
1032
- inputListProto['list'] = {
1033
- attr: {
1034
- get: function(){
1035
- var val = webshims.contentAttr(this, 'list');
1036
- return (val == null) ? undefined : val;
1037
- },
1038
- set: function(value){
1039
- var elem = this;
1040
- webshims.contentAttr(elem, 'list', value);
1041
- webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
1042
- }
1043
- },
1044
- initAttr: true,
1045
- reflect: true,
1046
- propType: 'element',
1047
- propNodeName: 'datalist'
1048
- };
1049
- } else {
1050
- //options only return options, if option-elements are rooted: but this makes this part of HTML5 less backwards compatible
1051
- if(!($('<datalist><select><option></option></select></datalist>').prop('options') || []).length ){
1052
- webshims.defineNodeNameProperty('datalist', 'options', {
1053
- prop: {
1054
- writeable: false,
1055
- get: function(){
1056
- var options = this.options || [];
1057
- if(!options.length){
1058
- var elem = this;
1059
- var select = $('select', elem);
1060
- if(select[0] && select[0].options && select[0].options.length){
1061
- options = select[0].options;
1062
- }
1063
- }
1064
- return options;
1065
- }
1066
- }
1067
- });
1068
- }
1069
- inputListProto['list'] = {
1070
- attr: {
1071
- get: function(){
1072
- var val = webshims.contentAttr(this, 'list');
1073
- if(val != null){
1074
- this.removeAttribute('list');
1075
- } else {
1076
- val = $.data(this, 'datalistListAttr');
1077
- }
1078
-
1079
- return (val == null) ? undefined : val;
1080
- },
1081
- set: function(value){
1082
- var elem = this;
1083
- $.data(elem, 'datalistListAttr', value);
1084
- webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
1085
- }
1086
- },
1087
- initAttr: true,
1088
- reflect: true,
1089
- propType: 'element',
1090
- propNodeName: 'datalist'
1091
- };
1092
- }
1093
-
1094
-
1095
- webshims.defineNodeNameProperties('input', inputListProto);
1096
-
1097
- if($.event.customEvent){
1098
- $.event.customEvent.updateDatalist = true;
1099
- $.event.customEvent.updateInput = true;
1100
- $.event.customEvent.datalistselect = true;
1101
- }
1102
- webshims.addReady(function(context, contextElem){
1103
- contextElem
1104
- .filter('datalist > select, datalist, datalist > option, datalist > select > option')
1105
- .closest('datalist')
1106
- .triggerHandler('updateDatalist')
1107
- ;
1108
-
1109
- });
1110
-
1111
-
1112
- };
1113
-
1114
-
1115
- /*
1116
- * ShadowList
1117
- */
1118
- var listidIndex = 0;
1119
-
1120
- var noDatalistSupport = {
1121
- submit: 1,
1122
- button: 1,
1123
- reset: 1,
1124
- hidden: 1,
1125
-
1126
- //ToDo
1127
- range: 1,
1128
- date: 1
1129
- };
1130
- var lteie6 = ($.browser.msie && parseInt($.browser.version, 10) < 7);
1131
- var globStoredOptions = {};
1132
- var getStoredOptions = function(name){
1133
- if(!name){return [];}
1134
- if(globStoredOptions[name]){
1135
- return globStoredOptions[name];
1136
- }
1137
- var data;
1138
- try {
1139
- data = JSON.parse(localStorage.getItem('storedDatalistOptions'+name));
1140
- } catch(e){}
1141
- globStoredOptions[name] = data || [];
1142
- return data || [];
1143
- };
1144
- var storeOptions = function(name, val){
1145
- if(!name){return;}
1146
- val = val || [];
1147
- try {
1148
- localStorage.setItem( 'storedDatalistOptions'+name, JSON.stringify(val) );
1149
- } catch(e){}
1150
- };
1151
-
1152
- var getText = function(elem){
1153
- return (elem.textContent || elem.innerText || $.text([ elem ]) || '');
1154
- };
1155
-
1156
- var shadowListProto = {
1157
- _create: function(opts){
1158
-
1159
- if(noDatalistSupport[$.prop(opts.input, 'type')]){return;}
1160
- var datalist = opts.datalist;
1161
- var data = $.data(opts.input, 'datalistWidget');
1162
- if(datalist && data && data.datalist !== datalist){
1163
- data.datalist = datalist;
1164
- data.id = opts.id;
1165
-
1166
- data.shadowList.prop('className', 'datalist-polyfill '+ (data.datalist.className || '') + ' '+ data.datalist.id +'-shadowdom');
1167
- if(formsCFG.positionDatalist){
1168
- data.shadowList.insertAfter(opts.input);
1169
- } else {
1170
- data.shadowList.appendTo('body');
1171
- }
1172
- $(data.datalist)
1173
- .unbind('updateDatalist.datalistWidget')
1174
- .bind('updateDatalist.datalistWidget', $.proxy(data, '_resetListCached'))
1175
- ;
1176
- data._resetListCached();
1177
- return;
1178
- } else if(!datalist){
1179
- if(data){
1180
- data.destroy();
1181
- }
1182
- return;
1183
- } else if(data && data.datalist === datalist){
1184
- return;
1185
- }
1186
- listidIndex++;
1187
- var that = this;
1188
- this.hideList = $.proxy(that, 'hideList');
1189
- this.timedHide = function(){
1190
- clearTimeout(that.hideTimer);
1191
- that.hideTimer = setTimeout(that.hideList, 9);
1192
- };
1193
- this.datalist = datalist;
1194
- this.id = opts.id;
1195
- this.hasViewableData = true;
1196
- this._autocomplete = $.attr(opts.input, 'autocomplete');
1197
- $.data(opts.input, 'datalistWidget', this);
1198
- this.shadowList = $('<div class="datalist-polyfill '+ (this.datalist.className || '') + ' '+ this.datalist.id +'-shadowdom' +'" />');
1199
-
1200
- if(formsCFG.positionDatalist || $(opts.input).hasClass('position-datalist')){
1201
- this.shadowList.insertAfter(opts.input);
1202
- } else {
1203
- this.shadowList.appendTo('body');
1204
- }
1205
-
1206
- this.index = -1;
1207
- this.input = opts.input;
1208
- this.arrayOptions = [];
1209
-
1210
- this.shadowList
1211
- .delegate('li', 'mouseenter.datalistWidget mousedown.datalistWidget click.datalistWidget', function(e){
1212
- var items = $('li:not(.hidden-item)', that.shadowList);
1213
- var select = (e.type == 'mousedown' || e.type == 'click');
1214
- that.markItem(items.index(e.currentTarget), select, items);
1215
- if(e.type == 'click'){
1216
- that.hideList();
1217
- if(formsCFG.customDatalist){
1218
- $(opts.input).trigger('datalistselect');
1219
- }
1220
- }
1221
- return (e.type != 'mousedown');
1222
- })
1223
- .bind('focusout', this.timedHide)
1224
- ;
1225
-
1226
- opts.input.setAttribute('autocomplete', 'off');
1227
-
1228
- $(opts.input)
1229
- .attr({
1230
- //role: 'combobox',
1231
- 'aria-haspopup': 'true'
1232
- })
1233
- .bind('input.datalistWidget', function(){
1234
- if(!that.triggeredByDatalist){
1235
- that.changedValue = false;
1236
- that.showHideOptions();
1237
- }
1238
- })
1239
-
1240
- .bind('keydown.datalistWidget', function(e){
1241
- var keyCode = e.keyCode;
1242
- var activeItem;
1243
- var items;
1244
- if(keyCode == 40 && !that.showList()){
1245
- that.markItem(that.index + 1, true);
1246
- return false;
1247
- }
1248
-
1249
- if(!that.isListVisible){return;}
1250
-
1251
-
1252
- if(keyCode == 38){
1253
- that.markItem(that.index - 1, true);
1254
- return false;
1255
- }
1256
- if(!e.shiftKey && (keyCode == 33 || keyCode == 36)){
1257
- that.markItem(0, true);
1258
- return false;
1259
- }
1260
- if(!e.shiftKey && (keyCode == 34 || keyCode == 35)){
1261
- items = $('li:not(.hidden-item)', that.shadowList);
1262
- that.markItem(items.length - 1, true, items);
1263
- return false;
1264
- }
1265
- if(keyCode == 13 || keyCode == 27){
1266
- if (keyCode == 13){
1267
- activeItem = $('li.active-item:not(.hidden-item)', that.shadowList);
1268
- that.changeValue( $('li.active-item:not(.hidden-item)', that.shadowList) );
1269
- }
1270
- that.hideList();
1271
- if(formsCFG.customDatalist && activeItem && activeItem[0]){
1272
- $(opts.input).trigger('datalistselect');
1273
- }
1274
- return false;
1275
- }
1276
- })
1277
- .bind('focus.datalistWidget', function(){
1278
- if($(this).hasClass('list-focus')){
1279
- that.showList();
1280
- }
1281
- })
1282
- .bind('mousedown.datalistWidget', function(){
1283
- if($(this).is(':focus')){
1284
- that.showList();
1285
- }
1286
- })
1287
- .bind('blur.datalistWidget', this.timedHide)
1288
- ;
1289
-
1290
-
1291
- $(this.datalist)
1292
- .unbind('updateDatalist.datalistWidget')
1293
- .bind('updateDatalist.datalistWidget', $.proxy(this, '_resetListCached'))
1294
- ;
1295
-
1296
- this._resetListCached();
1297
-
1298
- if(opts.input.form && (opts.input.name || opts.input.id)){
1299
- $(opts.input.form).bind('submit.datalistWidget'+opts.input.id, function(){
1300
- if(!$(opts.input).hasClass('no-datalist-cache') && that._autocomplete != 'off'){
1301
- var val = $.prop(opts.input, 'value');
1302
- var name = (opts.input.name || opts.input.id) + $.prop(opts.input, 'type');
1303
- if(!that.storedOptions){
1304
- that.storedOptions = getStoredOptions( name );
1305
- }
1306
- if(val && that.storedOptions.indexOf(val) == -1){
1307
- that.storedOptions.push(val);
1308
- storeOptions(name, that.storedOptions );
1309
- }
1310
- }
1311
- });
1312
- }
1313
- $(window).bind('unload.datalist'+this.id+' beforeunload.datalist'+this.id, function(){
1314
- that.destroy();
1315
- });
1316
- },
1317
- destroy: function(){
1318
- var autocomplete = $.attr(this.input, 'autocomplete');
1319
- $(this.input)
1320
- .unbind('.datalistWidget')
1321
- .removeData('datalistWidget')
1322
- ;
1323
- this.shadowList.remove();
1324
- $(document).unbind('.datalist'+this.id);
1325
- $(window).unbind('.datalist'+this.id);
1326
- if(this.input.form && this.input.id){
1327
- $(this.input.form).unbind('submit.datalistWidget'+this.input.id);
1328
- }
1329
- this.input.removeAttribute('aria-haspopup');
1330
- if(autocomplete === undefined){
1331
- this.input.removeAttribute('autocomplete');
1332
- } else {
1333
- $(this.input).attr('autocomplete', autocomplete);
1334
- }
1335
- },
1336
- _resetListCached: function(e){
1337
- var that = this;
1338
- var forceShow;
1339
- this.needsUpdate = true;
1340
- this.lastUpdatedValue = false;
1341
- this.lastUnfoundValue = '';
1342
-
1343
- if(!this.updateTimer){
1344
- if(window.QUnit || (forceShow = (e && document.activeElement == that.input))){
1345
- that.updateListOptions(forceShow);
1346
- } else {
1347
- webshims.ready('WINDOWLOAD', function(){
1348
- that.updateTimer = setTimeout(function(){
1349
- that.updateListOptions();
1350
- that = null;
1351
- listidIndex = 1;
1352
- }, 200 + (100 * listidIndex));
1353
- });
1354
- }
1355
- }
1356
- },
1357
- updateListOptions: function(_forceShow){
1358
- this.needsUpdate = false;
1359
- clearTimeout(this.updateTimer);
1360
- this.updateTimer = false;
1361
- this.shadowList
1362
- .css({
1363
- fontSize: $.css(this.input, 'fontSize'),
1364
- fontFamily: $.css(this.input, 'fontFamily')
1365
- })
1366
- ;
1367
- this.searchStart = formsCFG.customDatalist && $(this.input).hasClass('search-start');
1368
-
1369
- var list = [];
1370
-
1371
- var values = [];
1372
- var allOptions = [];
1373
- var rElem, rItem, rOptions, rI, rLen, item;
1374
- for(rOptions = $.prop(this.datalist, 'options'), rI = 0, rLen = rOptions.length; rI < rLen; rI++){
1375
- rElem = rOptions[rI];
1376
- if(rElem.disabled){return;}
1377
- rItem = {
1378
- value: $(rElem).val() || '',
1379
- text: $.trim($.attr(rElem, 'label') || getText(rElem)),
1380
- className: rElem.className || '',
1381
- style: $.attr(rElem, 'style') || ''
1382
- };
1383
- if(!rItem.text){
1384
- rItem.text = rItem.value;
1385
- } else if(rItem.text != rItem.value){
1386
- rItem.className += ' different-label-value';
1387
- }
1388
- values[rI] = rItem.value;
1389
- allOptions[rI] = rItem;
1390
- }
1391
-
1392
- if(!this.storedOptions){
1393
- this.storedOptions = ($(this.input).hasClass('no-datalist-cache') || this._autocomplete == 'off') ? [] : getStoredOptions((this.input.name || this.input.id) + $.prop(this.input, 'type'));
1394
- }
1395
-
1396
- this.storedOptions.forEach(function(val, i){
1397
- if(values.indexOf(val) == -1){
1398
- allOptions.push({value: val, text: val, className: 'stored-suggest', style: ''});
1399
- }
1400
- });
1401
-
1402
- for(rI = 0, rLen = allOptions.length; rI < rLen; rI++){
1403
- item = allOptions[rI];
1404
- list[rI] = '<li class="'+ item.className +'" style="'+ item.style +'" tabindex="-1" role="listitem"><span class="option-label">'+ item.text +'</span> <span class="option-value">'+item.value+'</span></li>';
1405
- }
1406
-
1407
- this.arrayOptions = allOptions;
1408
- this.shadowList.html('<div class="datalist-outer-box"><div class="datalist-box"><ul role="list">'+ list.join("\n") +'</ul></div></div>');
1409
-
1410
- if($.fn.bgIframe && lteie6){
1411
- this.shadowList.bgIframe();
1412
- }
1413
-
1414
- if(_forceShow || this.isListVisible){
1415
- this.showHideOptions();
1416
- }
1417
- },
1418
- showHideOptions: function(_fromShowList){
1419
- var value = $.prop(this.input, 'value').toLowerCase();
1420
- //first check prevent infinite loop, second creates simple lazy optimization
1421
- if(value === this.lastUpdatedValue || (this.lastUnfoundValue && value.indexOf(this.lastUnfoundValue) === 0)){
1422
- return;
1423
- }
1424
-
1425
- this.lastUpdatedValue = value;
1426
- var found = false;
1427
- var startSearch = this.searchStart;
1428
- var lis = $('li', this.shadowList);
1429
- if(value){
1430
- this.arrayOptions.forEach(function(item, i){
1431
- var search;
1432
- if(!('lowerText' in item)){
1433
- if(item.text != item.value){
1434
- item.lowerText = item.value.toLowerCase() + item.text.toLowerCase();
1435
- } else {
1436
- item.lowerText = item.text.toLowerCase();
1437
- }
1438
- }
1439
- search = item.lowerText.indexOf(value);
1440
- search = startSearch ? !search : search !== -1;
1441
- if(search){
1442
- $(lis[i]).removeClass('hidden-item');
1443
- found = true;
1444
- } else {
1445
- $(lis[i]).addClass('hidden-item');
1446
- }
1447
- });
1448
- } else if(lis.length) {
1449
- lis.removeClass('hidden-item');
1450
- found = true;
1451
- }
1452
-
1453
- this.hasViewableData = found;
1454
- if(!_fromShowList && found){
1455
- this.showList();
1456
- }
1457
- if(!found){
1458
- this.lastUnfoundValue = value;
1459
- this.hideList();
1460
- }
1461
- },
1462
- setPos: function(){
1463
- this.shadowList.css({marginTop: 0, marginLeft: 0, marginRight: 0, marginBottom: 0});
1464
- var css = (formsCFG.positionDatalist) ? $(this.input).position() : webshims.getRelOffset(this.shadowList, this.input);
1465
- css.top += $(this.input).outerHeight();
1466
- css.width = $(this.input).outerWidth() - (parseInt(this.shadowList.css('borderLeftWidth'), 10) || 0) - (parseInt(this.shadowList.css('borderRightWidth'), 10) || 0);
1467
- this.shadowList.css({marginTop: '', marginLeft: '', marginRight: '', marginBottom: ''}).css(css);
1468
- return css;
1469
- },
1470
- showList: function(){
1471
- if(this.isListVisible){return false;}
1472
- if(this.needsUpdate){
1473
- this.updateListOptions();
1474
- }
1475
- this.showHideOptions(true);
1476
- if(!this.hasViewableData){return false;}
1477
- this.isListVisible = true;
1478
- var that = this;
1479
-
1480
- that.setPos();
1481
- that.shadowList.addClass('datalist-visible').find('li.active-item').removeClass('active-item');
1482
-
1483
- $(window).unbind('.datalist'+that.id);
1484
- $(document)
1485
- .unbind('.datalist'+that.id)
1486
- .bind('mousedown.datalist'+that.id +' focusin.datalist'+that.id, function(e){
1487
- if(e.target === that.input || that.shadowList[0] === e.target || $.contains( that.shadowList[0], e.target )){
1488
- clearTimeout(that.hideTimer);
1489
- setTimeout(function(){
1490
- clearTimeout(that.hideTimer);
1491
- }, 9);
1492
- } else {
1493
- that.timedHide();
1494
- }
1495
- })
1496
- .bind('updateshadowdom.datalist'+that.id, function(){
1497
- that.setPos();
1498
- })
1499
- ;
1500
- return true;
1501
- },
1502
- hideList: function(){
1503
- if(!this.isListVisible){return false;}
1504
- var that = this;
1505
- var triggerChange = function(e){
1506
- if(that.changedValue){
1507
- $(that.input).trigger('change');
1508
- }
1509
- that.changedValue = false;
1510
- };
1511
-
1512
- that.shadowList.removeClass('datalist-visible list-item-active');
1513
- that.index = -1;
1514
- that.isListVisible = false;
1515
- if(that.changedValue){
1516
- that.triggeredByDatalist = true;
1517
- webshims.triggerInlineForm && webshims.triggerInlineForm(that.input, 'input');
1518
- if($(that.input).is(':focus')){
1519
- $(that.input).one('blur', triggerChange);
1520
- } else {
1521
- triggerChange();
1522
- }
1523
- that.triggeredByDatalist = false;
1524
- }
1525
- $(document).unbind('.datalist'+that.id);
1526
- $(window)
1527
- .unbind('.datalist'+that.id)
1528
- .one('resize.datalist'+that.id, function(){
1529
- that.shadowList.css({top: 0, left: 0});
1530
- })
1531
- ;
1532
- return true;
1533
- },
1534
- scrollIntoView: function(elem){
1535
- var ul = $('ul', this.shadowList);
1536
- var div = $('div.datalist-box', this.shadowList);
1537
- var elemPos = elem.position();
1538
- var containerHeight;
1539
- elemPos.top -= (parseInt(ul.css('paddingTop'), 10) || 0) + (parseInt(ul.css('marginTop'), 10) || 0) + (parseInt(ul.css('borderTopWidth'), 10) || 0);
1540
- if(elemPos.top < 0){
1541
- div.scrollTop( div.scrollTop() + elemPos.top - 2);
1542
- return;
1543
- }
1544
- elemPos.top += elem.outerHeight();
1545
- containerHeight = div.height();
1546
- if(elemPos.top > containerHeight){
1547
- div.scrollTop( div.scrollTop() + (elemPos.top - containerHeight) + 2);
1548
- }
1549
- },
1550
- changeValue: function(activeItem){
1551
- if(!activeItem[0]){return;}
1552
- var newValue = $('span.option-value', activeItem).text();
1553
- var oldValue = $.prop(this.input, 'value');
1554
- if(newValue != oldValue){
1555
- $(this.input)
1556
- .prop('value', newValue)
1557
- .triggerHandler('updateInput')
1558
- ;
1559
- this.changedValue = true;
1560
- }
1561
- },
1562
- markItem: function(index, doValue, items){
1563
- var activeItem;
1564
- var goesUp;
1565
-
1566
- items = items || $('li:not(.hidden-item)', this.shadowList);
1567
- if(!items.length){return;}
1568
- if(index < 0){
1569
- index = items.length - 1;
1570
- } else if(index >= items.length){
1571
- index = 0;
1572
- }
1573
- items.removeClass('active-item');
1574
- this.shadowList.addClass('list-item-active');
1575
- activeItem = items.filter(':eq('+ index +')').addClass('active-item');
1576
-
1577
- if(doValue){
1578
- this.changeValue(activeItem);
1579
- this.scrollIntoView(activeItem);
1580
- }
1581
- this.index = index;
1582
- }
1583
- };
1584
-
1585
- //init datalist update
1586
- initializeDatalist();
1587
- })();
1588
-
1589
- });//additional tests for partial implementation of forms features
1590
- (function($){
1591
- var Modernizr = window.Modernizr;
1592
- var webshims = $.webshims;
1593
- var bugs = webshims.bugs;
1594
- var form = $('<form action="#" style="width: 1px; height: 1px; overflow: hidden;"><select name="b" required="" /><input type="date" required="" name="a" /><input type="submit" /></form>');
1595
- var testRequiredFind = function(){
1596
- if(form[0].querySelector){
1597
- try {
1598
- bugs.findRequired = !(form[0].querySelector('select:required'));
1599
- } catch(er){
1600
- bugs.findRequired = false;
1601
- }
1602
- }
1603
- };
1604
- bugs.findRequired = false;
1605
- bugs.validationMessage = false;
1606
- bugs.valueAsNumberSet = false;
1607
-
1608
- webshims.capturingEventPrevented = function(e){
1609
- if(!e._isPolyfilled){
1610
- var isDefaultPrevented = e.isDefaultPrevented;
1611
- var preventDefault = e.preventDefault;
1612
- e.preventDefault = function(){
1613
- clearTimeout($.data(e.target, e.type + 'DefaultPrevented'));
1614
- $.data(e.target, e.type + 'DefaultPrevented', setTimeout(function(){
1615
- $.removeData(e.target, e.type + 'DefaultPrevented');
1616
- }, 30));
1617
- return preventDefault.apply(this, arguments);
1618
- };
1619
- e.isDefaultPrevented = function(){
1620
- return !!(isDefaultPrevented.apply(this, arguments) || $.data(e.target, e.type + 'DefaultPrevented') || false);
1621
- };
1622
- e._isPolyfilled = true;
1623
- }
1624
- };
1625
-
1626
- if(!Modernizr.formvalidation || bugs.bustedValidity){
1627
- testRequiredFind();
1628
- return;
1629
- }
1630
-
1631
- //create delegatable events
1632
- webshims.capturingEvents(['input']);
1633
- webshims.capturingEvents(['invalid'], true);
1634
-
1635
- Modernizr.bugfreeformvalidation = true;
1636
- if(window.opera || $.browser.webkit || window.testGoodWithFix){
1637
- var dateElem = $('input', form).eq(0);
1638
- var timer;
1639
- var onDomextend = function(fn){
1640
- webshims.loader.loadList(['dom-extend']);
1641
- webshims.ready('dom-extend', fn);
1642
- };
1643
- var loadFormFixes = function(e){
1644
- var reTest = ['form-extend', 'form-message', 'form-native-fix'];
1645
- if(e){
1646
- e.preventDefault();
1647
- e.stopImmediatePropagation();
1648
- }
1649
- clearTimeout(timer);
1650
- setTimeout(function(){
1651
- if(!form){return;}
1652
- form.remove();
1653
- form = dateElem = null;
1654
- }, 9);
1655
- if(!Modernizr.bugfreeformvalidation){
1656
- webshims.addPolyfill('form-native-fix', {
1657
- f: 'forms',
1658
- d: ['form-extend']
1659
- });
1660
- //remove form-extend readyness
1661
- webshims.modules['form-extend'].test = $.noop;
1662
- }
1663
-
1664
- if(webshims.isReady('form-number-date-api')){
1665
- reTest.push('form-number-date-api');
1666
- }
1667
-
1668
- webshims.reTest(reTest);
1669
-
1670
- if(dateElem){
1671
- try {
1672
- if(dateElem.prop({disabled: true, value: ''}).prop('disabled', false).is(':valid')){
1673
- onDomextend(function(){
1674
- webshims.onNodeNamesPropertyModify(['input', 'textarea'], ['disabled', 'readonly'], {
1675
- set: function(val){
1676
- var elem = this;
1677
- if(!val && elem){
1678
- $.prop(elem, 'value', $.prop(elem, 'value'));
1679
- }
1680
- }
1681
- });
1682
- webshims.onNodeNamesPropertyModify(['select'], ['disabled', 'readonly'], {
1683
- set: function(val){
1684
- var elem = this;
1685
- if(!val && elem){
1686
- val = $(elem).val();
1687
- ($('option:last-child', elem)[0] || {}).selected = true;
1688
- $(elem).val( val );
1689
- }
1690
- }
1691
- });
1692
- });
1693
- }
1694
- } catch(er){}
1695
- }
1696
-
1697
- if ($.browser.opera || window.testGoodWithFix) {
1698
- onDomextend(function(){
1699
-
1700
- //Opera shows native validation bubbles in case of input.checkValidity()
1701
- // Opera 11.6/12 hasn't fixed this issue right, it's buggy
1702
- var preventDefault = function(e){
1703
- e.preventDefault();
1704
- };
1705
-
1706
- ['form', 'input', 'textarea', 'select'].forEach(function(name){
1707
- var desc = webshims.defineNodeNameProperty(name, 'checkValidity', {
1708
- prop: {
1709
- value: function(){
1710
- if (!webshims.fromSubmit) {
1711
- $(this).bind('invalid.checkvalidity', preventDefault);
1712
- }
1713
-
1714
- webshims.fromCheckValidity = true;
1715
- var ret = desc.prop._supvalue.apply(this, arguments);
1716
- if (!webshims.fromSubmit) {
1717
- $(this).unbind('invalid.checkvalidity', preventDefault);
1718
- }
1719
- webshims.fromCheckValidity = false;
1720
- return ret;
1721
- }
1722
- }
1723
- });
1724
- });
1725
-
1726
- });
1727
- }
1728
- };
1729
-
1730
- form.appendTo('head');
1731
- if(window.opera || window.testGoodWithFix) {
1732
- testRequiredFind();
1733
- bugs.validationMessage = !(dateElem.prop('validationMessage'));
1734
- if((Modernizr.inputtypes || {}).date){
1735
- try {
1736
- dateElem.prop('valueAsNumber', 0);
1737
- } catch(er){}
1738
- bugs.valueAsNumberSet = (dateElem.prop('value') != '1970-01-01');
1739
- }
1740
- dateElem.prop('value', '');
1741
- }
1742
-
1743
- form.bind('submit', function(e){
1744
- Modernizr.bugfreeformvalidation = false;
1745
- loadFormFixes(e);
1746
- });
1747
-
1748
- timer = setTimeout(function(){
1749
- if (form) {
1750
- form.triggerHandler('submit');
1751
- }
1752
- }, 9);
1753
-
1754
- $('input, select', form).bind('invalid', loadFormFixes)
1755
- .filter('[type="submit"]')
1756
- .bind('click', function(e){
1757
- e.stopImmediatePropagation();
1758
- })
1759
- .trigger('click')
1760
- ;
1761
-
1762
- if($.browser.webkit && Modernizr.bugfreeformvalidation && !webshims.bugs.bustedValidity){
1763
- (function(){
1764
- var elems = /^(?:textarea|input)$/i;
1765
- var form = false;
1766
-
1767
- document.addEventListener('contextmenu', function(e){
1768
- if(elems.test( e.target.nodeName || '') && (form = e.target.form)){
1769
- setTimeout(function(){
1770
- form = false;
1771
- }, 1);
1772
- }
1773
- }, false);
1774
-
1775
- $(window).bind('invalid', function(e){
1776
- if(e.originalEvent && form && form == e.target.form){
1777
- e.wrongWebkitInvalid = true;
1778
- e.stopImmediatePropagation();
1779
- }
1780
- });
1781
- })();
1782
- }
1783
- }
1784
-
1785
- })(jQuery);
1786
-
1787
- jQuery.webshims.register('form-core', function($, webshims, window, document, undefined, options){
1788
- "use strict";
1789
-
1790
- var groupTypes = {radio: 1};
1791
- var checkTypes = {checkbox: 1, radio: 1};
1792
- var emptyJ = $([]);
1793
- var bugs = webshims.bugs;
1794
- var getGroupElements = function(elem){
1795
- elem = $(elem);
1796
- var name;
1797
- var form;
1798
- var ret = emptyJ;
1799
- if(groupTypes[elem[0].type]){
1800
- form = elem.prop('form');
1801
- name = elem[0].name;
1802
- if(!name){
1803
- ret = elem;
1804
- } else if(form){
1805
- ret = $(form[name]);
1806
- } else {
1807
- ret = $(document.getElementsByName(name)).filter(function(){
1808
- return !$.prop(this, 'form');
1809
- });
1810
- }
1811
- ret = ret.filter('[type="radio"]');
1812
- }
1813
- return ret;
1814
- };
1815
-
1816
- var getContentValidationMessage = webshims.getContentValidationMessage = function(elem, validity, key){
1817
- var message = $(elem).data('errormessage') || elem.getAttribute('x-moz-errormessage') || '';
1818
- if(key && message[key]){
1819
- message = message[key];
1820
- }
1821
- if(typeof message == 'object'){
1822
- validity = validity || $.prop(elem, 'validity') || {valid: 1};
1823
- if(!validity.valid){
1824
- $.each(validity, function(name, prop){
1825
- if(prop && name != 'valid' && message[name]){
1826
- message = message[name];
1827
- return false;
1828
- }
1829
- });
1830
- }
1831
- }
1832
-
1833
- if(typeof message == 'object'){
1834
- message = message.defaultMessage;
1835
- }
1836
- return message || '';
1837
- };
1838
-
1839
- /*
1840
- * Selectors for all browsers
1841
- */
1842
- var rangeTypes = {number: 1, range: 1, date: 1/*, time: 1, 'datetime-local': 1, datetime: 1, month: 1, week: 1*/};
1843
- $.extend($.expr[":"], {
1844
- "valid-element": function(elem){
1845
- return !!($.prop(elem, 'willValidate') && ($.prop(elem, 'validity') || {valid: 1}).valid);
1846
- },
1847
- "invalid-element": function(elem){
1848
- return !!($.prop(elem, 'willValidate') && !isValid(elem));
1849
- },
1850
- "required-element": function(elem){
1851
- return !!($.prop(elem, 'willValidate') && $.prop(elem, 'required'));
1852
- },
1853
- "optional-element": function(elem){
1854
- return !!($.prop(elem, 'willValidate') && $.prop(elem, 'required') === false);
1855
- },
1856
- "in-range": function(elem){
1857
- if(!rangeTypes[$.prop(elem, 'type')] || !$.prop(elem, 'willValidate')){
1858
- return false;
1859
- }
1860
- var val = $.prop(elem, 'validity');
1861
- return !!(val && !val.rangeOverflow && !val.rangeUnderflow);
1862
- },
1863
- "out-of-range": function(elem){
1864
- if(!rangeTypes[$.prop(elem, 'type')] || !$.prop(elem, 'willValidate')){
1865
- return false;
1866
- }
1867
- var val = $.prop(elem, 'validity');
1868
- return !!(val && (val.rangeOverflow || val.rangeUnderflow));
1869
- }
1870
-
1871
- });
1872
-
1873
- ['valid', 'invalid', 'required', 'optional'].forEach(function(name){
1874
- $.expr[":"][name] = $.expr.filters[name+"-element"];
1875
- });
1876
-
1877
-
1878
- $.expr[":"].focus = function( elem ) {
1879
- try {
1880
- var doc = elem.ownerDocument;
1881
- return elem === doc.activeElement && (!doc.hasFocus || doc.hasFocus());
1882
- } catch(e){}
1883
- return false;
1884
- };
1885
-
1886
- var customEvents = $.event.customEvent || {};
1887
- var isValid = function(elem){
1888
- return ($.prop(elem, 'validity') || {valid: 1}).valid;
1889
- };
1890
-
1891
- if (bugs.bustedValidity || bugs.findRequired || !Modernizr.bugfreeformvalidation) {
1892
- (function(){
1893
- var find = $.find;
1894
- var matchesSelector = $.find.matchesSelector;
1895
-
1896
- var regExp = /(\:valid|\:invalid|\:optional|\:required|\:in-range|\:out-of-range)(?=[\s\[\~\.\+\>\:\#*]|$)/ig;
1897
- var regFn = function(sel){
1898
- return sel + '-element';
1899
- };
1900
-
1901
- $.find = (function(){
1902
- var slice = Array.prototype.slice;
1903
- var fn = function(sel){
1904
- var ar = arguments;
1905
- ar = slice.call(ar, 1, ar.length);
1906
- ar.unshift(sel.replace(regExp, regFn));
1907
- return find.apply(this, ar);
1908
- };
1909
- for (var i in find) {
1910
- if(find.hasOwnProperty(i)){
1911
- fn[i] = find[i];
1912
- }
1913
- }
1914
- return fn;
1915
- })();
1916
- if(!Modernizr.prefixed || Modernizr.prefixed("matchesSelector", document.documentElement)){
1917
- $.find.matchesSelector = function(node, expr){
1918
- expr = expr.replace(regExp, regFn);
1919
- return matchesSelector.call(this, node, expr);
1920
- };
1921
- }
1922
-
1923
- })();
1924
- }
1925
-
1926
- //ToDo needs testing
1927
- var oldAttr = $.prop;
1928
- var changeVals = {selectedIndex: 1, value: 1, checked: 1, disabled: 1, readonly: 1};
1929
- $.prop = function(elem, name, val){
1930
- var ret = oldAttr.apply(this, arguments);
1931
- if(elem && 'form' in elem && changeVals[name] && val !== undefined && $(elem).hasClass('form-ui-invalid')){
1932
- if(isValid(elem)){
1933
- $(elem).getShadowElement().removeClass('form-ui-invalid');
1934
- if(name == 'checked' && val) {
1935
- getGroupElements(elem).not(elem).removeClass('form-ui-invalid').removeAttr('aria-invalid');
1936
- }
1937
- }
1938
- }
1939
- return ret;
1940
- };
1941
-
1942
- var returnValidityCause = function(validity, elem){
1943
- var ret;
1944
- $.each(validity, function(name, value){
1945
- if(value){
1946
- ret = (name == 'customError') ? $.prop(elem, 'validationMessage') : name;
1947
- return false;
1948
- }
1949
- });
1950
- return ret;
1951
- };
1952
-
1953
- var switchValidityClass = function(e){
1954
- var elem, timer;
1955
- if(!e.target){return;}
1956
- elem = $(e.target).getNativeElement()[0];
1957
- if(elem.type == 'submit' || !$.prop(elem, 'willValidate') || (e.type == 'focusout' && e.type == 'radio')){return;}
1958
- timer = $.data(elem, 'webshimsswitchvalidityclass');
1959
- var switchClass = function(){
1960
- var validity = $.prop(elem, 'validity');
1961
- var shadowElem = $(elem).getShadowElement();
1962
- var addClass, removeClass, trigger, generaltrigger, validityCause;
1963
-
1964
- $(elem).trigger('refreshCustomValidityRules');
1965
- if(validity.valid){
1966
- if(!shadowElem.hasClass('form-ui-valid')){
1967
- addClass = 'form-ui-valid';
1968
- removeClass = 'form-ui-invalid';
1969
- generaltrigger = 'changedvaliditystate';
1970
- trigger = 'changedvalid';
1971
- if(checkTypes[elem.type] && elem.checked){
1972
- getGroupElements(elem).not(elem).removeClass(removeClass).addClass(addClass).removeAttr('aria-invalid');
1973
- }
1974
- $.removeData(elem, 'webshimsinvalidcause');
1975
- }
1976
- } else {
1977
- validityCause = returnValidityCause(validity, elem);
1978
- if($.data(elem, 'webshimsinvalidcause') != validityCause){
1979
- $.data(elem, 'webshimsinvalidcause', validityCause);
1980
- generaltrigger = 'changedvaliditystate';
1981
- }
1982
- if(!shadowElem.hasClass('form-ui-invalid')){
1983
- addClass = 'form-ui-invalid';
1984
- removeClass = 'form-ui-valid';
1985
- if (checkTypes[elem.type] && !elem.checked) {
1986
- getGroupElements(elem).not(elem).removeClass(removeClass).addClass(addClass);
1987
- }
1988
- trigger = 'changedinvalid';
1989
- }
1990
- }
1991
- if(addClass){
1992
- shadowElem.addClass(addClass).removeClass(removeClass);
1993
- //jQuery 1.6.1 IE9 bug (doubble trigger bug)
1994
- setTimeout(function(){
1995
- $(elem).trigger(trigger);
1996
- }, 0);
1997
- }
1998
- if(generaltrigger){
1999
- setTimeout(function(){
2000
- $(elem).trigger(generaltrigger);
2001
- }, 0);
2002
- }
2003
- $.removeData(e.target, 'webshimsswitchvalidityclass');
2004
-
2005
- };
2006
- if(timer){
2007
- clearTimeout(timer);
2008
- }
2009
- if(e.type == 'refreshvalidityui'){
2010
- switchClass();
2011
- } else {
2012
- $.data(e.target, 'webshimsswitchvalidityclass', setTimeout(switchClass, 9));
2013
- }
2014
- };
2015
-
2016
- $(document).bind(options.validityUIEvents || 'focusout change refreshvalidityui', switchValidityClass);
2017
- customEvents.changedvaliditystate = true;
2018
- customEvents.refreshCustomValidityRules = true;
2019
- customEvents.changedvalid = true;
2020
- customEvents.changedinvalid = true;
2021
- customEvents.refreshvalidityui = true;
2022
-
2023
-
2024
- webshims.triggerInlineForm = function(elem, event){
2025
- $(elem).trigger(event);
2026
- };
2027
-
2028
- webshims.modules["form-core"].getGroupElements = getGroupElements;
2029
-
2030
-
2031
- var setRoot = function(){
2032
- webshims.scrollRoot = ($.browser.webkit || document.compatMode == 'BackCompat') ?
2033
- $(document.body) :
2034
- $(document.documentElement)
2035
- ;
2036
- };
2037
- setRoot();
2038
- webshims.ready('DOM', setRoot);
2039
-
2040
- webshims.getRelOffset = function(posElem, relElem){
2041
- posElem = $(posElem);
2042
- var offset = $(relElem).offset();
2043
- var bodyOffset;
2044
- $.swap($(posElem)[0], {visibility: 'hidden', display: 'inline-block', left: 0, top: 0}, function(){
2045
- bodyOffset = posElem.offset();
2046
- });
2047
- offset.top -= bodyOffset.top;
2048
- offset.left -= bodyOffset.left;
2049
- return offset;
2050
- };
2051
-
2052
- /* some extra validation UI */
2053
- webshims.validityAlert = (function(){
2054
- var alertElem = (!$.browser.msie || parseInt($.browser.version, 10) > 7) ? 'span' : 'label';
2055
- var errorBubble;
2056
- var hideTimer = false;
2057
- var focusTimer = false;
2058
- var resizeTimer = false;
2059
- var boundHide;
2060
-
2061
- var api = {
2062
- hideDelay: 5000,
2063
-
2064
- showFor: function(elem, message, noFocusElem, noBubble){
2065
- api._create();
2066
- elem = $(elem);
2067
- var visual = $(elem).getShadowElement();
2068
- var offset = api.getOffsetFromBody(visual);
2069
- api.clear();
2070
- if(noBubble){
2071
- this.hide();
2072
- } else {
2073
- this.getMessage(elem, message);
2074
- this.position(visual, offset);
2075
-
2076
- this.show();
2077
- if(this.hideDelay){
2078
- hideTimer = setTimeout(boundHide, this.hideDelay);
2079
- }
2080
- $(window)
2081
- .bind('resize.validityalert', function(){
2082
- clearTimeout(resizeTimer);
2083
- resizeTimer = setTimeout(function(){
2084
- api.position(visual);
2085
- }, 9);
2086
- })
2087
- ;
2088
- }
2089
-
2090
- if(!noFocusElem){
2091
- this.setFocus(visual, offset);
2092
- }
2093
- },
2094
- getOffsetFromBody: function(elem){
2095
- return webshims.getRelOffset(errorBubble, elem);
2096
- },
2097
- setFocus: function(visual, offset){
2098
- var focusElem = $(visual).getShadowFocusElement();
2099
- var scrollTop = webshims.scrollRoot.scrollTop();
2100
- var elemTop = ((offset || focusElem.offset()).top) - 30;
2101
- var smooth;
2102
-
2103
- if(webshims.getID && alertElem == 'label'){
2104
- errorBubble.attr('for', webshims.getID(focusElem));
2105
- }
2106
-
2107
- if(scrollTop > elemTop){
2108
- webshims.scrollRoot.animate(
2109
- {scrollTop: elemTop - 5},
2110
- {
2111
- queue: false,
2112
- duration: Math.max( Math.min( 600, (scrollTop - elemTop) * 1.5 ), 80 )
2113
- }
2114
- );
2115
- smooth = true;
2116
- }
2117
- try {
2118
- focusElem[0].focus();
2119
- } catch(e){}
2120
- if(smooth){
2121
- webshims.scrollRoot.scrollTop(scrollTop);
2122
- setTimeout(function(){
2123
- webshims.scrollRoot.scrollTop(scrollTop);
2124
- }, 0);
2125
- }
2126
- setTimeout(function(){
2127
- $(document).bind('focusout.validityalert', boundHide);
2128
- }, 10);
2129
- },
2130
- getMessage: function(elem, message){
2131
- if (!message) {
2132
- message = getContentValidationMessage(elem[0]) || elem.prop('validationMessage');
2133
- }
2134
- if (message) {
2135
- $('span.va-box', errorBubble).text(message);
2136
- }
2137
- else {
2138
- this.hide();
2139
- }
2140
- },
2141
- position: function(elem, offset){
2142
- offset = offset ? $.extend({}, offset) : api.getOffsetFromBody(elem);
2143
- offset.top += elem.outerHeight();
2144
- errorBubble.css(offset);
2145
- },
2146
- show: function(){
2147
- if(errorBubble.css('display') === 'none'){
2148
- errorBubble.css({opacity: 0}).show();
2149
- }
2150
- errorBubble.addClass('va-visible').fadeTo(400, 1);
2151
- },
2152
- hide: function(){
2153
- errorBubble.removeClass('va-visible').fadeOut();
2154
- },
2155
- clear: function(){
2156
- clearTimeout(focusTimer);
2157
- clearTimeout(hideTimer);
2158
- $(document).unbind('.validityalert');
2159
- $(window).unbind('.validityalert');
2160
- errorBubble.stop().removeAttr('for');
2161
- },
2162
- _create: function(){
2163
- if(errorBubble){return;}
2164
- errorBubble = api.errorBubble = $('<'+alertElem+' class="validity-alert-wrapper" role="alert"><span class="validity-alert"><span class="va-arrow"><span class="va-arrow-box"></span></span><span class="va-box"></span></span></'+alertElem+'>').css({position: 'absolute', display: 'none'});
2165
- webshims.ready('DOM', function(){
2166
- errorBubble.appendTo('body');
2167
- if($.fn.bgIframe && $.browser.msie && parseInt($.browser.version, 10) < 7){
2168
- errorBubble.bgIframe();
2169
- }
2170
- });
2171
- }
2172
- };
2173
-
2174
-
2175
- boundHide = $.proxy(api, 'hide');
2176
-
2177
- return api;
2178
- })();
2179
-
2180
-
2181
- /* extension, but also used to fix native implementation workaround/bugfixes */
2182
- (function(){
2183
- var firstEvent,
2184
- invalids = [],
2185
- stopSubmitTimer,
2186
- form
2187
- ;
2188
-
2189
- $(document).bind('invalid', function(e){
2190
- if(e.wrongWebkitInvalid){return;}
2191
- var jElm = $(e.target);
2192
- var shadowElem = jElm.getShadowElement();
2193
- if(!shadowElem.hasClass('form-ui-invalid')){
2194
- shadowElem.addClass('form-ui-invalid').removeClass('form-ui-valid');
2195
- setTimeout(function(){
2196
- $(e.target).trigger('changedinvalid').trigger('changedvaliditystate');
2197
- }, 0);
2198
- }
2199
-
2200
- if(!firstEvent){
2201
- //trigger firstinvalid
2202
- firstEvent = $.Event('firstinvalid');
2203
- firstEvent.isInvalidUIPrevented = e.isDefaultPrevented;
2204
- var firstSystemInvalid = $.Event('firstinvalidsystem');
2205
- $(document).triggerHandler(firstSystemInvalid, {element: e.target, form: e.target.form, isInvalidUIPrevented: e.isDefaultPrevented});
2206
- jElm.trigger(firstEvent);
2207
- }
2208
-
2209
- //if firstinvalid was prevented all invalids will be also prevented
2210
- if( firstEvent && firstEvent.isDefaultPrevented() ){
2211
- e.preventDefault();
2212
- }
2213
- invalids.push(e.target);
2214
- e.extraData = 'fix';
2215
- clearTimeout(stopSubmitTimer);
2216
- stopSubmitTimer = setTimeout(function(){
2217
- var lastEvent = {type: 'lastinvalid', cancelable: false, invalidlist: $(invalids)};
2218
- //reset firstinvalid
2219
- firstEvent = false;
2220
- invalids = [];
2221
- $(e.target).trigger(lastEvent, lastEvent);
2222
- }, 9);
2223
- jElm = null;
2224
- shadowElem = null;
2225
- });
2226
- })();
2227
-
2228
- $.fn.getErrorMessage = function(){
2229
- var message = '';
2230
- var elem = this[0];
2231
- if(elem){
2232
- message = getContentValidationMessage(elem) || $.prop(elem, 'customValidationMessage') || $.prop(elem, 'validationMessage');
2233
- }
2234
- return message;
2235
- };
2236
-
2237
- if(options.replaceValidationUI){
2238
- webshims.ready('DOM forms', function(){
2239
- $(document).bind('firstinvalid', function(e){
2240
- if(!e.isInvalidUIPrevented()){
2241
- e.preventDefault();
2242
- $.webshims.validityAlert.showFor( e.target, $(e.target).prop('customValidationMessage') );
2243
- }
2244
- });
2245
- });
2246
- }
2247
-
1
+ //DOM-Extension helper
2
+ jQuery.webshims.register('dom-extend', function($, webshims, window, document, undefined){
3
+ "use strict";
4
+ //shortcus
5
+ var modules = webshims.modules;
6
+ var listReg = /\s*,\s*/;
7
+
8
+ //proxying attribute
9
+ var olds = {};
10
+ var havePolyfill = {};
11
+ var extendedProps = {};
12
+ var extendQ = {};
13
+ var modifyProps = {};
14
+
15
+ var oldVal = $.fn.val;
16
+ var singleVal = function(elem, name, val, pass, _argless){
17
+ return (_argless) ? oldVal.call($(elem)) : oldVal.call($(elem), val);
18
+ };
19
+ $.fn.val = function(val){
20
+ var elem = this[0];
21
+ if(arguments.length && val == null){
22
+ val = '';
23
+ }
24
+ if(!arguments.length){
25
+ if(!elem || elem.nodeType !== 1){return oldVal.call(this);}
26
+ return $.prop(elem, 'value', val, 'val', true);
27
+ }
28
+ if($.isArray(val)){
29
+ return oldVal.apply(this, arguments);
30
+ }
31
+ var isFunction = $.isFunction(val);
32
+ return this.each(function(i){
33
+ elem = this;
34
+ if(elem.nodeType === 1){
35
+ if(isFunction){
36
+ var genVal = val.call( elem, i, $.prop(elem, 'value', undefined, 'val', true));
37
+ if(genVal == null){
38
+ genVal = '';
39
+ }
40
+ $.prop(elem, 'value', genVal, 'val') ;
41
+ } else {
42
+ $.prop(elem, 'value', val, 'val');
43
+ }
44
+ }
45
+ });
46
+ };
47
+
48
+ var dataID = '_webshimsLib'+ (Math.round(Math.random() * 1000));
49
+ var elementData = function(elem, key, val){
50
+ elem = elem.jquery ? elem[0] : elem;
51
+ if(!elem){return val || {};}
52
+ var data = $.data(elem, dataID);
53
+ if(val !== undefined){
54
+ if(!data){
55
+ data = $.data(elem, dataID, {});
56
+ }
57
+ if(key){
58
+ data[key] = val;
59
+ }
60
+ }
61
+
62
+ return key ? data && data[key] : data;
63
+ };
64
+
65
+
66
+ [{name: 'getNativeElement', prop: 'nativeElement'}, {name: 'getShadowElement', prop: 'shadowElement'}, {name: 'getShadowFocusElement', prop: 'shadowFocusElement'}].forEach(function(data){
67
+ $.fn[data.name] = function(){
68
+ return this.map(function(){
69
+ var shadowData = elementData(this, 'shadowData');
70
+ return shadowData && shadowData[data.prop] || this;
71
+ });
72
+ };
73
+ });
74
+
75
+
76
+ ['removeAttr', 'prop', 'attr'].forEach(function(type){
77
+ olds[type] = $[type];
78
+ $[type] = function(elem, name, value, pass, _argless){
79
+ var isVal = (pass == 'val');
80
+ var oldMethod = !isVal ? olds[type] : singleVal;
81
+ if( !elem || !havePolyfill[name] || elem.nodeType !== 1 || (!isVal && pass && type == 'attr' && $.attrFn[name]) ){
82
+ return oldMethod(elem, name, value, pass, _argless);
83
+ }
84
+
85
+ var nodeName = (elem.nodeName || '').toLowerCase();
86
+ var desc = extendedProps[nodeName];
87
+ var curType = (type == 'attr' && (value === false || value === null)) ? 'removeAttr' : type;
88
+ var propMethod;
89
+ var oldValMethod;
90
+ var ret;
91
+
92
+
93
+ if(!desc){
94
+ desc = extendedProps['*'];
95
+ }
96
+ if(desc){
97
+ desc = desc[name];
98
+ }
99
+
100
+ if(desc){
101
+ propMethod = desc[curType];
102
+ }
103
+
104
+ if(propMethod){
105
+ if(name == 'value'){
106
+ oldValMethod = propMethod.isVal;
107
+ propMethod.isVal = isVal;
108
+ }
109
+ if(curType === 'removeAttr'){
110
+ return propMethod.value.call(elem);
111
+ } else if(value === undefined){
112
+ return (propMethod.get) ?
113
+ propMethod.get.call(elem) :
114
+ propMethod.value
115
+ ;
116
+ } else if(propMethod.set) {
117
+ if(type == 'attr' && value === true){
118
+ value = name;
119
+ }
120
+
121
+ ret = propMethod.set.call(elem, value);
122
+ }
123
+ if(name == 'value'){
124
+ propMethod.isVal = oldValMethod;
125
+ }
126
+ } else {
127
+ ret = oldMethod(elem, name, value, pass, _argless);
128
+ }
129
+ if((value !== undefined || curType === 'removeAttr') && modifyProps[nodeName] && modifyProps[nodeName][name]){
130
+
131
+ var boolValue;
132
+ if(curType == 'removeAttr'){
133
+ boolValue = false;
134
+ } else if(curType == 'prop'){
135
+ boolValue = !!(value);
136
+ } else {
137
+ boolValue = true;
138
+ }
139
+
140
+ modifyProps[nodeName][name].forEach(function(fn){
141
+ if(!fn.only || (fn.only = 'prop' && type == 'prop') || (fn.only == 'attr' && type != 'prop')){
142
+ fn.call(elem, value, boolValue, (isVal) ? 'val' : curType, type);
143
+ }
144
+ });
145
+ }
146
+ return ret;
147
+ };
148
+
149
+ extendQ[type] = function(nodeName, prop, desc){
150
+
151
+ if(!extendedProps[nodeName]){
152
+ extendedProps[nodeName] = {};
153
+ }
154
+ if(!extendedProps[nodeName][prop]){
155
+ extendedProps[nodeName][prop] = {};
156
+ }
157
+ var oldDesc = extendedProps[nodeName][prop][type];
158
+ var getSup = function(propType, descriptor, oDesc){
159
+ if(descriptor && descriptor[propType]){
160
+ return descriptor[propType];
161
+ }
162
+ if(oDesc && oDesc[propType]){
163
+ return oDesc[propType];
164
+ }
165
+ if(type == 'prop' && prop == 'value'){
166
+ return function(value){
167
+ var elem = this;
168
+ return (desc.isVal) ?
169
+ singleVal(elem, prop, value, false, (arguments.length === 0)) :
170
+ olds[type](elem, prop, value)
171
+ ;
172
+ };
173
+ }
174
+ if(type == 'prop' && propType == 'value' && desc.value.apply){
175
+ return function(value){
176
+ var sup = olds[type](this, prop);
177
+ if(sup && sup.apply){
178
+ sup = sup.apply(this, arguments);
179
+ }
180
+ return sup;
181
+ };
182
+ }
183
+ return function(value){
184
+ return olds[type](this, prop, value);
185
+ };
186
+ };
187
+ extendedProps[nodeName][prop][type] = desc;
188
+ if(desc.value === undefined){
189
+ if(!desc.set){
190
+ desc.set = desc.writeable ?
191
+ getSup('set', desc, oldDesc) :
192
+ (webshims.cfg.useStrict && prop == 'prop') ?
193
+ function(){throw(prop +' is readonly on '+ nodeName);} :
194
+ $.noop
195
+ ;
196
+ }
197
+ if(!desc.get){
198
+ desc.get = getSup('get', desc, oldDesc);
199
+ }
200
+
201
+ }
202
+
203
+ ['value', 'get', 'set'].forEach(function(descProp){
204
+ if(desc[descProp]){
205
+ desc['_sup'+descProp] = getSup(descProp, oldDesc);
206
+ }
207
+ });
208
+ };
209
+
210
+ });
211
+
212
+ //see also: https://github.com/lojjic/PIE/issues/40 | https://prototype.lighthouseapp.com/projects/8886/tickets/1107-ie8-fatal-crash-when-prototypejs-is-loaded-with-rounded-cornershtc
213
+ var isExtendNativeSave = (!$.browser.msie || parseInt($.browser.version, 10) > 8);
214
+ var extendNativeValue = (function(){
215
+ var UNKNOWN = webshims.getPrototypeOf(document.createElement('foobar'));
216
+ var has = Object.prototype.hasOwnProperty;
217
+ return function(nodeName, prop, desc){
218
+ var elem = document.createElement(nodeName);
219
+ var elemProto = webshims.getPrototypeOf(elem);
220
+ if( isExtendNativeSave && elemProto && UNKNOWN !== elemProto && ( !elem[prop] || !has.call(elem, prop) ) ){
221
+ var sup = elem[prop];
222
+ desc._supvalue = function(){
223
+ if(sup && sup.apply){
224
+ return sup.apply(this, arguments);
225
+ }
226
+ return sup;
227
+ };
228
+ elemProto[prop] = desc.value;
229
+ } else {
230
+ desc._supvalue = function(){
231
+ var data = elementData(this, 'propValue');
232
+ if(data && data[prop] && data[prop].apply){
233
+ return data[prop].apply(this, arguments);
234
+ }
235
+ return data && data[prop];
236
+ };
237
+ initProp.extendValue(nodeName, prop, desc.value);
238
+ }
239
+ desc.value._supvalue = desc._supvalue;
240
+ };
241
+ })();
242
+
243
+ var initProp = (function(){
244
+
245
+ var initProps = {};
246
+
247
+ webshims.addReady(function(context, contextElem){
248
+ var nodeNameCache = {};
249
+ var getElementsByName = function(name){
250
+ if(!nodeNameCache[name]){
251
+ nodeNameCache[name] = $(context.getElementsByTagName(name));
252
+ if(contextElem[0] && $.nodeName(contextElem[0], name)){
253
+ nodeNameCache[name] = nodeNameCache[name].add(contextElem);
254
+ }
255
+ }
256
+ };
257
+
258
+
259
+ $.each(initProps, function(name, fns){
260
+ getElementsByName(name);
261
+ if(!fns || !fns.forEach){
262
+ webshims.warn('Error: with '+ name +'-property. methods: '+ fns);
263
+ return;
264
+ }
265
+ fns.forEach(function(fn){
266
+ nodeNameCache[name].each(fn);
267
+ });
268
+ });
269
+ nodeNameCache = null;
270
+ });
271
+
272
+ var tempCache;
273
+ var emptyQ = $([]);
274
+ var createNodeNameInit = function(nodeName, fn){
275
+ if(!initProps[nodeName]){
276
+ initProps[nodeName] = [fn];
277
+ } else {
278
+ initProps[nodeName].push(fn);
279
+ }
280
+ if($.isDOMReady){
281
+ (tempCache || $( document.getElementsByTagName(nodeName) )).each(fn);
282
+ }
283
+ };
284
+
285
+ var elementExtends = {};
286
+ return {
287
+ createTmpCache: function(nodeName){
288
+ if($.isDOMReady){
289
+ tempCache = tempCache || $( document.getElementsByTagName(nodeName) );
290
+ }
291
+ return tempCache || emptyQ;
292
+ },
293
+ flushTmpCache: function(){
294
+ tempCache = null;
295
+ },
296
+ content: function(nodeName, prop){
297
+ createNodeNameInit(nodeName, function(){
298
+ var val = $.attr(this, prop);
299
+ if(val != null){
300
+ $.attr(this, prop, val);
301
+ }
302
+ });
303
+ },
304
+ createElement: function(nodeName, fn){
305
+ createNodeNameInit(nodeName, fn);
306
+ },
307
+ extendValue: function(nodeName, prop, value){
308
+ createNodeNameInit(nodeName, function(){
309
+ $(this).each(function(){
310
+ var data = elementData(this, 'propValue', {});
311
+ data[prop] = this[prop];
312
+ this[prop] = value;
313
+ });
314
+ });
315
+ }
316
+ };
317
+ })();
318
+
319
+ var createPropDefault = function(descs, removeType){
320
+ if(descs.defaultValue === undefined){
321
+ descs.defaultValue = '';
322
+ }
323
+ if(!descs.removeAttr){
324
+ descs.removeAttr = {
325
+ value: function(){
326
+ descs[removeType || 'prop'].set.call(this, descs.defaultValue);
327
+ descs.removeAttr._supvalue.call(this);
328
+ }
329
+ };
330
+ }
331
+ if(!descs.attr){
332
+ descs.attr = {};
333
+ }
334
+ };
335
+
336
+ $.extend(webshims, {
337
+
338
+ getID: (function(){
339
+ var ID = new Date().getTime();
340
+ return function(elem){
341
+ elem = $(elem);
342
+ var id = elem.attr('id');
343
+ if(!id){
344
+ ID++;
345
+ id = 'ID-'+ ID;
346
+ elem.attr('id', id);
347
+ }
348
+ return id;
349
+ };
350
+ })(),
351
+ extendUNDEFProp: function(obj, props){
352
+ $.each(props, function(name, prop){
353
+ if( !(name in obj) ){
354
+ obj[name] = prop;
355
+ }
356
+ });
357
+ },
358
+ //http://www.w3.org/TR/html5/common-dom-interfaces.html#reflect
359
+ createPropDefault: createPropDefault,
360
+ data: elementData,
361
+ moveToFirstEvent: (function(){
362
+ var getData = $._data ? '_data' : 'data';
363
+ return function(elem, eventType, bindType){
364
+ var events = ($[getData](elem, 'events') || {})[eventType];
365
+ var fn;
366
+
367
+ if(events && events.length > 1){
368
+ fn = events.pop();
369
+ if(!bindType){
370
+ bindType = 'bind';
371
+ }
372
+ if(bindType == 'bind' && events.delegateCount){
373
+ events.splice( events.delegateCount, 0, fn);
374
+ } else {
375
+ events.unshift( fn );
376
+ }
377
+
378
+
379
+ }
380
+ elem = null;
381
+ };
382
+ })(),
383
+ addShadowDom: (function(){
384
+ var resizeTimer;
385
+ var lastHeight;
386
+ var lastWidth;
387
+
388
+ var docObserve = {
389
+ init: false,
390
+ runs: 0,
391
+ test: function(){
392
+ var height = docObserve.getHeight();
393
+ var width = docObserve.getWidth();
394
+ if(height != docObserve.height || width != docObserve.width){
395
+ docObserve.height = height;
396
+ docObserve.width = width;
397
+ docObserve.handler({type: 'docresize'});
398
+ docObserve.runs++;
399
+ if(docObserve.runs < 30){
400
+ setTimeout(docObserve.test, 30);
401
+ }
402
+ } else {
403
+ docObserve.runs = 0;
404
+ }
405
+ },
406
+ handler: function(e){
407
+ clearTimeout(resizeTimer);
408
+ resizeTimer = setTimeout(function(){
409
+ if(e.type == 'resize'){
410
+ var width = $(window).width();
411
+ var height = $(window).width();
412
+ if(height == lastHeight && width == lastWidth){
413
+ return;
414
+ }
415
+ lastHeight = height;
416
+ lastWidth = width;
417
+
418
+ docObserve.height = docObserve.getHeight();
419
+ docObserve.width = docObserve.getWidth();
420
+
421
+ }
422
+ $.event.trigger('updateshadowdom');
423
+ }, (e.type == 'resize') ? 50 : 9);
424
+ },
425
+ _create: function(){
426
+ $.each({ Height: "getHeight", Width: "getWidth" }, function(name, type){
427
+ var body = document.body;
428
+ var doc = document.documentElement;
429
+ docObserve[type] = function(){
430
+ return Math.max(
431
+ body[ "scroll" + name ], doc[ "scroll" + name ],
432
+ body[ "offset" + name ], doc[ "offset" + name ],
433
+ doc[ "client" + name ]
434
+ );
435
+ };
436
+ });
437
+ },
438
+ start: function(){
439
+ if(!this.init && document.body){
440
+ this.init = true;
441
+ this._create();
442
+ this.height = docObserve.getHeight();
443
+ this.width = docObserve.getWidth();
444
+ setInterval(this.test, 400);
445
+ $(this.test);
446
+ $(window).bind('load', this.test);
447
+ $(window).bind('resize', this.handler);
448
+ (function(){
449
+ var oldAnimate = $.fn.animate;
450
+ var animationTimer;
451
+
452
+ $.fn.animate = function(){
453
+ clearTimeout(animationTimer);
454
+ animationTimer = setTimeout(function(){
455
+ docObserve.test();
456
+ docObserve.handler({type: 'animationstart'});
457
+ }, 19);
458
+
459
+ return oldAnimate.apply(this, arguments);
460
+ };
461
+ })();
462
+ }
463
+ }
464
+ };
465
+
466
+
467
+ $.event.customEvent.updateshadowdom = true;
468
+ webshims.docObserve = function(){
469
+ webshims.ready('DOM', function(){
470
+ docObserve.start();
471
+ });
472
+ };
473
+ return function(nativeElem, shadowElem, opts){
474
+ opts = opts || {};
475
+ if(nativeElem.jquery){
476
+ nativeElem = nativeElem[0];
477
+ }
478
+ if(shadowElem.jquery){
479
+ shadowElem = shadowElem[0];
480
+ }
481
+ var nativeData = $.data(nativeElem, dataID) || $.data(nativeElem, dataID, {});
482
+ var shadowData = $.data(shadowElem, dataID) || $.data(shadowElem, dataID, {});
483
+ var shadowFocusElementData = {};
484
+ if(!opts.shadowFocusElement){
485
+ opts.shadowFocusElement = shadowElem;
486
+ } else if(opts.shadowFocusElement){
487
+ if(opts.shadowFocusElement.jquery){
488
+ opts.shadowFocusElement = opts.shadowFocusElement[0];
489
+ }
490
+ shadowFocusElementData = $.data(opts.shadowFocusElement, dataID) || $.data(opts.shadowFocusElement, dataID, shadowFocusElementData);
491
+ }
492
+
493
+ nativeData.hasShadow = shadowElem;
494
+ shadowFocusElementData.nativeElement = shadowData.nativeElement = nativeElem;
495
+ shadowFocusElementData.shadowData = shadowData.shadowData = nativeData.shadowData = {
496
+ nativeElement: nativeElem,
497
+ shadowElement: shadowElem,
498
+ shadowFocusElement: opts.shadowFocusElement
499
+ };
500
+ if(opts.shadowChilds){
501
+ opts.shadowChilds.each(function(){
502
+ elementData(this, 'shadowData', shadowData.shadowData);
503
+ });
504
+ }
505
+
506
+ if(opts.data){
507
+ shadowFocusElementData.shadowData.data = shadowData.shadowData.data = nativeData.shadowData.data = opts.data;
508
+ }
509
+ opts = null;
510
+ webshims.docObserve();
511
+ };
512
+ })(),
513
+ propTypes: {
514
+ standard: function(descs, name){
515
+ createPropDefault(descs);
516
+ if(descs.prop){return;}
517
+ descs.prop = {
518
+ set: function(val){
519
+ descs.attr.set.call(this, ''+val);
520
+ },
521
+ get: function(){
522
+ return descs.attr.get.call(this) || descs.defaultValue;
523
+ }
524
+ };
525
+
526
+ },
527
+ "boolean": function(descs, name){
528
+
529
+ createPropDefault(descs);
530
+ if(descs.prop){return;}
531
+ descs.prop = {
532
+ set: function(val){
533
+ if(val){
534
+ descs.attr.set.call(this, "");
535
+ } else {
536
+ descs.removeAttr.value.call(this);
537
+ }
538
+ },
539
+ get: function(){
540
+ return descs.attr.get.call(this) != null;
541
+ }
542
+ };
543
+ },
544
+ "src": (function(){
545
+ var anchor = document.createElement('a');
546
+ anchor.style.display = "none";
547
+ return function(descs, name){
548
+
549
+ createPropDefault(descs);
550
+ if(descs.prop){return;}
551
+ descs.prop = {
552
+ set: function(val){
553
+ descs.attr.set.call(this, val);
554
+ },
555
+ get: function(){
556
+ var href = this.getAttribute(name);
557
+ var ret;
558
+ if(href == null){return '';}
559
+
560
+ anchor.setAttribute('href', href+'' );
561
+
562
+ if(!$.support.hrefNormalized){
563
+ try {
564
+ $(anchor).insertAfter(this);
565
+ ret = anchor.getAttribute('href', 4);
566
+ } catch(er){
567
+ ret = anchor.getAttribute('href', 4);
568
+ }
569
+ $(anchor).detach();
570
+ }
571
+ return ret || anchor.href;
572
+ }
573
+ };
574
+ };
575
+ })(),
576
+ enumarated: function(descs, name){
577
+
578
+ createPropDefault(descs);
579
+ if(descs.prop){return;}
580
+ descs.prop = {
581
+ set: function(val){
582
+ descs.attr.set.call(this, val);
583
+ },
584
+ get: function(){
585
+ var val = (descs.attr.get.call(this) || '').toLowerCase();
586
+ if(!val || descs.limitedTo.indexOf(val) == -1){
587
+ val = descs.defaultValue;
588
+ }
589
+ return val;
590
+ }
591
+ };
592
+ }
593
+
594
+ // ,unsignedLong: $.noop
595
+ // ,"doubble": $.noop
596
+ // ,"long": $.noop
597
+ // ,tokenlist: $.noop
598
+ // ,settableTokenlist: $.noop
599
+ },
600
+ reflectProperties: function(nodeNames, props){
601
+ if(typeof props == 'string'){
602
+ props = props.split(listReg);
603
+ }
604
+ props.forEach(function(prop){
605
+ webshims.defineNodeNamesProperty(nodeNames, prop, {
606
+ prop: {
607
+ set: function(val){
608
+ $.attr(this, prop, val);
609
+ },
610
+ get: function(){
611
+ return $.attr(this, prop) || '';
612
+ }
613
+ }
614
+ });
615
+ });
616
+ },
617
+ defineNodeNameProperty: function(nodeName, prop, descs){
618
+ havePolyfill[prop] = true;
619
+
620
+ if(descs.reflect){
621
+ webshims.propTypes[descs.propType || 'standard'](descs, prop);
622
+ }
623
+
624
+ ['prop', 'attr', 'removeAttr'].forEach(function(type){
625
+ var desc = descs[type];
626
+ if(desc){
627
+ if(type === 'prop'){
628
+ desc = $.extend({writeable: true}, desc);
629
+ } else {
630
+ desc = $.extend({}, desc, {writeable: true});
631
+ }
632
+
633
+ extendQ[type](nodeName, prop, desc);
634
+ if(nodeName != '*' && webshims.cfg.extendNative && type == 'prop' && desc.value && $.isFunction(desc.value)){
635
+ extendNativeValue(nodeName, prop, desc);
636
+ }
637
+ descs[type] = desc;
638
+ }
639
+ });
640
+ if(descs.initAttr){
641
+ initProp.content(nodeName, prop);
642
+ }
643
+ return descs;
644
+ },
645
+
646
+ defineNodeNameProperties: function(name, descs, propType, _noTmpCache){
647
+ var olddesc;
648
+ for(var prop in descs){
649
+ if(!_noTmpCache && descs[prop].initAttr){
650
+ initProp.createTmpCache(name);
651
+ }
652
+ if(propType){
653
+ if(descs[prop][propType]){
654
+ //webshims.log('override: '+ name +'['+prop +'] for '+ propType);
655
+ } else {
656
+ descs[prop][propType] = {};
657
+ ['value', 'set', 'get'].forEach(function(copyProp){
658
+ if(copyProp in descs[prop]){
659
+ descs[prop][propType][copyProp] = descs[prop][copyProp];
660
+ delete descs[prop][copyProp];
661
+ }
662
+ });
663
+ }
664
+ }
665
+ descs[prop] = webshims.defineNodeNameProperty(name, prop, descs[prop]);
666
+ }
667
+ if(!_noTmpCache){
668
+ initProp.flushTmpCache();
669
+ }
670
+ return descs;
671
+ },
672
+
673
+ createElement: function(nodeName, create, descs){
674
+ var ret;
675
+ if($.isFunction(create)){
676
+ create = {
677
+ after: create
678
+ };
679
+ }
680
+ initProp.createTmpCache(nodeName);
681
+ if(create.before){
682
+ initProp.createElement(nodeName, create.before);
683
+ }
684
+ if(descs){
685
+ ret = webshims.defineNodeNameProperties(nodeName, descs, false, true);
686
+ }
687
+ if(create.after){
688
+ initProp.createElement(nodeName, create.after);
689
+ }
690
+ initProp.flushTmpCache();
691
+ return ret;
692
+ },
693
+ onNodeNamesPropertyModify: function(nodeNames, props, desc, only){
694
+ if(typeof nodeNames == 'string'){
695
+ nodeNames = nodeNames.split(listReg);
696
+ }
697
+ if($.isFunction(desc)){
698
+ desc = {set: desc};
699
+ }
700
+
701
+ nodeNames.forEach(function(name){
702
+ if(!modifyProps[name]){
703
+ modifyProps[name] = {};
704
+ }
705
+ if(typeof props == 'string'){
706
+ props = props.split(listReg);
707
+ }
708
+ if(desc.initAttr){
709
+ initProp.createTmpCache(name);
710
+ }
711
+ props.forEach(function(prop){
712
+ if(!modifyProps[name][prop]){
713
+ modifyProps[name][prop] = [];
714
+ havePolyfill[prop] = true;
715
+ }
716
+ if(desc.set){
717
+ if(only){
718
+ desc.set.only = only;
719
+ }
720
+ modifyProps[name][prop].push(desc.set);
721
+ }
722
+
723
+ if(desc.initAttr){
724
+ initProp.content(name, prop);
725
+ }
726
+ });
727
+ initProp.flushTmpCache();
728
+
729
+ });
730
+ },
731
+ defineNodeNamesBooleanProperty: function(elementNames, prop, descs){
732
+ if(!descs){
733
+ descs = {};
734
+ }
735
+ if($.isFunction(descs)){
736
+ descs.set = descs;
737
+ }
738
+ webshims.defineNodeNamesProperty(elementNames, prop, {
739
+ attr: {
740
+ set: function(val){
741
+ this.setAttribute(prop, val);
742
+ if(descs.set){
743
+ descs.set.call(this, true);
744
+ }
745
+ },
746
+ get: function(){
747
+ var ret = this.getAttribute(prop);
748
+ return (ret == null) ? undefined : prop;
749
+ }
750
+ },
751
+ removeAttr: {
752
+ value: function(){
753
+ this.removeAttribute(prop);
754
+ if(descs.set){
755
+ descs.set.call(this, false);
756
+ }
757
+ }
758
+ },
759
+ reflect: true,
760
+ propType: 'boolean',
761
+ initAttr: descs.initAttr || false
762
+ });
763
+ },
764
+ contentAttr: function(elem, name, val){
765
+ if(!elem.nodeName){return;}
766
+ var attr;
767
+ if(val === undefined){
768
+ attr = (elem.attributes[name] || {});
769
+ val = attr.specified ? attr.value : null;
770
+ return (val == null) ? undefined : val;
771
+ }
772
+
773
+ if(typeof val == 'boolean'){
774
+ if(!val){
775
+ elem.removeAttribute(name);
776
+ } else {
777
+ elem.setAttribute(name, name);
778
+ }
779
+ } else {
780
+ elem.setAttribute(name, val);
781
+ }
782
+ },
783
+
784
+ // set current Lang:
785
+ // - webshims.activeLang(lang:string);
786
+ // get current lang
787
+ // - webshims.activeLang();
788
+ // get current lang
789
+ // webshims.activeLang({
790
+ // register: moduleName:string,
791
+ // callback: callback:function
792
+ // });
793
+ // get/set including removeLang
794
+ // - webshims.activeLang({
795
+ // module: moduleName:string,
796
+ // callback: callback:function,
797
+ // langObj: languageObj:array/object
798
+ // });
799
+ activeLang: (function(){
800
+ var callbacks = [];
801
+ var registeredCallbacks = {};
802
+ var currentLang;
803
+ var shortLang;
804
+ var notLocal = /:\/\/|^\.*\//;
805
+ var loadRemoteLang = function(data, lang, options){
806
+ var langSrc;
807
+ if(lang && options && $.inArray(lang, options.availabeLangs || []) !== -1){
808
+ data.loading = true;
809
+ langSrc = options.langSrc;
810
+ if(!notLocal.test(langSrc)){
811
+ langSrc = webshims.cfg.basePath+langSrc;
812
+ }
813
+ webshims.loader.loadScript(langSrc+lang+'.js', function(){
814
+ if(data.langObj[lang]){
815
+ data.loading = false;
816
+ callLang(data, true);
817
+ } else {
818
+ $(function(){
819
+ if(data.langObj[lang]){
820
+ callLang(data, true);
821
+ }
822
+ data.loading = false;
823
+ });
824
+ }
825
+ });
826
+ return true;
827
+ }
828
+ return false;
829
+ };
830
+ var callRegister = function(module){
831
+ if(registeredCallbacks[module]){
832
+ registeredCallbacks[module].forEach(function(data){
833
+ data.callback();
834
+ });
835
+ }
836
+ };
837
+ var callLang = function(data, _noLoop){
838
+ if(data.activeLang != currentLang && data.activeLang !== shortLang){
839
+ var options = modules[data.module].options;
840
+ if( data.langObj[currentLang] || (shortLang && data.langObj[shortLang]) ){
841
+ data.activeLang = currentLang;
842
+ data.callback(data.langObj[currentLang] || data.langObj[shortLang], currentLang);
843
+ callRegister(data.module);
844
+ } else if( !_noLoop &&
845
+ !loadRemoteLang(data, currentLang, options) &&
846
+ !loadRemoteLang(data, shortLang, options) &&
847
+ data.langObj[''] && data.activeLang !== '' ) {
848
+ data.activeLang = '';
849
+ data.callback(data.langObj[''], currentLang);
850
+ callRegister(data.module);
851
+ }
852
+ }
853
+ };
854
+
855
+
856
+ var activeLang = function(lang){
857
+
858
+ if(typeof lang == 'string' && lang !== currentLang){
859
+ currentLang = lang;
860
+ shortLang = currentLang.split('-')[0];
861
+ if(currentLang == shortLang){
862
+ shortLang = false;
863
+ }
864
+ $.each(callbacks, function(i, data){
865
+ callLang(data);
866
+ });
867
+ } else if(typeof lang == 'object'){
868
+
869
+ if(lang.register){
870
+ if(!registeredCallbacks[lang.register]){
871
+ registeredCallbacks[lang.register] = [];
872
+ }
873
+ registeredCallbacks[lang.register].push(lang);
874
+ lang.callback();
875
+ } else {
876
+ if(!lang.activeLang){
877
+ lang.activeLang = '';
878
+ }
879
+ callbacks.push(lang);
880
+ callLang(lang);
881
+ }
882
+ }
883
+ return currentLang;
884
+ };
885
+
886
+ return activeLang;
887
+ })()
888
+ });
889
+
890
+ $.each({
891
+ defineNodeNamesProperty: 'defineNodeNameProperty',
892
+ defineNodeNamesProperties: 'defineNodeNameProperties',
893
+ createElements: 'createElement'
894
+ }, function(name, baseMethod){
895
+ webshims[name] = function(names, a, b, c){
896
+ if(typeof names == 'string'){
897
+ names = names.split(listReg);
898
+ }
899
+ var retDesc = {};
900
+ names.forEach(function(nodeName){
901
+ retDesc[nodeName] = webshims[baseMethod](nodeName, a, b, c);
902
+ });
903
+ return retDesc;
904
+ };
905
+ });
906
+
907
+ webshims.isReady('webshimLocalization', true);
908
+ });
909
+ //html5a11y
910
+ (function($, document){
911
+ var browserVersion = $.webshims.browserVersion;
912
+ if($.browser.mozilla && browserVersion > 5){return;}
913
+ if (!$.browser.msie || (browserVersion < 12 && browserVersion > 7)) {
914
+ var elemMappings = {
915
+ article: "article",
916
+ aside: "complementary",
917
+ section: "region",
918
+ nav: "navigation",
919
+ address: "contentinfo"
920
+ };
921
+ var addRole = function(elem, role){
922
+ var hasRole = elem.getAttribute('role');
923
+ if (!hasRole) {
924
+ elem.setAttribute('role', role);
925
+ }
926
+ };
927
+
928
+ $.webshims.addReady(function(context, contextElem){
929
+ $.each(elemMappings, function(name, role){
930
+ var elems = $(name, context).add(contextElem.filter(name));
931
+ for (var i = 0, len = elems.length; i < len; i++) {
932
+ addRole(elems[i], role);
933
+ }
934
+ });
935
+ if (context === document) {
936
+ var header = document.getElementsByTagName('header')[0];
937
+ var footers = document.getElementsByTagName('footer');
938
+ var footerLen = footers.length;
939
+ if (header && !$(header).closest('section, article')[0]) {
940
+ addRole(header, 'banner');
941
+ }
942
+ if (!footerLen) {
943
+ return;
944
+ }
945
+ var footer = footers[footerLen - 1];
946
+ if (!$(footer).closest('section, article')[0]) {
947
+ addRole(footer, 'contentinfo');
948
+ }
949
+ }
950
+ });
951
+ }
952
+ })(jQuery, document);
953
+ jQuery.webshims.register('form-datalist', function($, webshims, window, document, undefined){
954
+ "use strict";
955
+ var doc = document;
956
+
957
+ /*
958
+ * implement propType "element" currently only used for list-attribute (will be moved to dom-extend, if needed)
959
+ */
960
+ webshims.propTypes.element = function(descs){
961
+ webshims.createPropDefault(descs, 'attr');
962
+ if(descs.prop){return;}
963
+ descs.prop = {
964
+ get: function(){
965
+ var elem = descs.attr.get.call(this);
966
+ if(elem){
967
+ elem = document.getElementById(elem);
968
+ if(elem && descs.propNodeName && !$.nodeName(elem, descs.propNodeName)){
969
+ elem = null;
970
+ }
971
+ }
972
+ return elem || null;
973
+ },
974
+ writeable: false
975
+ };
976
+ };
977
+
978
+
979
+ /*
980
+ * Implements datalist element and list attribute
981
+ */
982
+
983
+ (function(){
984
+ var formsCFG = $.webshims.cfg.forms;
985
+ var listSupport = Modernizr.input.list;
986
+ if(listSupport && !formsCFG.customDatalist){return;}
987
+
988
+ var initializeDatalist = function(){
989
+
990
+
991
+ if(!listSupport){
992
+ webshims.defineNodeNameProperty('datalist', 'options', {
993
+ prop: {
994
+ writeable: false,
995
+ get: function(){
996
+ var elem = this;
997
+ var select = $('select', elem);
998
+ var options;
999
+ if(select[0]){
1000
+ options = select[0].options;
1001
+ } else {
1002
+ options = $('option', elem).get();
1003
+ if(options.length){
1004
+ webshims.warn('you should wrap your option-elements for a datalist in a select element to support IE and other old browsers.');
1005
+ }
1006
+ }
1007
+ return options;
1008
+ }
1009
+ }
1010
+ });
1011
+ }
1012
+
1013
+ var inputListProto = {
1014
+ //override autocomplete
1015
+ autocomplete: {
1016
+ attr: {
1017
+ get: function(){
1018
+ var elem = this;
1019
+ var data = $.data(elem, 'datalistWidget');
1020
+ if(data){
1021
+ return data._autocomplete;
1022
+ }
1023
+ return ('autocomplete' in elem) ? elem.autocomplete : elem.getAttribute('autocomplete');
1024
+ },
1025
+ set: function(value){
1026
+ var elem = this;
1027
+ var data = $.data(elem, 'datalistWidget');
1028
+ if(data){
1029
+ data._autocomplete = value;
1030
+ if(value == 'off'){
1031
+ data.hideList();
1032
+ }
1033
+ } else {
1034
+ if('autocomplete' in elem){
1035
+ elem.autocomplete = value;
1036
+ } else {
1037
+ elem.setAttribute('autocomplete', value);
1038
+ }
1039
+ }
1040
+ }
1041
+ }
1042
+ }
1043
+ };
1044
+
1045
+ // if(formsCFG.customDatalist && (!listSupport || !('selectedOption') in $('<input />')[0])){
1046
+ // //currently not supported x-browser (FF4 has not implemented and is not polyfilled )
1047
+ // inputListProto.selectedOption = {
1048
+ // prop: {
1049
+ // writeable: false,
1050
+ // get: function(){
1051
+ // var elem = this;
1052
+ // var list = $.prop(elem, 'list');
1053
+ // var ret = null;
1054
+ // var value, options;
1055
+ // if(!list){return ret;}
1056
+ // value = $.prop(elem, 'value');
1057
+ // if(!value){return ret;}
1058
+ // options = $.prop(list, 'options');
1059
+ // if(!options.length){return ret;}
1060
+ // $.each(options, function(i, option){
1061
+ // if(value == $.prop(option, 'value')){
1062
+ // ret = option;
1063
+ // return false;
1064
+ // }
1065
+ // });
1066
+ // return ret;
1067
+ // }
1068
+ // }
1069
+ // };
1070
+ // }
1071
+
1072
+ if(!listSupport){
1073
+ inputListProto['list'] = {
1074
+ attr: {
1075
+ get: function(){
1076
+ var val = webshims.contentAttr(this, 'list');
1077
+ return (val == null) ? undefined : val;
1078
+ },
1079
+ set: function(value){
1080
+ var elem = this;
1081
+ webshims.contentAttr(elem, 'list', value);
1082
+ webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
1083
+ }
1084
+ },
1085
+ initAttr: true,
1086
+ reflect: true,
1087
+ propType: 'element',
1088
+ propNodeName: 'datalist'
1089
+ };
1090
+ } else {
1091
+ //options only return options, if option-elements are rooted: but this makes this part of HTML5 less backwards compatible
1092
+ if(!($('<datalist><select><option></option></select></datalist>').prop('options') || []).length ){
1093
+ webshims.defineNodeNameProperty('datalist', 'options', {
1094
+ prop: {
1095
+ writeable: false,
1096
+ get: function(){
1097
+ var options = this.options || [];
1098
+ if(!options.length){
1099
+ var elem = this;
1100
+ var select = $('select', elem);
1101
+ if(select[0] && select[0].options && select[0].options.length){
1102
+ options = select[0].options;
1103
+ }
1104
+ }
1105
+ return options;
1106
+ }
1107
+ }
1108
+ });
1109
+ }
1110
+ inputListProto['list'] = {
1111
+ attr: {
1112
+ get: function(){
1113
+ var val = webshims.contentAttr(this, 'list');
1114
+ if(val != null){
1115
+ this.removeAttribute('list');
1116
+ } else {
1117
+ val = $.data(this, 'datalistListAttr');
1118
+ }
1119
+
1120
+ return (val == null) ? undefined : val;
1121
+ },
1122
+ set: function(value){
1123
+ var elem = this;
1124
+ $.data(elem, 'datalistListAttr', value);
1125
+ webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
1126
+ }
1127
+ },
1128
+ initAttr: true,
1129
+ reflect: true,
1130
+ propType: 'element',
1131
+ propNodeName: 'datalist'
1132
+ };
1133
+ }
1134
+
1135
+
1136
+ webshims.defineNodeNameProperties('input', inputListProto);
1137
+
1138
+ if($.event.customEvent){
1139
+ $.event.customEvent.updateDatalist = true;
1140
+ $.event.customEvent.updateInput = true;
1141
+ $.event.customEvent.datalistselect = true;
1142
+ }
1143
+ webshims.addReady(function(context, contextElem){
1144
+ contextElem
1145
+ .filter('datalist > select, datalist, datalist > option, datalist > select > option')
1146
+ .closest('datalist')
1147
+ .triggerHandler('updateDatalist')
1148
+ ;
1149
+
1150
+ });
1151
+
1152
+
1153
+ };
1154
+
1155
+
1156
+ /*
1157
+ * ShadowList
1158
+ */
1159
+ var listidIndex = 0;
1160
+
1161
+ var noDatalistSupport = {
1162
+ submit: 1,
1163
+ button: 1,
1164
+ reset: 1,
1165
+ hidden: 1,
1166
+
1167
+ //ToDo
1168
+ range: 1,
1169
+ date: 1
1170
+ };
1171
+ var lteie6 = ($.browser.msie && parseInt($.browser.version, 10) < 7);
1172
+ var globStoredOptions = {};
1173
+ var getStoredOptions = function(name){
1174
+ if(!name){return [];}
1175
+ if(globStoredOptions[name]){
1176
+ return globStoredOptions[name];
1177
+ }
1178
+ var data;
1179
+ try {
1180
+ data = JSON.parse(localStorage.getItem('storedDatalistOptions'+name));
1181
+ } catch(e){}
1182
+ globStoredOptions[name] = data || [];
1183
+ return data || [];
1184
+ };
1185
+ var storeOptions = function(name, val){
1186
+ if(!name){return;}
1187
+ val = val || [];
1188
+ try {
1189
+ localStorage.setItem( 'storedDatalistOptions'+name, JSON.stringify(val) );
1190
+ } catch(e){}
1191
+ };
1192
+
1193
+ var getText = function(elem){
1194
+ return (elem.textContent || elem.innerText || $.text([ elem ]) || '');
1195
+ };
1196
+
1197
+ var shadowListProto = {
1198
+ _create: function(opts){
1199
+
1200
+ if(noDatalistSupport[$.prop(opts.input, 'type')]){return;}
1201
+ var datalist = opts.datalist;
1202
+ var data = $.data(opts.input, 'datalistWidget');
1203
+ if(datalist && data && data.datalist !== datalist){
1204
+ data.datalist = datalist;
1205
+ data.id = opts.id;
1206
+
1207
+ data.shadowList.prop('className', 'datalist-polyfill '+ (data.datalist.className || '') + ' '+ data.datalist.id +'-shadowdom');
1208
+ if(formsCFG.positionDatalist){
1209
+ data.shadowList.insertAfter(opts.input);
1210
+ } else {
1211
+ data.shadowList.appendTo('body');
1212
+ }
1213
+ $(data.datalist)
1214
+ .off('updateDatalist.datalistWidget')
1215
+ .on('updateDatalist.datalistWidget', $.proxy(data, '_resetListCached'))
1216
+ ;
1217
+ data._resetListCached();
1218
+ return;
1219
+ } else if(!datalist){
1220
+ if(data){
1221
+ data.destroy();
1222
+ }
1223
+ return;
1224
+ } else if(data && data.datalist === datalist){
1225
+ return;
1226
+ }
1227
+ listidIndex++;
1228
+ var that = this;
1229
+ this.hideList = $.proxy(that, 'hideList');
1230
+ this.timedHide = function(){
1231
+ clearTimeout(that.hideTimer);
1232
+ that.hideTimer = setTimeout(that.hideList, 9);
1233
+ };
1234
+ this.datalist = datalist;
1235
+ this.id = opts.id;
1236
+ this.hasViewableData = true;
1237
+ this._autocomplete = $.attr(opts.input, 'autocomplete');
1238
+ $.data(opts.input, 'datalistWidget', this);
1239
+ this.shadowList = $('<div class="datalist-polyfill '+ (this.datalist.className || '') + ' '+ this.datalist.id +'-shadowdom' +'" />');
1240
+
1241
+ if(formsCFG.positionDatalist || $(opts.input).hasClass('position-datalist')){
1242
+ this.shadowList.insertAfter(opts.input);
1243
+ } else {
1244
+ this.shadowList.appendTo('body');
1245
+ }
1246
+
1247
+ this.index = -1;
1248
+ this.input = opts.input;
1249
+ this.arrayOptions = [];
1250
+
1251
+ this.shadowList
1252
+ .delegate('li', 'mouseenter.datalistWidget mousedown.datalistWidget click.datalistWidget', function(e){
1253
+ var items = $('li:not(.hidden-item)', that.shadowList);
1254
+ var select = (e.type == 'mousedown' || e.type == 'click');
1255
+ that.markItem(items.index(e.currentTarget), select, items);
1256
+ if(e.type == 'click'){
1257
+ that.hideList();
1258
+ if(formsCFG.customDatalist){
1259
+ $(opts.input).trigger('datalistselect');
1260
+ }
1261
+ }
1262
+ return (e.type != 'mousedown');
1263
+ })
1264
+ .on('focusout', this.timedHide)
1265
+ ;
1266
+
1267
+ opts.input.setAttribute('autocomplete', 'off');
1268
+
1269
+ $(opts.input)
1270
+ .attr({
1271
+ //role: 'combobox',
1272
+ 'aria-haspopup': 'true'
1273
+ })
1274
+ .on({
1275
+ 'input.datalistWidget': function(){
1276
+ if(!that.triggeredByDatalist){
1277
+ that.changedValue = false;
1278
+ that.showHideOptions();
1279
+ }
1280
+ },
1281
+ 'keydown.datalistWidget': function(e){
1282
+ var keyCode = e.keyCode;
1283
+ var activeItem;
1284
+ var items;
1285
+ if(keyCode == 40 && !that.showList()){
1286
+ that.markItem(that.index + 1, true);
1287
+ return false;
1288
+ }
1289
+
1290
+ if(!that.isListVisible){return;}
1291
+
1292
+
1293
+ if(keyCode == 38){
1294
+ that.markItem(that.index - 1, true);
1295
+ return false;
1296
+ }
1297
+ if(!e.shiftKey && (keyCode == 33 || keyCode == 36)){
1298
+ that.markItem(0, true);
1299
+ return false;
1300
+ }
1301
+ if(!e.shiftKey && (keyCode == 34 || keyCode == 35)){
1302
+ items = $('li:not(.hidden-item)', that.shadowList);
1303
+ that.markItem(items.length - 1, true, items);
1304
+ return false;
1305
+ }
1306
+ if(keyCode == 13 || keyCode == 27){
1307
+ if (keyCode == 13){
1308
+ activeItem = $('li.active-item:not(.hidden-item)', that.shadowList);
1309
+ that.changeValue( $('li.active-item:not(.hidden-item)', that.shadowList) );
1310
+ }
1311
+ that.hideList();
1312
+ if(formsCFG.customDatalist && activeItem && activeItem[0]){
1313
+ $(opts.input).trigger('datalistselect');
1314
+ }
1315
+ return false;
1316
+ }
1317
+ },
1318
+ 'focus.datalistWidget': function(){
1319
+ if($(this).hasClass('list-focus')){
1320
+ that.showList();
1321
+ }
1322
+ },
1323
+ 'mousedown.datalistWidget': function(){
1324
+ if($(this).is(':focus')){
1325
+ that.showList();
1326
+ }
1327
+ },
1328
+ 'blur.datalistWidget': this.timedHide
1329
+ })
1330
+ ;
1331
+
1332
+
1333
+ $(this.datalist)
1334
+ .off('updateDatalist.datalistWidget')
1335
+ .on('updateDatalist.datalistWidget', $.proxy(this, '_resetListCached'))
1336
+ ;
1337
+
1338
+ this._resetListCached();
1339
+
1340
+ if(opts.input.form && (opts.input.name || opts.input.id)){
1341
+ $(opts.input.form).on('submit.datalistWidget'+opts.input.id, function(){
1342
+ if(!$(opts.input).hasClass('no-datalist-cache') && that._autocomplete != 'off'){
1343
+ var val = $.prop(opts.input, 'value');
1344
+ var name = (opts.input.name || opts.input.id) + $.prop(opts.input, 'type');
1345
+ if(!that.storedOptions){
1346
+ that.storedOptions = getStoredOptions( name );
1347
+ }
1348
+ if(val && that.storedOptions.indexOf(val) == -1){
1349
+ that.storedOptions.push(val);
1350
+ storeOptions(name, that.storedOptions );
1351
+ }
1352
+ }
1353
+ });
1354
+ }
1355
+ $(window).on('unload.datalist'+this.id+' beforeunload.datalist'+this.id, function(){
1356
+ that.destroy();
1357
+ });
1358
+ },
1359
+ destroy: function(){
1360
+ var autocomplete = $.attr(this.input, 'autocomplete');
1361
+ $(this.input)
1362
+ .off('.datalistWidget')
1363
+ .removeData('datalistWidget')
1364
+ ;
1365
+ this.shadowList.remove();
1366
+ $(document).off('.datalist'+this.id);
1367
+ $(window).off('.datalist'+this.id);
1368
+ if(this.input.form && this.input.id){
1369
+ $(this.input.form).off('submit.datalistWidget'+this.input.id);
1370
+ }
1371
+ this.input.removeAttribute('aria-haspopup');
1372
+ if(autocomplete === undefined){
1373
+ this.input.removeAttribute('autocomplete');
1374
+ } else {
1375
+ $(this.input).attr('autocomplete', autocomplete);
1376
+ }
1377
+ },
1378
+ _resetListCached: function(e){
1379
+ var that = this;
1380
+ var forceShow;
1381
+ this.needsUpdate = true;
1382
+ this.lastUpdatedValue = false;
1383
+ this.lastUnfoundValue = '';
1384
+
1385
+ if(!this.updateTimer){
1386
+ if(window.QUnit || (forceShow = (e && document.activeElement == that.input))){
1387
+ that.updateListOptions(forceShow);
1388
+ } else {
1389
+ webshims.ready('WINDOWLOAD', function(){
1390
+ that.updateTimer = setTimeout(function(){
1391
+ that.updateListOptions();
1392
+ that = null;
1393
+ listidIndex = 1;
1394
+ }, 200 + (100 * listidIndex));
1395
+ });
1396
+ }
1397
+ }
1398
+ },
1399
+ maskHTML: function(str){
1400
+ return str.replace(/</g, '&lt;').replace(/>/g, '&gt;');
1401
+ },
1402
+ updateListOptions: function(_forceShow){
1403
+ this.needsUpdate = false;
1404
+ clearTimeout(this.updateTimer);
1405
+ this.updateTimer = false;
1406
+ this.shadowList
1407
+ .css({
1408
+ fontSize: $.css(this.input, 'fontSize'),
1409
+ fontFamily: $.css(this.input, 'fontFamily')
1410
+ })
1411
+ ;
1412
+ this.searchStart = formsCFG.customDatalist && $(this.input).hasClass('search-start');
1413
+
1414
+ var list = [];
1415
+
1416
+ var values = [];
1417
+ var allOptions = [];
1418
+ var rElem, rItem, rOptions, rI, rLen, item;
1419
+ for(rOptions = $.prop(this.datalist, 'options'), rI = 0, rLen = rOptions.length; rI < rLen; rI++){
1420
+ rElem = rOptions[rI];
1421
+ if(rElem.disabled){return;}
1422
+ rItem = {
1423
+ value: $(rElem).val() || '',
1424
+ text: $.trim($.attr(rElem, 'label') || getText(rElem)),
1425
+ className: rElem.className || '',
1426
+ style: $.attr(rElem, 'style') || ''
1427
+ };
1428
+ if(!rItem.text){
1429
+ rItem.text = rItem.value;
1430
+ } else if(rItem.text != rItem.value){
1431
+ rItem.className += ' different-label-value';
1432
+ }
1433
+ values[rI] = rItem.value;
1434
+ allOptions[rI] = rItem;
1435
+ }
1436
+
1437
+ if(!this.storedOptions){
1438
+ this.storedOptions = ($(this.input).hasClass('no-datalist-cache') || this._autocomplete == 'off') ? [] : getStoredOptions((this.input.name || this.input.id) + $.prop(this.input, 'type'));
1439
+ }
1440
+
1441
+ this.storedOptions.forEach(function(val, i){
1442
+ if(values.indexOf(val) == -1){
1443
+ allOptions.push({value: val, text: val, className: 'stored-suggest', style: ''});
1444
+ }
1445
+ });
1446
+
1447
+ for(rI = 0, rLen = allOptions.length; rI < rLen; rI++){
1448
+ item = allOptions[rI];
1449
+ 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>';
1450
+ }
1451
+
1452
+ this.arrayOptions = allOptions;
1453
+ this.shadowList.html('<div class="datalist-outer-box"><div class="datalist-box"><ul role="list">'+ list.join("\n") +'</ul></div></div>');
1454
+
1455
+ if($.fn.bgIframe && lteie6){
1456
+ this.shadowList.bgIframe();
1457
+ }
1458
+
1459
+ if(_forceShow || this.isListVisible){
1460
+ this.showHideOptions();
1461
+ }
1462
+ },
1463
+ showHideOptions: function(_fromShowList){
1464
+ var value = $.prop(this.input, 'value').toLowerCase();
1465
+ //first check prevent infinite loop, second creates simple lazy optimization
1466
+ if(value === this.lastUpdatedValue || (this.lastUnfoundValue && value.indexOf(this.lastUnfoundValue) === 0)){
1467
+ return;
1468
+ }
1469
+
1470
+ this.lastUpdatedValue = value;
1471
+ var found = false;
1472
+ var startSearch = this.searchStart;
1473
+ var lis = $('li', this.shadowList);
1474
+ if(value){
1475
+ this.arrayOptions.forEach(function(item, i){
1476
+ var search;
1477
+ if(!('lowerText' in item)){
1478
+ if(item.text != item.value){
1479
+ item.lowerText = item.value.toLowerCase() + item.text.toLowerCase();
1480
+ } else {
1481
+ item.lowerText = item.text.toLowerCase();
1482
+ }
1483
+ }
1484
+ search = item.lowerText.indexOf(value);
1485
+ search = startSearch ? !search : search !== -1;
1486
+ if(search){
1487
+ $(lis[i]).removeClass('hidden-item');
1488
+ found = true;
1489
+ } else {
1490
+ $(lis[i]).addClass('hidden-item');
1491
+ }
1492
+ });
1493
+ } else if(lis.length) {
1494
+ lis.removeClass('hidden-item');
1495
+ found = true;
1496
+ }
1497
+
1498
+ this.hasViewableData = found;
1499
+ if(!_fromShowList && found){
1500
+ this.showList();
1501
+ }
1502
+ if(!found){
1503
+ this.lastUnfoundValue = value;
1504
+ this.hideList();
1505
+ }
1506
+ },
1507
+ setPos: function(){
1508
+ this.shadowList.css({marginTop: 0, marginLeft: 0, marginRight: 0, marginBottom: 0});
1509
+ var css = (formsCFG.positionDatalist) ? $(this.input).position() : webshims.getRelOffset(this.shadowList, this.input);
1510
+ css.top += $(this.input).outerHeight();
1511
+ css.width = $(this.input).outerWidth() - (parseInt(this.shadowList.css('borderLeftWidth'), 10) || 0) - (parseInt(this.shadowList.css('borderRightWidth'), 10) || 0);
1512
+ this.shadowList.css({marginTop: '', marginLeft: '', marginRight: '', marginBottom: ''}).css(css);
1513
+ return css;
1514
+ },
1515
+ showList: function(){
1516
+ if(this.isListVisible){return false;}
1517
+ if(this.needsUpdate){
1518
+ this.updateListOptions();
1519
+ }
1520
+ this.showHideOptions(true);
1521
+ if(!this.hasViewableData){return false;}
1522
+ this.isListVisible = true;
1523
+ var that = this;
1524
+
1525
+ that.setPos();
1526
+ that.shadowList.addClass('datalist-visible').find('li.active-item').removeClass('active-item');
1527
+
1528
+ $(window).unbind('.datalist'+that.id);
1529
+ $(document)
1530
+ .off('.datalist'+that.id)
1531
+ .on('mousedown.datalist'+that.id +' focusin.datalist'+that.id, function(e){
1532
+ if(e.target === that.input || that.shadowList[0] === e.target || $.contains( that.shadowList[0], e.target )){
1533
+ clearTimeout(that.hideTimer);
1534
+ setTimeout(function(){
1535
+ clearTimeout(that.hideTimer);
1536
+ }, 9);
1537
+ } else {
1538
+ that.timedHide();
1539
+ }
1540
+ })
1541
+ .on('updateshadowdom.datalist'+that.id, function(){
1542
+ that.setPos();
1543
+ })
1544
+ ;
1545
+ return true;
1546
+ },
1547
+ hideList: function(){
1548
+ if(!this.isListVisible){return false;}
1549
+ var that = this;
1550
+ var triggerChange = function(e){
1551
+ if(that.changedValue){
1552
+ $(that.input).trigger('change');
1553
+ }
1554
+ that.changedValue = false;
1555
+ };
1556
+
1557
+ that.shadowList.removeClass('datalist-visible list-item-active');
1558
+ that.index = -1;
1559
+ that.isListVisible = false;
1560
+ if(that.changedValue){
1561
+ that.triggeredByDatalist = true;
1562
+ webshims.triggerInlineForm && webshims.triggerInlineForm(that.input, 'input');
1563
+ if($(that.input).is(':focus')){
1564
+ $(that.input).one('blur', triggerChange);
1565
+ } else {
1566
+ triggerChange();
1567
+ }
1568
+ that.triggeredByDatalist = false;
1569
+ }
1570
+ $(document).unbind('.datalist'+that.id);
1571
+ $(window)
1572
+ .off('.datalist'+that.id)
1573
+ .one('resize.datalist'+that.id, function(){
1574
+ that.shadowList.css({top: 0, left: 0});
1575
+ })
1576
+ ;
1577
+ return true;
1578
+ },
1579
+ scrollIntoView: function(elem){
1580
+ var ul = $('ul', this.shadowList);
1581
+ var div = $('div.datalist-box', this.shadowList);
1582
+ var elemPos = elem.position();
1583
+ var containerHeight;
1584
+ elemPos.top -= (parseInt(ul.css('paddingTop'), 10) || 0) + (parseInt(ul.css('marginTop'), 10) || 0) + (parseInt(ul.css('borderTopWidth'), 10) || 0);
1585
+ if(elemPos.top < 0){
1586
+ div.scrollTop( div.scrollTop() + elemPos.top - 2);
1587
+ return;
1588
+ }
1589
+ elemPos.top += elem.outerHeight();
1590
+ containerHeight = div.height();
1591
+ if(elemPos.top > containerHeight){
1592
+ div.scrollTop( div.scrollTop() + (elemPos.top - containerHeight) + 2);
1593
+ }
1594
+ },
1595
+ changeValue: function(activeItem){
1596
+ if(!activeItem[0]){return;}
1597
+ var newValue = $('span.option-value', activeItem).text();
1598
+ var oldValue = $.prop(this.input, 'value');
1599
+ if(newValue != oldValue){
1600
+ $(this.input)
1601
+ .prop('value', newValue)
1602
+ .triggerHandler('updateInput')
1603
+ ;
1604
+ this.changedValue = true;
1605
+ }
1606
+ },
1607
+ markItem: function(index, doValue, items){
1608
+ var activeItem;
1609
+ var goesUp;
1610
+
1611
+ items = items || $('li:not(.hidden-item)', this.shadowList);
1612
+ if(!items.length){return;}
1613
+ if(index < 0){
1614
+ index = items.length - 1;
1615
+ } else if(index >= items.length){
1616
+ index = 0;
1617
+ }
1618
+ items.removeClass('active-item');
1619
+ this.shadowList.addClass('list-item-active');
1620
+ activeItem = items.filter(':eq('+ index +')').addClass('active-item');
1621
+
1622
+ if(doValue){
1623
+ this.changeValue(activeItem);
1624
+ this.scrollIntoView(activeItem);
1625
+ }
1626
+ this.index = index;
1627
+ }
1628
+ };
1629
+
1630
+ //init datalist update
1631
+ initializeDatalist();
1632
+ })();
1633
+
1634
+ });//additional tests for partial implementation of forms features
1635
+ (function($){
1636
+ "use strict";
1637
+ var Modernizr = window.Modernizr;
1638
+ var webshims = $.webshims;
1639
+ var bugs = webshims.bugs;
1640
+ var form = $('<form action="#" style="width: 1px; height: 1px; overflow: hidden;"><select name="b" required="" /><input required="" name="a" /></form>');
1641
+ var testRequiredFind = function(){
1642
+ if(form[0].querySelector){
1643
+ try {
1644
+ bugs.findRequired = !(form[0].querySelector('select:required'));
1645
+ } catch(er){
1646
+ bugs.findRequired = false;
1647
+ }
1648
+ }
1649
+ };
1650
+ var inputElem = $('input', form).eq(0);
1651
+ var onDomextend = function(fn){
1652
+ webshims.loader.loadList(['dom-extend']);
1653
+ webshims.ready('dom-extend', fn);
1654
+ };
1655
+
1656
+ bugs.findRequired = false;
1657
+ bugs.validationMessage = false;
1658
+
1659
+ webshims.capturingEventPrevented = function(e){
1660
+ if(!e._isPolyfilled){
1661
+ var isDefaultPrevented = e.isDefaultPrevented;
1662
+ var preventDefault = e.preventDefault;
1663
+ e.preventDefault = function(){
1664
+ clearTimeout($.data(e.target, e.type + 'DefaultPrevented'));
1665
+ $.data(e.target, e.type + 'DefaultPrevented', setTimeout(function(){
1666
+ $.removeData(e.target, e.type + 'DefaultPrevented');
1667
+ }, 30));
1668
+ return preventDefault.apply(this, arguments);
1669
+ };
1670
+ e.isDefaultPrevented = function(){
1671
+ return !!(isDefaultPrevented.apply(this, arguments) || $.data(e.target, e.type + 'DefaultPrevented') || false);
1672
+ };
1673
+ e._isPolyfilled = true;
1674
+ }
1675
+ };
1676
+
1677
+ if(!Modernizr.formvalidation || bugs.bustedValidity){
1678
+ testRequiredFind();
1679
+ return;
1680
+ }
1681
+
1682
+ //create delegatable events
1683
+ webshims.capturingEvents(['input']);
1684
+ webshims.capturingEvents(['invalid'], true);
1685
+
1686
+ if(window.opera || window.testGoodWithFix){
1687
+
1688
+ form.appendTo('head');
1689
+
1690
+ testRequiredFind();
1691
+ bugs.validationMessage = !(inputElem.prop('validationMessage'));
1692
+
1693
+ webshims.reTest(['form-extend', 'form-message']);
1694
+
1695
+ form.remove();
1696
+
1697
+ $(function(){
1698
+ onDomextend(function(){
1699
+
1700
+ //Opera shows native validation bubbles in case of input.checkValidity()
1701
+ // Opera 11.6/12 hasn't fixed this issue right, it's buggy
1702
+ var preventDefault = function(e){
1703
+ e.preventDefault();
1704
+ };
1705
+
1706
+ ['form', 'input', 'textarea', 'select'].forEach(function(name){
1707
+ var desc = webshims.defineNodeNameProperty(name, 'checkValidity', {
1708
+ prop: {
1709
+ value: function(){
1710
+ if (!webshims.fromSubmit) {
1711
+ $(this).on('invalid.checkvalidity', preventDefault);
1712
+ }
1713
+
1714
+ webshims.fromCheckValidity = true;
1715
+ var ret = desc.prop._supvalue.apply(this, arguments);
1716
+ if (!webshims.fromSubmit) {
1717
+ $(this).unbind('invalid.checkvalidity', preventDefault);
1718
+ }
1719
+ webshims.fromCheckValidity = false;
1720
+ return ret;
1721
+ }
1722
+ }
1723
+ });
1724
+ });
1725
+
1726
+ });
1727
+ });
1728
+ }
1729
+
1730
+ if($.browser.webkit && !webshims.bugs.bustedValidity){
1731
+ (function(){
1732
+ var elems = /^(?:textarea|input)$/i;
1733
+ var form = false;
1734
+
1735
+ document.addEventListener('contextmenu', function(e){
1736
+ if(elems.test( e.target.nodeName || '') && (form = e.target.form)){
1737
+ setTimeout(function(){
1738
+ form = false;
1739
+ }, 1);
1740
+ }
1741
+ }, false);
1742
+
1743
+ $(window).on('invalid', function(e){
1744
+ if(e.originalEvent && form && form == e.target.form){
1745
+ e.wrongWebkitInvalid = true;
1746
+ e.stopImmediatePropagation();
1747
+ }
1748
+ });
1749
+ })();
1750
+ }
1751
+ })(jQuery);
1752
+
1753
+ jQuery.webshims.register('form-core', function($, webshims, window, document, undefined, options){
1754
+ "use strict";
1755
+
1756
+ var groupTypes = {radio: 1};
1757
+ var checkTypes = {checkbox: 1, radio: 1};
1758
+ var emptyJ = $([]);
1759
+ var bugs = webshims.bugs;
1760
+ var getGroupElements = function(elem){
1761
+ elem = $(elem);
1762
+ var name;
1763
+ var form;
1764
+ var ret = emptyJ;
1765
+ if(groupTypes[elem[0].type]){
1766
+ form = elem.prop('form');
1767
+ name = elem[0].name;
1768
+ if(!name){
1769
+ ret = elem;
1770
+ } else if(form){
1771
+ ret = $(form[name]);
1772
+ } else {
1773
+ ret = $(document.getElementsByName(name)).filter(function(){
1774
+ return !$.prop(this, 'form');
1775
+ });
1776
+ }
1777
+ ret = ret.filter('[type="radio"]');
1778
+ }
1779
+ return ret;
1780
+ };
1781
+
1782
+ var getContentValidationMessage = webshims.getContentValidationMessage = function(elem, validity, key){
1783
+ var message = $(elem).data('errormessage') || elem.getAttribute('x-moz-errormessage') || '';
1784
+ if(key && message[key]){
1785
+ message = message[key];
1786
+ }
1787
+ if(typeof message == 'object'){
1788
+ validity = validity || $.prop(elem, 'validity') || {valid: 1};
1789
+ if(!validity.valid){
1790
+ $.each(validity, function(name, prop){
1791
+ if(prop && name != 'valid' && message[name]){
1792
+ message = message[name];
1793
+ return false;
1794
+ }
1795
+ });
1796
+ }
1797
+ }
1798
+
1799
+ if(typeof message == 'object'){
1800
+ message = message.defaultMessage;
1801
+ }
1802
+ return message || '';
1803
+ };
1804
+
1805
+ /*
1806
+ * Selectors for all browsers
1807
+ */
1808
+ var rangeTypes = {number: 1, range: 1, date: 1/*, time: 1, 'datetime-local': 1, datetime: 1, month: 1, week: 1*/};
1809
+ var hasInvalid = function(elem){
1810
+ var ret = false;
1811
+ $($.prop(elem, 'elements')).each(function(){
1812
+ ret = $(this).is(':invalid');
1813
+ if(ret){
1814
+ return false;
1815
+ }
1816
+ });
1817
+ return ret;
1818
+ };
1819
+ $.extend($.expr[":"], {
1820
+ "valid-element": function(elem){
1821
+ return $.nodeName(elem, 'form') ? !hasInvalid(elem) :!!($.prop(elem, 'willValidate') && isValid(elem));
1822
+ },
1823
+ "invalid-element": function(elem){
1824
+ return $.nodeName(elem, 'form') ? hasInvalid(elem) : !!($.prop(elem, 'willValidate') && !isValid(elem));
1825
+ },
1826
+ "required-element": function(elem){
1827
+ return !!($.prop(elem, 'willValidate') && $.prop(elem, 'required'));
1828
+ },
1829
+ "user-error": function(elem){
1830
+ return ($.prop(elem, 'willValidate') && $(elem).hasClass('user-error'));
1831
+ },
1832
+ "optional-element": function(elem){
1833
+ return !!($.prop(elem, 'willValidate') && $.prop(elem, 'required') === false);
1834
+ },
1835
+ "in-range": function(elem){
1836
+ if(!rangeTypes[$.prop(elem, 'type')] || !$.prop(elem, 'willValidate')){
1837
+ return false;
1838
+ }
1839
+ var val = $.prop(elem, 'validity');
1840
+ return !!(val && !val.rangeOverflow && !val.rangeUnderflow);
1841
+ },
1842
+ "out-of-range": function(elem){
1843
+ if(!rangeTypes[$.prop(elem, 'type')] || !$.prop(elem, 'willValidate')){
1844
+ return false;
1845
+ }
1846
+ var val = $.prop(elem, 'validity');
1847
+ return !!(val && (val.rangeOverflow || val.rangeUnderflow));
1848
+ }
1849
+
1850
+ });
1851
+
1852
+ ['valid', 'invalid', 'required', 'optional'].forEach(function(name){
1853
+ $.expr[":"][name] = $.expr.filters[name+"-element"];
1854
+ });
1855
+
1856
+
1857
+ $.expr[":"].focus = function( elem ) {
1858
+ try {
1859
+ var doc = elem.ownerDocument;
1860
+ return elem === doc.activeElement && (!doc.hasFocus || doc.hasFocus());
1861
+ } catch(e){}
1862
+ return false;
1863
+ };
1864
+
1865
+ var customEvents = $.event.customEvent || {};
1866
+ var isValid = function(elem){
1867
+ return ($.prop(elem, 'validity') || {valid: 1}).valid;
1868
+ };
1869
+
1870
+ if (bugs.bustedValidity || bugs.findRequired) {
1871
+ (function(){
1872
+ var find = $.find;
1873
+ var matchesSelector = $.find.matchesSelector;
1874
+
1875
+ var regExp = /(\:valid|\:invalid|\:optional|\:required|\:in-range|\:out-of-range)(?=[\s\[\~\.\+\>\:\#*]|$)/ig;
1876
+ var regFn = function(sel){
1877
+ return sel + '-element';
1878
+ };
1879
+
1880
+ $.find = (function(){
1881
+ var slice = Array.prototype.slice;
1882
+ var fn = function(sel){
1883
+ var ar = arguments;
1884
+ ar = slice.call(ar, 1, ar.length);
1885
+ ar.unshift(sel.replace(regExp, regFn));
1886
+ return find.apply(this, ar);
1887
+ };
1888
+ for (var i in find) {
1889
+ if(find.hasOwnProperty(i)){
1890
+ fn[i] = find[i];
1891
+ }
1892
+ }
1893
+ return fn;
1894
+ })();
1895
+ if(!Modernizr.prefixed || Modernizr.prefixed("matchesSelector", document.documentElement)){
1896
+ $.find.matchesSelector = function(node, expr){
1897
+ expr = expr.replace(regExp, regFn);
1898
+ return matchesSelector.call(this, node, expr);
1899
+ };
1900
+ }
1901
+
1902
+ })();
1903
+ }
1904
+
1905
+ //ToDo needs testing
1906
+ var oldAttr = $.prop;
1907
+ var changeVals = {selectedIndex: 1, value: 1, checked: 1, disabled: 1, readonly: 1};
1908
+ $.prop = function(elem, name, val){
1909
+ var ret = oldAttr.apply(this, arguments);
1910
+ if(elem && 'form' in elem && changeVals[name] && val !== undefined && $(elem).hasClass(invalidClass)){
1911
+ if(isValid(elem)){
1912
+ $(elem).getShadowElement().removeClass(invalidClasses);
1913
+ if(name == 'checked' && val) {
1914
+ getGroupElements(elem).not(elem).removeClass(invalidClasses).removeAttr('aria-invalid');
1915
+ }
1916
+ }
1917
+ }
1918
+ return ret;
1919
+ };
1920
+
1921
+ var returnValidityCause = function(validity, elem){
1922
+ var ret;
1923
+ $.each(validity, function(name, value){
1924
+ if(value){
1925
+ ret = (name == 'customError') ? $.prop(elem, 'validationMessage') : name;
1926
+ return false;
1927
+ }
1928
+ });
1929
+ return ret;
1930
+ };
1931
+
1932
+ var isInGroup = function(name){
1933
+ var ret;
1934
+ try {
1935
+ ret = document.activeElement.name === name;
1936
+ } catch(e){}
1937
+ return ret;
1938
+ };
1939
+ /* form-ui-invalid/form-ui-valid are deprecated. use user-error/user-succes instead */
1940
+ var invalidClass = 'user-error';
1941
+ var invalidClasses = 'user-error form-ui-invalid';
1942
+ var validClass = 'user-success';
1943
+ var validClasses = 'user-success form-ui-valid';
1944
+ var switchValidityClass = function(e){
1945
+ var elem, timer;
1946
+ if(!e.target){return;}
1947
+ elem = $(e.target).getNativeElement()[0];
1948
+ if(elem.type == 'submit' || !$.prop(elem, 'willValidate')){return;}
1949
+ timer = $.data(elem, 'webshimsswitchvalidityclass');
1950
+ var switchClass = function(){
1951
+ if(e.type == 'focusout' && elem.type == 'radio' && isInGroup(elem.name)){return;}
1952
+ var validity = $.prop(elem, 'validity');
1953
+ var shadowElem = $(elem).getShadowElement();
1954
+ var addClass, removeClass, trigger, generaltrigger, validityCause;
1955
+
1956
+ $(elem).trigger('refreshCustomValidityRules');
1957
+ if(validity.valid){
1958
+ if(!shadowElem.hasClass(validClass)){
1959
+ addClass = validClasses;
1960
+ removeClass = invalidClasses;
1961
+ generaltrigger = 'changedvaliditystate';
1962
+ trigger = 'changedvalid';
1963
+ if(checkTypes[elem.type] && elem.checked){
1964
+ getGroupElements(elem).not(elem).removeClass(removeClass).addClass(addClass).removeAttr('aria-invalid');
1965
+ }
1966
+ $.removeData(elem, 'webshimsinvalidcause');
1967
+ }
1968
+ } else {
1969
+ validityCause = returnValidityCause(validity, elem);
1970
+ if($.data(elem, 'webshimsinvalidcause') != validityCause){
1971
+ $.data(elem, 'webshimsinvalidcause', validityCause);
1972
+ generaltrigger = 'changedvaliditystate';
1973
+ }
1974
+ if(!shadowElem.hasClass(invalidClass)){
1975
+ addClass = invalidClasses;
1976
+ removeClass = validClasses;
1977
+ if (checkTypes[elem.type] && !elem.checked) {
1978
+ getGroupElements(elem).not(elem).removeClass(removeClass).addClass(addClass);
1979
+ }
1980
+ trigger = 'changedinvalid';
1981
+ }
1982
+ }
1983
+ if(addClass){
1984
+ shadowElem.addClass(addClass).removeClass(removeClass);
1985
+ //jQuery 1.6.1 IE9 bug (doubble trigger bug)
1986
+ setTimeout(function(){
1987
+ $(elem).trigger(trigger);
1988
+ }, 0);
1989
+ }
1990
+ if(generaltrigger){
1991
+ setTimeout(function(){
1992
+ $(elem).trigger(generaltrigger);
1993
+ }, 0);
1994
+ }
1995
+ $.removeData(e.target, 'webshimsswitchvalidityclass');
1996
+ };
1997
+
1998
+ if(timer){
1999
+ clearTimeout(timer);
2000
+ }
2001
+ if(e.type == 'refreshvalidityui'){
2002
+ switchClass();
2003
+ } else {
2004
+ $.data(elem, 'webshimsswitchvalidityclass', setTimeout(switchClass, 9));
2005
+ }
2006
+ };
2007
+
2008
+ $(document).on(options.validityUIEvents || 'focusout change refreshvalidityui', switchValidityClass);
2009
+ customEvents.changedvaliditystate = true;
2010
+ customEvents.refreshCustomValidityRules = true;
2011
+ customEvents.changedvalid = true;
2012
+ customEvents.changedinvalid = true;
2013
+ customEvents.refreshvalidityui = true;
2014
+
2015
+
2016
+ webshims.triggerInlineForm = function(elem, event){
2017
+ $(elem).trigger(event);
2018
+ };
2019
+
2020
+ webshims.modules["form-core"].getGroupElements = getGroupElements;
2021
+
2022
+
2023
+ var setRoot = function(){
2024
+ webshims.scrollRoot = ($.browser.webkit || document.compatMode == 'BackCompat') ?
2025
+ $(document.body) :
2026
+ $(document.documentElement)
2027
+ ;
2028
+ };
2029
+ setRoot();
2030
+ webshims.ready('DOM', setRoot);
2031
+
2032
+ webshims.getRelOffset = function(posElem, relElem){
2033
+ posElem = $(posElem);
2034
+ var offset = $(relElem).offset();
2035
+ var bodyOffset;
2036
+ $.swap($(posElem)[0], {visibility: 'hidden', display: 'inline-block', left: 0, top: 0}, function(){
2037
+ bodyOffset = posElem.offset();
2038
+ });
2039
+ offset.top -= bodyOffset.top;
2040
+ offset.left -= bodyOffset.left;
2041
+ return offset;
2042
+ };
2043
+
2044
+ /* some extra validation UI */
2045
+ webshims.validityAlert = (function(){
2046
+ var alertElem = (!$.browser.msie || parseInt($.browser.version, 10) > 7) ? 'span' : 'label';
2047
+ var errorBubble;
2048
+ var hideTimer = false;
2049
+ var focusTimer = false;
2050
+ var resizeTimer = false;
2051
+ var boundHide;
2052
+
2053
+ var api = {
2054
+ hideDelay: 5000,
2055
+
2056
+ showFor: function(elem, message, noFocusElem, noBubble){
2057
+ api._create();
2058
+ elem = $(elem);
2059
+ var visual = $(elem).getShadowElement();
2060
+ var offset = api.getOffsetFromBody(visual);
2061
+ api.clear();
2062
+ if(noBubble){
2063
+ this.hide();
2064
+ } else {
2065
+ this.getMessage(elem, message);
2066
+ this.position(visual, offset);
2067
+
2068
+ this.show();
2069
+ if(this.hideDelay){
2070
+ hideTimer = setTimeout(boundHide, this.hideDelay);
2071
+ }
2072
+ $(window)
2073
+ .on('resize.validityalert', function(){
2074
+ clearTimeout(resizeTimer);
2075
+ resizeTimer = setTimeout(function(){
2076
+ api.position(visual);
2077
+ }, 9);
2078
+ })
2079
+ ;
2080
+ }
2081
+
2082
+ if(!noFocusElem){
2083
+ this.setFocus(visual, offset);
2084
+ }
2085
+ },
2086
+ getOffsetFromBody: function(elem){
2087
+ return webshims.getRelOffset(errorBubble, elem);
2088
+ },
2089
+ setFocus: function(visual, offset){
2090
+ var focusElem = $(visual).getShadowFocusElement();
2091
+ var scrollTop = webshims.scrollRoot.scrollTop();
2092
+ var elemTop = ((offset || focusElem.offset()).top) - 30;
2093
+ var smooth;
2094
+
2095
+ if(webshims.getID && alertElem == 'label'){
2096
+ errorBubble.attr('for', webshims.getID(focusElem));
2097
+ }
2098
+
2099
+ if(scrollTop > elemTop){
2100
+ webshims.scrollRoot.animate(
2101
+ {scrollTop: elemTop - 5},
2102
+ {
2103
+ queue: false,
2104
+ duration: Math.max( Math.min( 600, (scrollTop - elemTop) * 1.5 ), 80 )
2105
+ }
2106
+ );
2107
+ smooth = true;
2108
+ }
2109
+ try {
2110
+ focusElem[0].focus();
2111
+ } catch(e){}
2112
+ if(smooth){
2113
+ webshims.scrollRoot.scrollTop(scrollTop);
2114
+ setTimeout(function(){
2115
+ webshims.scrollRoot.scrollTop(scrollTop);
2116
+ }, 0);
2117
+ }
2118
+ setTimeout(function(){
2119
+ $(document).on('focusout.validityalert', boundHide);
2120
+ }, 10);
2121
+ },
2122
+ getMessage: function(elem, message){
2123
+ if (!message) {
2124
+ message = getContentValidationMessage(elem[0]) || elem.prop('validationMessage');
2125
+ }
2126
+ if (message) {
2127
+ $('span.va-box', errorBubble).text(message);
2128
+ }
2129
+ else {
2130
+ this.hide();
2131
+ }
2132
+ },
2133
+ position: function(elem, offset){
2134
+ offset = offset ? $.extend({}, offset) : api.getOffsetFromBody(elem);
2135
+ offset.top += elem.outerHeight();
2136
+ errorBubble.css(offset);
2137
+ },
2138
+ show: function(){
2139
+ if(errorBubble.css('display') === 'none'){
2140
+ errorBubble.css({opacity: 0}).show();
2141
+ }
2142
+ errorBubble.addClass('va-visible').fadeTo(400, 1);
2143
+ },
2144
+ hide: function(){
2145
+ errorBubble.removeClass('va-visible').fadeOut();
2146
+ },
2147
+ clear: function(){
2148
+ clearTimeout(focusTimer);
2149
+ clearTimeout(hideTimer);
2150
+ $(document).unbind('.validityalert');
2151
+ $(window).unbind('.validityalert');
2152
+ errorBubble.stop().removeAttr('for');
2153
+ },
2154
+ _create: function(){
2155
+ if(errorBubble){return;}
2156
+ errorBubble = api.errorBubble = $('<'+alertElem+' class="validity-alert-wrapper" role="alert"><span class="validity-alert"><span class="va-arrow"><span class="va-arrow-box"></span></span><span class="va-box"></span></span></'+alertElem+'>').css({position: 'absolute', display: 'none'});
2157
+ webshims.ready('DOM', function(){
2158
+ errorBubble.appendTo('body');
2159
+ if($.fn.bgIframe && $.browser.msie && parseInt($.browser.version, 10) < 7){
2160
+ errorBubble.bgIframe();
2161
+ }
2162
+ });
2163
+ }
2164
+ };
2165
+
2166
+
2167
+ boundHide = $.proxy(api, 'hide');
2168
+
2169
+ return api;
2170
+ })();
2171
+
2172
+
2173
+ /* extension, but also used to fix native implementation workaround/bugfixes */
2174
+ (function(){
2175
+ var firstEvent,
2176
+ invalids = [],
2177
+ stopSubmitTimer,
2178
+ form
2179
+ ;
2180
+
2181
+ $(document).on('invalid', function(e){
2182
+ if(e.wrongWebkitInvalid){return;}
2183
+ var jElm = $(e.target);
2184
+ var shadowElem = jElm.getShadowElement();
2185
+ if(!shadowElem.hasClass(invalidClass)){
2186
+ shadowElem.addClass(invalidClasses).removeClass(validClasses);
2187
+ setTimeout(function(){
2188
+ $(e.target).trigger('changedinvalid').trigger('changedvaliditystate');
2189
+ }, 0);
2190
+ }
2191
+
2192
+ if(!firstEvent){
2193
+ //trigger firstinvalid
2194
+ firstEvent = $.Event('firstinvalid');
2195
+ firstEvent.isInvalidUIPrevented = e.isDefaultPrevented;
2196
+ var firstSystemInvalid = $.Event('firstinvalidsystem');
2197
+ $(document).triggerHandler(firstSystemInvalid, {element: e.target, form: e.target.form, isInvalidUIPrevented: e.isDefaultPrevented});
2198
+ jElm.trigger(firstEvent);
2199
+ }
2200
+
2201
+ //if firstinvalid was prevented all invalids will be also prevented
2202
+ if( firstEvent && firstEvent.isDefaultPrevented() ){
2203
+ e.preventDefault();
2204
+ }
2205
+ invalids.push(e.target);
2206
+ e.extraData = 'fix';
2207
+ clearTimeout(stopSubmitTimer);
2208
+ stopSubmitTimer = setTimeout(function(){
2209
+ var lastEvent = {type: 'lastinvalid', cancelable: false, invalidlist: $(invalids)};
2210
+ //reset firstinvalid
2211
+ firstEvent = false;
2212
+ invalids = [];
2213
+ $(e.target).trigger(lastEvent, lastEvent);
2214
+ }, 9);
2215
+ jElm = null;
2216
+ shadowElem = null;
2217
+ });
2218
+ })();
2219
+
2220
+ $.fn.getErrorMessage = function(){
2221
+ var message = '';
2222
+ var elem = this[0];
2223
+ if(elem){
2224
+ message = getContentValidationMessage(elem) || $.prop(elem, 'customValidationMessage') || $.prop(elem, 'validationMessage');
2225
+ }
2226
+ return message;
2227
+ };
2228
+
2229
+ if(options.replaceValidationUI){
2230
+ webshims.ready('DOM forms', function(){
2231
+ $(document).on('firstinvalid', function(e){
2232
+ if(!e.isInvalidUIPrevented()){
2233
+ e.preventDefault();
2234
+ $.webshims.validityAlert.showFor( e.target, $(e.target).prop('customValidationMessage') );
2235
+ }
2236
+ });
2237
+ });
2238
+ }
2239
+
2248
2240
  });