webshims-rails 0.4.7 → 1.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +15 -0
  2. data/lib/webshims-rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/webshims/extras/custom-validity.js +1 -1
  4. data/vendor/assets/javascripts/webshims/extras/mousepress.js +1 -1
  5. data/vendor/assets/javascripts/webshims/polyfiller.js +197 -166
  6. data/vendor/assets/javascripts/webshims/shims/combos/1.js +1711 -1609
  7. data/vendor/assets/javascripts/webshims/shims/combos/10.js +2575 -2253
  8. data/vendor/assets/javascripts/webshims/shims/combos/11.js +2452 -1476
  9. data/vendor/assets/javascripts/webshims/shims/combos/12.js +1405 -1159
  10. data/vendor/assets/javascripts/webshims/shims/combos/13.js +1316 -963
  11. data/vendor/assets/javascripts/webshims/shims/combos/14.js +1862 -179
  12. data/vendor/assets/javascripts/webshims/shims/combos/15.js +4327 -287
  13. data/vendor/assets/javascripts/webshims/shims/combos/16.js +3887 -586
  14. data/vendor/assets/javascripts/webshims/shims/combos/17.js +2911 -2159
  15. data/vendor/assets/javascripts/webshims/shims/combos/18.js +3425 -1730
  16. data/vendor/assets/javascripts/webshims/shims/combos/19.js +2854 -1203
  17. data/vendor/assets/javascripts/webshims/shims/combos/2.js +3351 -2130
  18. data/vendor/assets/javascripts/webshims/shims/combos/20.js +2426 -581
  19. data/vendor/assets/javascripts/webshims/shims/combos/21.js +1915 -1574
  20. data/vendor/assets/javascripts/webshims/shims/combos/22.js +864 -2275
  21. data/vendor/assets/javascripts/webshims/shims/combos/23.js +609 -1811
  22. data/vendor/assets/javascripts/webshims/shims/combos/3.js +1655 -2736
  23. data/vendor/assets/javascripts/webshims/shims/combos/4.js +1037 -603
  24. data/vendor/assets/javascripts/webshims/shims/combos/5.js +3100 -773
  25. data/vendor/assets/javascripts/webshims/shims/combos/6.js +3631 -840
  26. data/vendor/assets/javascripts/webshims/shims/combos/7.js +3596 -1354
  27. data/vendor/assets/javascripts/webshims/shims/combos/8.js +1731 -188
  28. data/vendor/assets/javascripts/webshims/shims/combos/9.js +3243 -1431
  29. data/vendor/assets/javascripts/webshims/shims/dom-extend.js +107 -18
  30. data/vendor/assets/javascripts/webshims/shims/es5.js +1 -0
  31. data/vendor/assets/javascripts/webshims/shims/form-core.js +553 -464
  32. data/vendor/assets/javascripts/webshims/shims/form-datalist.js +160 -154
  33. data/vendor/assets/javascripts/webshims/shims/form-message.js +73 -49
  34. data/vendor/assets/javascripts/webshims/shims/form-native-extend.js +18 -1
  35. data/vendor/assets/javascripts/webshims/shims/form-number-date-api.js +161 -36
  36. data/vendor/assets/javascripts/webshims/shims/form-number-date-ui.js +2130 -813
  37. data/vendor/assets/javascripts/webshims/shims/form-shim-extend.js +206 -58
  38. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-ar.js → formcfg-ar.js} +30 -0
  39. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-ch-ZN.js → formcfg-ch-ZN.js} +31 -0
  40. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-de.txt → formcfg-de.txt} +50 -11
  41. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-el.js → formcfg-el.js} +31 -0
  42. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-en.txt → formcfg-en.txt} +44 -11
  43. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-es.js → formcfg-es.js} +31 -0
  44. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-fr.js → formcfg-fr.js} +31 -0
  45. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-he.js → formcfg-he.js} +31 -0
  46. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-hi.js → formcfg-hi.js} +31 -0
  47. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-hu.js → formcfg-hu.js} +31 -0
  48. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-it.js → formcfg-it.js} +31 -0
  49. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-ja.js → formcfg-ja.js} +31 -0
  50. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-nl.js → formcfg-nl.js} +31 -0
  51. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-pt-PT.js → formcfg-pt-PT.js} +31 -0
  52. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-ru.js → formcfg-ru.js} +31 -0
  53. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-sv.js → formcfg-sv.js} +32 -0
  54. data/vendor/assets/javascripts/webshims/shims/json-storage.js +16 -10
  55. data/vendor/assets/javascripts/webshims/shims/mediaelement-core.js +155 -122
  56. data/vendor/assets/javascripts/webshims/shims/mediaelement-jaris.js +76 -41
  57. data/vendor/assets/javascripts/webshims/shims/mediaelement-yt.js +8 -16
  58. data/vendor/assets/javascripts/webshims/shims/range-ui.js +388 -0
  59. data/vendor/assets/javascripts/webshims/shims/styles/config.rb +12 -0
  60. data/vendor/assets/javascripts/webshims/shims/styles/forms.png +0 -0
  61. data/vendor/assets/javascripts/webshims/shims/styles/scss/shim.scss +1186 -0
  62. data/vendor/assets/javascripts/webshims/shims/styles/shim.css +868 -548
  63. data/vendor/assets/javascripts/webshims/shims/styles/vertical-range.png +0 -0
  64. data/vendor/assets/javascripts/webshims/shims/swf/JarisFLVPlayer.swf +0 -0
  65. data/vendor/assets/javascripts/webshims/shims/swfmini.js +497 -0
  66. data/vendor/assets/javascripts/webshims/shims/track-ui.js +3 -0
  67. data/vendor/assets/javascripts/webshims/shims/track.js +29 -29
  68. metadata +26 -125
  69. data/vendor/assets/javascripts/webshims/minified/extras/custom-validity.js +0 -1
  70. data/vendor/assets/javascripts/webshims/minified/extras/modernizr-custom.js +0 -1
  71. data/vendor/assets/javascripts/webshims/minified/extras/mousepress.js +0 -1
  72. data/vendor/assets/javascripts/webshims/minified/polyfiller.js +0 -1
  73. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvas/canvas2png.js +0 -1
  74. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvas/flashcanvas.js +0 -1
  75. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvas/flashcanvas.swf +0 -0
  76. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvas/proxy.php +0 -73
  77. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvas/save.php +0 -49
  78. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/canvas2png.js +0 -1
  79. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/flash10canvas.swf +0 -0
  80. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/flash9canvas.swf +0 -0
  81. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/flashcanvas.js +0 -1
  82. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/proxy.php +0 -73
  83. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/save.php +0 -49
  84. data/vendor/assets/javascripts/webshims/minified/shims/combos/1.js +0 -1
  85. data/vendor/assets/javascripts/webshims/minified/shims/combos/10.js +0 -1
  86. data/vendor/assets/javascripts/webshims/minified/shims/combos/11.js +0 -1
  87. data/vendor/assets/javascripts/webshims/minified/shims/combos/12.js +0 -1
  88. data/vendor/assets/javascripts/webshims/minified/shims/combos/13.js +0 -1
  89. data/vendor/assets/javascripts/webshims/minified/shims/combos/14.js +0 -1
  90. data/vendor/assets/javascripts/webshims/minified/shims/combos/15.js +0 -1
  91. data/vendor/assets/javascripts/webshims/minified/shims/combos/16.js +0 -1
  92. data/vendor/assets/javascripts/webshims/minified/shims/combos/17.js +0 -1
  93. data/vendor/assets/javascripts/webshims/minified/shims/combos/18.js +0 -1
  94. data/vendor/assets/javascripts/webshims/minified/shims/combos/19.js +0 -1
  95. data/vendor/assets/javascripts/webshims/minified/shims/combos/2.js +0 -1
  96. data/vendor/assets/javascripts/webshims/minified/shims/combos/20.js +0 -1
  97. data/vendor/assets/javascripts/webshims/minified/shims/combos/21.js +0 -1
  98. data/vendor/assets/javascripts/webshims/minified/shims/combos/22.js +0 -1
  99. data/vendor/assets/javascripts/webshims/minified/shims/combos/23.js +0 -1
  100. data/vendor/assets/javascripts/webshims/minified/shims/combos/24.js +0 -1
  101. data/vendor/assets/javascripts/webshims/minified/shims/combos/25.js +0 -1
  102. data/vendor/assets/javascripts/webshims/minified/shims/combos/26.js +0 -1
  103. data/vendor/assets/javascripts/webshims/minified/shims/combos/27.js +0 -1
  104. data/vendor/assets/javascripts/webshims/minified/shims/combos/3.js +0 -1
  105. data/vendor/assets/javascripts/webshims/minified/shims/combos/4.js +0 -1
  106. data/vendor/assets/javascripts/webshims/minified/shims/combos/5.js +0 -1
  107. data/vendor/assets/javascripts/webshims/minified/shims/combos/59.js +0 -1
  108. data/vendor/assets/javascripts/webshims/minified/shims/combos/6.js +0 -1
  109. data/vendor/assets/javascripts/webshims/minified/shims/combos/7.js +0 -1
  110. data/vendor/assets/javascripts/webshims/minified/shims/combos/8.js +0 -1
  111. data/vendor/assets/javascripts/webshims/minified/shims/combos/9.js +0 -1
  112. data/vendor/assets/javascripts/webshims/minified/shims/details.js +0 -1
  113. data/vendor/assets/javascripts/webshims/minified/shims/dom-extend.js +0 -1
  114. data/vendor/assets/javascripts/webshims/minified/shims/es5.js +0 -1
  115. data/vendor/assets/javascripts/webshims/minified/shims/excanvas.js +0 -1
  116. data/vendor/assets/javascripts/webshims/minified/shims/form-core.js +0 -1
  117. data/vendor/assets/javascripts/webshims/minified/shims/form-datalist.js +0 -1
  118. data/vendor/assets/javascripts/webshims/minified/shims/form-message.js +0 -1
  119. data/vendor/assets/javascripts/webshims/minified/shims/form-native-extend.js +0 -1
  120. data/vendor/assets/javascripts/webshims/minified/shims/form-number-date-api.js +0 -1
  121. data/vendor/assets/javascripts/webshims/minified/shims/form-number-date-ui.js +0 -1
  122. data/vendor/assets/javascripts/webshims/minified/shims/form-shim-extend.js +0 -1
  123. data/vendor/assets/javascripts/webshims/minified/shims/geolocation.js +0 -1
  124. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-ar.js +0 -1
  125. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-ch-ZN.js +0 -1
  126. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-de.txt +0 -33
  127. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-el.js +0 -1
  128. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-en.txt +0 -34
  129. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-es.js +0 -1
  130. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-fr.js +0 -1
  131. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-he.js +0 -1
  132. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-hi.js +0 -1
  133. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-hu.js +0 -1
  134. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-it.js +0 -1
  135. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-ja.js +0 -1
  136. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-nl.js +0 -1
  137. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-pt-PT.js +0 -1
  138. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-ru.js +0 -1
  139. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-sv.js +0 -1
  140. data/vendor/assets/javascripts/webshims/minified/shims/json-storage.js +0 -1
  141. data/vendor/assets/javascripts/webshims/minified/shims/jwplayer/license.txt +0 -1
  142. data/vendor/assets/javascripts/webshims/minified/shims/jwplayer/player.swf +0 -0
  143. data/vendor/assets/javascripts/webshims/minified/shims/jwplayer/readme.html +0 -87
  144. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-core.js +0 -1
  145. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-jaris.js +0 -1
  146. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-native-fix.js +0 -1
  147. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-swf.js +0 -1
  148. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-yt.js +0 -1
  149. data/vendor/assets/javascripts/webshims/minified/shims/styles/details-arrows.png +0 -0
  150. data/vendor/assets/javascripts/webshims/minified/shims/styles/forms.png +0 -0
  151. data/vendor/assets/javascripts/webshims/minified/shims/styles/polyfill-loader.gif +0 -0
  152. data/vendor/assets/javascripts/webshims/minified/shims/styles/shim.css +0 -1
  153. data/vendor/assets/javascripts/webshims/minified/shims/swf/JarisFLVPlayer.swf +0 -0
  154. data/vendor/assets/javascripts/webshims/minified/shims/swf/jwwebshims.swf +0 -0
  155. data/vendor/assets/javascripts/webshims/minified/shims/swf/localStorage.swf +0 -0
  156. data/vendor/assets/javascripts/webshims/minified/shims/track-ui.js +0 -1
  157. data/vendor/assets/javascripts/webshims/minified/shims/track.js +0 -1
  158. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/README +0 -62
  159. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/README +0 -82
  160. data/vendor/assets/javascripts/webshims/shims/combos/24.js +0 -2872
  161. data/vendor/assets/javascripts/webshims/shims/combos/25.js +0 -2376
  162. data/vendor/assets/javascripts/webshims/shims/combos/26.js +0 -3009
  163. data/vendor/assets/javascripts/webshims/shims/combos/27.js +0 -4150
  164. data/vendor/assets/javascripts/webshims/shims/combos/59.js +0 -1747
  165. data/vendor/assets/javascripts/webshims/shims/jwplayer/license.txt +0 -1
  166. data/vendor/assets/javascripts/webshims/shims/jwplayer/player.swf +0 -0
  167. data/vendor/assets/javascripts/webshims/shims/jwplayer/readme.html +0 -87
  168. data/vendor/assets/javascripts/webshims/shims/mediaelement-swf.js +0 -972
