webshims-rails 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/lib/webshims-rails/version.rb +2 -2
  2. data/vendor/assets/javascripts/webshims/extras/custom-validity.js +253 -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 -10
  6. data/vendor/assets/javascripts/webshims/minified/extras/modernizr-custom.js +1 -20
  7. data/vendor/assets/javascripts/webshims/minified/extras/mousepress.js +1 -2
  8. data/vendor/assets/javascripts/webshims/minified/polyfiller.js +1 -30
  9. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvas/canvas2png.js +1 -42
  10. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvas/flashcanvas.js +1 -28
  11. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvas/flashcanvas.swf +0 -0
  12. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvas/proxy.php +0 -0
  13. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvas/save.php +0 -0
  14. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/canvas2png.js +1 -42
  15. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/flash10canvas.swf +0 -0
  16. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/flash9canvas.swf +0 -0
  17. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/flashcanvas.js +1 -31
  18. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/proxy.php +0 -0
  19. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/save.php +0 -0
  20. data/vendor/assets/javascripts/webshims/minified/shims/combos/1.js +1 -38
  21. data/vendor/assets/javascripts/webshims/minified/shims/combos/10.js +1 -80
  22. data/vendor/assets/javascripts/webshims/minified/shims/combos/11.js +1 -45
  23. data/vendor/assets/javascripts/webshims/minified/shims/combos/12.js +1 -44
  24. data/vendor/assets/javascripts/webshims/minified/shims/combos/13.js +1 -28
  25. data/vendor/assets/javascripts/webshims/minified/shims/combos/14.js +1 -19
  26. data/vendor/assets/javascripts/webshims/minified/shims/combos/15.js +1 -10
  27. data/vendor/assets/javascripts/webshims/minified/shims/combos/16.js +1 -58
  28. data/vendor/assets/javascripts/webshims/minified/shims/combos/17.js +1 -66
  29. data/vendor/assets/javascripts/webshims/minified/shims/combos/18.js +1 -62
  30. data/vendor/assets/javascripts/webshims/minified/shims/combos/19.js +1 -64
  31. data/vendor/assets/javascripts/webshims/minified/shims/combos/2.js +1 -73
  32. data/vendor/assets/javascripts/webshims/minified/shims/combos/20.js +1 -42
  33. data/vendor/assets/javascripts/webshims/minified/shims/combos/21.js +1 -54
  34. data/vendor/assets/javascripts/webshims/minified/shims/combos/22.js +1 -57
  35. data/vendor/assets/javascripts/webshims/minified/shims/combos/23.js +1 -70
  36. data/vendor/assets/javascripts/webshims/minified/shims/combos/24.js +1 -80
  37. data/vendor/assets/javascripts/webshims/minified/shims/combos/25.js +1 -60
  38. data/vendor/assets/javascripts/webshims/minified/shims/combos/26.js +1 -79
  39. data/vendor/assets/javascripts/webshims/minified/shims/combos/27.js +1 -101
  40. data/vendor/assets/javascripts/webshims/minified/shims/combos/3.js +1 -95
  41. data/vendor/assets/javascripts/webshims/minified/shims/combos/4.js +1 -27
  42. data/vendor/assets/javascripts/webshims/minified/shims/combos/5.js +1 -34
  43. data/vendor/assets/javascripts/webshims/minified/shims/combos/59.js +1 -56
  44. data/vendor/assets/javascripts/webshims/minified/shims/combos/6.js +1 -33
  45. data/vendor/assets/javascripts/webshims/minified/shims/combos/7.js +1 -40
  46. data/vendor/assets/javascripts/webshims/minified/shims/combos/8.js +1 -39
  47. data/vendor/assets/javascripts/webshims/minified/shims/combos/9.js +1 -65
  48. data/vendor/assets/javascripts/webshims/minified/shims/details.js +1 -5
  49. data/vendor/assets/javascripts/webshims/minified/shims/dom-extend.js +1 -23
  50. data/vendor/assets/javascripts/webshims/minified/shims/es5.js +1 -15
  51. data/vendor/assets/javascripts/webshims/minified/shims/excanvas.js +1 -21
  52. data/vendor/assets/javascripts/webshims/minified/shims/form-core.js +1 -19
  53. data/vendor/assets/javascripts/webshims/minified/shims/form-datalist.js +1 -22
  54. data/vendor/assets/javascripts/webshims/minified/shims/form-message.js +1 -8
  55. data/vendor/assets/javascripts/webshims/minified/shims/form-native-extend.js +1 -7
  56. data/vendor/assets/javascripts/webshims/minified/shims/form-number-date-api.js +1 -10
  57. data/vendor/assets/javascripts/webshims/minified/shims/form-number-date-ui.js +1 -23
  58. data/vendor/assets/javascripts/webshims/minified/shims/form-shim-extend.js +1 -46
  59. data/vendor/assets/javascripts/webshims/minified/shims/geolocation.js +1 -5
  60. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-ar.js +1 -7
  61. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-ch-ZN.js +1 -3
  62. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-de.txt +33 -33
  63. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-el.js +1 -7
  64. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-en.txt +34 -34
  65. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-es.js +1 -3
  66. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-fr.js +1 -3
  67. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-he.js +1 -6
  68. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-hi.js +1 -6
  69. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-hu.js +1 -3
  70. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-it.js +1 -3
  71. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-ja.js +1 -4
  72. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-nl.js +1 -3
  73. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-pt-PT.js +1 -3
  74. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-ru.js +1 -8
  75. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-sv.js +1 -3
  76. data/vendor/assets/javascripts/webshims/minified/shims/json-storage.js +1 -14
  77. data/vendor/assets/javascripts/webshims/minified/shims/jwplayer/license.txt +0 -0
  78. data/vendor/assets/javascripts/webshims/minified/shims/jwplayer/player.swf +0 -0
  79. data/vendor/assets/javascripts/webshims/minified/shims/jwplayer/readme.html +0 -0
  80. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-core.js +1 -16
  81. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-jaris.js +1 -23
  82. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-native-fix.js +1 -3
  83. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-swf.js +1 -26
  84. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-yt.js +1 -14
  85. data/vendor/assets/javascripts/webshims/minified/shims/range-ui.js +1 -0
  86. data/vendor/assets/javascripts/webshims/minified/shims/styles/details-arrows.png +0 -0
  87. data/vendor/assets/javascripts/webshims/minified/shims/styles/forms.png +0 -0
  88. data/vendor/assets/javascripts/webshims/minified/shims/styles/polyfill-loader.gif +0 -0
  89. data/vendor/assets/javascripts/webshims/minified/shims/styles/shim.css +1 -689
  90. data/vendor/assets/javascripts/webshims/minified/shims/swf/JarisFLVPlayer.swf +0 -0
  91. data/vendor/assets/javascripts/webshims/minified/shims/swf/jwwebshims.swf +0 -0
  92. data/vendor/assets/javascripts/webshims/minified/shims/swf/localStorage.swf +0 -0
  93. data/vendor/assets/javascripts/webshims/minified/shims/track-ui.js +1 -9
  94. data/vendor/assets/javascripts/webshims/minified/shims/track.js +1 -21
  95. data/vendor/assets/javascripts/webshims/polyfiller.js +1188 -1191
  96. data/vendor/assets/javascripts/webshims/{minified/shims → shims}/FlashCanvas/README +0 -0
  97. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/canvas2png.js +0 -0
  98. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/flashcanvas.js +0 -0
  99. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/flashcanvas.swf +0 -0
  100. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/proxy.php +0 -0
  101. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/save.php +0 -0
  102. data/vendor/assets/javascripts/webshims/{minified/shims → shims}/FlashCanvasPro/README +82 -82
  103. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/canvas2png.js +0 -0
  104. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/flash10canvas.swf +0 -0
  105. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/flash9canvas.swf +0 -0
  106. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/flashcanvas.js +0 -0
  107. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/proxy.php +0 -0
  108. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/save.php +0 -0
  109. data/vendor/assets/javascripts/webshims/shims/combos/1.js +1752 -1754
  110. data/vendor/assets/javascripts/webshims/shims/combos/10.js +3311 -3247
  111. data/vendor/assets/javascripts/webshims/shims/combos/11.js +1631 -1633
  112. data/vendor/assets/javascripts/webshims/shims/combos/12.js +1697 -1636
  113. data/vendor/assets/javascripts/webshims/shims/combos/13.js +1098 -1100
  114. data/vendor/assets/javascripts/webshims/shims/combos/14.js +477 -476
  115. data/vendor/assets/javascripts/webshims/shims/combos/15.js +317 -316
  116. data/vendor/assets/javascripts/webshims/shims/combos/16.js +2155 -2095
  117. data/vendor/assets/javascripts/webshims/shims/combos/17.js +2320 -2259
  118. data/vendor/assets/javascripts/webshims/shims/combos/18.js +1326 -1322
  119. data/vendor/assets/javascripts/webshims/shims/combos/19.js +2238 -2239
  120. data/vendor/assets/javascripts/webshims/shims/combos/2.js +2341 -2339
  121. data/vendor/assets/javascripts/webshims/shims/combos/20.js +1558 -1493
  122. data/vendor/assets/javascripts/webshims/shims/combos/21.js +1734 -1733
  123. data/vendor/assets/javascripts/webshims/shims/combos/22.js +2361 -2295
  124. data/vendor/assets/javascripts/webshims/shims/combos/23.js +2332 -2269
  125. data/vendor/assets/javascripts/webshims/shims/combos/24.js +2836 -2775
  126. data/vendor/assets/javascripts/webshims/shims/combos/25.js +1549 -1489
  127. data/vendor/assets/javascripts/webshims/shims/combos/26.js +2156 -2095
  128. data/vendor/assets/javascripts/webshims/shims/combos/27.js +3313 -3248
  129. data/vendor/assets/javascripts/webshims/shims/combos/3.js +3022 -3020
  130. data/vendor/assets/javascripts/webshims/shims/combos/4.js +771 -770
  131. data/vendor/assets/javascripts/webshims/shims/combos/5.js +1027 -1025
  132. data/vendor/assets/javascripts/webshims/shims/combos/59.js +1709 -1706
  133. data/vendor/assets/javascripts/webshims/shims/combos/6.js +387 -386
  134. data/vendor/assets/javascripts/webshims/shims/combos/7.js +643 -641
  135. data/vendor/assets/javascripts/webshims/shims/combos/8.js +1547 -1488
  136. data/vendor/assets/javascripts/webshims/shims/combos/9.js +2508 -2445
  137. data/vendor/assets/javascripts/webshims/shims/details.js +148 -148
  138. data/vendor/assets/javascripts/webshims/shims/dom-extend.js +949 -952
  139. data/vendor/assets/javascripts/webshims/shims/es5.js +802 -802
  140. data/vendor/assets/javascripts/webshims/shims/excanvas.js +924 -924
  141. data/vendor/assets/javascripts/webshims/shims/form-core.js +606 -606
  142. data/vendor/assets/javascripts/webshims/shims/form-datalist.js +681 -681
  143. data/vendor/assets/javascripts/webshims/shims/form-message.js +164 -164
  144. data/vendor/assets/javascripts/webshims/shims/form-native-extend.js +255 -255
  145. data/vendor/assets/javascripts/webshims/shims/form-number-date-api.js +383 -383
  146. data/vendor/assets/javascripts/webshims/shims/form-number-date-ui.js +2 -2
  147. data/vendor/assets/javascripts/webshims/shims/form-shim-extend.js +1568 -1569
  148. data/vendor/assets/javascripts/webshims/shims/geolocation.js +168 -168
  149. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ar.js +32 -32
  150. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ch-ZN.js +32 -32
  151. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-de.txt +33 -33
  152. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-el.js +32 -32
  153. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-en.txt +34 -34
  154. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-es.js +31 -31
  155. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-fr.js +32 -32
  156. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-he.js +32 -32
  157. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-hi.js +32 -32
  158. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-hu.js +32 -32
  159. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-it.js +32 -32
  160. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ja.js +32 -32
  161. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-nl.js +32 -32
  162. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-pt-PT.js +32 -32
  163. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ru.js +31 -31
  164. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-sv.js +32 -32
  165. data/vendor/assets/javascripts/webshims/shims/json-storage.js +308 -308
  166. data/vendor/assets/javascripts/webshims/shims/jwplayer/license.txt +0 -0
  167. data/vendor/assets/javascripts/webshims/shims/jwplayer/player.swf +0 -0
  168. data/vendor/assets/javascripts/webshims/shims/jwplayer/readme.html +0 -0
  169. data/vendor/assets/javascripts/webshims/shims/mediaelement-core.js +597 -536
  170. data/vendor/assets/javascripts/webshims/shims/mediaelement-jaris.js +891 -860
  171. data/vendor/assets/javascripts/webshims/shims/mediaelement-native-fix.js +98 -98
  172. data/vendor/assets/javascripts/webshims/shims/mediaelement-swf.js +960 -957
  173. data/vendor/assets/javascripts/webshims/shims/mediaelement-yt.js +543 -543
  174. data/vendor/assets/javascripts/webshims/shims/range-ui.js +66 -0
  175. data/vendor/assets/javascripts/webshims/shims/styles/details-arrows.png +0 -0
  176. data/vendor/assets/javascripts/webshims/shims/styles/forms.png +0 -0
  177. data/vendor/assets/javascripts/webshims/shims/styles/polyfill-loader.gif +0 -0
  178. data/vendor/assets/javascripts/webshims/shims/styles/shim.css +697 -689
  179. data/vendor/assets/javascripts/webshims/shims/swf/JarisFLVPlayer.swf +0 -0
  180. data/vendor/assets/javascripts/webshims/shims/swf/jwwebshims.swf +0 -0
  181. data/vendor/assets/javascripts/webshims/shims/swf/localStorage.swf +0 -0
  182. data/vendor/assets/javascripts/webshims/shims/track-ui.js +0 -0
  183. data/vendor/assets/javascripts/webshims/shims/track.js +0 -0
  184. metadata +6 -4
