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,1589 +1,1634 @@
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
-
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
+
1589
1634
  });