@@ -1,7 +1,280 @@
1
+ jQuery.webshims.register('form-native-extend', function($, webshims, window, doc, undefined, options){
2
+ "use strict";
3
+ var Modernizr = window.Modernizr;
4
+ var modernizrInputTypes = Modernizr.inputtypes;
5
+ if(!Modernizr.formvalidation || webshims.bugs.bustedValidity){return;}
6
+ var typeModels = webshims.inputTypes;
7
+ var validityRules = {};
8
+
9
+ var updateValidity = (function(){
10
+ var timer;
11
+ var getValidity = function(){
12
+ $(this).prop('validity');
13
+ };
14
+ var update = function(){
15
+ $('input').each(getValidity);
16
+ };
17
+ return function(fast){
18
+ clearTimeout(timer);
19
+ timer = setTimeout(update, 9);
20
+ };
21
+ })();
22
+ webshims.addInputType = function(type, obj){
23
+ typeModels[type] = obj;
24
+ //update validity of all implemented input types
25
+ if($.isDOMReady && Modernizr.formvalidation && !webshims.bugs.bustedValidity){
26
+ updateValidity();
27
+ }
28
+ };
29
+
30
+ webshims.addValidityRule = function(type, fn){
31
+ validityRules[type] = fn;
32
+ };
33
+
34
+ webshims.addValidityRule('typeMismatch', function (input, val, cache, validityState){
35
+ if(val === ''){return false;}
36
+ var ret = validityState.typeMismatch;
37
+ if(!('type' in cache)){
38
+ cache.type = (input[0].getAttribute('type') || '').toLowerCase();
39
+ }
40
+
41
+ if(typeModels[cache.type] && typeModels[cache.type].mismatch){
42
+ ret = typeModels[cache.type].mismatch(val, input);
43
+ }
44
+ return ret;
45
+ });
46
+
47
+ var overrideNativeMessages = options.overrideMessages;
48
+
49
+ var overrideValidity = (!modernizrInputTypes.number || !modernizrInputTypes.time || !modernizrInputTypes.range || overrideNativeMessages);
50
+ var validityProps = ['customError','typeMismatch','rangeUnderflow','rangeOverflow','stepMismatch','tooLong','patternMismatch','valueMissing','valid'];
51
+
52
+ var validityChanger = (overrideNativeMessages)? ['value', 'checked'] : ['value'];
53
+ var validityElements = [];
54
+ var testValidity = function(elem, init){
55
+ if(!elem){return;}
56
+ var type = (elem.getAttribute && elem.getAttribute('type') || elem.type || '').toLowerCase();
57
+
58
+ if(!overrideNativeMessages && !typeModels[type]){
59
+ return;
60
+ }
61
+
62
+ if(overrideNativeMessages && !init && type == 'radio' && elem.name){
63
+ $(doc.getElementsByName( elem.name )).each(function(){
64
+ $.prop(this, 'validity');
65
+ });
66
+ } else {
67
+ $.prop(elem, 'validity');
68
+ }
69
+ };
70
+
71
+ var oldSetCustomValidity = {};
72
+ ['input', 'textarea', 'select'].forEach(function(name){
73
+ var desc = webshims.defineNodeNameProperty(name, 'setCustomValidity', {
74
+ prop: {
75
+ value: function(error){
76
+ error = error+'';
77
+ var elem = (name == 'input') ? $(this).getNativeElement()[0] : this;
78
+ desc.prop._supvalue.call(elem, error);
79
+
80
+ if(webshims.bugs.validationMessage){
81
+ webshims.data(elem, 'customvalidationMessage', error);
82
+ }
83
+ if(overrideValidity){
84
+ webshims.data(elem, 'hasCustomError', !!(error));
85
+ testValidity(elem);
86
+ }
87
+ }
88
+ }
89
+ });
90
+ oldSetCustomValidity[name] = desc.prop._supvalue;
91
+ });
92
+
93
+
94
+ if(overrideValidity || overrideNativeMessages){
95
+ validityChanger.push('min');
96
+ validityChanger.push('max');
97
+ validityChanger.push('step');
98
+ validityElements.push('input');
99
+ }
100
+ if(overrideNativeMessages){
101
+ validityChanger.push('required');
102
+ validityChanger.push('pattern');
103
+ validityElements.push('select');
104
+ validityElements.push('textarea');
105
+ }
106
+
107
+ if(overrideValidity){
108
+ var stopValidity;
109
+ validityElements.forEach(function(nodeName){
110
+
111
+ var oldDesc = webshims.defineNodeNameProperty(nodeName, 'validity', {
112
+ prop: {
113
+ get: function(){
114
+ if(stopValidity){return;}
115
+ var elem = (nodeName == 'input') ? $(this).getNativeElement()[0] : this;
116
+
117
+ var validity = oldDesc.prop._supget.call(elem);
118
+
119
+ if(!validity){
120
+ return validity;
121
+ }
122
+ var validityState = {};
123
+ validityProps.forEach(function(prop){
124
+ validityState[prop] = validity[prop];
125
+ });
126
+
127
+ if( !$.prop(elem, 'willValidate') ){
128
+ return validityState;
129
+ }
130
+ stopValidity = true;
131
+ var jElm = $(elem),
132
+ cache = {type: (elem.getAttribute && elem.getAttribute('type') || '').toLowerCase(), nodeName: (elem.nodeName || '').toLowerCase()},
133
+ val = jElm.val(),
134
+ customError = !!(webshims.data(elem, 'hasCustomError')),
135
+ setCustomMessage
136
+ ;
137
+ stopValidity = false;
138
+ validityState.customError = customError;
139
+
140
+ if( validityState.valid && validityState.customError ){
141
+ validityState.valid = false;
142
+ } else if(!validityState.valid) {
143
+ var allFalse = true;
144
+ $.each(validityState, function(name, prop){
145
+ if(prop){
146
+ allFalse = false;
147
+ return false;
148
+ }
149
+ });
150
+
151
+ if(allFalse){
152
+ validityState.valid = true;
153
+ }
154
+
155
+ }
156
+
157
+ $.each(validityRules, function(rule, fn){
158
+ validityState[rule] = fn(jElm, val, cache, validityState);
159
+ if( validityState[rule] && (validityState.valid || !setCustomMessage) && (overrideNativeMessages || (typeModels[cache.type] && typeModels[cache.type].mismatch)) ) {
160
+ oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, rule));
161
+ validityState.valid = false;
162
+ setCustomMessage = true;
163
+ }
164
+ });
165
+ if(validityState.valid){
166
+ oldSetCustomValidity[nodeName].call(elem, '');
167
+ webshims.data(elem, 'hasCustomError', false);
168
+ } else if(overrideNativeMessages && !setCustomMessage && !customError){
169
+ $.each(validityState, function(name, prop){
170
+ if(name !== 'valid' && prop){
171
+ oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, name));
172
+ return false;
173
+ }
174
+ });
175
+ }
176
+ return validityState;
177
+ },
178
+ writeable: false
179
+
180
+ }
181
+ });
182
+ });
183
+
184
+ validityChanger.forEach(function(prop){
185
+ webshims.onNodeNamesPropertyModify(validityElements, prop, function(s){
186
+ testValidity(this);
187
+ });
188
+ });
189
+
190
+ if(doc.addEventListener){
191
+ var inputThrottle;
192
+ var testPassValidity = function(e){
193
+ if(!('form' in e.target)){return;}
194
+ var form = e.target.form;
195
+ clearTimeout(inputThrottle);
196
+ testValidity(e.target);
197
+ if(form && overrideNativeMessages){
198
+ $('input', form).each(function(){
199
+ if(this.type == 'password'){
200
+ testValidity(this);
201
+ }
202
+ });
203
+ }
204
+ };
205
+
206
+ doc.addEventListener('change', testPassValidity, true);
207
+
208
+ if(overrideNativeMessages){
209
+ doc.addEventListener('blur', testPassValidity, true);
210
+ doc.addEventListener('keydown', function(e){
211
+ if(e.keyCode != 13){return;}
212
+ testPassValidity(e);
213
+ }, true);
214
+ }
215
+
216
+ doc.addEventListener('input', function(e){
217
+ clearTimeout(inputThrottle);
218
+ inputThrottle = setTimeout(function(){
219
+ testValidity(e.target);
220
+ }, 290);
221
+ }, true);
222
+ }
223
+
224
+ var validityElementsSel = validityElements.join(',');
225
+
226
+ webshims.addReady(function(context, elem){
227
+ $(validityElementsSel, context).add(elem.filter(validityElementsSel)).each(function(){
228
+ $.prop(this, 'validity');
229
+ });
230
+ });
231
+
232
+
233
+ if(overrideNativeMessages){
234
+ webshims.ready('DOM form-message', function(){
235
+ webshims.activeLang({
236
+ register: 'form-core',
237
+ callback: function(){
238
+ $('input, select, textarea')
239
+ .getNativeElement()
240
+ .each(function(){
241
+ if(webshims.data(this, 'hasCustomError')){return;}
242
+ var elem = this;
243
+ var validity = $.prop(elem, 'validity') || {valid: true};
244
+ var nodeName;
245
+ if(validity.valid){return;}
246
+ nodeName = (elem.nodeName || '').toLowerCase();
247
+ $.each(validity, function(name, prop){
248
+ if(name !== 'valid' && prop){
249
+ oldSetCustomValidity[nodeName].call(elem, webshims.createValidationMessage(elem, name));
250
+ return false;
251
+ }
252
+ });
253
+ })
254
+ ;
255
+ }
256
+ });
257
+ });
258
+ }
259
+
260
+ } //end: overrideValidity
261
+
262
+ webshims.defineNodeNameProperty('input', 'type', {
263
+ prop: {
264
+ get: function(){
265
+ var elem = this;
266
+ var type = (elem.getAttribute('type') || '').toLowerCase();
267
+ return (webshims.inputTypes[type]) ? type : elem.type;
268
+ }
269
+ }
270
+ });
271
+
272
+
273
+ });
1
274
  jQuery.webshims.register('form-number-date-api', function($, webshims, window, document, undefined){
2
275
  "use strict";
3
276
 
4
- //ToDo
277
+
5
278
  if(!webshims.getStep){
6
279
  webshims.getStep = function(elem, type){
7
280
  var step = $.attr(elem, 'step');
@@ -13,7 +286,7 @@ jQuery.webshims.register('form-number-date-api', function($, webshims, window, d
13
286
  return step;
14
287
  }
15
288
  step = typeProtos.number.asNumber(step);
16
- return ((!isNaN(step) && step > 0) ? step : typeModels[type].step) * typeModels[type].stepScaleFactor;
289
+ return ((!isNaN(step) && step > 0) ? step : typeModels[type].step) * (typeModels[type].stepScaleFactor || 1);
17
290
  };
18
291
  }
19
292
  if(!webshims.addMinMaxNumberToCache){
@@ -40,7 +313,7 @@ jQuery.webshims.register('form-number-date-api', function($, webshims, window, d
40
313
  return (elem.getAttribute('type') || '').toLowerCase();
41
314
  },
42
315
  isDateTimePart = function(string){
43
- return (isNumber(string) || (string && string == '0' + (string * 1)));
316
+ return (string && !(isNaN(string * 1)));
44
317
  },
45
318
  addMinMaxNumberToCache = webshims.addMinMaxNumberToCache,
46
319
  addleadingZero = function(val, len){
@@ -60,11 +333,8 @@ jQuery.webshims.register('form-number-date-api', function($, webshims, window, d
60
333
  if(!('type' in cache)){
61
334
  cache.type = getType(input[0]);
62
335
  }
63
- //stepmismatch with date is computable, but it would be a typeMismatch (performance)
64
- if(cache.type == 'date'){
65
- return false;
66
- }
67
- var ret = (validityState || {}).stepMismatch, base;
336
+
337
+ var ret = (validityState || {}).stepMismatch || false, base;
68
338
  if(typeModels[cache.type] && typeModels[cache.type].step){
69
339
  if( !('step' in cache) ){
70
340
  cache.step = webshims.getStep(input[0], cache.type);
@@ -148,7 +418,7 @@ jQuery.webshims.register('form-number-date-api', function($, webshims, window, d
148
418
  if(set !== false){
149
419
  $.prop(elem, 'value', set);
150
420
  } else {
151
- webshims.warn('INVALID_STATE_ERR: DOM Exception 11');
421
+ webshims.error('INVALID_STATE_ERR: DOM Exception 11');
152
422
  }
153
423
  } else {
154
424
  valueAsNumberDescriptor.prop._supset && valueAsNumberDescriptor.prop._supset.apply(elem, arguments);
@@ -180,7 +450,7 @@ jQuery.webshims.register('form-number-date-api', function($, webshims, window, d
180
450
  $.prop(elem, 'value', set);
181
451
  return set;
182
452
  } else {
183
- webshims.warn('INVALID_STATE_ERR: DOM Exception 11');
453
+ webshims.error('INVALID_STATE_ERR: DOM Exception 11');
184
454
  }
185
455
  } else {
186
456
  return valueAsDateDescriptor.prop._supset && valueAsDateDescriptor.prop._supset.apply(elem, arguments) || null;
@@ -189,6 +459,69 @@ jQuery.webshims.register('form-number-date-api', function($, webshims, window, d
189
459
  }
190
460
  });
191
461
 
462
+ $.each({stepUp: 1, stepDown: -1}, function(name, stepFactor){
463
+ var stepDescriptor = webshims.defineNodeNameProperty('input', name, {
464
+ prop: {
465
+ value: function(factor){
466
+ var step, val, dateVal, valModStep, alignValue, cache;
467
+ var type = getType(this);
468
+ if(typeModels[type] && typeModels[type].asNumber){
469
+ cache = {type: type};
470
+ if(!factor){
471
+ factor = 1;
472
+ webshims.info("you should always use a factor for stepUp/stepDown");
473
+ }
474
+ factor *= stepFactor;
475
+
476
+ val = $.prop(this, 'valueAsNumber');
477
+
478
+ if(isNaN(val)){
479
+ webshims.info("valueAsNumber is NaN can't apply stepUp/stepDown ");
480
+ throw('invalid state error');
481
+ }
482
+
483
+ step = webshims.getStep(this, type);
484
+
485
+ if(step == 'any'){
486
+ webshims.info("step is 'any' can't apply stepUp/stepDown");
487
+ throw('invalid state error');
488
+ }
489
+
490
+ webshims.addMinMaxNumberToCache('min', $(this), cache);
491
+ webshims.addMinMaxNumberToCache('max', $(this), cache);
492
+
493
+ step *= factor;
494
+
495
+ val = (val + step).toFixed(5) * 1;
496
+ valModStep = (val - (cache.minAsNumber || 0)) % step;
497
+
498
+ if ( valModStep && (Math.abs(valModStep) > EPS) ) {
499
+ alignValue = val - valModStep;
500
+ alignValue += ( valModStep > 0 ) ? step : ( -step );
501
+ val = alignValue.toFixed(5) * 1;
502
+ }
503
+
504
+ if( (!isNaN(cache.maxAsNumber) && val > cache.maxAsNumber) || (!isNaN(cache.minAsNumber) && val < cache.minAsNumber) ){
505
+ webshims.info("max/min overflow can't apply stepUp/stepDown");
506
+ throw('invalid state error');
507
+ }
508
+ if(dateVal){
509
+ $.prop(this, 'valueAsDate', dateVal);
510
+ } else {
511
+ $.prop(this, 'valueAsNumber', val);
512
+ }
513
+ } else if(stepDescriptor.prop && stepDescriptor.prop.value){
514
+ return stepDescriptor.prop.value.apply(this, arguments);
515
+ } else {
516
+ webshims.info("no step method for type: "+ type);
517
+ throw('invalid state error');
518
+ }
519
+ }
520
+ }
521
+ });
522
+ });
523
+
524
+
192
525
  var typeProtos = {
193
526
 
194
527
  number: {
@@ -214,20 +547,24 @@ jQuery.webshims.register('form-number-date-api', function($, webshims, window, d
214
547
  date: {
215
548
  mismatch: function(val){
216
549
  if(!val || !val.split || !(/\d$/.test(val))){return true;}
550
+ var i;
217
551
  var valA = val.split(/\u002D/);
218
552
  if(valA.length !== 3){return true;}
219
553
  var ret = false;
220
- $.each(valA, function(i, part){
221
- if(!isDateTimePart(part)){
222
- ret = true;
223
- return false;
224
- }
225
- });
226
- if(ret){return ret;}
227
- if(valA[0].length !== 4 || valA[1].length != 2 || valA[1] > 12 || valA[2].length != 2 || valA[2] > 33){
554
+
555
+
556
+ if(valA[0].length < 4 || valA[1].length != 2 || valA[1] > 12 || valA[2].length != 2 || valA[2] > 33){
228
557
  ret = true;
558
+ } else {
559
+ for(i = 0; i < 3; i++){
560
+ if(!isDateTimePart(valA[i])){
561
+ ret = true;
562
+ break;
563
+ }
564
+ }
229
565
  }
230
- return (val !== this.dateToString( this.asDate(val, true) ) );
566
+
567
+ return ret || (val !== this.dateToString( this.asDate(val, true) ) );
231
568
  },
232
569
  step: 1,
233
570
  //stepBase: 0, 0 = default
@@ -250,7 +587,7 @@ jQuery.webshims.register('form-number-date-api', function($, webshims, window, d
250
587
  return (isNumber(num)) ? this.dateToString(new Date( num * 1)) : false;
251
588
  },
252
589
  dateToString: function(date){
253
- return (date && date.getFullYear) ? date.getUTCFullYear() +'-'+ addleadingZero(date.getUTCMonth()+1, 2) +'-'+ addleadingZero(date.getUTCDate(), 2) : false;
590
+ return (date && date.getFullYear) ? addleadingZero(date.getUTCFullYear(), 4) +'-'+ addleadingZero(date.getUTCMonth()+1, 2) +'-'+ addleadingZero(date.getUTCDate(), 2) : false;
254
591
  }
255
592
  },
256
593
  time: {
@@ -325,6 +662,53 @@ jQuery.webshims.register('form-number-date-api', function($, webshims, window, d
325
662
  return false;
326
663
  }
327
664
  }
665
+ },
666
+ month: {
667
+ mismatch: function(val){
668
+ return typeProtos.date.mismatch(val+'-01');
669
+ },
670
+ step: 1,
671
+ stepScaleFactor: false,
672
+ //stepBase: 0, 0 = default
673
+ asDate: function(val){
674
+ return new Date(typeProtos.date.asNumber(val+'-01'));
675
+ },
676
+ asNumber: function(val){
677
+ //1970-01
678
+ var ret = nan;
679
+ if(val && !this.mismatch(val)){
680
+ val = val.split(/\u002D/);
681
+ val[0] = (val[0] * 1) - 1970;
682
+ val[1] = (val[1] * 1) - 1;
683
+ ret = (val[0] * 12) + val[1];
684
+ }
685
+ return ret;
686
+ },
687
+ numberToString: function(num){
688
+ var mod;
689
+ var ret = false;
690
+ if(isNumber(num)){
691
+ mod = (num % 12);
692
+ num = ((num - mod) / 12) + 1970;
693
+ mod += 1;
694
+ if(mod < 1){
695
+ num -= 1;
696
+ mod += 12;
697
+ }
698
+ ret = addleadingZero(num, 4)+'-'+addleadingZero(mod, 2);
699
+
700
+ }
701
+
702
+ return ret;
703
+ },
704
+ dateToString: function(date){
705
+ if(date && date.getUTCHours){
706
+ var str = typeProtos.date.dateToString(date);
707
+ return (str.split && (str = str.split(/\u002D/))) ? str[0]+'-'+str[1] : false;
708
+ } else {
709
+ return false;
710
+ }
711
+ }
328
712
  }
329
713
  // ,'datetime-local': {
330
714
  // mismatch: function(val, _getParsed){
@@ -360,931 +744,3338 @@ jQuery.webshims.register('form-number-date-api', function($, webshims, window, d
360
744
  if(typeBugs || !supportsType('range') || !supportsType('time')){
361
745
  typeProtos.range = $.extend({}, typeProtos.number, typeProtos.range);
362
746
  typeProtos.time = $.extend({}, typeProtos.date, typeProtos.time);
747
+ typeProtos.month = $.extend({}, typeProtos.date, typeProtos.month);
363
748
  // typeProtos['datetime-local'] = $.extend({}, typeProtos.date, typeProtos.time, typeProtos['datetime-local']);
364
749
  }
365
750
 
366
- if(typeBugs || !supportsType('number')){
367
- webshims.addInputType('number', typeProtos.number);
751
+ //'datetime-local'
752
+ ['number', 'month', 'range', 'date', 'time'].forEach(function(type){
753
+ if(typeBugs || !supportsType(type)){
754
+ webshims.addInputType(type, typeProtos[type]);
755
+ }
756
+ });
757
+
758
+ if($('<input />').prop('labels') == null){
759
+ webshims.defineNodeNamesProperty('button, input, keygen, meter, output, progress, select, textarea', 'labels', {
760
+ prop: {
761
+ get: function(){
762
+ if(this.type == 'hidden'){return null;}
763
+ var id = this.id;
764
+ var labels = $(this)
765
+ .closest('label')
766
+ .filter(function(){
767
+ var hFor = (this.attributes['for'] || {});
768
+ return (!hFor.specified || hFor.value == id);
769
+ })
770
+ ;
771
+
772
+ if(id) {
773
+ labels = labels.add('label[for="'+ id +'"]');
774
+ }
775
+ return labels.get();
776
+ },
777
+ writeable: false
778
+ }
779
+ });
368
780
  }
369
781
 
370
- if(typeBugs || !supportsType('range')){
371
- webshims.addInputType('range', typeProtos.range);
372
- }
373
- if(typeBugs || !supportsType('date')){
374
- webshims.addInputType('date', typeProtos.date);
375
- }
376
- if(typeBugs || !supportsType('time')){
377
- webshims.addInputType('time', typeProtos.time);
378
- }
379
-
380
- // if(typeBugs || !supportsType('datetime-local')){
381
- // webshims.addInputType('datetime-local', typeProtos['datetime-local']);
382
- // }
383
-
384
782
  });
385
- /* number-date-ui */
386
- /* https://github.com/aFarkas/webshim/issues#issue/23 */
387
- jQuery.webshims.register('form-number-date-ui', function($, webshims, window, document, undefined, options){
388
- "use strict";
783
+ (function($){
389
784
 
390
- var triggerInlineForm = webshims.triggerInlineForm;
391
- var modernizrInputTypes = Modernizr.inputtypes;
392
- var adjustInputWithBtn = (function(){
393
- var fns = {"padding-box": "innerWidth", "border-box": "outerWidth", "content-box": "width"};
394
- var boxSizing = Modernizr.prefixed && Modernizr.prefixed("boxSizing");
395
-
396
- var getWidth = function(input){
397
- var widthFn = "width";
398
- if(boxSizing){
399
- widthFn = fns[input.css(boxSizing)] || widthFn;
785
+ var id = 0;
786
+ var isNumber = function(string){
787
+ return (typeof string == 'number' || (string && string == string * 1));
788
+ };
789
+ var retDefault = function(val, def){
790
+ if(!(typeof val == 'number' || (val && val == val * 1))){
791
+ return def;
792
+ }
793
+ return val * 1;
794
+ };
795
+ var createOpts = ['step', 'min', 'max', 'readonly', 'title', 'disabled', 'tabindex'];
796
+ var rangeProto = {
797
+ _create: function(){
798
+ var i;
799
+
800
+
801
+ this.element.addClass('ws-range').attr({role: 'slider'}).append('<span class="ws-range-min" /><span class="ws-range-rail"><span class="ws-range-thumb" /></span>');
802
+ this.trail = $('.ws-range-rail', this.element);
803
+ this.range = $('.ws-range-min', this.element);
804
+ this.thumb = $('.ws-range-thumb', this.trail);
805
+
806
+ this.updateMetrics();
807
+
808
+ this.orig = this.options.orig;
809
+
810
+ for(i = 0; i < createOpts.length; i++){
811
+ this[createOpts[i]](this.options[createOpts[i]]);
812
+ }
813
+ this.value = this._value;
814
+ this.value(this.options.value);
815
+ this.initDataList();
816
+ this.element.data('rangeUi', this);
817
+ this.addBindings();
818
+ this._init = true;
819
+ },
820
+ value: $.noop,
821
+ _value: function(val, _noNormalize, animate){
822
+ var left, posDif;
823
+ var o = this.options;
824
+ var oVal = val;
825
+ var thumbStyle = {};
826
+ var rangeStyle = {};
827
+ if(!_noNormalize && parseFloat(val, 10) != val){
828
+ val = o.min + ((o.max - o.min) / 2);
400
829
  }
401
830
 
402
- return {
403
- w: input[widthFn](),
404
- add: widthFn == "width"
405
- };
831
+ if(!_noNormalize){
832
+ val = this.normalizeVal(val);
833
+ }
834
+ left = 100 * ((val - o.min) / (o.max - o.min));
406
835
 
407
- };
408
-
409
-
410
- return function(input, button){
411
- var inputDim = getWidth(input);
412
- if(!inputDim.w){return;}
413
- var controlDim = {
414
- mL: (parseInt(button.css('marginLeft'), 10) || 0),
415
- w: button.outerWidth()
416
- };
417
- inputDim.mR = (parseInt(input.css('marginRight'), 10) || 0);
418
- if(inputDim.mR){
419
- input.css('marginRight', 0);
836
+ this.options.value = val;
837
+ this.thumb.stop();
838
+ this.range.stop();
839
+
840
+ rangeStyle[this.dirs.width] = left+'%';
841
+ if(this.vertical){
842
+ left = Math.abs(left - 100);
420
843
  }
421
- //is inside
422
- if( controlDim.mL <= (controlDim.w * -1) ){
423
- button.css('marginRight', Math.floor(Math.abs(controlDim.w + controlDim.mL - 0.1) + inputDim.mR));
424
- input.css('paddingRight', (parseInt(input.css('paddingRight'), 10) || 0) + Math.abs(controlDim.mL));
425
- if(inputDim.add){
426
- input.css('width', Math.floor(inputDim.w + controlDim.mL - (boxSizing ? 0.1 : 0.6)));
427
- }
844
+ thumbStyle[this.dirs.left] = left+'%';
845
+
846
+
847
+ if(!animate){
848
+ this.thumb.css(thumbStyle);
849
+ this.range.css(rangeStyle);
428
850
  } else {
429
- button.css('marginRight', inputDim.mR);
430
- input.css('width', Math.floor(inputDim.w - controlDim.mL - controlDim.w - (boxSizing ? 0.2 : 0.6)));
851
+ if(typeof animate != 'object'){
852
+ animate = {};
853
+ } else {
854
+ animate = $.extend({}, animate);
855
+ }
856
+ if(!animate.duration){
857
+ posDif = Math.abs(left - parseInt(this.thumb[0].style[this.dirs.left] || 50, 10));
858
+ animate.duration = Math.max(Math.min(999, posDif * 5), 99);
859
+ }
860
+ this.thumb.animate(thumbStyle, animate);
861
+ this.range.animate(rangeStyle, animate);
431
862
  }
432
- };
433
- })();
434
-
435
-
436
- var defaultDatepicker = {};
437
- var labelID = 0;
438
- var emptyJ = $([]);
439
- var isCheckValidity;
440
- var replaceInputUI = function(context, elem){
441
- $('input', context).add(elem.filter('input')).each(function(){
442
- var type = $.prop(this, 'type');
443
- if(replaceInputUI[type] && !webshims.data(this, 'shadowData')){
444
- replaceInputUI[type]($(this));
863
+ if(this.orig && (oVal != val || (!this._init && this.orig.value != val)) ){
864
+ this.options._change(val);
445
865
  }
446
- });
447
- };
448
- //set date is extremly slow in IE so we do it lazy
449
- var lazySetDate = function(elem, date){
450
- if(!options.lazyDate){
451
- elem.datepicker('setDate', date);
452
- return;
453
- }
454
- var timer = $.data(elem[0], 'setDateLazyTimer');
455
- if(timer){
456
- clearTimeout(timer);
457
- }
458
- $.data(elem[0], 'setDateLazyTimer', setTimeout(function(){
459
- elem.datepicker('setDate', date);
460
- $.removeData(elem[0], 'setDateLazyTimer');
461
- elem = null;
462
- }, 0));
463
- };
464
-
465
-
466
- var copyAttrs = {
467
- tabindex: 1,
468
- tabIndex: 1,
469
- title: 1,
470
- "aria-required": 1,
471
- "aria-invalid": 1
472
- };
473
- if(!options.copyAttrs){
474
- options.copyAttrs = {};
475
- }
476
-
477
- webshims.extendUNDEFProp(options.copyAttrs, copyAttrs);
478
-
479
- var getDimensions = function(orig){
480
- return (options.calculateWidth) ?
481
- {
482
- css: {
483
- marginRight: orig.css('marginRight'),
484
- marginLeft: orig.css('marginLeft')
485
- },
486
- outerWidth: orig.outerWidth()
866
+ this.element.attr({
867
+ 'aria-valuenow': this.options.value,
868
+ 'aria-valuetext': this.options.textValue ? this.options.textValue(this.options.value) : this.options.options[this.options.value] || this.options.value
869
+ });
870
+ },
871
+ initDataList: function(){
872
+ if(this.orig){
873
+ var listTimer;
874
+ var that = this;
875
+ var updateList = function(){
876
+ $(that.orig)
877
+ .jProp('list')
878
+ .off('updateDatalist', updateList)
879
+ .on('updateDatalist', updateList)
880
+ ;
881
+ clearTimeout(listTimer);
882
+ listTimer = setTimeout(function(){
883
+ if(that.list){
884
+ that.list();
885
+ }
886
+ }, 9);
887
+
888
+ };
487
889
 
488
- } :
489
- {}
490
- ;
491
- };
492
- var focusAttrs = copyAttrs;
493
-
494
- replaceInputUI.common = function(orig, shim, methods){
495
- if(Modernizr.formvalidation){
496
- orig.on('firstinvalid', function(e){
497
- if(!webshims.fromSubmit && isCheckValidity){return;}
498
- orig.off('invalid.replacedwidgetbubble').on('invalid.replacedwidgetbubble', function(evt){
499
- if(!e.isInvalidUIPrevented() && !evt.isDefaultPrevented()){
500
- webshims.validityAlert.showFor( e.target );
501
- e.preventDefault();
502
- evt.preventDefault();
503
- }
504
- orig.off('invalid.replacedwidgetbubble');
505
- });
890
+ $(this.orig).on('listdatalistchange', updateList);
891
+ this.list();
892
+ }
893
+ },
894
+ list: function(opts){
895
+ var o = this.options;
896
+ var min = o.min;
897
+ var max = o.max;
898
+ var trail = this.trail;
899
+ var that = this;
900
+
901
+ this.element.attr({'aria-valuetext': o.options[o.value] || o.value});
902
+ $('.ws-range-ticks', trail).remove();
903
+
904
+
905
+ $(this.orig).jProp('list').find('option').each(function(){
906
+ o.options[$.prop(this, 'value')] = $.prop(this, 'label');
506
907
  });
507
- }
508
- var i, prop;
509
- var focusElement = $('input, span.ui-slider-handle', shim);
510
- var attrs = orig[0].attributes;
511
- for(i in options.copyAttrs){
512
- if ((prop = attrs[i]) && prop.specified) {
513
- if(focusAttrs[i] && focusElement[0]){
514
- focusElement.attr(i, prop.nodeValue);
515
- } else {
516
- shim[0].setAttribute(i, prop.nodeValue);
908
+
909
+ $.each(o.options, function(val, label){
910
+ if(!isNumber(val) || val < min || val > max){return;}
911
+ var left = 100 * ((val - min) / (max - min));
912
+ var title = o.showLabels ? ' title="'+ label +'"' : '';
913
+ if(that.vertical){
914
+ left = Math.abs(left - 100);
517
915
  }
916
+ trail.append('<span class="ws-range-ticks"'+ title +' style="'+(that.dirs.left)+': '+left+'%;" />');
917
+ });
918
+ },
919
+ readonly: function(val){
920
+ val = !!val;
921
+ this.options.readonly = val;
922
+ this.element.attr('aria-readonly', ''+val);
923
+ },
924
+ disabled: function(val){
925
+ val = !!val;
926
+ this.options.disabled = val;
927
+ if(val){
928
+ this.element.attr({tabindex: -1, 'aria-disabled': 'true'});
929
+ } else {
930
+ this.element.attr({tabindex: this.options.tabindex, 'aria-disabled': 'false'});
518
931
  }
519
- }
520
-
521
- var id = orig.attr('id'),
522
- label = (id) ? $('label[for="'+ id +'"]', orig[0].form) : emptyJ
523
- ;
524
-
525
-
526
-
527
- shim.addClass(orig[0].className);
528
- webshims.addShadowDom(orig, shim, {
529
- data: methods || {},
530
- shadowFocusElement: $('input.input-datetime-local-date, span.ui-slider-handle', shim)[0],
531
- shadowChilds: focusElement
532
- });
533
-
534
- orig.after(shim);
932
+ },
933
+ tabindex: function(val){
934
+ this.options.tabindex = val;
935
+ if(!this.options.disabled){
936
+ this.element.attr({tabindex: val});
937
+ }
938
+ },
939
+ title: function(val){
940
+ this.element.prop('title', val);
941
+ },
942
+ min: function(val){
943
+ this.options.min = retDefault(val, 0);
944
+ this.value(this.options.value, true);
945
+ },
946
+ max: function(val){
947
+ this.options.max = retDefault(val, 100);
948
+ this.value(this.options.value, true);
949
+ },
950
+ step: function(val){
951
+ this.options.step = val == 'any' ? 'any' : retDefault(val, 1);
952
+ this.value(this.options.value);
953
+ },
535
954
 
536
- if(orig[0].form){
537
- $(orig[0].form).on('reset', function(e){
538
- if(e.originalEvent && !e.isDefaultPrevented()){
539
- setTimeout(function(){orig.prop( 'value', orig.prop('value') );}, 0);
955
+ normalizeVal: function(val){
956
+ var valModStep, alignValue, step;
957
+ var o = this.options;
958
+
959
+ if(val <= o.min){
960
+ val = o.min;
961
+ } else if(val >= o.max) {
962
+ val = o.max;
963
+ } else if(o.step != 'any'){
964
+ step = o.step;
965
+ valModStep = (val - o.min) % step;
966
+ alignValue = val - valModStep;
967
+
968
+ if ( Math.abs(valModStep) * 2 >= step ) {
969
+ alignValue += ( valModStep > 0 ) ? step : ( -step );
540
970
  }
541
- });
542
- }
543
-
544
- if(label[0]){
545
- shim.getShadowFocusElement().attr('aria-labelledby', webshims.getID(label));
546
- label.on('click', function(){
547
- orig.getShadowFocusElement().focus();
548
- return false;
549
- });
550
- }
551
- };
552
-
553
- if(Modernizr.formvalidation){
554
- ['input', 'form'].forEach(function(name){
555
- var desc = webshims.defineNodeNameProperty(name, 'checkValidity', {
556
- prop: {
557
- value: function(){
558
- isCheckValidity = true;
559
- var ret = desc.prop._supvalue.apply(this, arguments);
560
- isCheckValidity = false;
561
- return ret;
971
+ val = alignValue.toFixed(5) * 1;
972
+ }
973
+ return val;
974
+ },
975
+ doStep: function(factor, animate){
976
+ var step = retDefault(this.options.step, 1);
977
+ if(this.options.step == 'any'){
978
+ step = Math.min(step, (this.options.max - this.options.min) / 10);
979
+ }
980
+ this.value( this.options.value + (step * factor), false, animate );
981
+
982
+ },
983
+
984
+ getStepedValueFromPos: function(pos){
985
+ var val, valModStep, alignValue, step;
986
+
987
+ if(pos <= 0){
988
+ val = this.options[this.dirs.min];
989
+ } else if(pos > 100) {
990
+ val = this.options[this.dirs.max];
991
+ } else {
992
+ if(this.vertical){
993
+ pos = Math.abs(pos - 100);
994
+ }
995
+ val = ((this.options.max - this.options.min) * (pos / 100)) + this.options.min;
996
+ step = this.options.step;
997
+ if(step != 'any'){
998
+ valModStep = (val - this.options.min) % step;
999
+ alignValue = val - valModStep;
1000
+
1001
+ if ( Math.abs(valModStep) * 2 >= step ) {
1002
+ alignValue += ( valModStep > 0 ) ? step : ( -step );
562
1003
  }
1004
+ val = ((alignValue).toFixed(5)) * 1;
1005
+
563
1006
  }
564
- });
565
- });
566
- }
567
- //date and datetime-local implement if we have to replace
568
- if(!modernizrInputTypes['date'] /*||!modernizrInputTypes['datetime-local']*/ || options.replaceUI){
569
-
570
- var datetimeFactor = {
571
- trigger: [0.595,0.395],
572
- normal: [0.565,0.425]
573
- };
574
-
575
- var configureDatePicker = function(elem, datePicker, change, _wrapper){
576
- var stopFocusout;
577
- var focusedOut;
578
- var resetFocusHandler = function(){
579
- data.dpDiv.unbind('mousedown.webshimsmousedownhandler');
580
- stopFocusout = false;
581
- focusedOut = false;
582
- };
583
- var data = datePicker
584
- .on({
585
- focusin: function(){
586
- resetFocusHandler();
587
- data.dpDiv.unbind('mousedown.webshimsmousedownhandler').bind('mousedown.webshimsmousedownhandler', function(){
588
- stopFocusout = true;
589
- });
590
- },
591
- 'focusout blur': function(e){
592
- if(stopFocusout){
593
- focusedOut = true;
594
- e.stopImmediatePropagation();
1007
+ }
1008
+
1009
+ return val;
1010
+ },
1011
+ addBindings: function(){
1012
+ var leftOffset, widgetUnits, hasFocus;
1013
+ var that = this;
1014
+ var o = this.options;
1015
+
1016
+ var eventTimer = (function(){
1017
+ var events = {};
1018
+ return {
1019
+ init: function(name, curVal, fn){
1020
+ if(!events[name]){
1021
+ events[name] = {fn: fn};
1022
+ if(that.orig){
1023
+ $(that.orig).on(name, function(){
1024
+ events[name].val = $.prop(that.orig, 'value');
1025
+ });
1026
+ }
1027
+
595
1028
  }
596
- }
597
- })
598
- .datepicker($.extend({
599
- onClose: function(){
600
- if(focusedOut && datePicker.not(':focus')){
601
- resetFocusHandler();
602
- datePicker.trigger('focusout');
603
- datePicker.triggerHandler('blur');
604
- } else {
605
- resetFocusHandler();
1029
+ events[name].val = curVal;
1030
+ },
1031
+ call: function(name, val){
1032
+ if(events[name].val != val){
1033
+ clearTimeout(events[name].timer);
1034
+ events[name].val = val;
1035
+ events[name].timer = setTimeout(function(){
1036
+ events[name].fn(val, that);
1037
+ }, 0);
606
1038
  }
607
1039
  }
608
- }, defaultDatepicker, options.datepicker, elem.data('datepicker')))
609
- .on('change', change)
610
- .data('datepicker')
611
- ;
612
- data.dpDiv.addClass('input-date-datepicker-control');
1040
+ };
1041
+ })();
613
1042
 
614
- if(_wrapper){
615
- webshims.triggerDomUpdate(_wrapper[0]);
616
- }
617
- ['disabled', 'min', 'max', 'value', 'step', 'data-placeholder'].forEach(function(name){
618
- var fn = 'data-placeholder' ? 'attr' : 'prop';
619
- var val = elem[fn](name);
620
- if(val){
621
- elem[fn](name, val);
1043
+ var setValueFromPos = function(e, animate){
1044
+
1045
+ var val = that.getStepedValueFromPos((e[that.dirs.mouse] - leftOffset) * widgetUnits);
1046
+ if(val != o.value){
1047
+ that.value(val, false, animate);
1048
+ eventTimer.call('input', val);
622
1049
  }
623
- });
624
-
625
- return data;
626
- };
627
-
628
- // replaceInputUI['datetime-local'] = function(elem){
629
- // if(!$.fn.datepicker){return;}
630
- //
631
- // var date = $('<span role="group" class="input-datetime-local"><input type="text" class="input-datetime-local-date" /><input type="time" class="input-datetime-local-time" /></span>'),
632
- // attr = this.common(elem, date, replaceInputUI['datetime-local'].attrs),
633
- // datePicker = $('input.input-datetime-local-date', date),
634
- // datePickerChange = function(e){
635
- //
636
- // var value = datePicker.prop('value') || '',
637
- // timeVal = ''
638
- // ;
639
- // if(options.lazyDate){
640
- // var timer = $.data(datePicker[0], 'setDateLazyTimer');
641
- // if(timer){
642
- // clearTimeout(timer);
643
- // $.removeData(datePicker[0], 'setDateLazyTimer');
644
- // }
645
- // }
646
- //
647
- // if(value){
648
- // timeVal = $('input.input-datetime-local-time', date).prop('value') || '00:00';
649
- // try {
650
- // value = $.datepicker.parseDate(datePicker.datepicker('option', 'dateFormat'), value);
651
- // value = (value) ? $.datepicker.formatDate('yy-mm-dd', value) : datePicker.prop('value');
652
- // } catch (e) {value = datePicker.prop('value');}
653
- // }
654
- // value = (!value && !timeVal) ? '' : value + 'T' + timeVal;
655
- // replaceInputUI['datetime-local'].blockAttr = true;
656
- // elem.prop('value', value);
657
- // replaceInputUI['datetime-local'].blockAttr = false;
658
- // e.stopImmediatePropagation();
659
- // triggerInlineForm(elem[0], 'input');
660
- // triggerInlineForm(elem[0], 'change');
661
- // },
662
- // data = configureDatePicker(elem, datePicker, datePickerChange, date)
663
- // ;
664
- //
665
- //
666
- // $('input.input-datetime-local-time', date).bind('change', function(e){
667
- // var timeVal = $.prop(this, 'value');
668
- // var val = ['', ''];
669
- // if(timeVal){
670
- // val = elem.prop('value').split('T');
671
- // if((val.length < 2 || !val[0])){
672
- // val[0] = $.datepicker.formatDate('yy-mm-dd', new Date());
673
- // }
674
- // val[1] = timeVal;
675
- //
676
- // if (timeVal) {
677
- // try {
678
- // datePicker.prop('value', $.datepicker.formatDate(datePicker.datepicker('option', 'dateFormat'), $.datepicker.parseDate('yy-mm-dd', val[0])));
679
- // } catch (e) {}
680
- // }
681
- // }
682
- // val = (!val[0] && !val[1]) ? '' : val.join('T');
683
- // replaceInputUI['datetime-local'].blockAttr = true;
684
- // elem.prop('value', val);
685
- // replaceInputUI['datetime-local'].blockAttr = false;
686
- // e.stopImmediatePropagation();
687
- // triggerInlineForm(elem[0], 'input');
688
- // triggerInlineForm(elem[0], 'change');
689
- // });
690
- //
691
- //
692
- //
693
- // date.attr('aria-labelledby', attr.label.attr('id'));
694
- // attr.label.bind('click', function(){
695
- // datePicker.focus();
696
- // return false;
697
- // });
698
- //
699
- // if(attr.css){
700
- // date.css(attr.css);
701
- // if(attr.outerWidth){
702
- // date.outerWidth(attr.outerWidth);
703
- // var width = date.width();
704
- // var widthFac = (data.trigger[0]) ? datetimeFactor.trigger : datetimeFactor.normal;
705
- // datePicker.outerWidth(Math.floor((width * widthFac[0]) - subPixelCorrect), true);
706
- // $('input.input-datetime-local-time', date).outerWidth(Math.floor((width * widthFac[1]) - subPixelCorrect), true);
707
- // if(data.trigger[0]){
708
- // adjustInputWithBtn(datePicker, data.trigger);
709
- // }
710
- // }
711
- // }
712
- //
713
- //
714
- // };
715
- //
716
- // replaceInputUI['datetime-local'].attrs = {
717
- // disabled: function(orig, shim, value){
718
- // $('input.input-datetime-local-date', shim).prop('disabled', !!value);
719
- // $('input.input-datetime-local-time', shim).prop('disabled', !!value);
720
- // },
721
- // step: function(orig, shim, value){
722
- // $('input.input-datetime-local-time', shim).attr('step', value);
723
- // },
724
- // //ToDo: use min also on time
725
- // min: function(orig, shim, value){
726
- // if(value){
727
- // value = (value.split) ? value.split('T') : [];
728
- // try {
729
- // value = $.datepicker.parseDate('yy-mm-dd', value[0]);
730
- // } catch(e){value = false;}
731
- // }
732
- // if(!value){
733
- // value = null;
734
- // }
735
- // $('input.input-datetime-local-date', shim).datepicker('option', 'minDate', value);
736
- //
737
- // },
738
- // //ToDo: use max also on time
739
- // max: function(orig, shim, value){
740
- // if(value){
741
- // value = (value.split) ? value.split('T') : [];
742
- // try {
743
- // value = $.datepicker.parseDate('yy-mm-dd', value[0]);
744
- // } catch(e){value = false;}
745
- // }
746
- // if(!value){
747
- // value = null;
748
- // }
749
- // $('input.input-datetime-local-date', shim).datepicker('option', 'maxDate', value);
750
- // },
751
- // value: function(orig, shim, value){
752
- // var dateValue;
753
- // if(value){
754
- // value = (value.split) ? value.split('T') : [];
755
- // try {
756
- // dateValue = $.datepicker.parseDate('yy-mm-dd', value[0]);
757
- // } catch(e){dateValue = false;}
758
- // }
759
- // if(dateValue){
760
- // if(!replaceInputUI['datetime-local'].blockAttr){
761
- // lazySetDate($('input.input-datetime-local-date', shim), dateValue);
762
- // }
763
- // $('input.input-datetime-local-time', shim).prop('value', value[1] || '00:00');
764
- // } else {
765
- // $('input.input-datetime-local-date', shim).prop('value', value[0] || '');
766
- // $('input.input-datetime-local-time', shim).prop('value', value[1] || '');
767
- // }
768
- //
769
- //
770
- // }
771
- // };
772
-
773
-
774
- replaceInputUI.date = function(elem){
1050
+ };
775
1051
 
776
- if(!$.fn.datepicker){return;}
777
- var date = $('<input class="input-date" type="text" />'),
778
-
779
- change = function(e){
780
-
781
- replaceInputUI.date.blockAttr = true;
782
- var value;
783
- if(options.lazyDate){
784
- var timer = $.data(date[0], 'setDateLazyTimer');
785
- if(timer){
786
- clearTimeout(timer);
787
- $.removeData(date[0], 'setDateLazyTimer');
788
- }
789
- }
790
- try {
791
- value = $.datepicker.parseDate(date.datepicker('option', 'dateFormat'), date.prop('value') );
792
- value = (value) ? $.datepicker.formatDate( 'yy-mm-dd', value ) : date.prop('value');
793
- } catch(e){
794
- value = date.prop('value');
1052
+ var remove = function(e){
1053
+ if(e && e.type == 'mouseup'){
1054
+ eventTimer.call('input', o.value);
1055
+ eventTimer.call('change', o.value);
1056
+ }
1057
+ that.element.removeClass('ws-active');
1058
+ $(document).off('mousemove', setValueFromPos).off('mouseup', remove);
1059
+ };
1060
+ var add = function(e){
1061
+ e.preventDefault();
1062
+ $(document).off('mousemove', setValueFromPos).off('mouseup', remove);
1063
+ if(!o.readonly && !o.disabled){
1064
+ leftOffset = that.element.focus().addClass('ws-active').offset();
1065
+ widgetUnits = that.element[that.dirs.width]();
1066
+ if(!widgetUnits || !leftOffset){return;}
1067
+ leftOffset = leftOffset[that.dirs.pos];
1068
+ widgetUnits = 100 / (widgetUnits - ((that.thumb[that.dirs.outerWidth]() || 2) / 2));
1069
+ setValueFromPos(e, o.animate);
1070
+ $(document)
1071
+ .on({
1072
+ mouseup: remove,
1073
+ mousemove: setValueFromPos
1074
+ })
1075
+ ;
1076
+ e.stopPropagation();
1077
+ }
1078
+ };
1079
+ var elementEvts = {
1080
+ mousedown: add,
1081
+ focus: function(e){
1082
+ if(!o.disabled){
1083
+ eventTimer.init('input', o.value);
1084
+ eventTimer.init('change', o.value);
1085
+ that.element.addClass('ws-focus');
795
1086
  }
796
- elem.prop('value', value);
797
- replaceInputUI.date.blockAttr = false;
798
- e.stopImmediatePropagation();
799
- triggerInlineForm(elem[0], 'input');
800
- triggerInlineForm(elem[0], 'change');
1087
+ hasFocus = true;
1088
+ },
1089
+ blur: function(e){
1090
+ that.element.removeClass('ws-focus ws-active');
1091
+ hasFocus = false;
1092
+ eventTimer.init('input', o.value);
1093
+ eventTimer.call('change', o.value);
1094
+ },
1095
+ keyup: function(){
1096
+ that.element.removeClass('ws-active');
1097
+ eventTimer.call('input', o.value);
1098
+ eventTimer.call('change', o.value);
801
1099
  },
802
- data
803
1100
 
804
- ;
1101
+ keydown: function(e){
1102
+ var step = true;
1103
+ var code = e.keyCode;
1104
+ if(!o.readonly && !o.disabled){
1105
+ if (code == 39 || code == 38) {
1106
+ that.doStep(1);
1107
+ } else if (code == 37 || code == 40) {
1108
+ that.doStep(-1);
1109
+ } else if (code == 33) {
1110
+ that.doStep(10, o.animate);
1111
+ } else if (code == 34) {
1112
+ that.doStep(-10, o.animate);
1113
+ } else if (code == 36) {
1114
+ that.value(that.options.max, false, o.animate);
1115
+ } else if (code == 35) {
1116
+ that.value(that.options.min, false, o.animate);
1117
+ } else {
1118
+ step = false;
1119
+ }
1120
+ if (step) {
1121
+ that.element.addClass('ws-active');
1122
+ eventTimer.call('input', o.value);
1123
+ e.preventDefault();
1124
+ }
1125
+ }
1126
+ }
1127
+ };
805
1128
 
806
- this.common(elem, date, replaceInputUI.date.attrs);
1129
+ eventTimer.init('input', o.value, this.options.input);
1130
+ eventTimer.init('change', o.value, this.options.change);
807
1131
 
808
- data = configureDatePicker(elem, date, change);
1132
+ elementEvts[$.fn.mwheelIntent ? 'mwheelIntent' : 'mousewheel'] = function(e, delta){
1133
+ if(delta && hasFocus && !o.readonly && !o.disabled){
1134
+ that.doStep(delta);
1135
+ e.preventDefault();
1136
+ eventTimer.call('input', o.value);
1137
+ }
1138
+ };
1139
+ this.element.on(elementEvts);
1140
+ this.thumb.on({
1141
+ mousedown: add
1142
+ });
1143
+ },
1144
+ updateMetrics: function(){
1145
+ var width = this.element.innerWidth();
1146
+ this.vertical = (width && this.element.innerHeight() - width > 10);
809
1147
 
810
- $(document)
811
- .onTrigger('updateshadowdom', function(){
812
- if (data.trigger[0]) {
813
- elem.css({display: ''});
814
- if(elem[0].offsetWidth || elem[0].offsetHeight){
815
- var attr = getDimensions(elem);
816
- if (attr.css) {
817
- date.css(attr.css);
818
- if (attr.outerWidth) {
819
- date.outerWidth(attr.outerWidth);
820
- }
821
- adjustInputWithBtn(date, data.trigger);
822
- }
1148
+ this.dirs = this.vertical ?
1149
+ {mouse: 'pageY', pos: 'top', min: 'max', max: 'min', left: 'top', width: 'height', outerWidth: 'outerHeight'} :
1150
+ {mouse: 'pageX', pos: 'left', min: 'min', max: 'max', left: 'left', width: 'width', outerWidth: 'outerWidth'}
1151
+ ;
1152
+ this.element
1153
+ [this.vertical ? 'addClass' : 'removeClass']('vertical-range')
1154
+ [this.vertical ? 'addClass' : 'removeClass']('horizontal-range')
1155
+ ;
1156
+ }
1157
+ };
1158
+
1159
+ $.fn.rangeUI = function(opts){
1160
+ opts = $.extend({readonly: false, disabled: false, tabindex: 0, min: 0, step: 1, max: 100, value: 50, input: $.noop, change: $.noop, _change: $.noop, showLabels: true, options: {}}, opts);
1161
+ return this.each(function(){
1162
+ $.webshims.objectCreate(rangeProto, {
1163
+ element: {
1164
+ value: $(this)
1165
+ }
1166
+ }, opts);
1167
+ });
1168
+ };
1169
+ jQuery.webshims.isReady('range-ui', true);
1170
+ })(jQuery);
1171
+ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, document, undefined, options){
1172
+ "use strict";
1173
+ var curCfg;
1174
+ var formcfg = $.webshims.formcfg;
1175
+
1176
+ var stopPropagation = function(e){
1177
+ e.stopImmediatePropagation(e);
1178
+ };
1179
+ var createFormat = function(name){
1180
+ if(!curCfg.patterns[name+'Obj']){
1181
+ var obj = {};
1182
+ $.each(curCfg.patterns[name].split(curCfg[name+'Format']), function(i, name){
1183
+ obj[name] = i;
1184
+ });
1185
+ curCfg.patterns[name+'Obj'] = obj;
1186
+ }
1187
+ };
1188
+ var splitInputs = {
1189
+ date: {
1190
+ _create: function(){
1191
+ var obj = {
1192
+ splits: [$('<input type="text" class="yy" size="4" maxlength />')[0], $('<input type="text" class="mm" maxlength="2" size="2" />')[0], $('<input type="text" class="dd ws-spin" maxlength="2" size="2" />')[0]]
1193
+ };
1194
+ obj.elements = [obj.splits[0], $('<span class="ws-input-seperator" />')[0], obj.splits[1], $('<span class="ws-input-seperator" />')[0], obj.splits[2]];
1195
+ return obj;
1196
+ },
1197
+ sort: function(element){
1198
+ createFormat('d');
1199
+ var i = 0;
1200
+ var seperators = $('.ws-input-seperator', element).html(curCfg.dFormat);
1201
+ var inputs = $('input', element);
1202
+ $.each(curCfg.patterns.dObj, function(name, value){
1203
+ var input = inputs.filter('.'+ name);
1204
+ if(input[0]){
1205
+
1206
+ input.appendTo(element);
1207
+ if(i < seperators.length){
1208
+ seperators.eq(i).insertAfter(input);
823
1209
  }
1210
+ i++;
824
1211
  }
825
- elem.css({display: 'none'});
826
- })
827
- ;
1212
+ });
1213
+ }
1214
+ },
1215
+ month: {
1216
+ _create: function(){
1217
+ var obj = {
1218
+ splits: [$('<input type="text" class="yy" size="4" />')[0], $('<input type="text" class="mm ws-spin" />')[0]]
1219
+ };
1220
+ obj.elements = [obj.splits[0], $('<span class="ws-input-seperator" />')[0], obj.splits[1]];
1221
+ return obj;
1222
+ },
1223
+ sort: function(element){
1224
+ var seperator = $('.ws-input-seperator', element).html(curCfg.dFormat);
1225
+ var mm = $('input.mm', element);
1226
+ var action;
1227
+ if(curCfg.date.showMonthAfterYear){
1228
+ mm.appendTo(element);
1229
+ action = 'insertBefore';
1230
+ } else {
1231
+ mm.prependTo(element);
1232
+ action = 'insertAfter';
1233
+ }
1234
+ seperator[action](mm);
1235
+ }
1236
+ }
1237
+ };
1238
+ var labelWidth = (function(){
1239
+ var getId = function(){
1240
+ return webshims.getID(this);
828
1241
  };
1242
+ return function(element, labels, noFocus){
1243
+ $(element).attr({'aria-labelledby': labels.map(getId).get().join(' ')});
1244
+ if(!noFocus){
1245
+ labels.on('click', function(e){
1246
+ element.getShadowFocusElement().focus();
1247
+ e.preventDefault();
1248
+ return false;
1249
+ });
1250
+ }
1251
+ };
1252
+ })();
1253
+ var addZero = function(val){
1254
+ if(!val){return "";}
1255
+ val = val+'';
1256
+ return val.length == 1 ? '0'+val : val;
1257
+ };
1258
+
829
1259
 
830
-
831
- replaceInputUI.date.attrs = {
832
- disabled: function(orig, shim, value){
833
- $.prop(shim, 'disabled', !!value);
1260
+ (function(){
1261
+ var monthDigits = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
1262
+ formcfg.de = {
1263
+ numberFormat: {
1264
+ ",": ".",
1265
+ ".": ","
834
1266
  },
835
- min: function(orig, shim, value){
836
- try {
837
- value = $.datepicker.parseDate('yy-mm-dd', value);
838
- } catch(e){value = false;}
839
- if(value){
840
- $(shim).datepicker('option', 'minDate', value);
841
- }
1267
+ timeSigns: ":. ",
1268
+ numberSigns: ',',
1269
+ dateSigns: '.',
1270
+ dFormat: ".",
1271
+ patterns: {
1272
+ d: "dd.mm.yy"
842
1273
  },
843
- max: function(orig, shim, value){
844
- try {
845
- value = $.datepicker.parseDate('yy-mm-dd', value);
846
- } catch(e){value = false;}
847
- if(value){
848
- $(shim).datepicker('option', 'maxDate', value);
849
- }
1274
+ month: {
1275
+ currentText: 'Aktueller Monat'
850
1276
  },
851
- 'data-placeholder': function(orig, shim, value){
852
- var hintValue = (value || '').split('-');
853
- var dateFormat;
854
- if(hintValue.length == 3){
855
- value = $(shim).datepicker('option','dateFormat').replace('yy', hintValue[0]).replace('mm', hintValue[1]).replace('dd', hintValue[2]);
856
- }
857
- $.prop(shim, 'placeholder', value);
1277
+ date: {
1278
+ close: 'schließen',
1279
+ clear: 'Löschen',
1280
+ prevText: 'Zurück',
1281
+ nextText: 'Vor',
1282
+ currentText: 'Heute',
1283
+ monthNames: ['Januar','Februar','März','April','Mai','Juni',
1284
+ 'Juli','August','September','Oktober','November','Dezember'],
1285
+ monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun',
1286
+ 'Jul','Aug','Sep','Okt','Nov','Dez'],
1287
+ dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
1288
+ dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
1289
+ dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
1290
+ weekHeader: 'KW',
1291
+ firstDay: 1,
1292
+ isRTL: false,
1293
+ showMonthAfterYear: false,
1294
+ yearSuffix: ''
1295
+ }
1296
+ };
1297
+
1298
+ formcfg.en = {
1299
+ numberFormat: {
1300
+ ".": ".",
1301
+ ",": ","
858
1302
  },
859
- value: function(orig, shim, value){
860
- if(!replaceInputUI.date.blockAttr){
861
- try {
862
- var dateValue = $.datepicker.parseDate('yy-mm-dd', value);
863
- } catch(e){var dateValue = false;}
864
-
865
- if(dateValue){
866
- lazySetDate($(shim), dateValue);
867
- } else {
868
- $.prop(shim, 'value', value);
869
- }
1303
+ numberSigns: '.',
1304
+ dateSigns: '/',
1305
+ timeSigns: ":. ",
1306
+ dFormat: "/",
1307
+ patterns: {
1308
+ d: "mm/dd/yy"
1309
+ },
1310
+ month: {
1311
+ currentText: 'This month'
1312
+ },
1313
+ date: {
1314
+ "closeText": "Done",
1315
+ clear: 'Clear',
1316
+ "prevText": "Prev",
1317
+ "nextText": "Next",
1318
+ "currentText": "Today",
1319
+ "monthNames": ["January","February","March","April","May","June","July","August","September","October","November","December"],
1320
+ "monthNamesShort": ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
1321
+ "dayNames": ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],
1322
+ "dayNamesShort": ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],
1323
+ "dayNamesMin": ["Su","Mo","Tu","We","Th","Fr","Sa"],
1324
+ "weekHeader": "Wk",
1325
+ "firstDay": 0,
1326
+ "isRTL": false,
1327
+ "showMonthAfterYear": false,
1328
+ "yearSuffix": ""
1329
+ }
1330
+ };
1331
+
1332
+ formcfg['en-US'] = formcfg['en-US'] || formcfg['en'];
1333
+ formcfg[''] = formcfg[''] || formcfg['en-US'];
1334
+ curCfg = formcfg[''];
1335
+
1336
+ var createMonthKeys = function(langCfg){
1337
+ if(!langCfg.date.monthkeys){
1338
+ var create = function(i, name){
1339
+ var strNum;
1340
+ var num = i + 1;
1341
+ strNum = (num < 10) ? '0'+num : ''+num;
1342
+ langCfg.date.monthkeys[num] = strNum;
1343
+ langCfg.date.monthkeys[name] = strNum;
1344
+ langCfg.date.monthkeys[name.toLowerCase()] = strNum;
1345
+ };
1346
+ langCfg.date.monthkeys = {};
1347
+ langCfg.date.monthDigits = monthDigits;
1348
+ langCfg.numberSigns += '-';
1349
+ $.each(langCfg.date.monthNames, create);
1350
+ $.each(langCfg.date.monthNamesShort, create);
1351
+ }
1352
+ };
1353
+
1354
+ createMonthKeys(curCfg);
1355
+
1356
+ $.webshims.ready('dom-extend', function(){
1357
+ $.webshims.activeLang({
1358
+ register: 'form-core',
1359
+ callback: function(){
1360
+ $.each(arguments, function(i, val){
1361
+ if(formcfg[val]){
1362
+ curCfg = formcfg[val];
1363
+ createMonthKeys(curCfg);
1364
+ $(document).triggerHandler('wslocalechange');
1365
+ return false;
1366
+ }
1367
+ });
870
1368
  }
1369
+ });
1370
+ });
1371
+ })();
1372
+
1373
+
1374
+
1375
+ (function(){
1376
+
1377
+
1378
+ var mousePress = function(e){
1379
+ $(this)[e.type == 'mousepressstart' ? 'addClass' : 'removeClass']('mousepress-ui');
1380
+ };
1381
+
1382
+ var retDefault = function(val, def){
1383
+ if(!(typeof val == 'number' || (val && val == val * 1))){
1384
+ return def;
871
1385
  }
1386
+ return val * 1;
872
1387
  };
873
- }
874
- if (!modernizrInputTypes.range || options.replaceUI) {
875
- replaceInputUI.range = function(elem){
876
- if(!$.fn.slider){return;}
877
- var range = $('<span class="input-range"><span class="ui-slider-handle" role="slider" tabindex="0" /></span>'),
878
- change = function(e, ui){
879
- if(e.originalEvent){
880
- replaceInputUI.range.blockAttr = true;
881
- elem.prop('value', ui.value);
882
- replaceInputUI.range.blockAttr = false;
883
- triggerInlineForm(elem[0], 'input');
1388
+
1389
+ var createOpts = ['step', 'min', 'max', 'readonly', 'title', 'disabled', 'tabindex', 'placeholder', 'value'];
1390
+
1391
+
1392
+ var formatVal = {
1393
+ number: function(val){
1394
+ return (val+'').replace(/\,/g, '').replace(/\./, curCfg.numberFormat['.']);
1395
+ },
1396
+ time: function(val){
1397
+ return val;
1398
+ },
1399
+ //todo empty val for month/split
1400
+ month: function(val, options){
1401
+ var names;
1402
+ var p = val.split('-');
1403
+ if(p[0] && p[1]){
1404
+ names = curCfg.date[options.formatMonthNames] || curCfg.date[options.monthNames] || curCfg.date.monthNames;
1405
+ p[1] = names[(p[1] * 1) - 1];
1406
+ if(options && options.splitInput){
1407
+ val = [p[0] || '', p[1] || ''];
1408
+ } else if(p[1]){
1409
+ val = curCfg.date.showMonthAfterYear ? p.join(' ') : p[1]+' '+p[0];
884
1410
  }
885
1411
  }
886
- ;
887
-
888
- this.common(elem, range, replaceInputUI.range.attrs);
889
-
890
-
891
- $(document)
892
- .onTrigger('updateshadowdom', function(){
893
- elem.css({display: ''});
894
- if (elem[0].offsetWidth || elem[0].offsetHeight) {
895
- var attr = getDimensions(elem);
896
- if (attr.css) {
897
- range.css(attr.css);
898
- if (attr.outerWidth) {
899
- range.outerWidth(attr.outerWidth);
900
- }
901
- }
902
- }
903
- elem.css({display: 'none'});
904
- })
905
- ;
906
-
907
-
908
- range.slider($.extend(true, {}, options.slider, elem.data('slider')))
909
- .on({
910
- slide: change,
911
- slidechange: function(e){
912
- if(e.originalEvent){
913
- triggerInlineForm(elem[0], 'change');
914
- }
915
- }
916
- })
917
- ;
918
-
919
- ['disabled', 'min', 'max', 'step', 'value'].forEach(function(name){
920
- var val = elem.prop(name);
921
- var shadow;
922
- if(name == 'value' && !val){
923
-
924
- shadow = elem.getShadowElement();
925
- if(shadow){
926
- val = ($(shadow).slider('option', 'max') - $(shadow).slider('option', 'min')) / 2;
1412
+ return val;
1413
+ },
1414
+ date: function(val, opts){
1415
+ var p = (val+'').split('-');
1416
+ if(p[2] && p[1] && p[0]){
1417
+ if(opts && opts.splitInput){
1418
+ val = p;
1419
+ } else {
1420
+ val = curCfg.patterns.d.replace('yy', p[0] || '');
1421
+ val = val.replace('mm', p[1] || '');
1422
+ val = val.replace('dd', p[2] || '');
927
1423
  }
1424
+ } else if(opts && opts.splitInput){
1425
+ val = [p[0] || '', p[1] || '', p[2] || ''];
928
1426
  }
929
- if(val != null){
930
- elem.prop(name, val);
931
- }
932
- });
1427
+
1428
+ return val;
1429
+ }
933
1430
  };
934
1431
 
935
- replaceInputUI.range.attrs = {
936
- disabled: function(orig, shim, value){
937
- value = !!value;
938
- $(shim).slider( "option", "disabled", value );
939
- $('span', shim)
940
- .attr({
941
- 'aria-disabled': value+'',
942
- 'tabindex': (value) ? '-1' : '0'
943
- })
944
- ;
1432
+ var parseVal = {
1433
+ number: function(val){
1434
+ return (val+'').replace(curCfg.numberFormat[','], '').replace(curCfg.numberFormat['.'], '.');
945
1435
  },
946
- min: function(orig, shim, value){
947
- value = (value) ? value * 1 || 0 : 0;
948
- $(shim).slider( "option", "min", value );
949
- $('span', shim).attr({'aria-valuemin': value});
1436
+ time: function(val){
1437
+ return val;
950
1438
  },
951
- max: function(orig, shim, value){
952
- value = (value || value === 0) ? value * 1 || 100 : 100;
953
- $(shim).slider( "option", "max", value );
954
- $('span', shim).attr({'aria-valuemax': value});
955
- },
956
- value: function(orig, shim, value){
957
- value = $(orig).prop('valueAsNumber');
958
- if(!isNaN(value)){
959
- if(!replaceInputUI.range.blockAttr){
960
- $(shim).slider( "option", "value", value );
1439
+ month: function(val, opts){
1440
+
1441
+ var p = (!opts.splitInput) ? val.trim().split(/[\.\s-\/\\]+/) : val;
1442
+
1443
+ if(p.length == 2){
1444
+ p[0] = curCfg.date.monthkeys[p[0]] || p[0];
1445
+ p[1] = curCfg.date.monthkeys[p[1]] || p[1];
1446
+ if(p[1].length == 2){
1447
+ val = p[0]+'-'+p[1];
1448
+ } else if(p[0].length == 2){
1449
+ val = p[1]+'-'+p[0];
1450
+ } else {
1451
+ val = '';
961
1452
  }
962
- $('span', shim).attr({'aria-valuenow': value, 'aria-valuetext': value});
1453
+ } else if(opts.splitInput) {
1454
+ val = '';
963
1455
  }
1456
+ return val;
964
1457
  },
965
- step: function(orig, shim, value){
966
- value = (value && $.trim(value)) ? value * 1 || 1 : 1;
967
- $(shim).slider( "option", "step", value );
1458
+ date: function(val, opts){
1459
+ createFormat('d');
1460
+ var i;
1461
+ var obj;
1462
+ if(opts.splitInput){
1463
+ obj = {yy: 0, mm: 1, dd: 2};
1464
+ } else {
1465
+ obj = curCfg.patterns.dObj;
1466
+ val = val.split(curCfg.dFormat);
1467
+ }
1468
+
1469
+ return (val.length == 3 && val[0] && val[1] && val[2]) ?
1470
+ ([addZero(val[obj.yy]), addZero(val[obj.mm]), addZero(val[obj.dd])]).join('-') :
1471
+ ''
1472
+ ;
968
1473
  }
969
1474
  };
970
- }
971
-
972
- if(options.replaceUI || !Modernizr.inputtypes.date /*|| !Modernizr.inputtypes["datetime-local"]*/ || !Modernizr.inputtypes.range){
973
- var reflectFn = function(val){
974
- if(webshims.data(this, 'hasShadow')){
975
- $.prop(this, 'value', $.prop(this, 'value'));
1475
+
1476
+ var steps = {
1477
+ number: {
1478
+ step: 1
1479
+ },
1480
+ time: {
1481
+ step: 60
1482
+ },
1483
+ month: {
1484
+ step: 1,
1485
+ start: new Date()
1486
+ },
1487
+ date: {
1488
+ step: 1,
1489
+ start: new Date()
976
1490
  }
977
1491
  };
978
1492
 
979
- webshims.onNodeNamesPropertyModify('input', 'valueAsNumber', reflectFn);
980
- webshims.onNodeNamesPropertyModify('input', 'valueAsDate', reflectFn);
981
- }
982
-
983
- $.each(['disabled', 'min', 'max', 'value', 'step', 'data-placeholder'], function(i, attr){
984
- webshims.onNodeNamesPropertyModify('input', attr, function(val){
985
- var shadowData = webshims.data(this, 'shadowData');
986
- if(shadowData && shadowData.data && shadowData.data[attr] && shadowData.nativeElement === this){
987
- shadowData.data[attr](this, shadowData.shadowElement, val);
1493
+
1494
+ var placeholderFormat = {
1495
+ date: function(val, opts){
1496
+ var hintValue = (val || '').split('-');
1497
+ if(hintValue.length == 3){
1498
+ hintValue = opts.splitInput ?
1499
+ hintValue :
1500
+ curCfg.patterns.d.replace('yy', hintValue[0]).replace('mm', hintValue[1]).replace('dd', hintValue[2]);
1501
+ } else {
1502
+ hintValue = opts.splitInput ?
1503
+ [val, val, val] :
1504
+ val;
988
1505
  }
989
- }
990
- );
991
- });
992
- if(!options.availabeLangs){
993
- options.availabeLangs = 'af ar ar-DZ az bg bs ca cs da de el en-AU en-GB en-NZ eo es et eu fa fi fo fr fr-CH gl he hr hu hy id is it ja ko kz lt lv ml ms nl no pl pt-BR rm ro ru sk sl sq sr sr-SR sv ta th tr uk vi zh-CN zh-HK zh-TW'.split(' ');
994
- }
995
-
996
- var getDefaults = function(){
997
- if(!$.datepicker){return;}
998
-
999
- webshims.activeLang({
1000
- langObj: $.datepicker.regional,
1001
- module: 'form-number-date-ui',
1002
- callback: function(langObj){
1003
- var datepickerCFG = $.extend({}, defaultDatepicker, langObj, options.datepicker);
1004
-
1005
-
1006
- if(datepickerCFG.dateFormat && options.datepicker.dateFormat != datepickerCFG.dateFormat ){
1007
- $('input.hasDatepicker')
1008
- .filter('.input-date, .input-datetime-local-date')
1009
- .datepicker('option', 'dateFormat', datepickerCFG.dateFormat)
1010
- .getNativeElement()
1011
- .filter('[data-placeholder]')
1012
- .attr('data-placeholder', function(i, val){
1013
- return val;
1014
- })
1015
- ;
1506
+ return hintValue;
1507
+ },
1508
+ month: function(val, opts){
1509
+ var hintValue = (val || '').split('-');
1510
+
1511
+ if(hintValue.length == 2){
1512
+ hintValue = opts.splitInput ?
1513
+ hintValue :
1514
+ curCfg.patterns.d.replace('yy', hintValue[0]).replace('mm', hintValue[1]);
1515
+ } else {
1516
+ hintValue = opts.splitInput ?
1517
+ [val, val] :
1518
+ val;
1016
1519
  }
1017
- $.datepicker.setDefaults(datepickerCFG);
1520
+ return hintValue;
1018
1521
  }
1019
- });
1020
- $(document).unbind('jquery-uiReady.langchange input-widgetsReady.langchange');
1021
- };
1022
-
1023
- $(document).on('jquery-uiReady.langchange input-widgetsReady.langchange', getDefaults);
1024
- getDefaults();
1025
-
1026
- //implement set/arrow controls
1027
- (function(){
1028
- var supportsType = (function(){
1029
- var types = {};
1030
- return function(type){
1031
- if(type in types){
1032
- return types[type];
1033
- }
1034
- return (types[type] = ($('<input type="'+type+'" />')[0].type === type));
1035
1522
  };
1036
- })();
1037
-
1038
- if(supportsType('number') && supportsType('time')){return;}
1039
- var doc = document;
1040
- var options = webshims.cfg["forms-ext"];
1041
- var typeModels = webshims.inputTypes;
1042
- var allowedChars = {
1043
- number: '0123456789.',
1044
- time: '0123456789:.'
1045
- };
1046
-
1047
- var getNextStep = function(input, upDown, cache){
1048
1523
 
1049
- cache = cache || {};
1524
+ var createHelper = (function(){
1525
+ var types = {};
1526
+ return function(type){
1527
+ var input;
1528
+ if(!types[type]){
1529
+ input = $('<input type="'+type+'" />');
1530
+ types[type] = {
1531
+ asNumber: function(val){
1532
+ var type = (typeof val == 'object') ? 'valueAsDate' : 'value';
1533
+ return input.prop(type, val).prop('valueAsNumber');
1534
+ },
1535
+ asValue: function(val){
1536
+ var type = (typeof val == 'object') ? 'valueAsDate' : 'valueAsNumber';
1537
+ return input.prop(type, val).prop('value');
1538
+ }
1539
+ };
1540
+ }
1541
+ return types[type];
1542
+ };
1543
+ })();
1050
1544
 
1051
- if( !('type' in cache) ){
1052
- cache.type = $.prop(input, 'type');
1053
- }
1054
- if( !('step' in cache) ){
1055
- cache.step = webshims.getStep(input, cache.type);
1056
- }
1057
- if( !('valueAsNumber' in cache) ){
1058
- cache.valueAsNumber = typeModels[cache.type].asNumber($.prop(input, 'value'));
1059
- }
1060
- var delta = (cache.step == 'any') ? typeModels[cache.type].step * typeModels[cache.type].stepScaleFactor : cache.step,
1061
- ret
1062
- ;
1063
- webshims.addMinMaxNumberToCache('min', $(input), cache);
1064
- webshims.addMinMaxNumberToCache('max', $(input), cache);
1065
-
1066
- if(isNaN(cache.valueAsNumber)){
1067
- cache.valueAsNumber = typeModels[cache.type].stepBase || 0;
1068
- }
1069
- //make a valid step
1070
- if(cache.step !== 'any'){
1071
- ret = Math.round( ((cache.valueAsNumber - (cache.minAsnumber || 0)) % cache.step) * 1e7 ) / 1e7;
1072
- if(ret && Math.abs(ret) != cache.step){
1073
- cache.valueAsNumber = cache.valueAsNumber - ret;
1074
- }
1075
- }
1076
- ret = cache.valueAsNumber + (delta * upDown);
1077
- //using NUMBER.MIN/MAX is really stupid | ToDo: either use disabled state or make this more usable
1078
- if(!isNaN(cache.minAsNumber) && ret < cache.minAsNumber){
1079
- ret = (cache.valueAsNumber * upDown < cache.minAsNumber) ? cache.minAsNumber : isNaN(cache.maxAsNumber) ? cache.valueAsNumber : cache.maxAsNumber;
1080
- } else if(!isNaN(cache.maxAsNumber) && ret > cache.maxAsNumber){
1081
- ret = (cache.valueAsNumber * upDown > cache.maxAsNumber) ? cache.maxAsNumber : isNaN(cache.minAsNumber) ? cache.valueAsNumber : cache.minAsNumber;
1082
- } else {
1083
- ret = Math.round( ret * 1e7) / 1e7;
1084
- }
1085
- return ret;
1086
- };
1087
-
1088
- webshims.modules["form-number-date-ui"].getNextStep = getNextStep;
1545
+ steps.range = steps.number;
1546
+
1547
+
1548
+ var spinBtnProto = {
1549
+ _create: function(){
1550
+ var i;
1551
+ var o = this.options;
1552
+ var helper = createHelper(o.type);
1553
+ this.type = o.type;
1554
+ this.orig = o.orig;
1555
+
1556
+ this.elemHelper = $('<input type="'+ this.type+'" />');
1557
+ this.asNumber = helper.asNumber;
1558
+ this.asValue = helper.asValue;
1559
+
1560
+ this.buttonWrapper = $('<span class="input-buttons '+this.type+'-input-buttons"><span unselectable="on" class="step-controls"><span class="step-up"></span><span class="step-down"></span></span></span>')
1561
+ .insertAfter(this.element)
1562
+ ;
1563
+
1564
+ if(o.splitInput){
1565
+ this._addSplitInputs();
1566
+ } else {
1567
+ this.inputElements = this.element;
1568
+ }
1569
+
1570
+ this.options.containerElements.push(this.buttonWrapper[0]);
1571
+
1572
+ if(typeof steps[this.type].start == 'object'){
1573
+ steps[this.type].start = this.asNumber(steps[this.type].start);
1574
+ }
1575
+
1576
+
1577
+
1578
+ for(i = 0; i < createOpts.length; i++){
1579
+ this[createOpts[i]](o[createOpts[i]]);
1580
+ }
1581
+
1582
+ this.element.data('wsspinner', this);
1583
+
1584
+ this.addBindings();
1585
+
1586
+ if(!o.min && typeof o.relMin == 'number'){
1587
+ o.min = this.asValue(this.getRelNumber(o.relMin));
1588
+ $.prop(this.orig, 'min', o.min);
1589
+ }
1590
+
1591
+ if(!o.max && typeof o.relMax == 'number'){
1592
+ o.max = this.asValue(this.getRelNumber(o.relMax));
1593
+ $.prop(this.orig, 'max', o.max);
1594
+ }
1595
+
1596
+ this._init = true;
1597
+ },
1598
+ _addSplitInputs: function(){
1599
+ if(!this.inputElements){
1600
+ var create = splitInputs[this.type]._create();
1601
+ this.splits = create.splits;
1602
+ this.inputElements = $(create.elements).prependTo(this.element).filter('input');
1603
+ }
1604
+ },
1605
+ parseValue: function(){
1606
+ var value = this.inputElements.map(function(){
1607
+ return $.prop(this, 'value');
1608
+ }).get();
1609
+ if(!this.options.splitInput){
1610
+ value = value[0];
1611
+ }
1612
+ return parseVal[this.type](value, this.options);
1613
+ },
1614
+ formatValue: function(val, noSplit){
1615
+ return formatVal[this.type](val, noSplit === false ? false : this.options);
1616
+ },
1617
+ placeholder: function(val){
1618
+ var options = this.options;
1619
+ options.placeholder = val;
1620
+ var placeholder = val;
1621
+ if(placeholderFormat[this.type]){
1622
+ placeholder = placeholderFormat[this.type](val, this.options);
1623
+ }
1624
+ if(options.splitInput && typeof placeholder == 'object'){
1625
+ $.each(this.splits, function(i, elem){
1626
+ $.prop(elem, 'placeholder', placeholder[i]);
1627
+ });
1628
+ } else {
1629
+ this.element.prop('placeholder', placeholder);
1630
+ }
1631
+ },
1632
+ getRelNumber: function(rel){
1633
+ var start = steps[this.type].start || 0;
1634
+ if(rel){
1635
+ start += rel;
1636
+ }
1637
+ return start;
1638
+ },
1639
+ addZero: addZero,
1640
+ _setStartInRange: function(){
1641
+ var start = this.getRelNumber(this.options.relDefaultValue);
1642
+ if(!isNaN(this.minAsNumber) && start < this.minAsNumber){
1643
+ start = this.minAsNumber;
1644
+ } else if(!isNaN(this.maxAsNumber) && start > this.maxAsNumber){
1645
+ start = this.maxAsNumber;
1646
+ }
1647
+ this.elemHelper.prop('valueAsNumber', start);
1648
+ this.options.defValue = this.elemHelper.prop('value');
1649
+
1650
+ },
1651
+ reorderInputs: function(){
1652
+ if(splitInputs[this.type]){
1653
+ var element = this.element;
1654
+ splitInputs[this.type].sort(element);
1655
+ setTimeout(function(){
1656
+ var data = webshims.data(element);
1657
+ if(data && data.shadowData){
1658
+ data.shadowData.shadowFocusElement = element.find('input')[0] || element[0];
1659
+ }
1660
+ }, 9);
1661
+ }
1662
+ },
1663
+ value: function(val){
1664
+ this.valueAsNumber = this.asNumber(val);
1665
+ this.options.value = val;
1666
+ if(isNaN(this.valueAsNumber) || (!isNaN(this.minAsNumber) && this.valueAsNumber < this.minAsNumber) || (!isNaN(this.maxAsNumber) && this.valueAsNumber > this.maxAsNumber)){
1667
+ this._setStartInRange();
1668
+ } else {
1669
+ this.elemHelper.prop('value', val);
1670
+ this.options.defValue = "";
1671
+ }
1672
+
1673
+ val = formatVal[this.type](val, this.options);
1674
+ if(this.options.splitInput){
1675
+
1676
+ $.each(this.splits, function(i, elem){
1677
+ $.prop(elem, 'value', val[i]);
1678
+ });
1679
+ } else {
1680
+ this.element.prop('value', val);
1681
+ }
1682
+
1683
+ this._propertyChange('value');
1684
+ },
1685
+ initDataList: function(){
1686
+ var listTimer;
1687
+ var that = this;
1688
+ var updateList = function(){
1689
+ $(that.orig)
1690
+ .jProp('list')
1691
+ .off('updateDatalist', updateList)
1692
+ .on('updateDatalist', updateList)
1693
+ ;
1694
+ clearTimeout(listTimer);
1695
+ listTimer = setTimeout(function(){
1696
+ if(that.list){
1697
+ that.list();
1698
+ }
1699
+ }, 9);
1700
+
1701
+ };
1702
+
1703
+ $(this.orig).onTrigger('listdatalistchange', updateList);
1704
+ },
1705
+ getOptions: function(){
1706
+ var options = {};
1707
+ var datalist = $(this.orig).jProp('list');
1708
+ datalist.find('option').each(function(){
1709
+ options[$.prop(this, 'value')] = $.prop(this, 'label');
1710
+ });
1711
+ return [options, datalist.data('label')];
1712
+ },
1713
+ list: function(val){
1714
+ if(this.type == 'number' || this.type == 'time'){
1715
+ this.element.attr('list', $.attr(this.orig, 'list'));
1716
+ }
1717
+ this.options.list = val;
1718
+ this._propertyChange('list');
1719
+ },
1720
+ _propertyChange: $.noop,
1721
+ tabindex: function(val){
1722
+ this.options.tabindex = val;
1723
+ this.inputElements.prop('tabindex', this.options.tabindex);
1724
+ },
1725
+ title: function(val){
1726
+ this.options.title = val;
1727
+ this.element.prop('title', this.options.title);
1728
+ },
1729
+
1730
+ min: function(val){
1731
+ this.elemHelper.prop('min', val);
1732
+ this.minAsNumber = this.asNumber(val);
1733
+ if(this.valueAsNumber != null && isNaN(this.valueAsNumber)){
1734
+ this._setStartInRange();
1735
+ }
1736
+ this.options.min = val;
1737
+ this._propertyChange('min');
1738
+ },
1739
+ max: function(val){
1740
+ this.elemHelper.prop('max', val);
1741
+ this.maxAsNumber = this.asNumber(val);
1742
+ if(this.valueAsNumber != null && isNaN(this.valueAsNumber)){
1743
+ this._setStartInRange();
1744
+ }
1745
+ this.options.max = val;
1746
+ this._propertyChange('max');
1747
+ },
1748
+ step: function(val){
1749
+ var defStep = steps[this.type];
1750
+ this.options.step = val;
1751
+ this.elemHelper.prop('step', retDefault(val, defStep.step));
1752
+ },
1753
+ addBindings: function(){
1754
+ var isFocused;
1755
+
1756
+ var that = this;
1757
+ var o = this.options;
1758
+
1759
+ var eventTimer = (function(){
1760
+ var events = {};
1761
+ return {
1762
+ init: function(name, curVal, fn){
1763
+ if(!events[name]){
1764
+ events[name] = {fn: fn};
1765
+ $(that.orig).on(name, function(){
1766
+ events[name].val = $.prop(that.orig, 'value');
1767
+ });
1768
+ }
1769
+ events[name].val = curVal;
1770
+ },
1771
+ call: function(name, val){
1772
+ if(events[name] && events[name].val != val){
1773
+ clearTimeout(events[name].timer);
1774
+ events[name].val = val;
1775
+ events[name].timer = setTimeout(function(){
1776
+ events[name].fn(val, that);
1777
+ }, 9);
1778
+ }
1779
+ }
1780
+ };
1781
+ })();
1782
+ var initChangeEvents = function(){
1783
+ eventTimer.init('input', $.prop(that.orig, 'value'), that.options.input);
1784
+ eventTimer.init('change', $.prop(that.orig, 'value'), that.options.change);
1785
+ };
1786
+
1787
+ var step = {};
1788
+
1789
+ var preventBlur = function(e){
1790
+ if(preventBlur.prevent){
1791
+ e.preventDefault();
1792
+ (isFocused || that.element.getShadowFocusElement()).focus();
1793
+ e.stopImmediatePropagation();
1794
+ return true;
1795
+ }
1796
+ };
1797
+ var callSplitChange = (function(){
1798
+ var timer;
1799
+
1800
+ var call = function(e){
1801
+ var val;
1802
+ clearTimeout(timer);
1803
+ val = that.parseValue();
1804
+ $.prop(that.orig, 'value', val);
1805
+ eventTimer.call('input', val);
1806
+ if(!e || e.type != 'wsupdatevalue'){
1807
+ eventTimer.call('change', val);
1808
+ }
1809
+ };
1810
+
1811
+ var onFocus = function(){
1812
+ clearTimeout(timer);
1813
+ };
1814
+ var onBlur = function(e){
1815
+ clearTimeout(timer);
1816
+ timer = setTimeout(call, 0);
1817
+
1818
+ if(e.type == 'change'){
1819
+ stopPropagation(e);
1820
+ if(!o.splitInput){
1821
+ call();
1822
+ }
1823
+ }
1824
+ };
1825
+
1826
+ that.element.on('wsupdatevalue', call);
1827
+
1828
+ that.inputElements
1829
+ .add(that.buttonWrapper)
1830
+ .add(that.element)
1831
+ .on(
1832
+ {
1833
+ 'focus focusin': onFocus,
1834
+ 'blur focusout change': onBlur
1835
+ }
1836
+ )
1837
+ ;
1838
+ setTimeout(function(){
1839
+ if(that.popover){
1840
+ $('> *', that.popover.element)
1841
+ .on({
1842
+ 'focusin': onFocus,
1843
+ 'focusout': onBlur
1844
+ })
1845
+ ;
1846
+ }
1847
+ }, 0);
1848
+ })();
1849
+
1850
+ var spinEvents = {};
1851
+ var spinElement = o.splitInput ? this.inputElements.filter('.ws-spin') : this.inputElements.eq(0);
1852
+ var elementEvts = {
1853
+ blur: function(e){
1854
+ if(!preventBlur(e) && !o.disabled && !o.readonly){
1855
+ if(!preventBlur.prevent){
1856
+ isFocused = false;
1857
+ }
1858
+ }
1859
+ stopPropagation(e);
1860
+ },
1861
+ focus: function(e){
1862
+ if(!isFocused){
1863
+ initChangeEvents();
1864
+ isFocused = this;
1865
+ }
1866
+ },
1867
+ keypress: function(e){
1868
+ if(e.isDefaultPrevented()){return;}
1869
+ var chr;
1870
+ var stepped = true;
1871
+ var code = e.keyCode;
1872
+ if(!e.ctrlKey && !e.metaKey && curCfg[that.type+'Signs']){
1873
+ chr = String.fromCharCode(e.charCode == null ? code : e.charCode);
1874
+ stepped = !(chr < " " || (curCfg[that.type+'Signs']+'0123456789').indexOf(chr) > -1);
1875
+ } else {
1876
+ stepped = false;
1877
+ }
1878
+ if(stepped){
1879
+ e.preventDefault();
1880
+ }
1881
+ },
1882
+ 'input keydown keypress': (function(){
1883
+ var timer;
1884
+ var isStopped = false;
1885
+ var releaseTab = function(){
1886
+ if(isStopped === true){
1887
+ isStopped = 'semi';
1888
+ timer = setTimeout(releaseTab, 250);
1889
+ } else {
1890
+ isStopped = false;
1891
+ }
1892
+ };
1893
+ var stopTab = function(){
1894
+ isStopped = true;
1895
+ clearTimeout(timer);
1896
+ timer = setTimeout(releaseTab, 300);
1897
+ };
1898
+ var select = function(){
1899
+ this.focus();
1900
+ this.select();
1901
+ stopTab();
1902
+ };
1903
+
1904
+ return function(e){
1905
+ if(o.splitInput && o.jumpInputs){
1906
+ if(e.type == 'input'){
1907
+ if($.prop(this, 'value').length === $.prop(this, 'maxLength')){
1908
+ try {
1909
+ $(this)
1910
+ .next()
1911
+ .next('input')
1912
+ .each(select)
1913
+ ;
1914
+ } catch(er){}
1915
+ }
1916
+ } else if(!e.shiftKey && !e.crtlKey && e.keyCode == 9 && (isStopped === true || (isStopped && !$.prop(this, 'value')))){
1917
+ e.preventDefault();
1918
+ }
1919
+ }
1920
+ }
1921
+ })()
1922
+ };
1923
+ var mouseDownInit = function(){
1924
+ if(!o.disabled && !isFocused){
1925
+ that.element.getShadowFocusElement().focus();
1926
+ }
1927
+ preventBlur.set();
1928
+
1929
+ return false;
1930
+ };
1931
+
1932
+ preventBlur.set = (function(){
1933
+ var timer;
1934
+ var reset = function(){
1935
+ preventBlur.prevent = false;
1936
+ };
1937
+ return function(){
1938
+ clearTimeout(timer);
1939
+ preventBlur.prevent = true;
1940
+ setTimeout(reset, 9);
1941
+ };
1942
+ })();
1943
+
1944
+ ['stepUp', 'stepDown'].forEach(function(name){
1945
+ step[name] = function(factor){
1946
+ if(!o.disabled && !o.readonly){
1947
+ if(!isFocused){
1948
+ mouseDownInit();
1949
+ }
1950
+ var ret = false;
1951
+ if (!factor) {
1952
+ factor = 1;
1953
+ }
1954
+ try {
1955
+ that.elemHelper[name](factor);
1956
+ ret = that.elemHelper.prop('value');
1957
+ that.value(ret);
1958
+ eventTimer.call('input', ret);
1959
+ } catch (er) {}
1960
+ return ret;
1961
+ }
1962
+ };
1963
+ });
1964
+
1965
+
1966
+
1967
+ this.buttonWrapper.on('mousedown', mouseDownInit);
1968
+
1969
+ this.setInput = function(value){
1970
+ that.value(value);
1971
+ eventTimer.call('input', value);
1972
+ };
1973
+ this.setChange = function(value){
1974
+ that.setInput(value);
1975
+ eventTimer.call('change', value);
1976
+ };
1977
+
1978
+
1979
+
1980
+ this.inputElements.on(elementEvts);
1981
+
1982
+ if(!o.noSpinbtn){
1983
+ spinEvents[$.fn.mwheelIntent ? 'mwheelIntent' : 'mousewheel'] = function(e, delta){
1984
+ if(delta && isFocused && !o.disabled){
1985
+ step[delta > 0 ? 'stepUp' : 'stepDown']();
1986
+ e.preventDefault();
1987
+ }
1988
+ };
1989
+ spinEvents.keydown = function(e){
1990
+ if(o.list || e.isDefaultPrevented() || $.attr(this, 'list')){return;}
1991
+ var stepped = true;
1992
+ var code = e.keyCode;
1993
+ if (code == 38) {
1994
+ step.stepUp();
1995
+ } else if (code == 40) {
1996
+ step.stepDown();
1997
+ } else {
1998
+ stepped = false;
1999
+ }
2000
+ if(stepped){
2001
+ e.preventDefault();
2002
+ }
2003
+ };
2004
+
2005
+ spinElement.attr({'autocomplete': 'off', role: 'spinbutton'}).on(spinEvents);
2006
+ }
2007
+
2008
+
2009
+ if(!o.splitInput){
2010
+ $(document).on('wslocalechange',function(){
2011
+ if(o.value){
2012
+ that.value(o.value);
2013
+ }
2014
+
2015
+ if(placeholderFormat[that.type] && o.placeholder){
2016
+ that.placeholder(o.placeholder);
2017
+ }
2018
+ });
2019
+ } else {
2020
+ $(document).onTrigger('wslocalechange',function(){
2021
+ that.reorderInputs();
2022
+ });
2023
+ }
2024
+
2025
+ $('.step-up', this.buttonWrapper)
2026
+ .on({
2027
+ 'mousepressstart mousepressend': mousePress,
2028
+ 'mousedown mousepress': function(e){
2029
+ step.stepUp();
2030
+ }
2031
+ })
2032
+ ;
2033
+ $('.step-down', this.buttonWrapper)
2034
+ .on({
2035
+ 'mousepressstart mousepressend': mousePress,
2036
+ 'mousedown mousepress': function(e){
2037
+ step.stepDown();
2038
+ }
2039
+ })
2040
+ ;
2041
+ initChangeEvents();
2042
+ }
2043
+ };
2044
+
2045
+ ['readonly', 'disabled'].forEach(function(name){
2046
+ spinBtnProto[name] = function(val){
2047
+ if(this.options[name] != val || !this._init){
2048
+ this.options[name] = !!val;
2049
+ if(name == 'readonly' && this.options.noInput){
2050
+ this.element
2051
+ .prop(name, true)
2052
+ .attr({'aria-readonly': this.options[name]})
2053
+ ;
2054
+ } else {
2055
+ this.element.prop(name, this.options[name]);
2056
+ }
2057
+ this.buttonWrapper[this.options[name] ? 'addClass' : 'removeClass']('ws-'+name);
2058
+ }
2059
+ };
2060
+ });
2061
+
2062
+
2063
+ $.fn.spinbtnUI = function(opts){
2064
+ opts = $.extend({
2065
+ monthNames: 'monthNames',
2066
+ size: 1,
2067
+ startView: 0
2068
+ }, opts);
2069
+ return this.each(function(){
2070
+ $.webshims.objectCreate(spinBtnProto, {
2071
+ element: {
2072
+ value: $(this)
2073
+ }
2074
+ }, opts);
2075
+ });
2076
+ };
2077
+ })();
1089
2078
 
2079
+ (function(){
2080
+ var picker = {};
2081
+ var disable = {
2082
+
2083
+ };
2084
+
2085
+ var getDateArray = function(date){
2086
+ var ret = [date.getFullYear(), addZero(date.getMonth() + 1), addZero(date.getDate())];
2087
+ ret.month = ret[0]+'-'+ret[1];
2088
+ ret.date = ret[0]+'-'+ret[1]+'-'+ret[2];
2089
+ return ret;
2090
+ };
2091
+ var today = getDateArray(new Date());
2092
+
2093
+ var _setFocus = function(element, _noFocus){
2094
+ var setFocus, that;
2095
+ element = $(element || this.activeButton);
2096
+ this.activeButton.attr({tabindex: '-1', 'aria-selected': 'false'});
2097
+ this.activeButton = element.attr({tabindex: '0', 'aria-selected': 'true'});
2098
+ this.index = this.buttons.index(this.activeButton[0]);
2099
+
2100
+ clearTimeout(this.timer);
2101
+
2102
+ if(!this.popover.openedByFocus && !_noFocus){
2103
+ that = this;
2104
+ setFocus = function(noTrigger){
2105
+ clearTimeout(that.timer);
2106
+ that.timer = setTimeout(function(){
2107
+ if(element[0]){
2108
+ element[0].focus();
2109
+ if(noTrigger !== true && !element.is(':focus')){
2110
+ setFocus(true);
2111
+ }
2112
+ }
2113
+ }, that.popover.isVisible ? 99 : 360);
2114
+ };
2115
+ this.popover.activateElement(element);
2116
+ setFocus();
2117
+ }
2118
+
2119
+ };
2120
+
2121
+ var _initialFocus = function(){
2122
+ var sel;
2123
+ if(this.popover.navedInitFocus){
2124
+ sel = this.popover.navedInitFocus.sel || this.popover.navedInitFocus;
2125
+ if((!this.activeButton || !this.activeButton[0]) && this.buttons[sel]){
2126
+ this.activeButton = this.buttons[sel]();
2127
+ } else if(sel){
2128
+ this.activeButton = $(sel, this.element);
2129
+ }
2130
+
2131
+ if(!this.activeButton[0] && this.popover.navedInitFocus.alt){
2132
+ this.activeButton = this.buttons[this.popover.navedInitFocus.alt]();
2133
+ }
2134
+ }
2135
+
2136
+ if(!this.activeButton || !this.activeButton[0]){
2137
+ this.activeButton = this.buttons.filter('.checked-value');
2138
+ }
2139
+
2140
+ if(!this.activeButton[0]){
2141
+ this.activeButton = this.buttons.filter('.this-value');
2142
+ }
2143
+ if(!this.activeButton[0]){
2144
+ this.activeButton = this.buttons.eq(0);
2145
+ }
2146
+
2147
+ this.setFocus(this.activeButton, this.opts.noFocus);
2148
+ };
2149
+
2150
+
2151
+ webshims.ListBox = function (element, popover, opts){
2152
+ this.element = $('ul', element);
2153
+ this.popover = popover;
2154
+ this.opts = opts || {};
2155
+ this.buttons = $('button:not(:disabled)', this.element);
2156
+
2157
+
2158
+ this.ons(this);
2159
+ this._initialFocus();
2160
+ };
2161
+
2162
+ webshims.ListBox.prototype = {
2163
+ setFocus: _setFocus,
2164
+ _initialFocus: _initialFocus,
2165
+ prev: function(){
2166
+ var index = this.index - 1;
2167
+ if(index < 0){
2168
+ if(this.opts.prev){
2169
+ this.popover.navedInitFocus = 'last';
2170
+ this.popover.actionFn(this.opts.prev);
2171
+ this.popover.navedInitFocus = false;
2172
+ }
2173
+ } else {
2174
+ this.setFocus(this.buttons.eq(index));
2175
+ }
2176
+ },
2177
+ next: function(){
2178
+ var index = this.index + 1;
2179
+ if(index >= this.buttons.length){
2180
+ if(this.opts.next){
2181
+ this.popover.navedInitFocus = 'first';
2182
+ this.popover.actionFn(this.opts.next);
2183
+ this.popover.navedInitFocus = false;
2184
+ }
2185
+ } else {
2186
+ this.setFocus(this.buttons.eq(index));
2187
+ }
2188
+ },
2189
+ ons: function(that){
2190
+ this.element
2191
+ .on({
2192
+ 'keydown': function(e){
2193
+ var handled;
2194
+ var key = e.keyCode;
2195
+ if(e.ctrlKey){return;}
2196
+ if(key == 36 || key == 33){
2197
+ that.setFocus(that.buttons.eq(0));
2198
+ handled = true;
2199
+ } else if(key == 34 || key == 35){
2200
+ that.setFocus(that.buttons.eq(that.buttons.length - 1));
2201
+ handled = true;
2202
+ } else if(key == 38 || key == 37){
2203
+ that.prev();
2204
+ handled = true;
2205
+ } else if(key == 40 || key == 39){
2206
+ that.next();
2207
+ handled = true;
2208
+ }
2209
+ if(handled){
2210
+ return false;
2211
+ }
2212
+ }
2213
+ })
2214
+ ;
2215
+ }
2216
+ };
2217
+
2218
+ webshims.Grid = function (element, popover, opts){
2219
+ this.element = $('tbody', element);
2220
+ this.popover = popover;
2221
+ this.opts = opts || {};
2222
+ this.buttons = $('button:not(:disabled,.othermonth)', this.element);
2223
+
2224
+ this.ons(this);
2225
+
2226
+ this._initialFocus();
2227
+ if(this.popover.openedByFocus){
2228
+ this.popover.activeElement = this.activeButton;
2229
+ }
2230
+ };
2231
+
2232
+
2233
+
2234
+ webshims.Grid.prototype = {
2235
+ setFocus: _setFocus,
2236
+ _initialFocus: _initialFocus,
2237
+
2238
+ first: function(){
2239
+ this.setFocus(this.buttons.eq(0));
2240
+ },
2241
+ last: function(){
2242
+ this.setFocus(this.buttons.eq(this.buttons.length - 1));
2243
+ },
2244
+ upPage: function(){
2245
+ $('.ws-picker-header > button:not(:disabled)', this.popover.element).trigger('click');
2246
+ },
2247
+ downPage: function(){
2248
+ this.activeButton.filter(':not([data-action="changeInput"])').trigger('click');
2249
+ },
2250
+ ons: function(that){
2251
+ this.element
2252
+ .on({
2253
+ 'keydown': function(e){
2254
+ var handled;
2255
+ var key = e.keyCode;
2256
+
2257
+ if(e.shiftKey){return;}
2258
+
2259
+ if((e.ctrlKey && key == 40)){
2260
+ handled = 'downPage';
2261
+ } else if((e.ctrlKey && key == 38)){
2262
+ handled = 'upPage';
2263
+ } else if(key == 33 || (e.ctrlKey && key == 37)){
2264
+ handled = 'prevPage';
2265
+ } else if(key == 34 || (e.ctrlKey && key == 39)){
2266
+ handled = 'nextPage';
2267
+ } else if(e.keyCode == 36 || e.keyCode == 33){
2268
+ handled = 'first';
2269
+ } else if(e.keyCode == 35){
2270
+ handled = 'last';
2271
+ } else if(e.keyCode == 38){
2272
+ handled = 'up';
2273
+ } else if(e.keyCode == 37){
2274
+ handled = 'prev';
2275
+ } else if(e.keyCode == 40){
2276
+ handled = 'down';
2277
+ } else if(e.keyCode == 39){
2278
+ handled = 'next';
2279
+ }
2280
+ if(handled){
2281
+ that[handled]();
2282
+ return false;
2283
+ }
2284
+ }
2285
+ })
2286
+ ;
2287
+ }
2288
+ };
2289
+ $.each({
2290
+ prevPage: {get: 'last', action: 'prev'},
2291
+ nextPage: {get: 'first', action: 'next'}
2292
+ }, function(name, val){
2293
+ webshims.Grid.prototype[name] = function(){
2294
+ if(this.opts[val.action]){
2295
+ this.popover.navedInitFocus = {
2296
+ sel: 'button[data-id="'+ this.activeButton.attr('data-id') +'"]:not(:disabled,.othermonth)',
2297
+ alt: val.get
2298
+ };
2299
+ this.popover.actionFn(this.opts[val.action]);
2300
+ this.popover.navedInitFocus = false;
2301
+ }
2302
+ };
2303
+ });
2304
+
2305
+ $.each({
2306
+ up: {traverse: 'prevAll', get: 'last', action: 'prev', reverse: true},
2307
+ down: {traverse: 'nextAll', get: 'first', action: 'next'}
2308
+ }, function(name, val){
2309
+ webshims.Grid.prototype[name] = function(){
2310
+ var cellIndex = this.activeButton.closest('td').prop('cellIndex');
2311
+ var sel = 'td:nth-child('+(cellIndex + 1)+') button:not(:disabled,.othermonth)';
2312
+ var button = this.activeButton.closest('tr')[val.traverse]();
2313
+
2314
+ if(val.reverse){
2315
+ button = $(button.get().reverse());
2316
+ }
2317
+ button = button.find(sel)[val.get]();
2318
+
2319
+ if(!button[0]){
2320
+ if(this.opts[val.action]){
2321
+ this.popover.navedInitFocus = sel+':'+val.get;
2322
+ this.popover.actionFn(this.opts[val.action]);
2323
+ this.popover.navedInitFocus = false;
2324
+ }
2325
+ } else {
2326
+ this.setFocus(button.eq(0));
2327
+ }
2328
+ };
2329
+ });
2330
+
2331
+ $.each({
2332
+ prev: {traverse: 'prevAll',get: 'last', reverse: true},
2333
+ next: {traverse: 'nextAll', get: 'first'}
2334
+ }, function(name, val){
2335
+ webshims.Grid.prototype[name] = function(){
2336
+ var sel = 'button:not(:disabled,.othermonth)';
2337
+ var button = this.activeButton.closest('td')[val.traverse]('td');
2338
+ if(val.reverse){
2339
+ button = $(button.get().reverse());
2340
+ }
2341
+ button = button.find(sel)[val.get]();
2342
+ if(!button[0]){
2343
+ button = this.activeButton.closest('tr')[val.traverse]('tr');
2344
+ if(val.reverse){
2345
+ button = $(button.get().reverse());
2346
+ }
2347
+ button = button.find(sel)[val.get]();
2348
+ }
2349
+
2350
+ if(!button[0]){
2351
+ if(this.opts[name]){
2352
+ this.popover.navedInitFocus = val.get;
2353
+ this.popover.actionFn(this.opts[name]);
2354
+ this.popover.navedInitFocus = false;
2355
+ }
2356
+ } else {
2357
+ this.setFocus(button.eq(0));
2358
+ }
2359
+ };
2360
+ });
2361
+
2362
+ picker.getWeek = function(date){
2363
+ var onejan = new Date(date.getFullYear(),0,1);
2364
+ return Math.ceil((((date - onejan) / 86400000) + onejan.getDay()+1)/7);
2365
+ };
2366
+ picker.getYearList = function(value, data){
2367
+ var j, i, val, disabled, lis, prevDisabled, nextDisabled, classStr, classArray, start;
2368
+
2369
+
2370
+ var size = data.options.size;
2371
+ var max = data.options.max.split('-');
2372
+ var min = data.options.min.split('-');
2373
+ var currentValue = data.options.value.split('-');
2374
+ var xthCorrect = 0;
2375
+ var enabled = 0;
2376
+ var str = '';
2377
+ var rowNum = 0;
2378
+
2379
+ if(data.options.useDecadeBase == 'max' && max[0]){
2380
+ xthCorrect = 11 - (max[0] % 12);
2381
+ } else if(data.options.useDecadeBase == 'min' && min[0]){
2382
+ xthCorrect = 11 - (min[0] % 12);
2383
+ }
2384
+
2385
+ value = value[0] * 1;
2386
+ start = value - ((value + xthCorrect) % (12 * size));
2387
+
2388
+
2389
+
2390
+ for(j = 0; j < size; j++){
2391
+ if(j){
2392
+ start += 12;
2393
+ } else {
2394
+ prevDisabled = picker.isInRange([start-1], max, min) ? {'data-action': 'setYearList','value': start-1} : false;
2395
+ }
2396
+
2397
+ str += '<div class="year-list picker-list ws-index-'+ j +'"><div class="ws-picker-header"><button disabled="disabled">'+ start +' – '+(start + 11)+'</button></div>';
2398
+ lis = [];
2399
+ for(i = 0; i < 12; i++){
2400
+ val = start + i ;
2401
+ classArray = [];
2402
+ if( !picker.isInRange([val], max, min) ){
2403
+ disabled = ' disabled=""';
2404
+ } else {
2405
+ disabled = '';
2406
+ enabled++;
2407
+ }
2408
+
2409
+ if(val == today[0]){
2410
+ classArray.push('this-value');
2411
+ }
2412
+
2413
+ if(currentValue[0] == val){
2414
+ classArray.push('checked-value');
2415
+ }
2416
+
2417
+ classStr = classArray.length ? ' class="'+ (classArray.join(' ')) +'"' : '';
2418
+
2419
+ if(i && !(i % 3)){
2420
+ rowNum++;
2421
+ lis.push('</tr><tr class="ws-row-'+ rowNum +'">');
2422
+ }
2423
+ lis.push('<td class="ws-item-'+ i +'" role="presentation"><button data-id="year-'+ i +'" type="button"'+ disabled + classStr +' data-action="setMonthList" value="'+val+'" tabindex="-1" role="gridcell">'+val+'</button></td>');
2424
+ }
2425
+ if(j == size - 1){
2426
+ nextDisabled = picker.isInRange([val+1], max, min) ? {'data-action': 'setYearList','value': val+1} : false;
2427
+ }
2428
+ str += '<div class="picker-grid"><table role="grid" aria-label="'+ start +' – '+(start + 11)+'"><tbody><tr class="ws-row-0">'+ (lis.join(''))+ '</tr></tbody></table></div></div>';
2429
+ }
2430
+
2431
+ return {
2432
+ enabled: enabled,
2433
+ main: str,
2434
+ next: nextDisabled,
2435
+ prev: prevDisabled,
2436
+ type: 'Grid'
2437
+ };
2438
+ };
2439
+
2440
+
2441
+ picker.getMonthList = function(value, data){
2442
+
2443
+ var j, i, name, val, disabled, lis, fullyDisabled, prevDisabled, nextDisabled, classStr, classArray;
2444
+ var o = data.options;
2445
+ var size = o.size;
2446
+ var max = o.max.split('-');
2447
+ var min = o.min.split('-');
2448
+ var currentValue = o.value.split('-');
2449
+ var enabled = 0;
2450
+ var rowNum = 0;
2451
+ var str = '';
2452
+
2453
+ value = value[0] - Math.floor((size - 1) / 2);
2454
+ for(j = 0; j < size; j++){
2455
+ if(j){
2456
+ value++;
2457
+ } else {
2458
+ prevDisabled = picker.isInRange([value-1], max, min) ? {'data-action': 'setMonthList','value': value-1} : false;
2459
+ }
2460
+ if(j == size - 1){
2461
+ nextDisabled = picker.isInRange([value+1], max, min) ? {'data-action': 'setMonthList','value': value+1} : false;
2462
+ }
2463
+ lis = [];
2464
+
2465
+ if( !picker.isInRange([value, '01'], max, min) && !picker.isInRange([value, '12'], max, min)){
2466
+ disabled = ' disabled=""';
2467
+ fullyDisabled = true;
2468
+ } else {
2469
+ fullyDisabled = false;
2470
+ disabled = '';
2471
+ }
2472
+
2473
+ if(o.minView >= 1){
2474
+ disabled = ' disabled=""';
2475
+ }
2476
+
2477
+ str += '<div class="month-list picker-list ws-index-'+ j +'"><div class="ws-picker-header">';
2478
+
2479
+ str += o.selectNav ?
2480
+ '<select data-action="setMonthList" class="year-select">'+ picker.createYearSelect(value, max, min).join('') +'</select>' :
2481
+ '<button data-action="setYearList"'+disabled+' value="'+ value +'" tabindex="-1">'+ value +'</button>';
2482
+ str += '</div>';
2483
+
2484
+ for(i = 0; i < 12; i++){
2485
+ val = curCfg.date.monthkeys[i+1];
2486
+ name = (curCfg.date[o.monthNames] || curCfg.date.monthNames)[i];
2487
+ classArray = [];
2488
+ if(fullyDisabled || !picker.isInRange([value, val], max, min) ){
2489
+ disabled = ' disabled=""';
2490
+ } else {
2491
+ disabled = '';
2492
+ enabled++;
2493
+ }
2494
+
2495
+ if(value == today[0] && today[1] == val){
2496
+ classArray.push('this-value');
2497
+ }
2498
+
2499
+ if(currentValue[0] == value && currentValue[1] == val){
2500
+ classArray.push('checked-value');
2501
+ }
2502
+
2503
+ classStr = (classArray.length) ? ' class="'+ (classArray.join(' ')) +'"' : '';
2504
+ if(i && !(i % 3)){
2505
+ rowNum++;
2506
+ lis.push('</tr><tr class="ws-row-'+ rowNum +'">');
2507
+ }
2508
+
2509
+ lis.push('<td class="ws-item-'+ i +'" role="presentation"><button data-id="month-'+ i +'" type="button"'+ disabled + classStr +' data-action="'+ (data.type == 'month' ? 'changeInput' : 'setDayList' ) +'" value="'+value+'-'+val+'" tabindex="-1" role="gridcell" aria-label="'+ curCfg.date.monthNames[i] +'">'+name+'</button></td>');
2510
+
2511
+ }
2512
+
2513
+ str += '<div class="picker-grid"><table role="grid" aria-label="'+value+'"><tbody><tr class="ws-row-0">'+ (lis.join(''))+ '</tr></tbody></table></div></div>';
2514
+ }
2515
+
2516
+ return {
2517
+ enabled: enabled,
2518
+ main: str,
2519
+ prev: prevDisabled,
2520
+ next: nextDisabled,
2521
+ type: 'Grid'
2522
+ };
2523
+ };
2524
+
2525
+
2526
+ picker.getDayList = function(value, data){
2527
+
2528
+ var j, i, k, day, nDay, name, val, disabled, lis, prevDisabled, nextDisabled, addTr, week, rowNum;
2529
+
2530
+ var lastMotnh, curMonth, otherMonth, dateArray, monthName, fullMonthName, buttonStr, date2, classArray;
2531
+ var o = data.options;
2532
+ var size = o.size;
2533
+ var max = o.max.split('-');
2534
+ var min = o.min.split('-');
2535
+ var currentValue = o.value.split('-');
2536
+ var monthNames = curCfg.date[o.monthNamesHead] || curCfg.date[o.monthNames] || curCfg.date.monthNames;
2537
+ var enabled = 0;
2538
+ var str = [];
2539
+ var date = new Date(value[0], value[1] - 1, 1);
2540
+
2541
+ date.setMonth(date.getMonth() - Math.floor((size - 1) / 2));
2542
+
2543
+ for(j = 0; j < size; j++){
2544
+ date.setDate(1);
2545
+ lastMotnh = date.getMonth();
2546
+ rowNum = 0;
2547
+ if(!j){
2548
+ date2 = new Date(date.getTime());
2549
+ date2.setDate(-1);
2550
+ dateArray = getDateArray(date2);
2551
+ prevDisabled = picker.isInRange(dateArray, max, min) ? {'data-action': 'setDayList','value': dateArray[0]+'-'+dateArray[1]} : false;
2552
+ }
2553
+
2554
+ dateArray = getDateArray(date);
2555
+
2556
+ str.push('<div class="day-list picker-list ws-index-'+ j +'"><div class="ws-picker-header">');
2557
+ if( o.selectNav ){
2558
+ monthName = ['<select data-action="setDayList" class="month-select" tabindex="0">'+ picker.createMonthSelect(dateArray, max, min, monthNames).join('') +'</select>', '<select data-action="setDayList" class="year-select" tabindex="0">'+ picker.createYearSelect(dateArray[0], max, min, '-'+dateArray[1]).join('') +'</select>'];
2559
+ if(curCfg.date.showMonthAfterYear){
2560
+ monthName.reverse();
2561
+ }
2562
+ str.push( monthName.join(' ') );
2563
+ }
2564
+
2565
+ fullMonthName = [curCfg.date.monthNames[(dateArray[1] * 1) - 1], dateArray[0]];
2566
+ monthName = [monthNames[(dateArray[1] * 1) - 1], dateArray[0]];
2567
+ if(curCfg.date.showMonthAfterYear){
2568
+ monthName.reverse();
2569
+ fullMonthName.reverse();
2570
+ }
2571
+
2572
+ if(!data.options.selectNav) {
2573
+ str.push(
2574
+ '<button data-action="setMonthList"'+ (o.minView >= 2 ? ' disabled="" ' : '') +' value="'+ dateArray.date +'" tabindex="-1">'+ monthName.join(' ') +'</button>'
2575
+ );
2576
+ }
2577
+
2578
+
2579
+ str.push('</div><div class="picker-grid"><table role="grid" aria-label="'+ fullMonthName.join(' ') +'"><thead><tr>');
2580
+
2581
+ if(data.options.showWeek){
2582
+ str.push('<th class="week-header">'+ curCfg.date.weekHeader +'</th>');
2583
+ }
2584
+ for(k = curCfg.date.firstDay; k < curCfg.date.dayNamesShort.length; k++){
2585
+ str.push('<th class="day-'+ k +'"><abbr title="'+ curCfg.date.dayNames[k] +'">'+ curCfg.date.dayNamesShort[k] +'</abbr></th>');
2586
+ }
2587
+ k = curCfg.date.firstDay;
2588
+ while(k--){
2589
+ str.push('<th class="day-'+ k +'"><abbr title="'+ curCfg.date.dayNames[k] +'">'+ curCfg.date.dayNamesShort[k] +'</abbr></th>');
2590
+ }
2591
+ str.push('</tr></thead><tbody><tr class="ws-row-0">');
2592
+
2593
+ if(data.options.showWeek) {
2594
+ week = picker.getWeek(date);
2595
+ str.push('<td class="week-cell">'+ week +'</td>');
2596
+ }
2597
+
2598
+ for (i = 0; i < 99; i++) {
2599
+ addTr = (i && !(i % 7));
2600
+ curMonth = date.getMonth();
2601
+ otherMonth = lastMotnh != curMonth;
2602
+ day = date.getDay();
2603
+ classArray = [];
2604
+
2605
+ if(addTr && otherMonth ){
2606
+ str.push('</tr>');
2607
+ break;
2608
+ }
2609
+ if(addTr){
2610
+ rowNum++;
2611
+ str.push('</tr><tr class="ws-row-'+ rowNum +'">');
2612
+ if(data.options.showWeek) {
2613
+ week++;
2614
+ str.push('<td class="week-cell">'+ week +'</td>');
2615
+ }
2616
+ }
2617
+
2618
+ if(!i){
2619
+
2620
+ if(day != curCfg.date.firstDay){
2621
+ nDay = day - curCfg.date.firstDay;
2622
+ if(nDay < 0){
2623
+ nDay += 7;
2624
+ }
2625
+ date.setDate(date.getDate() - nDay);
2626
+ day = date.getDay();
2627
+ curMonth = date.getMonth();
2628
+ otherMonth = lastMotnh != curMonth;
2629
+ }
2630
+ }
2631
+
2632
+ dateArray = getDateArray(date);
2633
+ buttonStr = '<td role="presentation" class="day-'+ day +'"><button data-id="day-'+ date.getDate() +'" role="gridcell" data-action="changeInput" value="'+ (dateArray.join('-')) +'"';
2634
+
2635
+ if(otherMonth){
2636
+ classArray.push('othermonth');
2637
+ } else {
2638
+ classArray.push('day-'+date.getDate());
2639
+ }
2640
+
2641
+ if(dateArray[0] == today[0] && today[1] == dateArray[1] && today[2] == dateArray[2]){
2642
+ classArray.push('this-value');
2643
+ }
2644
+
2645
+ if(currentValue[0] == dateArray[0] && dateArray[1] == currentValue[1] && dateArray[2] == currentValue[2]){
2646
+ classArray.push('checked-value');
2647
+ }
2648
+
2649
+ if(classArray.length){
2650
+ buttonStr += ' class="'+ classArray.join(' ') +'"';
2651
+ }
2652
+
2653
+ if(!picker.isInRange(dateArray, max, min) || (data.options.disableDays && $.inArray(day, data.options.disableDays) != -1)){
2654
+ buttonStr += ' disabled=""';
2655
+ }
2656
+
2657
+ str.push(buttonStr+' tabindex="-1">'+ date.getDate() +'</button></td>');
2658
+
2659
+ date.setDate(date.getDate() + 1);
2660
+ }
2661
+ str.push('</tbody></table></div></div>');
2662
+ if(j == size - 1){
2663
+ dateArray = getDateArray(date);
2664
+ dateArray[2] = 1;
2665
+ nextDisabled = picker.isInRange(dateArray, max, min) ? {'data-action': 'setDayList','value': dateArray.date} : false;
2666
+ }
2667
+ }
2668
+
2669
+
2670
+ return {
2671
+ enabled: 9,
2672
+ main: str.join(''),
2673
+ prev: prevDisabled,
2674
+ next: nextDisabled,
2675
+ type: 'Grid'
2676
+ };
2677
+ };
2678
+
2679
+ picker.isInRange = function(values, max, min){
2680
+ var i;
2681
+ var ret = true;
2682
+ for(i = 0; i < values.length; i++){
2683
+
2684
+ if(min[i] && min[i] > values[i]){
2685
+ ret = false;
2686
+ break;
2687
+ } else if( !(min[i] && min[i] == values[i]) ){
2688
+ break;
2689
+ }
2690
+ }
2691
+ if(ret){
2692
+ for(i = 0; i < values.length; i++){
2693
+
2694
+ if((max[i] && max[i] < values[i])){
2695
+ ret = false;
2696
+ break;
2697
+ } else if( !(max[i] && max[i] == values[i]) ){
2698
+ break;
2699
+ }
2700
+ }
2701
+ }
2702
+ return ret;
2703
+ };
2704
+
2705
+ picker.createMonthSelect = function(value, max, min, monthNames){
2706
+ if(!monthNames){
2707
+ monthNames = curCfg.date.monthNames;
2708
+ }
2709
+
2710
+ var selected;
2711
+ var i = 0;
2712
+ var options = [];
2713
+ var tempVal = value[1]-1;
2714
+ for(; i < monthNames.length; i++){
2715
+ selected = tempVal == i ? ' selected=""' : '';
2716
+ if(selected || picker.isInRange([value[0], i+1], max, min)){
2717
+ options.push('<option value="'+ value[0]+'-'+addZero(i+1) + '"'+selected+'>'+ monthNames[i] +'</option>');
2718
+ }
2719
+ }
2720
+ return options;
2721
+ };
2722
+
2723
+ picker.createYearSelect = function(value, max, min, valueAdd){
2724
+
2725
+ var temp;
2726
+ var goUp = true;
2727
+ var goDown = true;
2728
+ var options = ['<option selected="">'+ value + '</option>'];
2729
+ var i = 0;
2730
+ if(!valueAdd){
2731
+ valueAdd = '';
2732
+ }
2733
+ while(i < 8 && (goUp || goDown)){
2734
+ i++;
2735
+ temp = value-i;
2736
+ if(goUp && picker.isInRange([temp], max, min)){
2737
+ options.unshift('<option value="'+ (temp+valueAdd) +'">'+ temp +'</option>');
2738
+ } else {
2739
+ goUp = false;
2740
+ }
2741
+ temp = value + i;
2742
+ if(goDown && picker.isInRange([temp], max, min)){
2743
+ options.push('<option value="'+ (temp+valueAdd) +'">'+ temp +'</option>');
2744
+ } else {
2745
+ goDown = false;
2746
+ }
2747
+ }
2748
+ return options;
2749
+ };
2750
+
2751
+ var actions = {
2752
+ changeInput: function(val, popover, data){
2753
+ popover.stopOpen = true;
2754
+ data.element.getShadowFocusElement().focus();
2755
+ setTimeout(function(){
2756
+ popover.stopOpen = false;
2757
+ }, 9);
2758
+ popover.hide();
2759
+ data.setChange(val);
2760
+ }
2761
+ };
2762
+
2763
+ (function(){
2764
+ var retNames = function(name){
2765
+ return 'get'+name+'List';
2766
+ };
2767
+ var retSetNames = function(name){
2768
+ return 'set'+name+'List';
2769
+ };
2770
+ var stops = {
2771
+ date: 'Day',
2772
+ week: 'Day',
2773
+ month: 'Month'
2774
+ };
2775
+
2776
+ $.each({'setYearList' : ['Year', 'Month', 'Day'], 'setMonthList': ['Month', 'Day'], 'setDayList': ['Day']}, function(setName, names){
2777
+ var getNames = names.map(retNames);
2778
+ var setNames = names.map(retSetNames);
2779
+ actions[setName] = function(val, popover, data, startAt){
2780
+ val = ''+val;
2781
+ var o = data.options;
2782
+ var values = val.split('-');
2783
+ if(!startAt){
2784
+ startAt = 0;
2785
+ }
2786
+ $.each(getNames, function(i, item){
2787
+ if(i >= startAt){
2788
+ var content = picker[item](values, data);
2789
+
2790
+ if( values.length < 2 || content.enabled > 1 || stops[data.type] === names[i]){
2791
+ popover.element
2792
+ .attr({'data-currentview': setNames[i]})
2793
+ .addClass('ws-size-'+o.size)
2794
+ .data('pickercontent', {
2795
+ data: data,
2796
+ content: content,
2797
+ values: values
2798
+ })
2799
+ ;
2800
+ popover.bodyElement.html(content.main);
2801
+ if(content.prev){
2802
+ popover.prevElement
2803
+ .attr(content.prev)
2804
+ .prop({disabled: false})
2805
+ ;
2806
+ } else {
2807
+ popover.prevElement
2808
+ .removeAttr('data-action')
2809
+ .prop({disabled: true})
2810
+ ;
2811
+ }
2812
+ if(content.next){
2813
+ popover.nextElement
2814
+ .attr(content.next)
2815
+ .prop({disabled: false})
2816
+ ;
2817
+ } else {
2818
+ popover.nextElement
2819
+ .removeAttr('data-action')
2820
+ .prop({disabled: true})
2821
+ ;
2822
+ }
2823
+ if(webshims[content.type]){
2824
+ new webshims[content.type](popover.bodyElement.children(), popover, content);
2825
+ }
2826
+ popover.element.trigger('pickerchange');
2827
+ return false;
2828
+ }
2829
+ }
2830
+ });
2831
+ };
2832
+ });
2833
+ })();
2834
+
2835
+ picker.commonInit = function(data, popover){
2836
+ var actionfn = function(e){
2837
+ if(!$(this).is('.othermonth') || $(this).css('cursor') == 'pointer'){
2838
+ popover.actionFn({
2839
+ 'data-action': $.attr(this, 'data-action'),
2840
+ value: $(this).val() || $.attr(this, 'value')
2841
+ });
2842
+ }
2843
+ return false;
2844
+ };
2845
+ var id = new Date().getTime();
2846
+ var generateList = function(o, max, min){
2847
+ var options = [];
2848
+ var label = '';
2849
+ var labelId = '';
2850
+ o.options = data.getOptions() || {};
2851
+ $('div.ws-options', popover.contentElement).remove();
2852
+ $.each(o.options[0], function(val, label){
2853
+ var disabled = picker.isInRange(val.split('-'), o.maxS, o.minS) ?
2854
+ '' :
2855
+ ' disabled="" '
2856
+ ;
2857
+ options.push('<li role="presentation"><button value="'+ val +'" '+disabled+' data-action="changeInput" tabindex="-1" role="option">'+ (label || data.formatValue(val, false)) +'</button></li>');
2858
+ });
2859
+ if(options.length){
2860
+ id++;
2861
+ if(o.options[1]){
2862
+ labelId = 'datalist-'+id;
2863
+ label = '<h5 id="'+labelId+'">'+ o.options[1] +'</h5>';
2864
+ labelId = ' aria-labelledbyid="'+ labelId +'" ';
2865
+ }
2866
+ new webshims.ListBox($('<div class="ws-options">'+label+'<ul role="listbox" '+ labelId +'>'+ options.join('') +'</div>').insertAfter(popover.bodyElement)[0], popover, {noFocus: true});
2867
+ }
2868
+ };
2869
+ var updateContent = function(){
2870
+ if(popover.isDirty){
2871
+ var o = data.options;
2872
+ o.maxS = o.max.split('-');
2873
+ o.minS = o.min.split('-');
2874
+
2875
+ $('button', popover.buttonRow).each(function(){
2876
+ var text;
2877
+ if($(this).is('.ws-empty')){
2878
+ text = curCfg.date.clear;
2879
+ if(!text){
2880
+ text = formcfg[''].date.clear || 'clear';
2881
+ webshims.warn("could not get clear text from form cfg");
2882
+ }
2883
+ } else if($(this).is('.ws-current')){
2884
+ text = (curCfg[data.type] || {}).currentText;
2885
+ if(!text){
2886
+ text = (formcfg[''][[data.type]] || {}).currentText || 'current';
2887
+ webshims.warn("could not get currentText from form cfg");
2888
+ }
2889
+ $.prop(this, 'disabled', !picker.isInRange(today[data.type].split('-'), o.maxS, o.minS));
2890
+ }
2891
+ if(text){
2892
+ $(this).text(text).attr({'aria-label': text});
2893
+ if(webshims.assumeARIA){
2894
+ $.attr(this, 'aria-label', text);
2895
+ }
2896
+ }
2897
+
2898
+ });
2899
+ popover.nextElement.attr({'aria-label': curCfg.date.nextText});
2900
+ $('> span', popover.nextElement).html(curCfg.date.nextText);
2901
+ popover.prevElement.attr({'aria-label': curCfg.date.prevText});
2902
+ $('> span', popover.prevElement).html(curCfg.date.prevText);
2903
+
2904
+ generateList(o, o.maxS, o.minS);
2905
+
2906
+ }
2907
+ $('button.ws-empty', popover.buttonRow).prop('disabled', $.prop(data.orig, 'required'));
2908
+ popover.isDirty = false;
2909
+ };
2910
+
2911
+ popover.actionFn = function(obj){
2912
+ if(actions[obj['data-action']]){
2913
+ actions[obj['data-action']](obj.value, popover, data, 0);
2914
+ } else {
2915
+ webshims.warn('no action for '+ obj['data-action']);
2916
+ }
2917
+ };
2918
+
2919
+ popover.contentElement.html('<button class="ws-prev" tabindex="0"><span></span></button> <button class="ws-next" tabindex="0"><span></span></button><div class="ws-picker-body"></div><div class="ws-button-row"><button type="button" class="ws-current" data-action="changeInput" value="'+today[data.type]+'" tabindex="0"></button> <button type="button" data-action="changeInput" value="" class="ws-empty" tabindex="0"></button></div>');
2920
+ popover.nextElement = $('button.ws-next', popover.contentElement);
2921
+ popover.prevElement = $('button.ws-prev', popover.contentElement);
2922
+ popover.bodyElement = $('div.ws-picker-body', popover.contentElement);
2923
+ popover.buttonRow = $('div.ws-button-row', popover.contentElement);
2924
+
2925
+ popover.isDirty = true;
2926
+
2927
+ popover.contentElement
2928
+ .on('click', 'button[data-action]', actionfn)
2929
+ .on('change', 'select[data-action]', actionfn)
2930
+ ;
2931
+
2932
+ popover.contentElement.on({
2933
+ keydown: function(e){
2934
+ if(e.keyCode == 9){
2935
+ var tabbable = $('[tabindex="0"]:not(:disabled)', this).filter(':visible');
2936
+ var index = tabbable.index(e.target);
2937
+ if(e.shiftKey && index <= 0){
2938
+ tabbable.last().focus();
2939
+ return false;
2940
+ }
2941
+ if(!e.shiftKey && index >= tabbable.length - 1){
2942
+ tabbable.first().focus();
2943
+ return false;
2944
+ }
2945
+ } else if(e.keyCode == 27){
2946
+ data.element.getShadowFocusElement().focus();
2947
+ popover.hide();
2948
+ return false;
2949
+ }
2950
+ }
2951
+ });
2952
+
2953
+ $(data.options.orig).on('input', function(){
2954
+ var currentView;
2955
+ if(data.options.updateOnInput && popover.isVisible && data.options.value && (currentView = popover.element.attr('data-currentview'))){
2956
+ actions[currentView]( data.options.value , popover, data, 0);
2957
+ }
2958
+ });
2959
+
2960
+ data._propertyChange = (function(){
2961
+ var timer;
2962
+ var update = function(){
2963
+ if(popover.isVisible){
2964
+ updateContent();
2965
+ }
2966
+ };
2967
+ return function(prop){
2968
+ if(prop == 'value'){return;}
2969
+ popover.isDirty = true;
2970
+ if(popover.isVisible){
2971
+ clearTimeout(timer);
2972
+ timer = setTimeout(update, 9);
2973
+ }
2974
+ };
2975
+ })();
2976
+
2977
+ popover.activeElement = $([]);
2978
+
2979
+ popover.activateElement = function(element){
2980
+ element = $(element);
2981
+ if(element[0] != popover.activeElement[0]){
2982
+ popover.activeElement.removeClass('ws-focus');
2983
+ element.addClass('ws-focus');
2984
+ }
2985
+ popover.activeElement = element;
2986
+ };
2987
+ popover.element.on({
2988
+ wspopoverbeforeshow: function(){
2989
+ data.element.triggerHandler('wsupdatevalue');
2990
+ updateContent();
2991
+ }
2992
+ });
2993
+
2994
+ $(document).onTrigger('wslocalechange', data._propertyChange);
2995
+ };
2996
+
2997
+ picker._common = function(data){
2998
+ var popover = webshims.objectCreate(webshims.wsPopover, {}, {prepareFor: data.element});
2999
+ var opener = $('<button type="button" class="ws-popover-opener"><span /></button>').appendTo(data.buttonWrapper);
3000
+ var options = data.options;
3001
+ var init = false;
3002
+
3003
+ var show = function(){
3004
+ if(!options.disabled && !options.readonly && !popover.isVisible){
3005
+ if(!init){
3006
+ picker.commonInit(data, popover);
3007
+ }
3008
+
3009
+ if(!init || data.options.restartView) {
3010
+ actions.setYearList( options.defValue || options.value, popover, data, data.options.startView);
3011
+ } else {
3012
+ actions[popover.element.attr('data-currentview') || 'setYearList']( options.defValue || options.value, popover, data, 0);
3013
+ }
3014
+
3015
+ init = true;
3016
+ popover.show(data.element);
3017
+ }
3018
+ };
3019
+
3020
+ options.containerElements.push(popover.element[0]);
3021
+
3022
+ if(!options.startView){
3023
+ options.startView = 0;
3024
+ }
3025
+ if(!options.minView){
3026
+ options.minView = 0;
3027
+ }
3028
+ if(options.startView < options.minView){
3029
+ options.minView = options.startView;
3030
+ webshims.warn("wrong config for minView/startView.");
3031
+ }
3032
+ if(!options.size){
3033
+ options.size = 1;
3034
+ }
3035
+
3036
+ popover.element
3037
+ .addClass(data.type+'-popover input-picker')
3038
+ .attr({role: 'application'})
3039
+ .on({
3040
+ wspopoverhide: function(){
3041
+ popover.openedByFocus = false;
3042
+ },
3043
+ focusin: function(e){
3044
+ if(popover.activateElement){
3045
+ popover.openedByFocus = false;
3046
+ popover.activateElement(e.target);
3047
+ }
3048
+ },
3049
+ focusout: function(){
3050
+ if(popover.activeElement){
3051
+ popover.activeElement.removeClass('ws-focus');
3052
+ }
3053
+ }
3054
+ })
3055
+ ;
3056
+
3057
+ labelWidth(popover.element.children('div.ws-po-outerbox').attr({role: 'group'}), options.labels, true);
3058
+ labelWidth(opener, options.labels, true);
3059
+
3060
+ opener
3061
+ .attr({
3062
+ 'tabindex': options.labels.length ? 0 : '-1'
3063
+ })
3064
+ .on({
3065
+ mousedown: function(){
3066
+ stopPropagation.apply(this, arguments);
3067
+ popover.preventBlur();
3068
+ },
3069
+ click: function(){
3070
+ if(popover.isVisible && popover.activeElement){
3071
+ popover.openedByFocus = false;
3072
+ popover.activeElement.focus();
3073
+ }
3074
+ show();
3075
+ },
3076
+ focus: function(){
3077
+ popover.preventBlur();
3078
+ }
3079
+ })
3080
+ ;
3081
+
3082
+ (function(){
3083
+ var mouseFocus = false;
3084
+ var resetMouseFocus = function(){
3085
+ mouseFocus = false;
3086
+ };
3087
+ data.inputElements.on({
3088
+ focus: function(){
3089
+ if(!popover.stopOpen && (data.options.openOnFocus || (mouseFocus && options.openOnMouseFocus))){
3090
+ popover.openedByFocus = !options.noInput;
3091
+ show();
3092
+ } else {
3093
+ popover.preventBlur();
3094
+ }
3095
+ },
3096
+ mousedown: function(){
3097
+ mouseFocus = true;
3098
+ setTimeout(resetMouseFocus, 9);
3099
+ if(data.element.is(':focus')){
3100
+ popover.openedByFocus = !options.noInput;
3101
+ show();
3102
+ }
3103
+ popover.preventBlur();
3104
+ }
3105
+ });
3106
+ })();
3107
+ data.popover = popover;
3108
+ };
3109
+
3110
+ picker.month = picker._common;
3111
+ picker.date = picker.month;
3112
+
3113
+ webshims.picker = picker;
3114
+ })();
1090
3115
 
1091
- if(options.stepArrows){
1092
- var stepDisableEnable = {
1093
- // don't change getter
1094
- set: function(value){
1095
- var stepcontrols = webshims.data(this, 'step-controls');
1096
- if(stepcontrols){
1097
- stepcontrols[ (this.disabled || this.readonly) ? 'addClass' : 'removeClass' ]('disabled-step-control');
3116
+ (function(){
3117
+
3118
+ var stopCircular, isCheckValidity;
3119
+
3120
+ var modernizrInputTypes = Modernizr.inputtypes;
3121
+ var inputTypes = {
3122
+
3123
+ };
3124
+ var copyProps = [
3125
+ 'disabled',
3126
+ 'readonly',
3127
+ 'value',
3128
+ 'min',
3129
+ 'max',
3130
+ 'step',
3131
+ 'title',
3132
+ 'placeholder'
3133
+ ];
3134
+
3135
+ //
3136
+ var copyAttrs = ['data-placeholder', 'tabindex'];
3137
+
3138
+ $.each(copyProps.concat(copyAttrs), function(i, name){
3139
+ var fnName = name.replace(/^data\-/, '');
3140
+ webshims.onNodeNamesPropertyModify('input', name, function(val){
3141
+ if(!stopCircular){
3142
+ var shadowData = webshims.data(this, 'shadowData');
3143
+ if(shadowData && shadowData.data && shadowData.nativeElement === this && shadowData.data[fnName]){
3144
+ shadowData.data[fnName](val);
3145
+ }
3146
+ }
3147
+ });
3148
+ });
3149
+
3150
+ if(options.replaceUI && 'valueAsNumber' in document.createElement('input')){
3151
+ var reflectFn = function(val){
3152
+ if(webshims.data(this, 'hasShadow')){
3153
+ $.prop(this, 'value', $.prop(this, 'value'));
3154
+ }
3155
+ };
3156
+
3157
+ webshims.onNodeNamesPropertyModify('input', 'valueAsNumber', reflectFn);
3158
+ webshims.onNodeNamesPropertyModify('input', 'valueAsDate', reflectFn);
3159
+ }
3160
+
3161
+ var extendType = (function(){
3162
+ return function(name, data){
3163
+ inputTypes[name] = data;
3164
+ data.attrs = $.merge([], copyAttrs, data.attrs);
3165
+ data.props = $.merge([], copyProps, data.props);
3166
+ };
3167
+ })();
3168
+
3169
+ var isVisible = function(){
3170
+ return $.css(this, 'display') != 'none';
3171
+ };
3172
+ var sizeInput = function(data){
3173
+ var init;
3174
+ var updateStyles = function(){
3175
+ $.style( data.orig, 'display', '' );
3176
+ var hasButtons, marginR, marginL;
3177
+ var correctWidth = 0.6;
3178
+ if(!init || data.orig.offsetWidth){
3179
+ hasButtons = data.buttonWrapper && data.buttonWrapper.filter(isVisible).length;
3180
+ marginR = $.css( data.orig, 'marginRight');
3181
+ data.element.css({
3182
+ marginLeft: $.css( data.orig, 'marginLeft'),
3183
+ marginRight: hasButtons ? 0 : marginR
3184
+ });
3185
+
3186
+ if(hasButtons){
3187
+ marginL = (parseInt(data.buttonWrapper.css('marginLeft'), 10) || 0);
3188
+ data.element.css({paddingRight: ''});
3189
+
3190
+ if(marginL < 0){
3191
+ marginR = (parseInt(marginR, 10) || 0) + ((data.buttonWrapper.outerWidth() + marginL) * -1);
3192
+ data.buttonWrapper.css('marginRight', marginR);
3193
+ data.element
3194
+ .css({paddingRight: ''})
3195
+ .css({
3196
+ paddingRight: (parseInt( data.element.css('paddingRight'), 10) || 0) + data.buttonWrapper.outerWidth()
3197
+ })
3198
+ ;
3199
+ } else {
3200
+ data.buttonWrapper.css('marginRight', marginR);
3201
+ correctWidth = data.buttonWrapper.outerWidth(true) + 0.6;
3202
+ }
3203
+ }
3204
+
3205
+ data.element.outerWidth( $(data.orig).outerWidth() - correctWidth );
3206
+ }
3207
+ init = true;
3208
+ $.style( data.orig, 'display', 'none' );
3209
+ };
3210
+ $(document).onTrigger('updateshadowdom', updateStyles);
3211
+ };
3212
+
3213
+
3214
+ var implementType = function(){
3215
+ var type = $.prop(this, 'type');
3216
+
3217
+ var i, opts, data, optsName, labels;
3218
+ if(inputTypes[type] && webshims.implement(this, 'inputwidgets')){
3219
+ data = {};
3220
+ optsName = type;
3221
+
3222
+ //todo: do we need deep extend?
3223
+
3224
+ labels = $(this).jProp('labels');
3225
+
3226
+ opts = $.extend({}, options.widgets, options[type], $($.prop(this, 'form')).data(type) || {}, $(this).data(type) || {}, {
3227
+ orig: this,
3228
+ type: type,
3229
+ labels: labels,
3230
+ options: {},
3231
+ input: function(val){
3232
+ opts._change(val, 'input');
3233
+ },
3234
+ change: function(val){
3235
+ opts._change(val, 'change');
3236
+ },
3237
+ _change: function(val, trigger){
3238
+ stopCircular = true;
3239
+ $.prop(opts.orig, 'value', val);
3240
+ stopCircular = false;
3241
+ if(trigger){
3242
+ $(opts.orig).trigger(trigger);
3243
+ }
3244
+ },
3245
+ containerElements: []
3246
+ });
3247
+
3248
+
3249
+ for(i = 0; i < copyProps.length; i++){
3250
+ opts[copyProps[i]] = $.prop(this, copyProps[i]);
3251
+ }
3252
+
3253
+ for(i = 0; i < copyAttrs.length; i++){
3254
+ optsName = copyAttrs[i].replace(/^data\-/, '');
3255
+ if(optsName == 'placeholder' || !opts[optsName]){
3256
+ opts[optsName] = $.attr(this, copyAttrs[i]) || opts[optsName];
3257
+ }
3258
+ }
3259
+
3260
+ data.shim = inputTypes[type]._create(opts);
3261
+
3262
+ webshims.addShadowDom(this, data.shim.element, {
3263
+ data: data.shim || {}
3264
+ });
3265
+
3266
+ data.shim.options.containerElements.push(data.shim.element[0]);
3267
+
3268
+ labelWidth($(this).getShadowFocusElement(), labels);
3269
+ $.attr(this, 'required', $.attr(this, 'required'));
3270
+ $(this).on('change', function(e){
3271
+ if(!stopCircular){
3272
+ data.shim.value($.prop(this, 'value'));
3273
+ }
3274
+ });
3275
+
3276
+ (function(){
3277
+ var has = {
3278
+ focusin: true,
3279
+ focus: true
3280
+ };
3281
+ var timer;
3282
+ var hasFocusTriggered = false;
3283
+ var hasFocus = false;
3284
+
3285
+ $(data.shim.options.containerElements)
3286
+ .on({
3287
+ 'focusin focus focusout blur': function(e){
3288
+ e.stopImmediatePropagation();
3289
+ hasFocus = has[e.type];
3290
+ clearTimeout(timer);
3291
+ timer = setTimeout(function(){
3292
+ if(hasFocus != hasFocusTriggered){
3293
+ hasFocusTriggered = hasFocus;
3294
+ $(opts.orig).triggerHandler(hasFocus ? 'focus' : 'blur');
3295
+ $(opts.orig).trigger(hasFocus ? 'focusin' : 'focusout');
3296
+ }
3297
+ hasFocusTriggered = hasFocus;
3298
+ }, 0);
3299
+ }
3300
+ })
3301
+ ;
3302
+ })();
3303
+
3304
+
3305
+ data.shim.element.on('change input', stopPropagation);
3306
+
3307
+ if(Modernizr.formvalidation){
3308
+ $(opts.orig).on('firstinvalid', function(e){
3309
+ if(!webshims.fromSubmit && isCheckValidity){return;}
3310
+ $(opts.orig).off('invalid.replacedwidgetbubble').on('invalid.replacedwidgetbubble', function(evt){
3311
+ if(!e.isInvalidUIPrevented() && !evt.isDefaultPrevented()){
3312
+ webshims.validityAlert.showFor( e.target );
3313
+ e.preventDefault();
3314
+ evt.preventDefault();
3315
+ }
3316
+ $(opts.orig).off('invalid.replacedwidgetbubble');
3317
+ });
3318
+ });
3319
+ }
3320
+
3321
+
3322
+ if(data.shim.buttonWrapper && data.shim.buttonWrapper.filter(isVisible).length){
3323
+ data.shim.element.addClass('has-input-buttons');
1098
3324
  }
3325
+
3326
+ if(opts.calculateWidth){
3327
+ sizeInput(data.shim);
3328
+ }
3329
+ $(this).css({display: 'none'});
1099
3330
  }
1100
3331
  };
1101
- webshims.onNodeNamesPropertyModify('input', 'disabled', stepDisableEnable);
1102
- webshims.onNodeNamesPropertyModify('input', 'readonly', $.extend({}, stepDisableEnable));
1103
- }
1104
- var stepKeys = {
1105
- 38: 1,
1106
- 40: -1
1107
- };
1108
-
1109
- var changeInput = function(elem, type){
1110
- var blockBlurChange = false;
1111
- var DELAY = 9;
1112
- var doChangeValue, blockChangeValue;
1113
-
1114
- function step(dir){
1115
- if($.prop(elem, 'disabled') || elem.readOnly || !dir){return;}
1116
- doChangeValue = typeModels[type].numberToString(getNextStep(elem, dir, {type: type}));
1117
- $.prop(elem, 'value', doChangeValue);
1118
- triggerInlineForm(elem, 'input');
1119
- }
1120
-
1121
- function setFocus(){
1122
- blockBlurChange = true;
1123
- setTimeout(function(){
1124
- blockBlurChange = false;
1125
- }, DELAY + 9);
1126
- setTimeout(function(){
1127
- if(!$(elem).is(':focus')){
1128
- try{
1129
- elem.focus();
1130
- } catch(e){}
1131
- }
1132
- }, 1);
3332
+
3333
+ if(!modernizrInputTypes.range || options.replaceUI){
3334
+ extendType('range', {
3335
+ _create: function(opts, set){
3336
+ return $('<span />').insertAfter(opts.orig).rangeUI(opts).data('rangeUi');
3337
+ }
3338
+ });
1133
3339
  }
1134
-
1135
- function triggerChange(){
1136
- var curValue = $.prop(elem, 'value');
1137
- if(curValue == doChangeValue && curValue != blockChangeValue && typeof curValue == 'string'){
1138
- triggerInlineForm(elem, 'change');
1139
- }
1140
- blockChangeValue = curValue;
3340
+
3341
+ if(Modernizr.formvalidation){
3342
+ ['input', 'form'].forEach(function(name){
3343
+ var desc = webshims.defineNodeNameProperty(name, 'checkValidity', {
3344
+ prop: {
3345
+ value: function(){
3346
+ isCheckValidity = true;
3347
+ var ret = desc.prop._supvalue.apply(this, arguments);
3348
+ isCheckValidity = false;
3349
+ return ret;
3350
+ }
3351
+ }
3352
+ });
3353
+ });
1141
3354
  }
1142
-
1143
- function init(){
1144
- blockChangeValue = $(elem)
1145
- .on({
1146
- 'change.stepcontrol focus.stepcontrol': function(e){
1147
- if(!blockBlurChange || e.type != 'focus'){
1148
- blockChangeValue = $.prop(elem, 'value');
3355
+
3356
+
3357
+ ['number', 'time', 'month', 'date'].forEach(function(name){
3358
+ if(!modernizrInputTypes[name] || options.replaceUI){
3359
+ extendType(name, {
3360
+ _create: function(opts, set){
3361
+
3362
+ if(opts.splitInput && !splitInputs[name]){
3363
+ webshims.warn('splitInput not supported for '+ name);
3364
+ opts.splitInput = false;
1149
3365
  }
1150
- },
1151
- 'blur.stepcontrol': function(){
1152
- if(!blockBlurChange){
1153
- setTimeout(function(){
1154
- if(!blockBlurChange && !$(elem).is(':focus')){
1155
- triggerChange();
1156
- }
1157
- doChangeValue = false;
1158
- }, DELAY);
3366
+ var markup = opts.splitInput ?
3367
+ '<span class="ws-'+name+' ws-input" role="group"></span>' :
3368
+ '<input class="ws-'+name+'" type="text" />';
3369
+ var data = $(markup) //role="spinbutton"???
3370
+ .insertAfter(opts.orig)
3371
+ .spinbtnUI(opts)
3372
+ .data('wsspinner')
3373
+ ;
3374
+ if(webshims.picker && webshims.picker[name]){
3375
+ webshims.picker[name](data);
1159
3376
  }
3377
+ data.buttonWrapper.addClass('input-button-size-'+(data.buttonWrapper.children().filter(isVisible).length));
3378
+ return data;
1160
3379
  }
1161
- })
1162
- .prop('value')
3380
+ });
3381
+ }
3382
+ });
3383
+
3384
+
3385
+ webshims.addReady(function(context, contextElem){
3386
+ $('input', context)
3387
+ .add(contextElem.filter('input'))
3388
+ .each(implementType)
1163
3389
  ;
1164
- }
3390
+ });
3391
+ })();
3392
+ });
3393
+
1165
3394
 
1166
- init();
1167
- return {
1168
- triggerChange: triggerChange,
1169
- step: step,
1170
- setFocus: setFocus
3395
+ jQuery.webshims.register('form-datalist', function($, webshims, window, document, undefined, options){
3396
+ "use strict";
3397
+ var doc = document;
3398
+
3399
+ /*
3400
+ * implement propType "element" currently only used for list-attribute (will be moved to dom-extend, if needed)
3401
+ */
3402
+ webshims.propTypes.element = function(descs){
3403
+ webshims.createPropDefault(descs, 'attr');
3404
+ if(descs.prop){return;}
3405
+ descs.prop = {
3406
+ get: function(){
3407
+ var elem = $.attr(this, 'list');
3408
+ if(elem){
3409
+ elem = document.getElementById(elem);
3410
+ if(elem && descs.propNodeName && !$.nodeName(elem, descs.propNodeName)){
3411
+ elem = null;
3412
+ }
3413
+ }
3414
+ return elem || null;
3415
+ },
3416
+ writeable: false
1171
3417
  };
1172
3418
  };
1173
3419
 
1174
- webshims.addReady(function(context, contextElem){
1175
- //ui for numeric values
1176
- if(options.stepArrows){
1177
- $('input', context).add(contextElem.filter('input')).each(function(){
1178
- var type = $.prop(this, 'type');
1179
- if(!typeModels[type] || !typeModels[type].asNumber || !options.stepArrows || (options.stepArrows !== true && !options.stepArrows[type]) || supportsType(type) || $(elem).hasClass('has-step-controls')){return;}
1180
- var elem = this;
1181
- var uiEvents = changeInput(elem, type);
1182
- var controls = $('<span class="step-controls" unselectable="on"><span class="step-up" /><span class="step-down" /></span>')
1183
- .insertAfter(elem)
1184
- .on({
1185
- 'selectstart dragstart': function(){return false;},
1186
- 'mousedown mousepress': function(e){
1187
- if(!$(e.target).hasClass('step-controls')){
1188
- uiEvents.step(($(e.target).hasClass('step-up')) ? 1 : -1);
3420
+
3421
+ /*
3422
+ * Implements datalist element and list attribute
3423
+ */
3424
+
3425
+ (function(){
3426
+ var formsCFG = $.webshims.cfg.forms;
3427
+ var listSupport = Modernizr.input.list;
3428
+ if(listSupport && !formsCFG.customDatalist){return;}
3429
+
3430
+ var initializeDatalist = function(){
3431
+
3432
+
3433
+ if(!listSupport){
3434
+ webshims.defineNodeNameProperty('datalist', 'options', {
3435
+ prop: {
3436
+ writeable: false,
3437
+ get: function(){
3438
+ var elem = this;
3439
+ var select = $('select', elem);
3440
+ var options;
3441
+ if(select[0]){
3442
+ options = select[0].options;
3443
+ } else {
3444
+ options = $('option', elem).get();
3445
+ if(options.length){
3446
+ webshims.warn('you should wrap your option-elements for a datalist in a select element to support IE and other old browsers.');
3447
+ }
1189
3448
  }
1190
- uiEvents.setFocus();
1191
- return false;
3449
+ return options;
3450
+ }
3451
+ }
3452
+ });
3453
+ }
3454
+
3455
+ var inputListProto = {
3456
+ //override autocomplete
3457
+ autocomplete: {
3458
+ attr: {
3459
+ get: function(){
3460
+ var elem = this;
3461
+ var data = $.data(elem, 'datalistWidget');
3462
+ if(data){
3463
+ return data._autocomplete;
3464
+ }
3465
+ return ('autocomplete' in elem) ? elem.autocomplete : elem.getAttribute('autocomplete');
1192
3466
  },
1193
- 'mousepressstart mousepressend': function(e){
1194
- if(e.type == 'mousepressend'){
1195
- uiEvents.triggerChange();
3467
+ set: function(value){
3468
+ var elem = this;
3469
+ var data = $.data(elem, 'datalistWidget');
3470
+ if(data){
3471
+ data._autocomplete = value;
3472
+ if(value == 'off'){
3473
+ data.hideList();
3474
+ }
3475
+ } else {
3476
+ if('autocomplete' in elem){
3477
+ elem.autocomplete = value;
3478
+ } else {
3479
+ elem.setAttribute('autocomplete', value);
3480
+ }
1196
3481
  }
1197
- $(e.target)[e.type == 'mousepressstart' ? 'addClass' : 'removeClass']('mousepress-ui');
1198
3482
  }
1199
- })
1200
- ;
1201
- var mwheelUpDown = function(e, d){
1202
- if(d){
1203
- uiEvents.step(d);
1204
- return false;
3483
+ }
3484
+ }
3485
+ };
3486
+
3487
+ if(formsCFG.customDatalist && (!listSupport || !('selectedOption' in $('<input />')[0]))){
3488
+ //currently not supported x-browser (FF4 has not implemented and is not polyfilled )
3489
+ inputListProto.selectedOption = {
3490
+ prop: {
3491
+ writeable: false,
3492
+ get: function(){
3493
+ var elem = this;
3494
+ var list = $.prop(elem, 'list');
3495
+ var ret = null;
3496
+ var value, options;
3497
+ if(!list){return ret;}
3498
+ value = $.prop(elem, 'value');
3499
+ if(!value){return ret;}
3500
+ options = $.prop(list, 'options');
3501
+ if(!options.length){return ret;}
3502
+ $.each(options, function(i, option){
3503
+ if(value == $.prop(option, 'value')){
3504
+ ret = option;
3505
+ return false;
3506
+ }
3507
+ });
3508
+ return ret;
3509
+ }
1205
3510
  }
1206
3511
  };
3512
+ }
3513
+
3514
+ if(!listSupport){
1207
3515
 
1208
- var jElm = $(elem)
1209
- .addClass('has-step-controls')
1210
- .attr({
1211
- readonly: elem.readOnly,
1212
- disabled: elem.disabled,
1213
- autocomplete: 'off',
1214
- role: 'spinbutton'
1215
- })
1216
- .on('keyup', function(e){
1217
- var step = stepKeys[e.keyCode];
1218
- if(step){
1219
- uiEvents.triggerChange(step);
3516
+ inputListProto['list'] = {
3517
+ attr: {
3518
+ get: function(){
3519
+ var val = webshims.contentAttr(this, 'list');
3520
+ return (val == null) ? undefined : val;
3521
+ },
3522
+ set: function(value){
3523
+ var elem = this;
3524
+ webshims.contentAttr(elem, 'list', value);
3525
+ webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
3526
+ $(elem).triggerHandler('listdatalistchange');
1220
3527
  }
1221
- })
1222
- .on('keypress', function(e){
1223
- var step = stepKeys[e.keyCode];
1224
- if(step){
1225
- uiEvents.step(step);
1226
- return false;
3528
+ },
3529
+ initAttr: true,
3530
+ reflect: true,
3531
+ propType: 'element',
3532
+ propNodeName: 'datalist'
3533
+ };
3534
+ } else {
3535
+ //options only return options, if option-elements are rooted: but this makes this part of HTML5 less backwards compatible
3536
+ if(!($('<datalist><select><option></option></select></datalist>').prop('options') || []).length ){
3537
+ webshims.defineNodeNameProperty('datalist', 'options', {
3538
+ prop: {
3539
+ writeable: false,
3540
+ get: function(){
3541
+ var options = this.options || [];
3542
+ if(!options.length){
3543
+ var elem = this;
3544
+ var select = $('select', elem);
3545
+ if(select[0] && select[0].options && select[0].options.length){
3546
+ options = select[0].options;
3547
+ }
3548
+ }
3549
+ return options;
3550
+ }
3551
+ }
3552
+ });
3553
+ }
3554
+ inputListProto['list'] = {
3555
+ attr: {
3556
+ get: function(){
3557
+ var val = webshims.contentAttr(this, 'list');
3558
+ if(val != null){
3559
+ $.data(this, 'datalistListAttr', val);
3560
+ this.removeAttribute('list');
3561
+ } else {
3562
+ val = $.data(this, 'datalistListAttr');
3563
+ }
3564
+
3565
+ return (val == null) ? undefined : val;
3566
+ },
3567
+ set: function(value){
3568
+ var elem = this;
3569
+ $.data(elem, 'datalistListAttr', value);
3570
+ webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
3571
+ $(elem).triggerHandler('listdatalistchange');
1227
3572
  }
3573
+ },
3574
+ initAttr: true,
3575
+ reflect: true,
3576
+ propType: 'element',
3577
+ propNodeName: 'datalist'
3578
+ };
3579
+ }
3580
+
3581
+ webshims.defineNodeNameProperties('input', inputListProto);
3582
+
3583
+ webshims.addReady(function(context, contextElem){
3584
+ contextElem
3585
+ .filter('datalist > select, datalist, datalist > option, datalist > select > option')
3586
+ .closest('datalist')
3587
+ .each(function(){
3588
+ $(this).triggerHandler('updateDatalist');
1228
3589
  })
3590
+
1229
3591
  ;
1230
3592
 
1231
- if(allowedChars[type]){
1232
- jElm.on('keypress', (function(){
1233
- var chars = allowedChars[type];
1234
- return function(event){
1235
- var chr = String.fromCharCode(event.charCode == null ? event.keyCode : event.charCode);
1236
- return event.ctrlKey || event.metaKey || (chr < ' ' || chars.indexOf(chr) > -1);
1237
- };
1238
- })());
3593
+ });
3594
+
3595
+
3596
+ };
3597
+
3598
+
3599
+ /*
3600
+ * ShadowList
3601
+ */
3602
+ var listidIndex = 0;
3603
+ var noDatalistSupport = {
3604
+ submit: 1,
3605
+ button: 1,
3606
+ reset: 1,
3607
+ hidden: 1,
3608
+
3609
+ range: 1,
3610
+ date: 1,
3611
+ month: 1
3612
+ };
3613
+ if(webshims.modules["form-number-date-ui"].loaded){
3614
+ $.extend(noDatalistSupport, {
3615
+ number: 1,
3616
+ time: 1
3617
+ });
3618
+ }
3619
+
3620
+ var globStoredOptions = {};
3621
+ var getStoredOptions = function(name){
3622
+ if(!name){return [];}
3623
+ if(globStoredOptions[name]){
3624
+ return globStoredOptions[name];
3625
+ }
3626
+ var data;
3627
+ try {
3628
+ data = JSON.parse(localStorage.getItem('storedDatalistOptions'+name));
3629
+ } catch(e){}
3630
+ globStoredOptions[name] = data || [];
3631
+ return data || [];
3632
+ };
3633
+ var storeOptions = function(name, val){
3634
+ if(!name){return;}
3635
+ val = val || [];
3636
+ try {
3637
+ localStorage.setItem( 'storedDatalistOptions'+name, JSON.stringify(val) );
3638
+ } catch(e){}
3639
+ };
3640
+
3641
+ var getText = function(elem){
3642
+ return (elem.textContent || elem.innerText || $.text([ elem ]) || '');
3643
+ };
3644
+ var lReg = /</g;
3645
+ var gReg = />/g;
3646
+
3647
+ var shadowListProto = {
3648
+ _create: function(opts){
3649
+
3650
+ if(noDatalistSupport[$.prop(opts.input, 'type')] || noDatalistSupport[$.attr(opts.input, 'type')]){return;}
3651
+ var datalist = opts.datalist;
3652
+ var data = $.data(opts.input, 'datalistWidget');
3653
+ if(datalist && data && data.datalist !== datalist){
3654
+ data.datalist = datalist;
3655
+ data.id = opts.id;
3656
+
3657
+
3658
+ $(data.datalist)
3659
+ .off('updateDatalist.datalistWidget')
3660
+ .on('updateDatalist.datalistWidget', $.proxy(data, '_resetListCached'))
3661
+ ;
3662
+
3663
+ data._resetListCached();
3664
+ return;
3665
+ } else if(!datalist){
3666
+ if(data){
3667
+ data.destroy();
3668
+ }
3669
+ return;
3670
+ } else if(data && data.datalist === datalist){
3671
+ return;
1239
3672
  }
3673
+ listidIndex++;
3674
+ var that = this;
3675
+ this.hideList = $.proxy(that, 'hideList');
1240
3676
 
1241
- jElm
3677
+ this.datalist = datalist;
3678
+ this.id = opts.id;
3679
+ this.hasViewableData = true;
3680
+ this._autocomplete = $.attr(opts.input, 'autocomplete');
3681
+ $.data(opts.input, 'datalistWidget', this);
3682
+
3683
+ this.popover = webshims.objectCreate(webshims.wsPopover, {}, options.datalistPopover);
3684
+ this.shadowList = this.popover.element.addClass('datalist-polyfill');
3685
+
3686
+
3687
+ this.index = -1;
3688
+ this.input = opts.input;
3689
+ this.arrayOptions = [];
3690
+
3691
+ this.shadowList
3692
+ .delegate('li', 'mouseenter.datalistWidget mousedown.datalistWidget click.datalistWidget', function(e){
3693
+ var items = $('li:not(.hidden-item)', that.shadowList);
3694
+ var select = (e.type == 'mousedown' || e.type == 'click');
3695
+ that.markItem(items.index(e.currentTarget), select, items);
3696
+ if(e.type == 'click'){
3697
+ that.hideList();
3698
+ if(formsCFG.customDatalist){
3699
+ $(opts.input).getNativeElement().trigger('datalistselect');
3700
+ }
3701
+ }
3702
+ return (e.type != 'mousedown');
3703
+ })
3704
+ ;
3705
+
3706
+ opts.input.setAttribute('autocomplete', 'off');
3707
+
3708
+ $(opts.input)
3709
+ .attr({
3710
+ //role: 'combobox',
3711
+ 'aria-haspopup': 'true'
3712
+ })
1242
3713
  .on({
1243
- focus: function(){
1244
- jElm.add(controls).off('.mwhellwebshims')
1245
- .on('mousewheel.mwhellwebshims', mwheelUpDown)
1246
- ;
3714
+ 'input.datalistWidget': function(){
3715
+ if(!that.triggeredByDatalist){
3716
+ that.changedValue = false;
3717
+ that.showHideOptions();
3718
+ }
3719
+ },
3720
+ 'keydown.datalistWidget': function(e){
3721
+ var keyCode = e.keyCode;
3722
+ var activeItem;
3723
+ var items;
3724
+ if(keyCode == 40 && !that.showList()){
3725
+ that.markItem(that.index + 1, true);
3726
+ return false;
3727
+ }
3728
+
3729
+ if(!that.popover.isVisible){return;}
3730
+
3731
+
3732
+ if(keyCode == 38){
3733
+ that.markItem(that.index - 1, true);
3734
+ return false;
3735
+ }
3736
+ if(!e.shiftKey && (keyCode == 33 || keyCode == 36)){
3737
+ that.markItem(0, true);
3738
+ return false;
3739
+ }
3740
+ if(!e.shiftKey && (keyCode == 34 || keyCode == 35)){
3741
+ items = $('li:not(.hidden-item)', that.shadowList);
3742
+ that.markItem(items.length - 1, true, items);
3743
+ return false;
3744
+ }
3745
+ if(keyCode == 13 || keyCode == 27){
3746
+ if (keyCode == 13){
3747
+ activeItem = $('li.active-item:not(.hidden-item)', that.shadowList);
3748
+ that.changeValue( $('li.active-item:not(.hidden-item)', that.shadowList) );
3749
+ }
3750
+ that.hideList();
3751
+ if(formsCFG.customDatalist && activeItem && activeItem[0]){
3752
+ $(opts.input).getNativeElement().trigger('datalistselect');
3753
+ }
3754
+ return false;
3755
+ }
3756
+ },
3757
+ 'focus.datalistWidget': function(){
3758
+ if($(this).hasClass('list-focus')){
3759
+ that.showList();
3760
+ }
1247
3761
  },
1248
- blur: function(){
1249
- $(elem).add(controls).off('.mwhellwebshims');
3762
+ 'mousedown.datalistWidget': function(){
3763
+ if($(this).is(':focus')){
3764
+ that.showList();
3765
+ }
1250
3766
  }
1251
3767
  })
1252
3768
  ;
1253
3769
 
1254
- webshims.data(elem, 'step-controls', controls);
1255
- if(options.calculateWidth){
1256
- var init;
1257
- $(document)
1258
- .onTrigger('updateshadowdom', function(){
1259
- if(!init && (elem.offsetWidth || elem.offsetHeight)){
1260
- init = true;
1261
- adjustInputWithBtn(jElm, controls);
1262
- controls.css('marginTop', (jElm.outerHeight() - controls.outerHeight()) / 2);
3770
+
3771
+ $(this.datalist)
3772
+ .off('updateDatalist.datalistWidget')
3773
+ .on('updateDatalist.datalistWidget', $.proxy(this, '_resetListCached'))
3774
+ ;
3775
+
3776
+ this._resetListCached();
3777
+
3778
+ if(opts.input.form && (opts.input.name || opts.input.id)){
3779
+ $(opts.input.form).on('submit.datalistWidget'+opts.input.id, function(){
3780
+ if(!$(opts.input).hasClass('no-datalist-cache') && that._autocomplete != 'off'){
3781
+ var val = $.prop(opts.input, 'value');
3782
+ var name = (opts.input.name || opts.input.id) + $.prop(opts.input, 'type');
3783
+ if(!that.storedOptions){
3784
+ that.storedOptions = getStoredOptions( name );
1263
3785
  }
1264
- })
1265
- ;
3786
+ if(val && that.storedOptions.indexOf(val) == -1){
3787
+ that.storedOptions.push(val);
3788
+ storeOptions(name, that.storedOptions );
3789
+ }
3790
+ }
3791
+ });
1266
3792
  }
1267
- });
1268
- }
1269
- });
1270
- })();
3793
+ $(window).on('unload.datalist'+this.id+' beforeunload.datalist'+this.id, function(){
3794
+ that.destroy();
3795
+ });
3796
+ },
3797
+ destroy: function(){
3798
+ var autocomplete = $.attr(this.input, 'autocomplete');
3799
+ $(this.input)
3800
+ .off('.datalistWidget')
3801
+ .removeData('datalistWidget')
3802
+ ;
3803
+ this.shadowList.remove();
3804
+ $(document).off('.datalist'+this.id);
3805
+ $(window).off('.datalist'+this.id);
3806
+ if(this.input.form && this.input.id){
3807
+ $(this.input.form).off('submit.datalistWidget'+this.input.id);
3808
+ }
3809
+ this.input.removeAttribute('aria-haspopup');
3810
+ if(autocomplete === undefined){
3811
+ this.input.removeAttribute('autocomplete');
3812
+ } else {
3813
+ $(this.input).attr('autocomplete', autocomplete);
3814
+ }
3815
+ },
3816
+ _resetListCached: function(e){
3817
+ var that = this;
3818
+ var forceShow;
3819
+ this.needsUpdate = true;
3820
+ this.lastUpdatedValue = false;
3821
+ this.lastUnfoundValue = '';
1271
3822
 
1272
-
1273
- webshims.addReady(function(context, elem){
1274
- $(document).on('jquery-uiReady.initinputui input-widgetsReady.initinputui', function(e){
1275
- if($.datepicker || $.fn.slider){
1276
- if($.datepicker && !defaultDatepicker.dateFormat){
1277
- defaultDatepicker.dateFormat = $.datepicker._defaults.dateFormat;
3823
+ if(!this.updateTimer){
3824
+ if(window.QUnit || (forceShow = ($(that.input).is(':focus') && ($(that.input).hasClass('list-focus') || $.prop(that.input, 'value'))) )){
3825
+ that.updateListOptions(forceShow);
3826
+ } else {
3827
+ webshims.ready('WINDOWLOAD', function(){
3828
+ that.updateTimer = setTimeout(function(){
3829
+ that.updateListOptions();
3830
+ that = null;
3831
+ listidIndex = 1;
3832
+ }, 200 + (100 * listidIndex));
3833
+ });
3834
+ }
1278
3835
  }
1279
- replaceInputUI(context, elem);
1280
- }
1281
- if($.datepicker && $.fn.slider){
1282
- $(document).unbind('.initinputui');
1283
- } else if(!webshims.modules["input-widgets"].src){
1284
- webshims.warn('jQuery UI Widget factory is already included, but not datepicker or slider. configure src of $.webshims.modules["input-widgets"].src');
3836
+ },
3837
+ updateListOptions: function(_forceShow){
3838
+ this.needsUpdate = false;
3839
+ clearTimeout(this.updateTimer);
3840
+ this.updateTimer = false;
3841
+
3842
+ this.searchStart = formsCFG.customDatalist && $(this.input).hasClass('search-start');
3843
+ this.addMarkElement = options.addMark || $(this.input).hasClass('mark-option-text');
3844
+
3845
+ var list = [];
3846
+
3847
+ var values = [];
3848
+ var allOptions = [];
3849
+ var rElem, rItem, rOptions, rI, rLen, item, value;
3850
+ for(rOptions = $.prop(this.datalist, 'options'), rI = 0, rLen = rOptions.length; rI < rLen; rI++){
3851
+ rElem = rOptions[rI];
3852
+ if(!rElem.disabled && (value = $(rElem).val())){
3853
+ rItem = {
3854
+ value: value.replace(lReg, '&lt;').replace(gReg, '&gt;'),
3855
+ label: $.trim($.attr(rElem, 'label') || getText(rElem)).replace(lReg, '&lt;').replace(gReg, '&gt;'),
3856
+ className: rElem.className || ''
3857
+ };
3858
+
3859
+ if(rItem.label){
3860
+ rItem.className += ' has-option-label';
3861
+ }
3862
+ values.push(rItem.value);
3863
+ allOptions.push(rItem);
3864
+ }
3865
+ }
3866
+
3867
+ if(!this.storedOptions){
3868
+ this.storedOptions = ($(this.input).hasClass('no-datalist-cache') || this._autocomplete == 'off') ? [] : getStoredOptions((this.input.name || this.input.id) + $.prop(this.input, 'type'));
3869
+ }
3870
+
3871
+ this.storedOptions.forEach(function(val, i){
3872
+ if(values.indexOf(val) == -1){
3873
+ allOptions.push({value: val, label: '', className: 'stored-suggest', style: ''});
3874
+ }
3875
+ });
3876
+
3877
+ for(rI = 0, rLen = allOptions.length; rI < rLen; rI++){
3878
+ item = allOptions[rI];
3879
+ list[rI] = '<li class="'+ item.className +'" tabindex="-1" role="listitem">'+ this.getOptionContent(item) +'</li>';
3880
+ }
3881
+
3882
+ this.arrayOptions = allOptions;
3883
+ this.popover.contentElement.html('<div class="datalist-box"><ul role="list">'+ list.join("\n") +'</ul></div>');
3884
+
3885
+
3886
+ if(_forceShow || this.popover.isVisible){
3887
+ this.showHideOptions();
3888
+ }
3889
+ },
3890
+ getOptionContent: function(item){
3891
+ var content = '';
3892
+ if(options.getOptionContent){
3893
+ content = options.apply(this, arguments) || '';
3894
+ } else {
3895
+ content = '<span class="option-value">'+ item.value +'</span>';
3896
+ if(item.label){
3897
+ content += ' <span class="option-label">'+ item.label +'</span>';
3898
+ }
3899
+ }
3900
+ return content;
3901
+ },
3902
+ showHideOptions: function(_fromShowList){
3903
+ var value = $.prop(this.input, 'value').toLowerCase();
3904
+
3905
+ //first check prevent infinite loop, second creates simple lazy optimization
3906
+ if(value === this.lastUpdatedValue){
3907
+ return;
3908
+ }
3909
+ if(this.lastUnfoundValue && value.indexOf(this.lastUnfoundValue) === 0){
3910
+ this.hideList();
3911
+ return;
3912
+ }
3913
+
3914
+
3915
+ this.lastUpdatedValue = value;
3916
+ var found = false;
3917
+ var startSearch = this.searchStart;
3918
+ var lis = $('li', this.shadowList);
3919
+ var that = this;
3920
+ if(value){
3921
+
3922
+ this.arrayOptions.forEach(function(item, i){
3923
+ var search, searchIndex, foundName;
3924
+ if(!('lowerValue' in item)){
3925
+ item.lowerValue = item.value.toLowerCase();
3926
+ if(item.label && item.label != item.value ){
3927
+ item.lowerLabel = item.label.toLowerCase();
3928
+ }
3929
+ }
3930
+
3931
+ if(value != item.lowerValue && item.lowerLabel != value){
3932
+ searchIndex = item.lowerValue.indexOf(value);
3933
+ search = startSearch ? !searchIndex : searchIndex !== -1;
3934
+ if(search){
3935
+ foundName = 'value';
3936
+ } else if(item.lowerLabel){
3937
+ searchIndex = item.lowerLabel.indexOf(value);
3938
+ search = startSearch ? !searchIndex : searchIndex !== -1;
3939
+ foundName = 'label';
3940
+ }
3941
+ }
3942
+
3943
+ if(search){
3944
+ that.addMark($(lis[i]).removeClass('hidden-item'), item, foundName, searchIndex, value.length);
3945
+ found = true;
3946
+ } else {
3947
+ $(lis[i]).addClass('hidden-item');
3948
+ }
3949
+ });
3950
+ } else if(lis.length) {
3951
+ this.removeMark(lis.removeClass('hidden-item'));
3952
+ found = true;
3953
+ }
3954
+
3955
+ this.hasViewableData = found;
3956
+ if(!_fromShowList && found){
3957
+ this.showList();
3958
+ }
3959
+
3960
+ if(!found){
3961
+ this.lastUnfoundValue = value;
3962
+ this.hideList();
3963
+ } else {
3964
+ this.lastUnfoundValue = false;
3965
+ }
3966
+ },
3967
+ otherType: {
3968
+ value: 'label',
3969
+ label: 'value'
3970
+ },
3971
+ addMark: function(elem, item, prop, start, length){
3972
+ if(this.addMarkElement){
3973
+ var text = item[prop].substr(start, length);
3974
+ text = item[prop].replace(text ,'<mark>'+ text +'</mark>');
3975
+ $('.option-'+ this.otherType[prop] +' > mark', elem).each(this._replaceMark);
3976
+ $('.option-'+prop, elem).html(text);
3977
+
3978
+ }
3979
+ },
3980
+ _replaceMark: function(){
3981
+ var content = $(this).html();
3982
+ $(this).replaceWith(content);
3983
+ },
3984
+ removeMark: function(lis){
3985
+ if(this.addMarkElement){
3986
+ $('mark', lis).each(this._replaceMark);
3987
+ }
3988
+ },
3989
+ showList: function(){
3990
+ if(this.popover.isVisible){return false;}
3991
+ if(this.needsUpdate){
3992
+ this.updateListOptions();
3993
+ }
3994
+ this.showHideOptions(true);
3995
+ if(!this.hasViewableData){return false;}
3996
+ var that = this;
3997
+
3998
+ that.shadowList.find('li.active-item').removeClass('active-item');
3999
+ that.popover.show(this.input);
4000
+
4001
+
4002
+ return true;
4003
+ },
4004
+ hideList: function(){
4005
+ if(!this.popover.isVisible){return false;}
4006
+ var that = this;
4007
+
4008
+
4009
+ this.popover.hide();
4010
+ that.shadowList.removeClass('datalist-visible list-item-active');
4011
+ that.index = -1;
4012
+ if(that.changedValue){
4013
+ that.triggeredByDatalist = true;
4014
+ $(that.input).trigger('input').trigger('change');
4015
+ that.changedValue = false;
4016
+ that.triggeredByDatalist = false;
4017
+ }
4018
+
4019
+ return true;
4020
+ },
4021
+ scrollIntoView: function(elem){
4022
+ var ul = $('ul', this.shadowList);
4023
+ var div = $('div.datalist-box', this.shadowList);
4024
+ var elemPos = elem.position();
4025
+ var containerHeight;
4026
+ elemPos.top -= (parseInt(ul.css('paddingTop'), 10) || 0) + (parseInt(ul.css('marginTop'), 10) || 0) + (parseInt(ul.css('borderTopWidth'), 10) || 0);
4027
+ if(elemPos.top < 0){
4028
+ div.scrollTop( div.scrollTop() + elemPos.top - 2);
4029
+ return;
4030
+ }
4031
+ elemPos.top += elem.outerHeight();
4032
+ containerHeight = div.height();
4033
+ if(elemPos.top > containerHeight){
4034
+ div.scrollTop( div.scrollTop() + (elemPos.top - containerHeight) + 2);
4035
+ }
4036
+ },
4037
+ changeValue: function(activeItem){
4038
+ if(!activeItem[0]){return;}
4039
+ var spinner;
4040
+ var newValue = $('span.option-value', activeItem).text();
4041
+ var oldValue = $.prop(this.input, 'value');
4042
+ if(newValue != oldValue){
4043
+
4044
+ $(this.input)
4045
+ .prop('value', newValue)
4046
+ .triggerHandler('updateInput')
4047
+ ;
4048
+ this.changedValue = true;
4049
+ if((spinner = $.data(this.input, 'wsspinner')) && spinner.setInput){
4050
+ spinner.setInput(newValue);
4051
+ }
4052
+ }
4053
+ },
4054
+ markItem: function(index, doValue, items){
4055
+ var activeItem;
4056
+ var goesUp;
4057
+
4058
+ items = items || $('li:not(.hidden-item)', this.shadowList);
4059
+ if(!items.length){return;}
4060
+ if(index < 0){
4061
+ index = items.length - 1;
4062
+ } else if(index >= items.length){
4063
+ index = 0;
4064
+ }
4065
+ items.removeClass('active-item');
4066
+ this.shadowList.addClass('list-item-active');
4067
+ activeItem = items.filter(':eq('+ index +')').addClass('active-item');
4068
+
4069
+ if(doValue){
4070
+ this.changeValue(activeItem);
4071
+ this.scrollIntoView(activeItem);
4072
+ }
4073
+ this.index = index;
1285
4074
  }
1286
- });
1287
- });
4075
+ };
4076
+
4077
+ //init datalist update
4078
+ initializeDatalist();
4079
+ })();
1288
4080
 
1289
- });
1290
-
4081
+ });