@@ -1,1634 +1,1632 @@
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
-
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(elem, eventType, bindType){
362
+ var events = ($._data(elem, 'events') || {})[eventType];
363
+ var fn;
364
+
365
+ if(events && events.length > 1){
366
+ fn = events.pop();
367
+ if(!bindType){
368
+ bindType = 'bind';
369
+ }
370
+ if(bindType == 'bind' && events.delegateCount){
371
+ events.splice( events.delegateCount, 0, fn);
372
+ } else {
373
+ events.unshift( fn );
374
+ }
375
+
376
+
377
+ }
378
+ elem = null;
379
+ },
380
+ addShadowDom: (function(){
381
+ var resizeTimer;
382
+ var lastHeight;
383
+ var lastWidth;
384
+
385
+ var docObserve = {
386
+ init: false,
387
+ runs: 0,
388
+ test: function(){
389
+ var height = docObserve.getHeight();
390
+ var width = docObserve.getWidth();
391
+
392
+ if(height != docObserve.height || width != docObserve.width){
393
+ docObserve.height = height;
394
+ docObserve.width = width;
395
+ docObserve.handler({type: 'docresize'});
396
+ docObserve.runs++;
397
+ if(docObserve.runs < 9){
398
+ setTimeout(docObserve.test, 90);
399
+ }
400
+ } else {
401
+ docObserve.runs = 0;
402
+ }
403
+ },
404
+ handler: function(e){
405
+ clearTimeout(resizeTimer);
406
+ resizeTimer = setTimeout(function(){
407
+ if(e.type == 'resize'){
408
+ var width = $(window).width();
409
+ var height = $(window).width();
410
+ if(height == lastHeight && width == lastWidth){
411
+ return;
412
+ }
413
+ lastHeight = height;
414
+ lastWidth = width;
415
+
416
+ docObserve.height = docObserve.getHeight();
417
+ docObserve.width = docObserve.getWidth();
418
+
419
+ }
420
+ $.event.trigger('updateshadowdom');
421
+ }, (e.type == 'resize') ? 50 : 9);
422
+ },
423
+ _create: function(){
424
+ $.each({ Height: "getHeight", Width: "getWidth" }, function(name, type){
425
+ var body = document.body;
426
+ var doc = document.documentElement;
427
+ docObserve[type] = function(){
428
+ return Math.max(
429
+ body[ "scroll" + name ], doc[ "scroll" + name ],
430
+ body[ "offset" + name ], doc[ "offset" + name ],
431
+ doc[ "client" + name ]
432
+ );
433
+ };
434
+ });
435
+ },
436
+ start: function(){
437
+ if(!this.init && document.body){
438
+ this.init = true;
439
+ this._create();
440
+ this.height = docObserve.getHeight();
441
+ this.width = docObserve.getWidth();
442
+ setInterval(this.test, 600);
443
+ $(this.test);
444
+ webshims.ready('WINDOWLOAD', this.test);
445
+ $(window).bind('resize', this.handler);
446
+ (function(){
447
+ var oldAnimate = $.fn.animate;
448
+ var animationTimer;
449
+
450
+ $.fn.animate = function(){
451
+ clearTimeout(animationTimer);
452
+ animationTimer = setTimeout(function(){
453
+ docObserve.test();
454
+ }, 99);
455
+
456
+ return oldAnimate.apply(this, arguments);
457
+ };
458
+ })();
459
+ }
460
+ }
461
+ };
462
+
463
+
464
+ $.event.customEvent.updateshadowdom = true;
465
+ webshims.docObserve = function(){
466
+ webshims.ready('DOM', function(){
467
+ docObserve.start();
468
+ });
469
+ };
470
+ return function(nativeElem, shadowElem, opts){
471
+ opts = opts || {};
472
+ if(nativeElem.jquery){
473
+ nativeElem = nativeElem[0];
474
+ }
475
+ if(shadowElem.jquery){
476
+ shadowElem = shadowElem[0];
477
+ }
478
+ var nativeData = $.data(nativeElem, dataID) || $.data(nativeElem, dataID, {});
479
+ var shadowData = $.data(shadowElem, dataID) || $.data(shadowElem, dataID, {});
480
+ var shadowFocusElementData = {};
481
+ if(!opts.shadowFocusElement){
482
+ opts.shadowFocusElement = shadowElem;
483
+ } else if(opts.shadowFocusElement){
484
+ if(opts.shadowFocusElement.jquery){
485
+ opts.shadowFocusElement = opts.shadowFocusElement[0];
486
+ }
487
+ shadowFocusElementData = $.data(opts.shadowFocusElement, dataID) || $.data(opts.shadowFocusElement, dataID, shadowFocusElementData);
488
+ }
489
+
490
+ nativeData.hasShadow = shadowElem;
491
+ shadowFocusElementData.nativeElement = shadowData.nativeElement = nativeElem;
492
+ shadowFocusElementData.shadowData = shadowData.shadowData = nativeData.shadowData = {
493
+ nativeElement: nativeElem,
494
+ shadowElement: shadowElem,
495
+ shadowFocusElement: opts.shadowFocusElement
496
+ };
497
+ if(opts.shadowChilds){
498
+ opts.shadowChilds.each(function(){
499
+ elementData(this, 'shadowData', shadowData.shadowData);
500
+ });
501
+ }
502
+
503
+ if(opts.data){
504
+ shadowFocusElementData.shadowData.data = shadowData.shadowData.data = nativeData.shadowData.data = opts.data;
505
+ }
506
+ opts = null;
507
+ webshims.docObserve();
508
+ };
509
+ })(),
510
+ propTypes: {
511
+ standard: function(descs, name){
512
+ createPropDefault(descs);
513
+ if(descs.prop){return;}
514
+ descs.prop = {
515
+ set: function(val){
516
+ descs.attr.set.call(this, ''+val);
517
+ },
518
+ get: function(){
519
+ return descs.attr.get.call(this) || descs.defaultValue;
520
+ }
521
+ };
522
+
523
+ },
524
+ "boolean": function(descs, name){
525
+
526
+ createPropDefault(descs);
527
+ if(descs.prop){return;}
528
+ descs.prop = {
529
+ set: function(val){
530
+ if(val){
531
+ descs.attr.set.call(this, "");
532
+ } else {
533
+ descs.removeAttr.value.call(this);
534
+ }
535
+ },
536
+ get: function(){
537
+ return descs.attr.get.call(this) != null;
538
+ }
539
+ };
540
+ },
541
+ "src": (function(){
542
+ var anchor = document.createElement('a');
543
+ anchor.style.display = "none";
544
+ return function(descs, name){
545
+
546
+ createPropDefault(descs);
547
+ if(descs.prop){return;}
548
+ descs.prop = {
549
+ set: function(val){
550
+ descs.attr.set.call(this, val);
551
+ },
552
+ get: function(){
553
+ var href = this.getAttribute(name);
554
+ var ret;
555
+ if(href == null){return '';}
556
+
557
+ anchor.setAttribute('href', href+'' );
558
+
559
+ if(!$.support.hrefNormalized){
560
+ try {
561
+ $(anchor).insertAfter(this);
562
+ ret = anchor.getAttribute('href', 4);
563
+ } catch(er){
564
+ ret = anchor.getAttribute('href', 4);
565
+ }
566
+ $(anchor).detach();
567
+ }
568
+ return ret || anchor.href;
569
+ }
570
+ };
571
+ };
572
+ })(),
573
+ enumarated: function(descs, name){
574
+
575
+ createPropDefault(descs);
576
+ if(descs.prop){return;}
577
+ descs.prop = {
578
+ set: function(val){
579
+ descs.attr.set.call(this, val);
580
+ },
581
+ get: function(){
582
+ var val = (descs.attr.get.call(this) || '').toLowerCase();
583
+ if(!val || descs.limitedTo.indexOf(val) == -1){
584
+ val = descs.defaultValue;
585
+ }
586
+ return val;
587
+ }
588
+ };
589
+ }
590
+
591
+ // ,unsignedLong: $.noop
592
+ // ,"doubble": $.noop
593
+ // ,"long": $.noop
594
+ // ,tokenlist: $.noop
595
+ // ,settableTokenlist: $.noop
596
+ },
597
+ reflectProperties: function(nodeNames, props){
598
+ if(typeof props == 'string'){
599
+ props = props.split(listReg);
600
+ }
601
+ props.forEach(function(prop){
602
+ webshims.defineNodeNamesProperty(nodeNames, prop, {
603
+ prop: {
604
+ set: function(val){
605
+ $.attr(this, prop, val);
606
+ },
607
+ get: function(){
608
+ return $.attr(this, prop) || '';
609
+ }
610
+ }
611
+ });
612
+ });
613
+ },
614
+ defineNodeNameProperty: function(nodeName, prop, descs){
615
+ havePolyfill[prop] = true;
616
+
617
+ if(descs.reflect){
618
+ webshims.propTypes[descs.propType || 'standard'](descs, prop);
619
+ }
620
+
621
+ ['prop', 'attr', 'removeAttr'].forEach(function(type){
622
+ var desc = descs[type];
623
+ if(desc){
624
+ if(type === 'prop'){
625
+ desc = $.extend({writeable: true}, desc);
626
+ } else {
627
+ desc = $.extend({}, desc, {writeable: true});
628
+ }
629
+
630
+ extendQ[type](nodeName, prop, desc);
631
+ if(nodeName != '*' && webshims.cfg.extendNative && type == 'prop' && desc.value && $.isFunction(desc.value)){
632
+ extendNativeValue(nodeName, prop, desc);
633
+ }
634
+ descs[type] = desc;
635
+ }
636
+ });
637
+ if(descs.initAttr){
638
+ initProp.content(nodeName, prop);
639
+ }
640
+ return descs;
641
+ },
642
+
643
+ defineNodeNameProperties: function(name, descs, propType, _noTmpCache){
644
+ var olddesc;
645
+ for(var prop in descs){
646
+ if(!_noTmpCache && descs[prop].initAttr){
647
+ initProp.createTmpCache(name);
648
+ }
649
+ if(propType){
650
+ if(descs[prop][propType]){
651
+ //webshims.log('override: '+ name +'['+prop +'] for '+ propType);
652
+ } else {
653
+ descs[prop][propType] = {};
654
+ ['value', 'set', 'get'].forEach(function(copyProp){
655
+ if(copyProp in descs[prop]){
656
+ descs[prop][propType][copyProp] = descs[prop][copyProp];
657
+ delete descs[prop][copyProp];
658
+ }
659
+ });
660
+ }
661
+ }
662
+ descs[prop] = webshims.defineNodeNameProperty(name, prop, descs[prop]);
663
+ }
664
+ if(!_noTmpCache){
665
+ initProp.flushTmpCache();
666
+ }
667
+ return descs;
668
+ },
669
+
670
+ createElement: function(nodeName, create, descs){
671
+ var ret;
672
+ if($.isFunction(create)){
673
+ create = {
674
+ after: create
675
+ };
676
+ }
677
+ initProp.createTmpCache(nodeName);
678
+ if(create.before){
679
+ initProp.createElement(nodeName, create.before);
680
+ }
681
+ if(descs){
682
+ ret = webshims.defineNodeNameProperties(nodeName, descs, false, true);
683
+ }
684
+ if(create.after){
685
+ initProp.createElement(nodeName, create.after);
686
+ }
687
+ initProp.flushTmpCache();
688
+ return ret;
689
+ },
690
+ onNodeNamesPropertyModify: function(nodeNames, props, desc, only){
691
+ if(typeof nodeNames == 'string'){
692
+ nodeNames = nodeNames.split(listReg);
693
+ }
694
+ if($.isFunction(desc)){
695
+ desc = {set: desc};
696
+ }
697
+
698
+ nodeNames.forEach(function(name){
699
+ if(!modifyProps[name]){
700
+ modifyProps[name] = {};
701
+ }
702
+ if(typeof props == 'string'){
703
+ props = props.split(listReg);
704
+ }
705
+ if(desc.initAttr){
706
+ initProp.createTmpCache(name);
707
+ }
708
+ props.forEach(function(prop){
709
+ if(!modifyProps[name][prop]){
710
+ modifyProps[name][prop] = [];
711
+ havePolyfill[prop] = true;
712
+ }
713
+ if(desc.set){
714
+ if(only){
715
+ desc.set.only = only;
716
+ }
717
+ modifyProps[name][prop].push(desc.set);
718
+ }
719
+
720
+ if(desc.initAttr){
721
+ initProp.content(name, prop);
722
+ }
723
+ });
724
+ initProp.flushTmpCache();
725
+
726
+ });
727
+ },
728
+ defineNodeNamesBooleanProperty: function(elementNames, prop, descs){
729
+ if(!descs){
730
+ descs = {};
731
+ }
732
+ if($.isFunction(descs)){
733
+ descs.set = descs;
734
+ }
735
+ webshims.defineNodeNamesProperty(elementNames, prop, {
736
+ attr: {
737
+ set: function(val){
738
+ this.setAttribute(prop, val);
739
+ if(descs.set){
740
+ descs.set.call(this, true);
741
+ }
742
+ },
743
+ get: function(){
744
+ var ret = this.getAttribute(prop);
745
+ return (ret == null) ? undefined : prop;
746
+ }
747
+ },
748
+ removeAttr: {
749
+ value: function(){
750
+ this.removeAttribute(prop);
751
+ if(descs.set){
752
+ descs.set.call(this, false);
753
+ }
754
+ }
755
+ },
756
+ reflect: true,
757
+ propType: 'boolean',
758
+ initAttr: descs.initAttr || false
759
+ });
760
+ },
761
+ contentAttr: function(elem, name, val){
762
+ if(!elem.nodeName){return;}
763
+ var attr;
764
+ if(val === undefined){
765
+ attr = (elem.attributes[name] || {});
766
+ val = attr.specified ? attr.value : null;
767
+ return (val == null) ? undefined : val;
768
+ }
769
+
770
+ if(typeof val == 'boolean'){
771
+ if(!val){
772
+ elem.removeAttribute(name);
773
+ } else {
774
+ elem.setAttribute(name, name);
775
+ }
776
+ } else {
777
+ elem.setAttribute(name, val);
778
+ }
779
+ },
780
+
781
+ // set current Lang:
782
+ // - webshims.activeLang(lang:string);
783
+ // get current lang
784
+ // - webshims.activeLang();
785
+ // get current lang
786
+ // webshims.activeLang({
787
+ // register: moduleName:string,
788
+ // callback: callback:function
789
+ // });
790
+ // get/set including removeLang
791
+ // - webshims.activeLang({
792
+ // module: moduleName:string,
793
+ // callback: callback:function,
794
+ // langObj: languageObj:array/object
795
+ // });
796
+ activeLang: (function(){
797
+ var callbacks = [];
798
+ var registeredCallbacks = {};
799
+ var currentLang;
800
+ var shortLang;
801
+ var notLocal = /:\/\/|^\.*\//;
802
+ var loadRemoteLang = function(data, lang, options){
803
+ var langSrc;
804
+ if(lang && options && $.inArray(lang, options.availabeLangs || []) !== -1){
805
+ data.loading = true;
806
+ langSrc = options.langSrc;
807
+ if(!notLocal.test(langSrc)){
808
+ langSrc = webshims.cfg.basePath+langSrc;
809
+ }
810
+ webshims.loader.loadScript(langSrc+lang+'.js', function(){
811
+ if(data.langObj[lang]){
812
+ data.loading = false;
813
+ callLang(data, true);
814
+ } else {
815
+ $(function(){
816
+ if(data.langObj[lang]){
817
+ callLang(data, true);
818
+ }
819
+ data.loading = false;
820
+ });
821
+ }
822
+ });
823
+ return true;
824
+ }
825
+ return false;
826
+ };
827
+ var callRegister = function(module){
828
+ if(registeredCallbacks[module]){
829
+ registeredCallbacks[module].forEach(function(data){
830
+ data.callback();
831
+ });
832
+ }
833
+ };
834
+ var callLang = function(data, _noLoop){
835
+ if(data.activeLang != currentLang && data.activeLang !== shortLang){
836
+ var options = modules[data.module].options;
837
+ if( data.langObj[currentLang] || (shortLang && data.langObj[shortLang]) ){
838
+ data.activeLang = currentLang;
839
+ data.callback(data.langObj[currentLang] || data.langObj[shortLang], currentLang);
840
+ callRegister(data.module);
841
+ } else if( !_noLoop &&
842
+ !loadRemoteLang(data, currentLang, options) &&
843
+ !loadRemoteLang(data, shortLang, options) &&
844
+ data.langObj[''] && data.activeLang !== '' ) {
845
+ data.activeLang = '';
846
+ data.callback(data.langObj[''], currentLang);
847
+ callRegister(data.module);
848
+ }
849
+ }
850
+ };
851
+
852
+
853
+ var activeLang = function(lang){
854
+
855
+ if(typeof lang == 'string' && lang !== currentLang){
856
+ currentLang = lang;
857
+ shortLang = currentLang.split('-')[0];
858
+ if(currentLang == shortLang){
859
+ shortLang = false;
860
+ }
861
+ $.each(callbacks, function(i, data){
862
+ callLang(data);
863
+ });
864
+ } else if(typeof lang == 'object'){
865
+
866
+ if(lang.register){
867
+ if(!registeredCallbacks[lang.register]){
868
+ registeredCallbacks[lang.register] = [];
869
+ }
870
+ registeredCallbacks[lang.register].push(lang);
871
+ lang.callback();
872
+ } else {
873
+ if(!lang.activeLang){
874
+ lang.activeLang = '';
875
+ }
876
+ callbacks.push(lang);
877
+ callLang(lang);
878
+ }
879
+ }
880
+ return currentLang;
881
+ };
882
+
883
+ return activeLang;
884
+ })()
885
+ });
886
+
887
+ $.each({
888
+ defineNodeNamesProperty: 'defineNodeNameProperty',
889
+ defineNodeNamesProperties: 'defineNodeNameProperties',
890
+ createElements: 'createElement'
891
+ }, function(name, baseMethod){
892
+ webshims[name] = function(names, a, b, c){
893
+ if(typeof names == 'string'){
894
+ names = names.split(listReg);
895
+ }
896
+ var retDesc = {};
897
+ names.forEach(function(nodeName){
898
+ retDesc[nodeName] = webshims[baseMethod](nodeName, a, b, c);
899
+ });
900
+ return retDesc;
901
+ };
902
+ });
903
+
904
+ webshims.isReady('webshimLocalization', true);
905
+ });
906
+ //html5a11y
907
+ (function($, document){
908
+ var browserVersion = $.webshims.browserVersion;
909
+ if($.browser.mozilla && browserVersion > 5){return;}
910
+ if (!$.browser.msie || (browserVersion < 12 && browserVersion > 7)) {
911
+ var elemMappings = {
912
+ article: "article",
913
+ aside: "complementary",
914
+ section: "region",
915
+ nav: "navigation",
916
+ address: "contentinfo"
917
+ };
918
+ var addRole = function(elem, role){
919
+ var hasRole = elem.getAttribute('role');
920
+ if (!hasRole) {
921
+ elem.setAttribute('role', role);
922
+ }
923
+ };
924
+
925
+ $.webshims.addReady(function(context, contextElem){
926
+ $.each(elemMappings, function(name, role){
927
+ var elems = $(name, context).add(contextElem.filter(name));
928
+ for (var i = 0, len = elems.length; i < len; i++) {
929
+ addRole(elems[i], role);
930
+ }
931
+ });
932
+ if (context === document) {
933
+ var header = document.getElementsByTagName('header')[0];
934
+ var footers = document.getElementsByTagName('footer');
935
+ var footerLen = footers.length;
936
+ if (header && !$(header).closest('section, article')[0]) {
937
+ addRole(header, 'banner');
938
+ }
939
+ if (!footerLen) {
940
+ return;
941
+ }
942
+ var footer = footers[footerLen - 1];
943
+ if (!$(footer).closest('section, article')[0]) {
944
+ addRole(footer, 'contentinfo');
945
+ }
946
+ }
947
+ });
948
+ }
949
+ })(jQuery, document);
950
+
951
+ jQuery.webshims.register('form-datalist', function($, webshims, window, document, undefined){
952
+ "use strict";
953
+ var doc = document;
954
+
955
+ /*
956
+ * implement propType "element" currently only used for list-attribute (will be moved to dom-extend, if needed)
957
+ */
958
+ webshims.propTypes.element = function(descs){
959
+ webshims.createPropDefault(descs, 'attr');
960
+ if(descs.prop){return;}
961
+ descs.prop = {
962
+ get: function(){
963
+ var elem = descs.attr.get.call(this);
964
+ if(elem){
965
+ elem = document.getElementById(elem);
966
+ if(elem && descs.propNodeName && !$.nodeName(elem, descs.propNodeName)){
967
+ elem = null;
968
+ }
969
+ }
970
+ return elem || null;
971
+ },
972
+ writeable: false
973
+ };
974
+ };
975
+
976
+
977
+ /*
978
+ * Implements datalist element and list attribute
979
+ */
980
+
981
+ (function(){
982
+ var formsCFG = $.webshims.cfg.forms;
983
+ var listSupport = Modernizr.input.list;
984
+ if(listSupport && !formsCFG.customDatalist){return;}
985
+
986
+ var initializeDatalist = function(){
987
+
988
+
989
+ if(!listSupport){
990
+ webshims.defineNodeNameProperty('datalist', 'options', {
991
+ prop: {
992
+ writeable: false,
993
+ get: function(){
994
+ var elem = this;
995
+ var select = $('select', elem);
996
+ var options;
997
+ if(select[0]){
998
+ options = select[0].options;
999
+ } else {
1000
+ options = $('option', elem).get();
1001
+ if(options.length){
1002
+ webshims.warn('you should wrap your option-elements for a datalist in a select element to support IE and other old browsers.');
1003
+ }
1004
+ }
1005
+ return options;
1006
+ }
1007
+ }
1008
+ });
1009
+ }
1010
+
1011
+ var inputListProto = {
1012
+ //override autocomplete
1013
+ autocomplete: {
1014
+ attr: {
1015
+ get: function(){
1016
+ var elem = this;
1017
+ var data = $.data(elem, 'datalistWidget');
1018
+ if(data){
1019
+ return data._autocomplete;
1020
+ }
1021
+ return ('autocomplete' in elem) ? elem.autocomplete : elem.getAttribute('autocomplete');
1022
+ },
1023
+ set: function(value){
1024
+ var elem = this;
1025
+ var data = $.data(elem, 'datalistWidget');
1026
+ if(data){
1027
+ data._autocomplete = value;
1028
+ if(value == 'off'){
1029
+ data.hideList();
1030
+ }
1031
+ } else {
1032
+ if('autocomplete' in elem){
1033
+ elem.autocomplete = value;
1034
+ } else {
1035
+ elem.setAttribute('autocomplete', value);
1036
+ }
1037
+ }
1038
+ }
1039
+ }
1040
+ }
1041
+ };
1042
+
1043
+ // if(formsCFG.customDatalist && (!listSupport || !('selectedOption') in $('<input />')[0])){
1044
+ // //currently not supported x-browser (FF4 has not implemented and is not polyfilled )
1045
+ // inputListProto.selectedOption = {
1046
+ // prop: {
1047
+ // writeable: false,
1048
+ // get: function(){
1049
+ // var elem = this;
1050
+ // var list = $.prop(elem, 'list');
1051
+ // var ret = null;
1052
+ // var value, options;
1053
+ // if(!list){return ret;}
1054
+ // value = $.prop(elem, 'value');
1055
+ // if(!value){return ret;}
1056
+ // options = $.prop(list, 'options');
1057
+ // if(!options.length){return ret;}
1058
+ // $.each(options, function(i, option){
1059
+ // if(value == $.prop(option, 'value')){
1060
+ // ret = option;
1061
+ // return false;
1062
+ // }
1063
+ // });
1064
+ // return ret;
1065
+ // }
1066
+ // }
1067
+ // };
1068
+ // }
1069
+
1070
+ if(!listSupport){
1071
+ inputListProto['list'] = {
1072
+ attr: {
1073
+ get: function(){
1074
+ var val = webshims.contentAttr(this, 'list');
1075
+ return (val == null) ? undefined : val;
1076
+ },
1077
+ set: function(value){
1078
+ var elem = this;
1079
+ webshims.contentAttr(elem, 'list', value);
1080
+ webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
1081
+ }
1082
+ },
1083
+ initAttr: true,
1084
+ reflect: true,
1085
+ propType: 'element',
1086
+ propNodeName: 'datalist'
1087
+ };
1088
+ } else {
1089
+ //options only return options, if option-elements are rooted: but this makes this part of HTML5 less backwards compatible
1090
+ if(!($('<datalist><select><option></option></select></datalist>').prop('options') || []).length ){
1091
+ webshims.defineNodeNameProperty('datalist', 'options', {
1092
+ prop: {
1093
+ writeable: false,
1094
+ get: function(){
1095
+ var options = this.options || [];
1096
+ if(!options.length){
1097
+ var elem = this;
1098
+ var select = $('select', elem);
1099
+ if(select[0] && select[0].options && select[0].options.length){
1100
+ options = select[0].options;
1101
+ }
1102
+ }
1103
+ return options;
1104
+ }
1105
+ }
1106
+ });
1107
+ }
1108
+ inputListProto['list'] = {
1109
+ attr: {
1110
+ get: function(){
1111
+ var val = webshims.contentAttr(this, 'list');
1112
+ if(val != null){
1113
+ this.removeAttribute('list');
1114
+ } else {
1115
+ val = $.data(this, 'datalistListAttr');
1116
+ }
1117
+
1118
+ return (val == null) ? undefined : val;
1119
+ },
1120
+ set: function(value){
1121
+ var elem = this;
1122
+ $.data(elem, 'datalistListAttr', value);
1123
+ webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
1124
+ }
1125
+ },
1126
+ initAttr: true,
1127
+ reflect: true,
1128
+ propType: 'element',
1129
+ propNodeName: 'datalist'
1130
+ };
1131
+ }
1132
+
1133
+
1134
+ webshims.defineNodeNameProperties('input', inputListProto);
1135
+
1136
+ if($.event.customEvent){
1137
+ $.event.customEvent.updateDatalist = true;
1138
+ $.event.customEvent.updateInput = true;
1139
+ $.event.customEvent.datalistselect = true;
1140
+ }
1141
+ webshims.addReady(function(context, contextElem){
1142
+ contextElem
1143
+ .filter('datalist > select, datalist, datalist > option, datalist > select > option')
1144
+ .closest('datalist')
1145
+ .triggerHandler('updateDatalist')
1146
+ ;
1147
+
1148
+ });
1149
+
1150
+
1151
+ };
1152
+
1153
+
1154
+ /*
1155
+ * ShadowList
1156
+ */
1157
+ var listidIndex = 0;
1158
+
1159
+ var noDatalistSupport = {
1160
+ submit: 1,
1161
+ button: 1,
1162
+ reset: 1,
1163
+ hidden: 1,
1164
+
1165
+ //ToDo
1166
+ range: 1,
1167
+ date: 1
1168
+ };
1169
+ var lteie6 = ($.browser.msie && parseInt($.browser.version, 10) < 7);
1170
+ var globStoredOptions = {};
1171
+ var getStoredOptions = function(name){
1172
+ if(!name){return [];}
1173
+ if(globStoredOptions[name]){
1174
+ return globStoredOptions[name];
1175
+ }
1176
+ var data;
1177
+ try {
1178
+ data = JSON.parse(localStorage.getItem('storedDatalistOptions'+name));
1179
+ } catch(e){}
1180
+ globStoredOptions[name] = data || [];
1181
+ return data || [];
1182
+ };
1183
+ var storeOptions = function(name, val){
1184
+ if(!name){return;}
1185
+ val = val || [];
1186
+ try {
1187
+ localStorage.setItem( 'storedDatalistOptions'+name, JSON.stringify(val) );
1188
+ } catch(e){}
1189
+ };
1190
+
1191
+ var getText = function(elem){
1192
+ return (elem.textContent || elem.innerText || $.text([ elem ]) || '');
1193
+ };
1194
+
1195
+ var shadowListProto = {
1196
+ _create: function(opts){
1197
+
1198
+ if(noDatalistSupport[$.prop(opts.input, 'type')]){return;}
1199
+ var datalist = opts.datalist;
1200
+ var data = $.data(opts.input, 'datalistWidget');
1201
+ if(datalist && data && data.datalist !== datalist){
1202
+ data.datalist = datalist;
1203
+ data.id = opts.id;
1204
+
1205
+ data.shadowList.prop('className', 'datalist-polyfill '+ (data.datalist.className || '') + ' '+ data.datalist.id +'-shadowdom');
1206
+ if(formsCFG.positionDatalist){
1207
+ data.shadowList.insertAfter(opts.input);
1208
+ } else {
1209
+ data.shadowList.appendTo('body');
1210
+ }
1211
+ $(data.datalist)
1212
+ .off('updateDatalist.datalistWidget')
1213
+ .on('updateDatalist.datalistWidget', $.proxy(data, '_resetListCached'))
1214
+ ;
1215
+ data._resetListCached();
1216
+ return;
1217
+ } else if(!datalist){
1218
+ if(data){
1219
+ data.destroy();
1220
+ }
1221
+ return;
1222
+ } else if(data && data.datalist === datalist){
1223
+ return;
1224
+ }
1225
+ listidIndex++;
1226
+ var that = this;
1227
+ this.hideList = $.proxy(that, 'hideList');
1228
+ this.timedHide = function(){
1229
+ clearTimeout(that.hideTimer);
1230
+ that.hideTimer = setTimeout(that.hideList, 9);
1231
+ };
1232
+ this.datalist = datalist;
1233
+ this.id = opts.id;
1234
+ this.hasViewableData = true;
1235
+ this._autocomplete = $.attr(opts.input, 'autocomplete');
1236
+ $.data(opts.input, 'datalistWidget', this);
1237
+ this.shadowList = $('<div class="datalist-polyfill '+ (this.datalist.className || '') + ' '+ this.datalist.id +'-shadowdom' +'" />');
1238
+
1239
+ if(formsCFG.positionDatalist || $(opts.input).hasClass('position-datalist')){
1240
+ this.shadowList.insertAfter(opts.input);
1241
+ } else {
1242
+ this.shadowList.appendTo('body');
1243
+ }
1244
+
1245
+ this.index = -1;
1246
+ this.input = opts.input;
1247
+ this.arrayOptions = [];
1248
+
1249
+ this.shadowList
1250
+ .delegate('li', 'mouseenter.datalistWidget mousedown.datalistWidget click.datalistWidget', function(e){
1251
+ var items = $('li:not(.hidden-item)', that.shadowList);
1252
+ var select = (e.type == 'mousedown' || e.type == 'click');
1253
+ that.markItem(items.index(e.currentTarget), select, items);
1254
+ if(e.type == 'click'){
1255
+ that.hideList();
1256
+ if(formsCFG.customDatalist){
1257
+ $(opts.input).trigger('datalistselect');
1258
+ }
1259
+ }
1260
+ return (e.type != 'mousedown');
1261
+ })
1262
+ .on('focusout', this.timedHide)
1263
+ ;
1264
+
1265
+ opts.input.setAttribute('autocomplete', 'off');
1266
+
1267
+ $(opts.input)
1268
+ .attr({
1269
+ //role: 'combobox',
1270
+ 'aria-haspopup': 'true'
1271
+ })
1272
+ .on({
1273
+ 'input.datalistWidget': function(){
1274
+ if(!that.triggeredByDatalist){
1275
+ that.changedValue = false;
1276
+ that.showHideOptions();
1277
+ }
1278
+ },
1279
+ 'keydown.datalistWidget': function(e){
1280
+ var keyCode = e.keyCode;
1281
+ var activeItem;
1282
+ var items;
1283
+ if(keyCode == 40 && !that.showList()){
1284
+ that.markItem(that.index + 1, true);
1285
+ return false;
1286
+ }
1287
+
1288
+ if(!that.isListVisible){return;}
1289
+
1290
+
1291
+ if(keyCode == 38){
1292
+ that.markItem(that.index - 1, true);
1293
+ return false;
1294
+ }
1295
+ if(!e.shiftKey && (keyCode == 33 || keyCode == 36)){
1296
+ that.markItem(0, true);
1297
+ return false;
1298
+ }
1299
+ if(!e.shiftKey && (keyCode == 34 || keyCode == 35)){
1300
+ items = $('li:not(.hidden-item)', that.shadowList);
1301
+ that.markItem(items.length - 1, true, items);
1302
+ return false;
1303
+ }
1304
+ if(keyCode == 13 || keyCode == 27){
1305
+ if (keyCode == 13){
1306
+ activeItem = $('li.active-item:not(.hidden-item)', that.shadowList);
1307
+ that.changeValue( $('li.active-item:not(.hidden-item)', that.shadowList) );
1308
+ }
1309
+ that.hideList();
1310
+ if(formsCFG.customDatalist && activeItem && activeItem[0]){
1311
+ $(opts.input).trigger('datalistselect');
1312
+ }
1313
+ return false;
1314
+ }
1315
+ },
1316
+ 'focus.datalistWidget': function(){
1317
+ if($(this).hasClass('list-focus')){
1318
+ that.showList();
1319
+ }
1320
+ },
1321
+ 'mousedown.datalistWidget': function(){
1322
+ if($(this).is(':focus')){
1323
+ that.showList();
1324
+ }
1325
+ },
1326
+ 'blur.datalistWidget': this.timedHide
1327
+ })
1328
+ ;
1329
+
1330
+
1331
+ $(this.datalist)
1332
+ .off('updateDatalist.datalistWidget')
1333
+ .on('updateDatalist.datalistWidget', $.proxy(this, '_resetListCached'))
1334
+ ;
1335
+
1336
+ this._resetListCached();
1337
+
1338
+ if(opts.input.form && (opts.input.name || opts.input.id)){
1339
+ $(opts.input.form).on('submit.datalistWidget'+opts.input.id, function(){
1340
+ if(!$(opts.input).hasClass('no-datalist-cache') && that._autocomplete != 'off'){
1341
+ var val = $.prop(opts.input, 'value');
1342
+ var name = (opts.input.name || opts.input.id) + $.prop(opts.input, 'type');
1343
+ if(!that.storedOptions){
1344
+ that.storedOptions = getStoredOptions( name );
1345
+ }
1346
+ if(val && that.storedOptions.indexOf(val) == -1){
1347
+ that.storedOptions.push(val);
1348
+ storeOptions(name, that.storedOptions );
1349
+ }
1350
+ }
1351
+ });
1352
+ }
1353
+ $(window).on('unload.datalist'+this.id+' beforeunload.datalist'+this.id, function(){
1354
+ that.destroy();
1355
+ });
1356
+ },
1357
+ destroy: function(){
1358
+ var autocomplete = $.attr(this.input, 'autocomplete');
1359
+ $(this.input)
1360
+ .off('.datalistWidget')
1361
+ .removeData('datalistWidget')
1362
+ ;
1363
+ this.shadowList.remove();
1364
+ $(document).off('.datalist'+this.id);
1365
+ $(window).off('.datalist'+this.id);
1366
+ if(this.input.form && this.input.id){
1367
+ $(this.input.form).off('submit.datalistWidget'+this.input.id);
1368
+ }
1369
+ this.input.removeAttribute('aria-haspopup');
1370
+ if(autocomplete === undefined){
1371
+ this.input.removeAttribute('autocomplete');
1372
+ } else {
1373
+ $(this.input).attr('autocomplete', autocomplete);
1374
+ }
1375
+ },
1376
+ _resetListCached: function(e){
1377
+ var that = this;
1378
+ var forceShow;
1379
+ this.needsUpdate = true;
1380
+ this.lastUpdatedValue = false;
1381
+ this.lastUnfoundValue = '';
1382
+
1383
+ if(!this.updateTimer){
1384
+ if(window.QUnit || (forceShow = (e && document.activeElement == that.input))){
1385
+ that.updateListOptions(forceShow);
1386
+ } else {
1387
+ webshims.ready('WINDOWLOAD', function(){
1388
+ that.updateTimer = setTimeout(function(){
1389
+ that.updateListOptions();
1390
+ that = null;
1391
+ listidIndex = 1;
1392
+ }, 200 + (100 * listidIndex));
1393
+ });
1394
+ }
1395
+ }
1396
+ },
1397
+ maskHTML: function(str){
1398
+ return str.replace(/</g, '&lt;').replace(/>/g, '&gt;');
1399
+ },
1400
+ updateListOptions: function(_forceShow){
1401
+ this.needsUpdate = false;
1402
+ clearTimeout(this.updateTimer);
1403
+ this.updateTimer = false;
1404
+ this.shadowList
1405
+ .css({
1406
+ fontSize: $.css(this.input, 'fontSize'),
1407
+ fontFamily: $.css(this.input, 'fontFamily')
1408
+ })
1409
+ ;
1410
+ this.searchStart = formsCFG.customDatalist && $(this.input).hasClass('search-start');
1411
+
1412
+ var list = [];
1413
+
1414
+ var values = [];
1415
+ var allOptions = [];
1416
+ var rElem, rItem, rOptions, rI, rLen, item;
1417
+ for(rOptions = $.prop(this.datalist, 'options'), rI = 0, rLen = rOptions.length; rI < rLen; rI++){
1418
+ rElem = rOptions[rI];
1419
+ if(rElem.disabled){return;}
1420
+ rItem = {
1421
+ value: $(rElem).val() || '',
1422
+ text: $.trim($.attr(rElem, 'label') || getText(rElem)),
1423
+ className: rElem.className || '',
1424
+ style: $.attr(rElem, 'style') || ''
1425
+ };
1426
+ if(!rItem.text){
1427
+ rItem.text = rItem.value;
1428
+ } else if(rItem.text != rItem.value){
1429
+ rItem.className += ' different-label-value';
1430
+ }
1431
+ values[rI] = rItem.value;
1432
+ allOptions[rI] = rItem;
1433
+ }
1434
+
1435
+ if(!this.storedOptions){
1436
+ this.storedOptions = ($(this.input).hasClass('no-datalist-cache') || this._autocomplete == 'off') ? [] : getStoredOptions((this.input.name || this.input.id) + $.prop(this.input, 'type'));
1437
+ }
1438
+
1439
+ this.storedOptions.forEach(function(val, i){
1440
+ if(values.indexOf(val) == -1){
1441
+ allOptions.push({value: val, text: val, className: 'stored-suggest', style: ''});
1442
+ }
1443
+ });
1444
+
1445
+ for(rI = 0, rLen = allOptions.length; rI < rLen; rI++){
1446
+ item = allOptions[rI];
1447
+ 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>';
1448
+ }
1449
+
1450
+ this.arrayOptions = allOptions;
1451
+ this.shadowList.html('<div class="datalist-outer-box"><div class="datalist-box"><ul role="list">'+ list.join("\n") +'</ul></div></div>');
1452
+
1453
+ if($.fn.bgIframe && lteie6){
1454
+ this.shadowList.bgIframe();
1455
+ }
1456
+
1457
+ if(_forceShow || this.isListVisible){
1458
+ this.showHideOptions();
1459
+ }
1460
+ },
1461
+ showHideOptions: function(_fromShowList){
1462
+ var value = $.prop(this.input, 'value').toLowerCase();
1463
+ //first check prevent infinite loop, second creates simple lazy optimization
1464
+ if(value === this.lastUpdatedValue || (this.lastUnfoundValue && value.indexOf(this.lastUnfoundValue) === 0)){
1465
+ return;
1466
+ }
1467
+
1468
+ this.lastUpdatedValue = value;
1469
+ var found = false;
1470
+ var startSearch = this.searchStart;
1471
+ var lis = $('li', this.shadowList);
1472
+ if(value){
1473
+ this.arrayOptions.forEach(function(item, i){
1474
+ var search;
1475
+ if(!('lowerText' in item)){
1476
+ if(item.text != item.value){
1477
+ item.lowerText = item.value.toLowerCase() + item.text.toLowerCase();
1478
+ } else {
1479
+ item.lowerText = item.text.toLowerCase();
1480
+ }
1481
+ }
1482
+ search = item.lowerText.indexOf(value);
1483
+ search = startSearch ? !search : search !== -1;
1484
+ if(search){
1485
+ $(lis[i]).removeClass('hidden-item');
1486
+ found = true;
1487
+ } else {
1488
+ $(lis[i]).addClass('hidden-item');
1489
+ }
1490
+ });
1491
+ } else if(lis.length) {
1492
+ lis.removeClass('hidden-item');
1493
+ found = true;
1494
+ }
1495
+
1496
+ this.hasViewableData = found;
1497
+ if(!_fromShowList && found){
1498
+ this.showList();
1499
+ }
1500
+ if(!found){
1501
+ this.lastUnfoundValue = value;
1502
+ this.hideList();
1503
+ }
1504
+ },
1505
+ setPos: function(){
1506
+ this.shadowList.css({marginTop: 0, marginLeft: 0, marginRight: 0, marginBottom: 0});
1507
+ var css = (formsCFG.positionDatalist) ? $(this.input).position() : webshims.getRelOffset(this.shadowList, this.input);
1508
+ css.top += $(this.input).outerHeight();
1509
+ css.width = $(this.input).outerWidth() - (parseInt(this.shadowList.css('borderLeftWidth'), 10) || 0) - (parseInt(this.shadowList.css('borderRightWidth'), 10) || 0);
1510
+ this.shadowList.css({marginTop: '', marginLeft: '', marginRight: '', marginBottom: ''}).css(css);
1511
+ return css;
1512
+ },
1513
+ showList: function(){
1514
+ if(this.isListVisible){return false;}
1515
+ if(this.needsUpdate){
1516
+ this.updateListOptions();
1517
+ }
1518
+ this.showHideOptions(true);
1519
+ if(!this.hasViewableData){return false;}
1520
+ this.isListVisible = true;
1521
+ var that = this;
1522
+
1523
+ that.setPos();
1524
+ that.shadowList.addClass('datalist-visible').find('li.active-item').removeClass('active-item');
1525
+
1526
+ $(window).unbind('.datalist'+that.id);
1527
+ $(document)
1528
+ .off('.datalist'+that.id)
1529
+ .on('mousedown.datalist'+that.id +' focusin.datalist'+that.id, function(e){
1530
+ if(e.target === that.input || that.shadowList[0] === e.target || $.contains( that.shadowList[0], e.target )){
1531
+ clearTimeout(that.hideTimer);
1532
+ setTimeout(function(){
1533
+ clearTimeout(that.hideTimer);
1534
+ }, 9);
1535
+ } else {
1536
+ that.timedHide();
1537
+ }
1538
+ })
1539
+ .on('updateshadowdom.datalist'+that.id, function(){
1540
+ that.setPos();
1541
+ })
1542
+ ;
1543
+ return true;
1544
+ },
1545
+ hideList: function(){
1546
+ if(!this.isListVisible){return false;}
1547
+ var that = this;
1548
+ var triggerChange = function(e){
1549
+ if(that.changedValue){
1550
+ $(that.input).trigger('change');
1551
+ }
1552
+ that.changedValue = false;
1553
+ };
1554
+
1555
+ that.shadowList.removeClass('datalist-visible list-item-active');
1556
+ that.index = -1;
1557
+ that.isListVisible = false;
1558
+ if(that.changedValue){
1559
+ that.triggeredByDatalist = true;
1560
+ webshims.triggerInlineForm && webshims.triggerInlineForm(that.input, 'input');
1561
+ if($(that.input).is(':focus')){
1562
+ $(that.input).one('blur', triggerChange);
1563
+ } else {
1564
+ triggerChange();
1565
+ }
1566
+ that.triggeredByDatalist = false;
1567
+ }
1568
+ $(document).unbind('.datalist'+that.id);
1569
+ $(window)
1570
+ .off('.datalist'+that.id)
1571
+ .one('resize.datalist'+that.id, function(){
1572
+ that.shadowList.css({top: 0, left: 0});
1573
+ })
1574
+ ;
1575
+ return true;
1576
+ },
1577
+ scrollIntoView: function(elem){
1578
+ var ul = $('ul', this.shadowList);
1579
+ var div = $('div.datalist-box', this.shadowList);
1580
+ var elemPos = elem.position();
1581
+ var containerHeight;
1582
+ elemPos.top -= (parseInt(ul.css('paddingTop'), 10) || 0) + (parseInt(ul.css('marginTop'), 10) || 0) + (parseInt(ul.css('borderTopWidth'), 10) || 0);
1583
+ if(elemPos.top < 0){
1584
+ div.scrollTop( div.scrollTop() + elemPos.top - 2);
1585
+ return;
1586
+ }
1587
+ elemPos.top += elem.outerHeight();
1588
+ containerHeight = div.height();
1589
+ if(elemPos.top > containerHeight){
1590
+ div.scrollTop( div.scrollTop() + (elemPos.top - containerHeight) + 2);
1591
+ }
1592
+ },
1593
+ changeValue: function(activeItem){
1594
+ if(!activeItem[0]){return;}
1595
+ var newValue = $('span.option-value', activeItem).text();
1596
+ var oldValue = $.prop(this.input, 'value');
1597
+ if(newValue != oldValue){
1598
+ $(this.input)
1599
+ .prop('value', newValue)
1600
+ .triggerHandler('updateInput')
1601
+ ;
1602
+ this.changedValue = true;
1603
+ }
1604
+ },
1605
+ markItem: function(index, doValue, items){
1606
+ var activeItem;
1607
+ var goesUp;
1608
+
1609
+ items = items || $('li:not(.hidden-item)', this.shadowList);
1610
+ if(!items.length){return;}
1611
+ if(index < 0){
1612
+ index = items.length - 1;
1613
+ } else if(index >= items.length){
1614
+ index = 0;
1615
+ }
1616
+ items.removeClass('active-item');
1617
+ this.shadowList.addClass('list-item-active');
1618
+ activeItem = items.filter(':eq('+ index +')').addClass('active-item');
1619
+
1620
+ if(doValue){
1621
+ this.changeValue(activeItem);
1622
+ this.scrollIntoView(activeItem);
1623
+ }
1624
+ this.index = index;
1625
+ }
1626
+ };
1627
+
1628
+ //init datalist update
1629
+ initializeDatalist();
1630
+ })();
1631
+
1634
1632
  });