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,1635 +1,2611 @@
1
- //DOM-Extension helper
2
- jQuery.webshims.register('dom-extend', function($, webshims, window, document, undefined){
3
- "use strict";
4
- //shortcus
5
- var modules = webshims.modules;
6
- var listReg = /\s*,\s*/;
7
-
8
- //proxying attribute
9
- var olds = {};
10
- var havePolyfill = {};
11
- var extendedProps = {};
12
- var extendQ = {};
13
- var modifyProps = {};
14
-
15
- var oldVal = $.fn.val;
16
- var singleVal = function(elem, name, val, pass, _argless){
17
- return (_argless) ? oldVal.call($(elem)) : oldVal.call($(elem), val);
18
- };
19
-
20
- $.fn.onTrigger = function(evt, fn){
21
- return this.on(evt, fn).each(fn);
22
- };
1
+ (function($){
23
2
 
24
- $.fn.val = function(val){
25
- var elem = this[0];
26
- if(arguments.length && val == null){
27
- val = '';
28
- }
29
- if(!arguments.length){
30
- if(!elem || elem.nodeType !== 1){return oldVal.call(this);}
31
- return $.prop(elem, 'value', val, 'val', true);
32
- }
33
- if($.isArray(val)){
34
- return oldVal.apply(this, arguments);
35
- }
36
- var isFunction = $.isFunction(val);
37
- return this.each(function(i){
38
- elem = this;
39
- if(elem.nodeType === 1){
40
- if(isFunction){
41
- var genVal = val.call( elem, i, $.prop(elem, 'value', undefined, 'val', true));
42
- if(genVal == null){
43
- genVal = '';
44
- }
45
- $.prop(elem, 'value', genVal, 'val') ;
46
- } else {
47
- $.prop(elem, 'value', val, 'val');
48
- }
49
- }
50
- });
3
+ var id = 0;
4
+ var isNumber = function(string){
5
+ return (typeof string == 'number' || (string && string == string * 1));
51
6
  };
52
-
53
- var dataID = '_webshimsLib'+ (Math.round(Math.random() * 1000));
54
- var elementData = function(elem, key, val){
55
- elem = elem.jquery ? elem[0] : elem;
56
- if(!elem){return val || {};}
57
- var data = $.data(elem, dataID);
58
- if(val !== undefined){
59
- if(!data){
60
- data = $.data(elem, dataID, {});
61
- }
62
- if(key){
63
- data[key] = val;
64
- }
7
+ var retDefault = function(val, def){
8
+ if(!(typeof val == 'number' || (val && val == val * 1))){
9
+ return def;
65
10
  }
66
-
67
- return key ? data && data[key] : data;
11
+ return val * 1;
68
12
  };
69
-
70
-
71
- [{name: 'getNativeElement', prop: 'nativeElement'}, {name: 'getShadowElement', prop: 'shadowElement'}, {name: 'getShadowFocusElement', prop: 'shadowFocusElement'}].forEach(function(data){
72
- $.fn[data.name] = function(){
73
- return this.map(function(){
74
- var shadowData = elementData(this, 'shadowData');
75
- return shadowData && shadowData[data.prop] || this;
76
- });
77
- };
78
- });
79
-
80
-
81
- ['removeAttr', 'prop', 'attr'].forEach(function(type){
82
- olds[type] = $[type];
83
- $[type] = function(elem, name, value, pass, _argless){
84
- var isVal = (pass == 'val');
85
- var oldMethod = !isVal ? olds[type] : singleVal;
86
- if( !elem || !havePolyfill[name] || elem.nodeType !== 1 || (!isVal && pass && type == 'attr' && $.attrFn[name]) ){
87
- return oldMethod(elem, name, value, pass, _argless);
88
- }
13
+ var createOpts = ['step', 'min', 'max', 'readonly', 'title', 'disabled', 'tabindex'];
14
+ var rangeProto = {
15
+ _create: function(){
16
+ var i;
89
17
 
90
- var nodeName = (elem.nodeName || '').toLowerCase();
91
- var desc = extendedProps[nodeName];
92
- var curType = (type == 'attr' && (value === false || value === null)) ? 'removeAttr' : type;
93
- var propMethod;
94
- var oldValMethod;
95
- var ret;
96
18
 
19
+ 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>');
20
+ this.trail = $('.ws-range-rail', this.element);
21
+ this.range = $('.ws-range-min', this.element);
22
+ this.thumb = $('.ws-range-thumb', this.trail);
97
23
 
98
- if(!desc){
99
- desc = extendedProps['*'];
24
+ this.updateMetrics();
25
+
26
+ this.orig = this.options.orig;
27
+
28
+ for(i = 0; i < createOpts.length; i++){
29
+ this[createOpts[i]](this.options[createOpts[i]]);
100
30
  }
101
- if(desc){
102
- desc = desc[name];
31
+ this.value = this._value;
32
+ this.value(this.options.value);
33
+ this.initDataList();
34
+ this.element.data('rangeUi', this);
35
+ this.addBindings();
36
+ this._init = true;
37
+ },
38
+ value: $.noop,
39
+ _value: function(val, _noNormalize, animate){
40
+ var left, posDif;
41
+ var o = this.options;
42
+ var oVal = val;
43
+ var thumbStyle = {};
44
+ var rangeStyle = {};
45
+ if(!_noNormalize && parseFloat(val, 10) != val){
46
+ val = o.min + ((o.max - o.min) / 2);
103
47
  }
104
48
 
105
- if(desc){
106
- propMethod = desc[curType];
49
+ if(!_noNormalize){
50
+ val = this.normalizeVal(val);
107
51
  }
52
+ left = 100 * ((val - o.min) / (o.max - o.min));
108
53
 
109
- if(propMethod){
110
- if(name == 'value'){
111
- oldValMethod = propMethod.isVal;
112
- propMethod.isVal = isVal;
113
- }
114
- if(curType === 'removeAttr'){
115
- return propMethod.value.call(elem);
116
- } else if(value === undefined){
117
- return (propMethod.get) ?
118
- propMethod.get.call(elem) :
119
- propMethod.value
120
- ;
121
- } else if(propMethod.set) {
122
- if(type == 'attr' && value === true){
123
- value = name;
124
- }
125
-
126
- ret = propMethod.set.call(elem, value);
127
- }
128
- if(name == 'value'){
129
- propMethod.isVal = oldValMethod;
130
- }
131
- } else {
132
- ret = oldMethod(elem, name, value, pass, _argless);
54
+ this.options.value = val;
55
+ this.thumb.stop();
56
+ this.range.stop();
57
+
58
+ rangeStyle[this.dirs.width] = left+'%';
59
+ if(this.vertical){
60
+ left = Math.abs(left - 100);
133
61
  }
134
- if((value !== undefined || curType === 'removeAttr') && modifyProps[nodeName] && modifyProps[nodeName][name]){
135
-
136
- var boolValue;
137
- if(curType == 'removeAttr'){
138
- boolValue = false;
139
- } else if(curType == 'prop'){
140
- boolValue = !!(value);
62
+ thumbStyle[this.dirs.left] = left+'%';
63
+
64
+
65
+ if(!animate){
66
+ this.thumb.css(thumbStyle);
67
+ this.range.css(rangeStyle);
68
+ } else {
69
+ if(typeof animate != 'object'){
70
+ animate = {};
141
71
  } else {
142
- boolValue = true;
72
+ animate = $.extend({}, animate);
143
73
  }
144
-
145
- modifyProps[nodeName][name].forEach(function(fn){
146
- if(!fn.only || (fn.only = 'prop' && type == 'prop') || (fn.only == 'attr' && type != 'prop')){
147
- fn.call(elem, value, boolValue, (isVal) ? 'val' : curType, type);
148
- }
149
- });
150
- }
151
- return ret;
152
- };
153
-
154
- extendQ[type] = function(nodeName, prop, desc){
155
-
156
- if(!extendedProps[nodeName]){
157
- extendedProps[nodeName] = {};
74
+ if(!animate.duration){
75
+ posDif = Math.abs(left - parseInt(this.thumb[0].style[this.dirs.left] || 50, 10));
76
+ animate.duration = Math.max(Math.min(999, posDif * 5), 99);
77
+ }
78
+ this.thumb.animate(thumbStyle, animate);
79
+ this.range.animate(rangeStyle, animate);
158
80
  }
159
- if(!extendedProps[nodeName][prop]){
160
- extendedProps[nodeName][prop] = {};
81
+ if(this.orig && (oVal != val || (!this._init && this.orig.value != val)) ){
82
+ this.options._change(val);
161
83
  }
162
- var oldDesc = extendedProps[nodeName][prop][type];
163
- var getSup = function(propType, descriptor, oDesc){
164
- if(descriptor && descriptor[propType]){
165
- return descriptor[propType];
166
- }
167
- if(oDesc && oDesc[propType]){
168
- return oDesc[propType];
169
- }
170
- if(type == 'prop' && prop == 'value'){
171
- return function(value){
172
- var elem = this;
173
- return (desc.isVal) ?
174
- singleVal(elem, prop, value, false, (arguments.length === 0)) :
175
- olds[type](elem, prop, value)
176
- ;
177
- };
178
- }
179
- if(type == 'prop' && propType == 'value' && desc.value.apply){
180
- return function(value){
181
- var sup = olds[type](this, prop);
182
- if(sup && sup.apply){
183
- sup = sup.apply(this, arguments);
184
- }
185
- return sup;
186
- };
187
- }
188
- return function(value){
189
- return olds[type](this, prop, value);
190
- };
191
- };
192
- extendedProps[nodeName][prop][type] = desc;
193
- if(desc.value === undefined){
194
- if(!desc.set){
195
- desc.set = desc.writeable ?
196
- getSup('set', desc, oldDesc) :
197
- (webshims.cfg.useStrict && prop == 'prop') ?
198
- function(){throw(prop +' is readonly on '+ nodeName);} :
199
- $.noop
84
+ this.element.attr({
85
+ 'aria-valuenow': this.options.value,
86
+ 'aria-valuetext': this.options.textValue ? this.options.textValue(this.options.value) : this.options.options[this.options.value] || this.options.value
87
+ });
88
+ },
89
+ initDataList: function(){
90
+ if(this.orig){
91
+ var listTimer;
92
+ var that = this;
93
+ var updateList = function(){
94
+ $(that.orig)
95
+ .jProp('list')
96
+ .off('updateDatalist', updateList)
97
+ .on('updateDatalist', updateList)
200
98
  ;
201
- }
202
- if(!desc.get){
203
- desc.get = getSup('get', desc, oldDesc);
204
- }
99
+ clearTimeout(listTimer);
100
+ listTimer = setTimeout(function(){
101
+ if(that.list){
102
+ that.list();
103
+ }
104
+ }, 9);
105
+
106
+ };
205
107
 
108
+ $(this.orig).on('listdatalistchange', updateList);
109
+ this.list();
206
110
  }
111
+ },
112
+ list: function(opts){
113
+ var o = this.options;
114
+ var min = o.min;
115
+ var max = o.max;
116
+ var trail = this.trail;
117
+ var that = this;
118
+
119
+ this.element.attr({'aria-valuetext': o.options[o.value] || o.value});
120
+ $('.ws-range-ticks', trail).remove();
207
121
 
208
- ['value', 'get', 'set'].forEach(function(descProp){
209
- if(desc[descProp]){
210
- desc['_sup'+descProp] = getSup(descProp, oldDesc);
211
- }
212
- });
213
- };
214
-
215
- });
216
-
217
- //see also: https://github.com/lojjic/PIE/issues/40 | https://prototype.lighthouseapp.com/projects/8886/tickets/1107-ie8-fatal-crash-when-prototypejs-is-loaded-with-rounded-cornershtc
218
- var isExtendNativeSave = Modernizr.ES5;
219
- var extendNativeValue = (function(){
220
- var UNKNOWN = webshims.getPrototypeOf(document.createElement('foobar'));
221
- var has = Object.prototype.hasOwnProperty;
222
- return function(nodeName, prop, desc){
223
- var elem;
224
- var elemProto;
225
- if( isExtendNativeSave && (elem = document.createElement(nodeName)) && (elemProto = webshims.getPrototypeOf(elem)) && UNKNOWN !== elemProto && ( !elem[prop] || !has.call(elem, prop) ) ){
226
- var sup = elem[prop];
227
- desc._supvalue = function(){
228
- if(sup && sup.apply){
229
- return sup.apply(this, arguments);
230
- }
231
- return sup;
232
- };
233
- elemProto[prop] = desc.value;
234
- } else {
235
- desc._supvalue = function(){
236
- var data = elementData(this, 'propValue');
237
- if(data && data[prop] && data[prop].apply){
238
- return data[prop].apply(this, arguments);
239
- }
240
- return data && data[prop];
241
- };
242
- initProp.extendValue(nodeName, prop, desc.value);
243
- }
244
- desc.value._supvalue = desc._supvalue;
245
- };
246
- })();
247
-
248
- var initProp = (function(){
249
-
250
- var initProps = {};
251
-
252
- webshims.addReady(function(context, contextElem){
253
- var nodeNameCache = {};
254
- var getElementsByName = function(name){
255
- if(!nodeNameCache[name]){
256
- nodeNameCache[name] = $(context.getElementsByTagName(name));
257
- if(contextElem[0] && $.nodeName(contextElem[0], name)){
258
- nodeNameCache[name] = nodeNameCache[name].add(contextElem);
259
- }
260
- }
261
- };
262
122
 
123
+ $(this.orig).jProp('list').find('option').each(function(){
124
+ o.options[$.prop(this, 'value')] = $.prop(this, 'label');
125
+ });
263
126
 
264
- $.each(initProps, function(name, fns){
265
- getElementsByName(name);
266
- if(!fns || !fns.forEach){
267
- webshims.warn('Error: with '+ name +'-property. methods: '+ fns);
268
- return;
127
+ $.each(o.options, function(val, label){
128
+ if(!isNumber(val) || val < min || val > max){return;}
129
+ var left = 100 * ((val - min) / (max - min));
130
+ var title = o.showLabels ? ' title="'+ label +'"' : '';
131
+ if(that.vertical){
132
+ left = Math.abs(left - 100);
269
133
  }
270
- fns.forEach(function(fn){
271
- nodeNameCache[name].each(fn);
272
- });
134
+ trail.append('<span class="ws-range-ticks"'+ title +' style="'+(that.dirs.left)+': '+left+'%;" />');
273
135
  });
274
- nodeNameCache = null;
275
- });
276
-
277
- var tempCache;
278
- var emptyQ = $([]);
279
- var createNodeNameInit = function(nodeName, fn){
280
- if(!initProps[nodeName]){
281
- initProps[nodeName] = [fn];
136
+ },
137
+ readonly: function(val){
138
+ val = !!val;
139
+ this.options.readonly = val;
140
+ this.element.attr('aria-readonly', ''+val);
141
+ },
142
+ disabled: function(val){
143
+ val = !!val;
144
+ this.options.disabled = val;
145
+ if(val){
146
+ this.element.attr({tabindex: -1, 'aria-disabled': 'true'});
282
147
  } else {
283
- initProps[nodeName].push(fn);
148
+ this.element.attr({tabindex: this.options.tabindex, 'aria-disabled': 'false'});
284
149
  }
285
- if($.isDOMReady){
286
- (tempCache || $( document.getElementsByTagName(nodeName) )).each(fn);
150
+ },
151
+ tabindex: function(val){
152
+ this.options.tabindex = val;
153
+ if(!this.options.disabled){
154
+ this.element.attr({tabindex: val});
287
155
  }
288
- };
156
+ },
157
+ title: function(val){
158
+ this.element.prop('title', val);
159
+ },
160
+ min: function(val){
161
+ this.options.min = retDefault(val, 0);
162
+ this.value(this.options.value, true);
163
+ },
164
+ max: function(val){
165
+ this.options.max = retDefault(val, 100);
166
+ this.value(this.options.value, true);
167
+ },
168
+ step: function(val){
169
+ this.options.step = val == 'any' ? 'any' : retDefault(val, 1);
170
+ this.value(this.options.value);
171
+ },
289
172
 
290
- var elementExtends = {};
291
- return {
292
- createTmpCache: function(nodeName){
293
- if($.isDOMReady){
294
- tempCache = tempCache || $( document.getElementsByTagName(nodeName) );
173
+ normalizeVal: function(val){
174
+ var valModStep, alignValue, step;
175
+ var o = this.options;
176
+
177
+ if(val <= o.min){
178
+ val = o.min;
179
+ } else if(val >= o.max) {
180
+ val = o.max;
181
+ } else if(o.step != 'any'){
182
+ step = o.step;
183
+ valModStep = (val - o.min) % step;
184
+ alignValue = val - valModStep;
185
+
186
+ if ( Math.abs(valModStep) * 2 >= step ) {
187
+ alignValue += ( valModStep > 0 ) ? step : ( -step );
295
188
  }
296
- return tempCache || emptyQ;
297
- },
298
- flushTmpCache: function(){
299
- tempCache = null;
300
- },
301
- content: function(nodeName, prop){
302
- createNodeNameInit(nodeName, function(){
303
- var val = $.attr(this, prop);
304
- if(val != null){
305
- $.attr(this, prop, val);
306
- }
307
- });
308
- },
309
- createElement: function(nodeName, fn){
310
- createNodeNameInit(nodeName, fn);
311
- },
312
- extendValue: function(nodeName, prop, value){
313
- createNodeNameInit(nodeName, function(){
314
- $(this).each(function(){
315
- var data = elementData(this, 'propValue', {});
316
- data[prop] = this[prop];
317
- this[prop] = value;
318
- });
319
- });
189
+ val = alignValue.toFixed(5) * 1;
320
190
  }
321
- };
322
- })();
323
-
324
- var createPropDefault = function(descs, removeType){
325
- if(descs.defaultValue === undefined){
326
- descs.defaultValue = '';
327
- }
328
- if(!descs.removeAttr){
329
- descs.removeAttr = {
330
- value: function(){
331
- descs[removeType || 'prop'].set.call(this, descs.defaultValue);
332
- descs.removeAttr._supvalue.call(this);
333
- }
334
- };
335
- }
336
- if(!descs.attr){
337
- descs.attr = {};
338
- }
339
- };
340
-
341
- $.extend(webshims, {
342
-
343
- getID: (function(){
344
- var ID = new Date().getTime();
345
- return function(elem){
346
- elem = $(elem);
347
- var id = elem.attr('id');
348
- if(!id){
349
- ID++;
350
- id = 'ID-'+ ID;
351
- elem.attr('id', id);
352
- }
353
- return id;
354
- };
355
- })(),
356
- extendUNDEFProp: function(obj, props){
357
- $.each(props, function(name, prop){
358
- if( !(name in obj) ){
359
- obj[name] = prop;
360
- }
361
- });
191
+ return val;
362
192
  },
363
- //http://www.w3.org/TR/html5/common-dom-interfaces.html#reflect
364
- createPropDefault: createPropDefault,
365
- data: elementData,
366
- moveToFirstEvent: function(elem, eventType, bindType){
367
- var events = ($._data(elem, 'events') || {})[eventType];
368
- var fn;
369
-
370
- if(events && events.length > 1){
371
- fn = events.pop();
372
- if(!bindType){
373
- bindType = 'bind';
374
- }
375
- if(bindType == 'bind' && events.delegateCount){
376
- events.splice( events.delegateCount, 0, fn);
377
- } else {
378
- events.unshift( fn );
379
- }
380
-
381
-
193
+ doStep: function(factor, animate){
194
+ var step = retDefault(this.options.step, 1);
195
+ if(this.options.step == 'any'){
196
+ step = Math.min(step, (this.options.max - this.options.min) / 10);
382
197
  }
383
- elem = null;
198
+ this.value( this.options.value + (step * factor), false, animate );
199
+
384
200
  },
385
- addShadowDom: (function(){
386
- var resizeTimer;
387
- var lastHeight;
388
- var lastWidth;
389
-
390
- var docObserve = {
391
- init: false,
392
- runs: 0,
393
- test: function(){
394
- var height = docObserve.getHeight();
395
- var width = docObserve.getWidth();
201
+
202
+ getStepedValueFromPos: function(pos){
203
+ var val, valModStep, alignValue, step;
204
+
205
+ if(pos <= 0){
206
+ val = this.options[this.dirs.min];
207
+ } else if(pos > 100) {
208
+ val = this.options[this.dirs.max];
209
+ } else {
210
+ if(this.vertical){
211
+ pos = Math.abs(pos - 100);
212
+ }
213
+ val = ((this.options.max - this.options.min) * (pos / 100)) + this.options.min;
214
+ step = this.options.step;
215
+ if(step != 'any'){
216
+ valModStep = (val - this.options.min) % step;
217
+ alignValue = val - valModStep;
396
218
 
397
- if(height != docObserve.height || width != docObserve.width){
398
- docObserve.height = height;
399
- docObserve.width = width;
400
- docObserve.handler({type: 'docresize'});
401
- docObserve.runs++;
402
- if(docObserve.runs < 9){
403
- setTimeout(docObserve.test, 90);
404
- }
405
- } else {
406
- docObserve.runs = 0;
219
+ if ( Math.abs(valModStep) * 2 >= step ) {
220
+ alignValue += ( valModStep > 0 ) ? step : ( -step );
407
221
  }
408
- },
409
- handler: function(e){
410
- clearTimeout(resizeTimer);
411
- resizeTimer = setTimeout(function(){
412
- if(e.type == 'resize'){
413
- var width = $(window).width();
414
- var height = $(window).width();
415
- if(height == lastHeight && width == lastWidth){
416
- return;
222
+ val = ((alignValue).toFixed(5)) * 1;
223
+
224
+ }
225
+ }
226
+
227
+ return val;
228
+ },
229
+ addBindings: function(){
230
+ var leftOffset, widgetUnits, hasFocus;
231
+ var that = this;
232
+ var o = this.options;
233
+
234
+ var eventTimer = (function(){
235
+ var events = {};
236
+ return {
237
+ init: function(name, curVal, fn){
238
+ if(!events[name]){
239
+ events[name] = {fn: fn};
240
+ if(that.orig){
241
+ $(that.orig).on(name, function(){
242
+ events[name].val = $.prop(that.orig, 'value');
243
+ });
417
244
  }
418
- lastHeight = height;
419
- lastWidth = width;
420
-
421
- docObserve.height = docObserve.getHeight();
422
- docObserve.width = docObserve.getWidth();
423
245
 
424
246
  }
425
- $(document).triggerHandler('updateshadowdom');
426
- }, (e.type == 'resize') ? 50 : 9);
427
- },
428
- _create: function(){
429
- $.each({ Height: "getHeight", Width: "getWidth" }, function(name, type){
430
- var body = document.body;
431
- var doc = document.documentElement;
432
- docObserve[type] = function(){
433
- return Math.max(
434
- body[ "scroll" + name ], doc[ "scroll" + name ],
435
- body[ "offset" + name ], doc[ "offset" + name ],
436
- doc[ "client" + name ]
437
- );
438
- };
439
- });
440
- },
441
- start: function(){
442
- if(!this.init && document.body){
443
- this.init = true;
444
- this._create();
445
- this.height = docObserve.getHeight();
446
- this.width = docObserve.getWidth();
447
- setInterval(this.test, 600);
448
- $(this.test);
449
- webshims.ready('WINDOWLOAD', this.test);
450
- $(window).bind('resize', this.handler);
451
- (function(){
452
- var oldAnimate = $.fn.animate;
453
- var animationTimer;
454
-
455
- $.fn.animate = function(){
456
- clearTimeout(animationTimer);
457
- animationTimer = setTimeout(function(){
458
- docObserve.test();
459
- }, 99);
460
-
461
- return oldAnimate.apply(this, arguments);
462
- };
463
- })();
247
+ events[name].val = curVal;
248
+ },
249
+ call: function(name, val){
250
+ if(events[name].val != val){
251
+ clearTimeout(events[name].timer);
252
+ events[name].val = val;
253
+ events[name].timer = setTimeout(function(){
254
+ events[name].fn(val, that);
255
+ }, 0);
256
+ }
464
257
  }
258
+ };
259
+ })();
260
+
261
+ var setValueFromPos = function(e, animate){
262
+
263
+ var val = that.getStepedValueFromPos((e[that.dirs.mouse] - leftOffset) * widgetUnits);
264
+ if(val != o.value){
265
+ that.value(val, false, animate);
266
+ eventTimer.call('input', val);
465
267
  }
466
268
  };
467
269
 
468
-
469
- webshims.docObserve = function(){
470
- webshims.ready('DOM', function(){
471
- docObserve.start();
472
- });
473
- };
474
- return function(nativeElem, shadowElem, opts){
475
- opts = opts || {};
476
- if(nativeElem.jquery){
477
- nativeElem = nativeElem[0];
478
- }
479
- if(shadowElem.jquery){
480
- shadowElem = shadowElem[0];
481
- }
482
- var nativeData = $.data(nativeElem, dataID) || $.data(nativeElem, dataID, {});
483
- var shadowData = $.data(shadowElem, dataID) || $.data(shadowElem, dataID, {});
484
- var shadowFocusElementData = {};
485
- if(!opts.shadowFocusElement){
486
- opts.shadowFocusElement = shadowElem;
487
- } else if(opts.shadowFocusElement){
488
- if(opts.shadowFocusElement.jquery){
489
- opts.shadowFocusElement = opts.shadowFocusElement[0];
490
- }
491
- shadowFocusElementData = $.data(opts.shadowFocusElement, dataID) || $.data(opts.shadowFocusElement, dataID, shadowFocusElementData);
492
- }
493
-
494
- nativeData.hasShadow = shadowElem;
495
- shadowFocusElementData.nativeElement = shadowData.nativeElement = nativeElem;
496
- shadowFocusElementData.shadowData = shadowData.shadowData = nativeData.shadowData = {
497
- nativeElement: nativeElem,
498
- shadowElement: shadowElem,
499
- shadowFocusElement: opts.shadowFocusElement
500
- };
501
- if(opts.shadowChilds){
502
- opts.shadowChilds.each(function(){
503
- elementData(this, 'shadowData', shadowData.shadowData);
504
- });
270
+ var remove = function(e){
271
+ if(e && e.type == 'mouseup'){
272
+ eventTimer.call('input', o.value);
273
+ eventTimer.call('change', o.value);
505
274
  }
506
-
507
- if(opts.data){
508
- shadowFocusElementData.shadowData.data = shadowData.shadowData.data = nativeData.shadowData.data = opts.data;
275
+ that.element.removeClass('ws-active');
276
+ $(document).off('mousemove', setValueFromPos).off('mouseup', remove);
277
+ };
278
+ var add = function(e){
279
+ e.preventDefault();
280
+ $(document).off('mousemove', setValueFromPos).off('mouseup', remove);
281
+ if(!o.readonly && !o.disabled){
282
+ leftOffset = that.element.focus().addClass('ws-active').offset();
283
+ widgetUnits = that.element[that.dirs.width]();
284
+ if(!widgetUnits || !leftOffset){return;}
285
+ leftOffset = leftOffset[that.dirs.pos];
286
+ widgetUnits = 100 / (widgetUnits - ((that.thumb[that.dirs.outerWidth]() || 2) / 2));
287
+ setValueFromPos(e, o.animate);
288
+ $(document)
289
+ .on({
290
+ mouseup: remove,
291
+ mousemove: setValueFromPos
292
+ })
293
+ ;
294
+ e.stopPropagation();
509
295
  }
510
- opts = null;
511
- webshims.docObserve();
512
296
  };
513
- })(),
514
- propTypes: {
515
- standard: function(descs, name){
516
- createPropDefault(descs);
517
- if(descs.prop){return;}
518
- descs.prop = {
519
- set: function(val){
520
- descs.attr.set.call(this, ''+val);
521
- },
522
- get: function(){
523
- return descs.attr.get.call(this) || descs.defaultValue;
297
+ var elementEvts = {
298
+ mousedown: add,
299
+ focus: function(e){
300
+ if(!o.disabled){
301
+ eventTimer.init('input', o.value);
302
+ eventTimer.init('change', o.value);
303
+ that.element.addClass('ws-focus');
524
304
  }
525
- };
305
+ hasFocus = true;
306
+ },
307
+ blur: function(e){
308
+ that.element.removeClass('ws-focus ws-active');
309
+ hasFocus = false;
310
+ eventTimer.init('input', o.value);
311
+ eventTimer.call('change', o.value);
312
+ },
313
+ keyup: function(){
314
+ that.element.removeClass('ws-active');
315
+ eventTimer.call('input', o.value);
316
+ eventTimer.call('change', o.value);
317
+ },
526
318
 
527
- },
528
- "boolean": function(descs, name){
529
-
530
- createPropDefault(descs);
531
- if(descs.prop){return;}
532
- descs.prop = {
533
- set: function(val){
534
- if(val){
535
- descs.attr.set.call(this, "");
319
+ keydown: function(e){
320
+ var step = true;
321
+ var code = e.keyCode;
322
+ if(!o.readonly && !o.disabled){
323
+ if (code == 39 || code == 38) {
324
+ that.doStep(1);
325
+ } else if (code == 37 || code == 40) {
326
+ that.doStep(-1);
327
+ } else if (code == 33) {
328
+ that.doStep(10, o.animate);
329
+ } else if (code == 34) {
330
+ that.doStep(-10, o.animate);
331
+ } else if (code == 36) {
332
+ that.value(that.options.max, false, o.animate);
333
+ } else if (code == 35) {
334
+ that.value(that.options.min, false, o.animate);
536
335
  } else {
537
- descs.removeAttr.value.call(this);
538
- }
539
- },
540
- get: function(){
541
- return descs.attr.get.call(this) != null;
542
- }
543
- };
544
- },
545
- "src": (function(){
546
- var anchor = document.createElement('a');
547
- anchor.style.display = "none";
548
- return function(descs, name){
549
-
550
- createPropDefault(descs);
551
- if(descs.prop){return;}
552
- descs.prop = {
553
- set: function(val){
554
- descs.attr.set.call(this, val);
555
- },
556
- get: function(){
557
- var href = this.getAttribute(name);
558
- var ret;
559
- if(href == null){return '';}
560
-
561
- anchor.setAttribute('href', href+'' );
562
-
563
- if(!$.support.hrefNormalized){
564
- try {
565
- $(anchor).insertAfter(this);
566
- ret = anchor.getAttribute('href', 4);
567
- } catch(er){
568
- ret = anchor.getAttribute('href', 4);
569
- }
570
- $(anchor).detach();
571
- }
572
- return ret || anchor.href;
336
+ step = false;
573
337
  }
574
- };
575
- };
576
- })(),
577
- enumarated: function(descs, name){
578
-
579
- createPropDefault(descs);
580
- if(descs.prop){return;}
581
- descs.prop = {
582
- set: function(val){
583
- descs.attr.set.call(this, val);
584
- },
585
- get: function(){
586
- var val = (descs.attr.get.call(this) || '').toLowerCase();
587
- if(!val || descs.limitedTo.indexOf(val) == -1){
588
- val = descs.defaultValue;
589
- }
590
- return val;
338
+ if (step) {
339
+ that.element.addClass('ws-active');
340
+ eventTimer.call('input', o.value);
341
+ e.preventDefault();
591
342
  }
592
- };
343
+ }
593
344
  }
345
+ };
594
346
 
595
- // ,unsignedLong: $.noop
596
- // ,"doubble": $.noop
597
- // ,"long": $.noop
598
- // ,tokenlist: $.noop
599
- // ,settableTokenlist: $.noop
600
- },
601
- reflectProperties: function(nodeNames, props){
602
- if(typeof props == 'string'){
603
- props = props.split(listReg);
604
- }
605
- props.forEach(function(prop){
606
- webshims.defineNodeNamesProperty(nodeNames, prop, {
607
- prop: {
608
- set: function(val){
609
- $.attr(this, prop, val);
610
- },
611
- get: function(){
612
- return $.attr(this, prop) || '';
613
- }
614
- }
615
- });
616
- });
617
- },
618
- defineNodeNameProperty: function(nodeName, prop, descs){
619
- havePolyfill[prop] = true;
620
-
621
- if(descs.reflect){
622
- webshims.propTypes[descs.propType || 'standard'](descs, prop);
623
- }
347
+ eventTimer.init('input', o.value, this.options.input);
348
+ eventTimer.init('change', o.value, this.options.change);
624
349
 
625
- ['prop', 'attr', 'removeAttr'].forEach(function(type){
626
- var desc = descs[type];
627
- if(desc){
628
- if(type === 'prop'){
629
- desc = $.extend({writeable: true}, desc);
630
- } else {
631
- desc = $.extend({}, desc, {writeable: true});
632
- }
633
-
634
- extendQ[type](nodeName, prop, desc);
635
- if(nodeName != '*' && webshims.cfg.extendNative && type == 'prop' && desc.value && $.isFunction(desc.value)){
636
- extendNativeValue(nodeName, prop, desc);
637
- }
638
- descs[type] = desc;
350
+ elementEvts[$.fn.mwheelIntent ? 'mwheelIntent' : 'mousewheel'] = function(e, delta){
351
+ if(delta && hasFocus && !o.readonly && !o.disabled){
352
+ that.doStep(delta);
353
+ e.preventDefault();
354
+ eventTimer.call('input', o.value);
639
355
  }
356
+ };
357
+ this.element.on(elementEvts);
358
+ this.thumb.on({
359
+ mousedown: add
640
360
  });
641
- if(descs.initAttr){
642
- initProp.content(nodeName, prop);
643
- }
644
- return descs;
645
361
  },
646
-
647
- defineNodeNameProperties: function(name, descs, propType, _noTmpCache){
648
- var olddesc;
649
- for(var prop in descs){
650
- if(!_noTmpCache && descs[prop].initAttr){
651
- initProp.createTmpCache(name);
362
+ updateMetrics: function(){
363
+ var width = this.element.innerWidth();
364
+ this.vertical = (width && this.element.innerHeight() - width > 10);
365
+
366
+ this.dirs = this.vertical ?
367
+ {mouse: 'pageY', pos: 'top', min: 'max', max: 'min', left: 'top', width: 'height', outerWidth: 'outerHeight'} :
368
+ {mouse: 'pageX', pos: 'left', min: 'min', max: 'max', left: 'left', width: 'width', outerWidth: 'outerWidth'}
369
+ ;
370
+ this.element
371
+ [this.vertical ? 'addClass' : 'removeClass']('vertical-range')
372
+ [this.vertical ? 'addClass' : 'removeClass']('horizontal-range')
373
+ ;
374
+ }
375
+ };
376
+
377
+ $.fn.rangeUI = function(opts){
378
+ 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);
379
+ return this.each(function(){
380
+ $.webshims.objectCreate(rangeProto, {
381
+ element: {
382
+ value: $(this)
652
383
  }
653
- if(propType){
654
- if(descs[prop][propType]){
655
- //webshims.log('override: '+ name +'['+prop +'] for '+ propType);
656
- } else {
657
- descs[prop][propType] = {};
658
- ['value', 'set', 'get'].forEach(function(copyProp){
659
- if(copyProp in descs[prop]){
660
- descs[prop][propType][copyProp] = descs[prop][copyProp];
661
- delete descs[prop][copyProp];
662
- }
663
- });
384
+ }, opts);
385
+ });
386
+ };
387
+ jQuery.webshims.isReady('range-ui', true);
388
+ })(jQuery);
389
+ jQuery.webshims.register('form-number-date-ui', function($, webshims, window, document, undefined, options){
390
+ "use strict";
391
+ var curCfg;
392
+ var formcfg = $.webshims.formcfg;
393
+
394
+ var stopPropagation = function(e){
395
+ e.stopImmediatePropagation(e);
396
+ };
397
+ var createFormat = function(name){
398
+ if(!curCfg.patterns[name+'Obj']){
399
+ var obj = {};
400
+ $.each(curCfg.patterns[name].split(curCfg[name+'Format']), function(i, name){
401
+ obj[name] = i;
402
+ });
403
+ curCfg.patterns[name+'Obj'] = obj;
404
+ }
405
+ };
406
+ var splitInputs = {
407
+ date: {
408
+ _create: function(){
409
+ var obj = {
410
+ 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]]
411
+ };
412
+ obj.elements = [obj.splits[0], $('<span class="ws-input-seperator" />')[0], obj.splits[1], $('<span class="ws-input-seperator" />')[0], obj.splits[2]];
413
+ return obj;
414
+ },
415
+ sort: function(element){
416
+ createFormat('d');
417
+ var i = 0;
418
+ var seperators = $('.ws-input-seperator', element).html(curCfg.dFormat);
419
+ var inputs = $('input', element);
420
+ $.each(curCfg.patterns.dObj, function(name, value){
421
+ var input = inputs.filter('.'+ name);
422
+ if(input[0]){
423
+
424
+ input.appendTo(element);
425
+ if(i < seperators.length){
426
+ seperators.eq(i).insertAfter(input);
427
+ }
428
+ i++;
664
429
  }
665
- }
666
- descs[prop] = webshims.defineNodeNameProperty(name, prop, descs[prop]);
667
- }
668
- if(!_noTmpCache){
669
- initProp.flushTmpCache();
430
+ });
670
431
  }
671
- return descs;
672
432
  },
673
-
674
- createElement: function(nodeName, create, descs){
675
- var ret;
676
- if($.isFunction(create)){
677
- create = {
678
- after: create
433
+ month: {
434
+ _create: function(){
435
+ var obj = {
436
+ splits: [$('<input type="text" class="yy" size="4" />')[0], $('<input type="text" class="mm ws-spin" />')[0]]
679
437
  };
438
+ obj.elements = [obj.splits[0], $('<span class="ws-input-seperator" />')[0], obj.splits[1]];
439
+ return obj;
440
+ },
441
+ sort: function(element){
442
+ var seperator = $('.ws-input-seperator', element).html(curCfg.dFormat);
443
+ var mm = $('input.mm', element);
444
+ var action;
445
+ if(curCfg.date.showMonthAfterYear){
446
+ mm.appendTo(element);
447
+ action = 'insertBefore';
448
+ } else {
449
+ mm.prependTo(element);
450
+ action = 'insertAfter';
451
+ }
452
+ seperator[action](mm);
680
453
  }
681
- initProp.createTmpCache(nodeName);
682
- if(create.before){
683
- initProp.createElement(nodeName, create.before);
684
- }
685
- if(descs){
686
- ret = webshims.defineNodeNameProperties(nodeName, descs, false, true);
454
+ }
455
+ };
456
+ var labelWidth = (function(){
457
+ var getId = function(){
458
+ return webshims.getID(this);
459
+ };
460
+ return function(element, labels, noFocus){
461
+ $(element).attr({'aria-labelledby': labels.map(getId).get().join(' ')});
462
+ if(!noFocus){
463
+ labels.on('click', function(e){
464
+ element.getShadowFocusElement().focus();
465
+ e.preventDefault();
466
+ return false;
467
+ });
687
468
  }
688
- if(create.after){
689
- initProp.createElement(nodeName, create.after);
469
+ };
470
+ })();
471
+ var addZero = function(val){
472
+ if(!val){return "";}
473
+ val = val+'';
474
+ return val.length == 1 ? '0'+val : val;
475
+ };
476
+
477
+
478
+ (function(){
479
+ var monthDigits = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
480
+ formcfg.de = {
481
+ numberFormat: {
482
+ ",": ".",
483
+ ".": ","
484
+ },
485
+ timeSigns: ":. ",
486
+ numberSigns: ',',
487
+ dateSigns: '.',
488
+ dFormat: ".",
489
+ patterns: {
490
+ d: "dd.mm.yy"
491
+ },
492
+ month: {
493
+ currentText: 'Aktueller Monat'
494
+ },
495
+ date: {
496
+ close: 'schließen',
497
+ clear: 'Löschen',
498
+ prevText: 'Zurück',
499
+ nextText: 'Vor',
500
+ currentText: 'Heute',
501
+ monthNames: ['Januar','Februar','März','April','Mai','Juni',
502
+ 'Juli','August','September','Oktober','November','Dezember'],
503
+ monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun',
504
+ 'Jul','Aug','Sep','Okt','Nov','Dez'],
505
+ dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
506
+ dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
507
+ dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
508
+ weekHeader: 'KW',
509
+ firstDay: 1,
510
+ isRTL: false,
511
+ showMonthAfterYear: false,
512
+ yearSuffix: ''
690
513
  }
691
- initProp.flushTmpCache();
692
- return ret;
693
- },
694
- onNodeNamesPropertyModify: function(nodeNames, props, desc, only){
695
- if(typeof nodeNames == 'string'){
696
- nodeNames = nodeNames.split(listReg);
514
+ };
515
+
516
+ formcfg.en = {
517
+ numberFormat: {
518
+ ".": ".",
519
+ ",": ","
520
+ },
521
+ numberSigns: '.',
522
+ dateSigns: '/',
523
+ timeSigns: ":. ",
524
+ dFormat: "/",
525
+ patterns: {
526
+ d: "mm/dd/yy"
527
+ },
528
+ month: {
529
+ currentText: 'This month'
530
+ },
531
+ date: {
532
+ "closeText": "Done",
533
+ clear: 'Clear',
534
+ "prevText": "Prev",
535
+ "nextText": "Next",
536
+ "currentText": "Today",
537
+ "monthNames": ["January","February","March","April","May","June","July","August","September","October","November","December"],
538
+ "monthNamesShort": ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
539
+ "dayNames": ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],
540
+ "dayNamesShort": ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],
541
+ "dayNamesMin": ["Su","Mo","Tu","We","Th","Fr","Sa"],
542
+ "weekHeader": "Wk",
543
+ "firstDay": 0,
544
+ "isRTL": false,
545
+ "showMonthAfterYear": false,
546
+ "yearSuffix": ""
697
547
  }
698
- if($.isFunction(desc)){
699
- desc = {set: desc};
548
+ };
549
+
550
+ formcfg['en-US'] = formcfg['en-US'] || formcfg['en'];
551
+ formcfg[''] = formcfg[''] || formcfg['en-US'];
552
+ curCfg = formcfg[''];
553
+
554
+ var createMonthKeys = function(langCfg){
555
+ if(!langCfg.date.monthkeys){
556
+ var create = function(i, name){
557
+ var strNum;
558
+ var num = i + 1;
559
+ strNum = (num < 10) ? '0'+num : ''+num;
560
+ langCfg.date.monthkeys[num] = strNum;
561
+ langCfg.date.monthkeys[name] = strNum;
562
+ langCfg.date.monthkeys[name.toLowerCase()] = strNum;
563
+ };
564
+ langCfg.date.monthkeys = {};
565
+ langCfg.date.monthDigits = monthDigits;
566
+ langCfg.numberSigns += '-';
567
+ $.each(langCfg.date.monthNames, create);
568
+ $.each(langCfg.date.monthNamesShort, create);
700
569
  }
701
-
702
- nodeNames.forEach(function(name){
703
- if(!modifyProps[name]){
704
- modifyProps[name] = {};
570
+ };
571
+
572
+ createMonthKeys(curCfg);
573
+
574
+ $.webshims.ready('dom-extend', function(){
575
+ $.webshims.activeLang({
576
+ register: 'form-core',
577
+ callback: function(){
578
+ $.each(arguments, function(i, val){
579
+ if(formcfg[val]){
580
+ curCfg = formcfg[val];
581
+ createMonthKeys(curCfg);
582
+ $(document).triggerHandler('wslocalechange');
583
+ return false;
584
+ }
585
+ });
586
+ }
587
+ });
588
+ });
589
+ })();
590
+
591
+
592
+
593
+ (function(){
594
+
595
+
596
+ var mousePress = function(e){
597
+ $(this)[e.type == 'mousepressstart' ? 'addClass' : 'removeClass']('mousepress-ui');
598
+ };
599
+
600
+ var retDefault = function(val, def){
601
+ if(!(typeof val == 'number' || (val && val == val * 1))){
602
+ return def;
603
+ }
604
+ return val * 1;
605
+ };
606
+
607
+ var createOpts = ['step', 'min', 'max', 'readonly', 'title', 'disabled', 'tabindex', 'placeholder', 'value'];
608
+
609
+
610
+ var formatVal = {
611
+ number: function(val){
612
+ return (val+'').replace(/\,/g, '').replace(/\./, curCfg.numberFormat['.']);
613
+ },
614
+ time: function(val){
615
+ return val;
616
+ },
617
+ //todo empty val for month/split
618
+ month: function(val, options){
619
+ var names;
620
+ var p = val.split('-');
621
+ if(p[0] && p[1]){
622
+ names = curCfg.date[options.formatMonthNames] || curCfg.date[options.monthNames] || curCfg.date.monthNames;
623
+ p[1] = names[(p[1] * 1) - 1];
624
+ if(options && options.splitInput){
625
+ val = [p[0] || '', p[1] || ''];
626
+ } else if(p[1]){
627
+ val = curCfg.date.showMonthAfterYear ? p.join(' ') : p[1]+' '+p[0];
628
+ }
629
+ }
630
+ return val;
631
+ },
632
+ date: function(val, opts){
633
+ var p = (val+'').split('-');
634
+ if(p[2] && p[1] && p[0]){
635
+ if(opts && opts.splitInput){
636
+ val = p;
637
+ } else {
638
+ val = curCfg.patterns.d.replace('yy', p[0] || '');
639
+ val = val.replace('mm', p[1] || '');
640
+ val = val.replace('dd', p[2] || '');
641
+ }
642
+ } else if(opts && opts.splitInput){
643
+ val = [p[0] || '', p[1] || '', p[2] || ''];
644
+ }
645
+
646
+ return val;
647
+ }
648
+ };
649
+
650
+ var parseVal = {
651
+ number: function(val){
652
+ return (val+'').replace(curCfg.numberFormat[','], '').replace(curCfg.numberFormat['.'], '.');
653
+ },
654
+ time: function(val){
655
+ return val;
656
+ },
657
+ month: function(val, opts){
658
+
659
+ var p = (!opts.splitInput) ? val.trim().split(/[\.\s-\/\\]+/) : val;
660
+
661
+ if(p.length == 2){
662
+ p[0] = curCfg.date.monthkeys[p[0]] || p[0];
663
+ p[1] = curCfg.date.monthkeys[p[1]] || p[1];
664
+ if(p[1].length == 2){
665
+ val = p[0]+'-'+p[1];
666
+ } else if(p[0].length == 2){
667
+ val = p[1]+'-'+p[0];
668
+ } else {
669
+ val = '';
670
+ }
671
+ } else if(opts.splitInput) {
672
+ val = '';
673
+ }
674
+ return val;
675
+ },
676
+ date: function(val, opts){
677
+ createFormat('d');
678
+ var i;
679
+ var obj;
680
+ if(opts.splitInput){
681
+ obj = {yy: 0, mm: 1, dd: 2};
682
+ } else {
683
+ obj = curCfg.patterns.dObj;
684
+ val = val.split(curCfg.dFormat);
685
+ }
686
+
687
+ return (val.length == 3 && val[0] && val[1] && val[2]) ?
688
+ ([addZero(val[obj.yy]), addZero(val[obj.mm]), addZero(val[obj.dd])]).join('-') :
689
+ ''
690
+ ;
691
+ }
692
+ };
693
+
694
+ var steps = {
695
+ number: {
696
+ step: 1
697
+ },
698
+ time: {
699
+ step: 60
700
+ },
701
+ month: {
702
+ step: 1,
703
+ start: new Date()
704
+ },
705
+ date: {
706
+ step: 1,
707
+ start: new Date()
708
+ }
709
+ };
710
+
711
+
712
+ var placeholderFormat = {
713
+ date: function(val, opts){
714
+ var hintValue = (val || '').split('-');
715
+ if(hintValue.length == 3){
716
+ hintValue = opts.splitInput ?
717
+ hintValue :
718
+ curCfg.patterns.d.replace('yy', hintValue[0]).replace('mm', hintValue[1]).replace('dd', hintValue[2]);
719
+ } else {
720
+ hintValue = opts.splitInput ?
721
+ [val, val, val] :
722
+ val;
723
+ }
724
+ return hintValue;
725
+ },
726
+ month: function(val, opts){
727
+ var hintValue = (val || '').split('-');
728
+
729
+ if(hintValue.length == 2){
730
+ hintValue = opts.splitInput ?
731
+ hintValue :
732
+ curCfg.patterns.d.replace('yy', hintValue[0]).replace('mm', hintValue[1]);
733
+ } else {
734
+ hintValue = opts.splitInput ?
735
+ [val, val] :
736
+ val;
737
+ }
738
+ return hintValue;
739
+ }
740
+ };
741
+
742
+ var createHelper = (function(){
743
+ var types = {};
744
+ return function(type){
745
+ var input;
746
+ if(!types[type]){
747
+ input = $('<input type="'+type+'" />');
748
+ types[type] = {
749
+ asNumber: function(val){
750
+ var type = (typeof val == 'object') ? 'valueAsDate' : 'value';
751
+ return input.prop(type, val).prop('valueAsNumber');
752
+ },
753
+ asValue: function(val){
754
+ var type = (typeof val == 'object') ? 'valueAsDate' : 'valueAsNumber';
755
+ return input.prop(type, val).prop('value');
756
+ }
757
+ };
758
+ }
759
+ return types[type];
760
+ };
761
+ })();
762
+
763
+ steps.range = steps.number;
764
+
765
+
766
+ var spinBtnProto = {
767
+ _create: function(){
768
+ var i;
769
+ var o = this.options;
770
+ var helper = createHelper(o.type);
771
+ this.type = o.type;
772
+ this.orig = o.orig;
773
+
774
+ this.elemHelper = $('<input type="'+ this.type+'" />');
775
+ this.asNumber = helper.asNumber;
776
+ this.asValue = helper.asValue;
777
+
778
+ 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>')
779
+ .insertAfter(this.element)
780
+ ;
781
+
782
+ if(o.splitInput){
783
+ this._addSplitInputs();
784
+ } else {
785
+ this.inputElements = this.element;
786
+ }
787
+
788
+ this.options.containerElements.push(this.buttonWrapper[0]);
789
+
790
+ if(typeof steps[this.type].start == 'object'){
791
+ steps[this.type].start = this.asNumber(steps[this.type].start);
792
+ }
793
+
794
+
795
+
796
+ for(i = 0; i < createOpts.length; i++){
797
+ this[createOpts[i]](o[createOpts[i]]);
798
+ }
799
+
800
+ this.element.data('wsspinner', this);
801
+
802
+ this.addBindings();
803
+
804
+ if(!o.min && typeof o.relMin == 'number'){
805
+ o.min = this.asValue(this.getRelNumber(o.relMin));
806
+ $.prop(this.orig, 'min', o.min);
807
+ }
808
+
809
+ if(!o.max && typeof o.relMax == 'number'){
810
+ o.max = this.asValue(this.getRelNumber(o.relMax));
811
+ $.prop(this.orig, 'max', o.max);
812
+ }
813
+
814
+ this._init = true;
815
+ },
816
+ _addSplitInputs: function(){
817
+ if(!this.inputElements){
818
+ var create = splitInputs[this.type]._create();
819
+ this.splits = create.splits;
820
+ this.inputElements = $(create.elements).prependTo(this.element).filter('input');
821
+ }
822
+ },
823
+ parseValue: function(){
824
+ var value = this.inputElements.map(function(){
825
+ return $.prop(this, 'value');
826
+ }).get();
827
+ if(!this.options.splitInput){
828
+ value = value[0];
829
+ }
830
+ return parseVal[this.type](value, this.options);
831
+ },
832
+ formatValue: function(val, noSplit){
833
+ return formatVal[this.type](val, noSplit === false ? false : this.options);
834
+ },
835
+ placeholder: function(val){
836
+ var options = this.options;
837
+ options.placeholder = val;
838
+ var placeholder = val;
839
+ if(placeholderFormat[this.type]){
840
+ placeholder = placeholderFormat[this.type](val, this.options);
841
+ }
842
+ if(options.splitInput && typeof placeholder == 'object'){
843
+ $.each(this.splits, function(i, elem){
844
+ $.prop(elem, 'placeholder', placeholder[i]);
845
+ });
846
+ } else {
847
+ this.element.prop('placeholder', placeholder);
848
+ }
849
+ },
850
+ getRelNumber: function(rel){
851
+ var start = steps[this.type].start || 0;
852
+ if(rel){
853
+ start += rel;
854
+ }
855
+ return start;
856
+ },
857
+ addZero: addZero,
858
+ _setStartInRange: function(){
859
+ var start = this.getRelNumber(this.options.relDefaultValue);
860
+ if(!isNaN(this.minAsNumber) && start < this.minAsNumber){
861
+ start = this.minAsNumber;
862
+ } else if(!isNaN(this.maxAsNumber) && start > this.maxAsNumber){
863
+ start = this.maxAsNumber;
864
+ }
865
+ this.elemHelper.prop('valueAsNumber', start);
866
+ this.options.defValue = this.elemHelper.prop('value');
867
+
868
+ },
869
+ reorderInputs: function(){
870
+ if(splitInputs[this.type]){
871
+ var element = this.element;
872
+ splitInputs[this.type].sort(element);
873
+ setTimeout(function(){
874
+ var data = webshims.data(element);
875
+ if(data && data.shadowData){
876
+ data.shadowData.shadowFocusElement = element.find('input')[0] || element[0];
877
+ }
878
+ }, 9);
879
+ }
880
+ },
881
+ value: function(val){
882
+ this.valueAsNumber = this.asNumber(val);
883
+ this.options.value = val;
884
+ if(isNaN(this.valueAsNumber) || (!isNaN(this.minAsNumber) && this.valueAsNumber < this.minAsNumber) || (!isNaN(this.maxAsNumber) && this.valueAsNumber > this.maxAsNumber)){
885
+ this._setStartInRange();
886
+ } else {
887
+ this.elemHelper.prop('value', val);
888
+ this.options.defValue = "";
889
+ }
890
+
891
+ val = formatVal[this.type](val, this.options);
892
+ if(this.options.splitInput){
893
+
894
+ $.each(this.splits, function(i, elem){
895
+ $.prop(elem, 'value', val[i]);
896
+ });
897
+ } else {
898
+ this.element.prop('value', val);
899
+ }
900
+
901
+ this._propertyChange('value');
902
+ },
903
+ initDataList: function(){
904
+ var listTimer;
905
+ var that = this;
906
+ var updateList = function(){
907
+ $(that.orig)
908
+ .jProp('list')
909
+ .off('updateDatalist', updateList)
910
+ .on('updateDatalist', updateList)
911
+ ;
912
+ clearTimeout(listTimer);
913
+ listTimer = setTimeout(function(){
914
+ if(that.list){
915
+ that.list();
916
+ }
917
+ }, 9);
918
+
919
+ };
920
+
921
+ $(this.orig).onTrigger('listdatalistchange', updateList);
922
+ },
923
+ getOptions: function(){
924
+ var options = {};
925
+ var datalist = $(this.orig).jProp('list');
926
+ datalist.find('option').each(function(){
927
+ options[$.prop(this, 'value')] = $.prop(this, 'label');
928
+ });
929
+ return [options, datalist.data('label')];
930
+ },
931
+ list: function(val){
932
+ if(this.type == 'number' || this.type == 'time'){
933
+ this.element.attr('list', $.attr(this.orig, 'list'));
934
+ }
935
+ this.options.list = val;
936
+ this._propertyChange('list');
937
+ },
938
+ _propertyChange: $.noop,
939
+ tabindex: function(val){
940
+ this.options.tabindex = val;
941
+ this.inputElements.prop('tabindex', this.options.tabindex);
942
+ },
943
+ title: function(val){
944
+ this.options.title = val;
945
+ this.element.prop('title', this.options.title);
946
+ },
947
+
948
+ min: function(val){
949
+ this.elemHelper.prop('min', val);
950
+ this.minAsNumber = this.asNumber(val);
951
+ if(this.valueAsNumber != null && isNaN(this.valueAsNumber)){
952
+ this._setStartInRange();
953
+ }
954
+ this.options.min = val;
955
+ this._propertyChange('min');
956
+ },
957
+ max: function(val){
958
+ this.elemHelper.prop('max', val);
959
+ this.maxAsNumber = this.asNumber(val);
960
+ if(this.valueAsNumber != null && isNaN(this.valueAsNumber)){
961
+ this._setStartInRange();
962
+ }
963
+ this.options.max = val;
964
+ this._propertyChange('max');
965
+ },
966
+ step: function(val){
967
+ var defStep = steps[this.type];
968
+ this.options.step = val;
969
+ this.elemHelper.prop('step', retDefault(val, defStep.step));
970
+ },
971
+ addBindings: function(){
972
+ var isFocused;
973
+
974
+ var that = this;
975
+ var o = this.options;
976
+
977
+ var eventTimer = (function(){
978
+ var events = {};
979
+ return {
980
+ init: function(name, curVal, fn){
981
+ if(!events[name]){
982
+ events[name] = {fn: fn};
983
+ $(that.orig).on(name, function(){
984
+ events[name].val = $.prop(that.orig, 'value');
985
+ });
986
+ }
987
+ events[name].val = curVal;
988
+ },
989
+ call: function(name, val){
990
+ if(events[name] && events[name].val != val){
991
+ clearTimeout(events[name].timer);
992
+ events[name].val = val;
993
+ events[name].timer = setTimeout(function(){
994
+ events[name].fn(val, that);
995
+ }, 9);
996
+ }
997
+ }
998
+ };
999
+ })();
1000
+ var initChangeEvents = function(){
1001
+ eventTimer.init('input', $.prop(that.orig, 'value'), that.options.input);
1002
+ eventTimer.init('change', $.prop(that.orig, 'value'), that.options.change);
1003
+ };
1004
+
1005
+ var step = {};
1006
+
1007
+ var preventBlur = function(e){
1008
+ if(preventBlur.prevent){
1009
+ e.preventDefault();
1010
+ (isFocused || that.element.getShadowFocusElement()).focus();
1011
+ e.stopImmediatePropagation();
1012
+ return true;
1013
+ }
1014
+ };
1015
+ var callSplitChange = (function(){
1016
+ var timer;
1017
+
1018
+ var call = function(e){
1019
+ var val;
1020
+ clearTimeout(timer);
1021
+ val = that.parseValue();
1022
+ $.prop(that.orig, 'value', val);
1023
+ eventTimer.call('input', val);
1024
+ if(!e || e.type != 'wsupdatevalue'){
1025
+ eventTimer.call('change', val);
1026
+ }
1027
+ };
1028
+
1029
+ var onFocus = function(){
1030
+ clearTimeout(timer);
1031
+ };
1032
+ var onBlur = function(e){
1033
+ clearTimeout(timer);
1034
+ timer = setTimeout(call, 0);
1035
+
1036
+ if(e.type == 'change'){
1037
+ stopPropagation(e);
1038
+ if(!o.splitInput){
1039
+ call();
1040
+ }
1041
+ }
1042
+ };
1043
+
1044
+ that.element.on('wsupdatevalue', call);
1045
+
1046
+ that.inputElements
1047
+ .add(that.buttonWrapper)
1048
+ .add(that.element)
1049
+ .on(
1050
+ {
1051
+ 'focus focusin': onFocus,
1052
+ 'blur focusout change': onBlur
1053
+ }
1054
+ )
1055
+ ;
1056
+ setTimeout(function(){
1057
+ if(that.popover){
1058
+ $('> *', that.popover.element)
1059
+ .on({
1060
+ 'focusin': onFocus,
1061
+ 'focusout': onBlur
1062
+ })
1063
+ ;
1064
+ }
1065
+ }, 0);
1066
+ })();
1067
+
1068
+ var spinEvents = {};
1069
+ var spinElement = o.splitInput ? this.inputElements.filter('.ws-spin') : this.inputElements.eq(0);
1070
+ var elementEvts = {
1071
+ blur: function(e){
1072
+ if(!preventBlur(e) && !o.disabled && !o.readonly){
1073
+ if(!preventBlur.prevent){
1074
+ isFocused = false;
1075
+ }
1076
+ }
1077
+ stopPropagation(e);
1078
+ },
1079
+ focus: function(e){
1080
+ if(!isFocused){
1081
+ initChangeEvents();
1082
+ isFocused = this;
1083
+ }
1084
+ },
1085
+ keypress: function(e){
1086
+ if(e.isDefaultPrevented()){return;}
1087
+ var chr;
1088
+ var stepped = true;
1089
+ var code = e.keyCode;
1090
+ if(!e.ctrlKey && !e.metaKey && curCfg[that.type+'Signs']){
1091
+ chr = String.fromCharCode(e.charCode == null ? code : e.charCode);
1092
+ stepped = !(chr < " " || (curCfg[that.type+'Signs']+'0123456789').indexOf(chr) > -1);
1093
+ } else {
1094
+ stepped = false;
1095
+ }
1096
+ if(stepped){
1097
+ e.preventDefault();
1098
+ }
1099
+ },
1100
+ 'input keydown keypress': (function(){
1101
+ var timer;
1102
+ var isStopped = false;
1103
+ var releaseTab = function(){
1104
+ if(isStopped === true){
1105
+ isStopped = 'semi';
1106
+ timer = setTimeout(releaseTab, 250);
1107
+ } else {
1108
+ isStopped = false;
1109
+ }
1110
+ };
1111
+ var stopTab = function(){
1112
+ isStopped = true;
1113
+ clearTimeout(timer);
1114
+ timer = setTimeout(releaseTab, 300);
1115
+ };
1116
+ var select = function(){
1117
+ this.focus();
1118
+ this.select();
1119
+ stopTab();
1120
+ };
1121
+
1122
+ return function(e){
1123
+ if(o.splitInput && o.jumpInputs){
1124
+ if(e.type == 'input'){
1125
+ if($.prop(this, 'value').length === $.prop(this, 'maxLength')){
1126
+ try {
1127
+ $(this)
1128
+ .next()
1129
+ .next('input')
1130
+ .each(select)
1131
+ ;
1132
+ } catch(er){}
1133
+ }
1134
+ } else if(!e.shiftKey && !e.crtlKey && e.keyCode == 9 && (isStopped === true || (isStopped && !$.prop(this, 'value')))){
1135
+ e.preventDefault();
1136
+ }
1137
+ }
1138
+ }
1139
+ })()
1140
+ };
1141
+ var mouseDownInit = function(){
1142
+ if(!o.disabled && !isFocused){
1143
+ that.element.getShadowFocusElement().focus();
1144
+ }
1145
+ preventBlur.set();
1146
+
1147
+ return false;
1148
+ };
1149
+
1150
+ preventBlur.set = (function(){
1151
+ var timer;
1152
+ var reset = function(){
1153
+ preventBlur.prevent = false;
1154
+ };
1155
+ return function(){
1156
+ clearTimeout(timer);
1157
+ preventBlur.prevent = true;
1158
+ setTimeout(reset, 9);
1159
+ };
1160
+ })();
1161
+
1162
+ ['stepUp', 'stepDown'].forEach(function(name){
1163
+ step[name] = function(factor){
1164
+ if(!o.disabled && !o.readonly){
1165
+ if(!isFocused){
1166
+ mouseDownInit();
1167
+ }
1168
+ var ret = false;
1169
+ if (!factor) {
1170
+ factor = 1;
1171
+ }
1172
+ try {
1173
+ that.elemHelper[name](factor);
1174
+ ret = that.elemHelper.prop('value');
1175
+ that.value(ret);
1176
+ eventTimer.call('input', ret);
1177
+ } catch (er) {}
1178
+ return ret;
1179
+ }
1180
+ };
1181
+ });
1182
+
1183
+
1184
+
1185
+ this.buttonWrapper.on('mousedown', mouseDownInit);
1186
+
1187
+ this.setInput = function(value){
1188
+ that.value(value);
1189
+ eventTimer.call('input', value);
1190
+ };
1191
+ this.setChange = function(value){
1192
+ that.setInput(value);
1193
+ eventTimer.call('change', value);
1194
+ };
1195
+
1196
+
1197
+
1198
+ this.inputElements.on(elementEvts);
1199
+
1200
+ if(!o.noSpinbtn){
1201
+ spinEvents[$.fn.mwheelIntent ? 'mwheelIntent' : 'mousewheel'] = function(e, delta){
1202
+ if(delta && isFocused && !o.disabled){
1203
+ step[delta > 0 ? 'stepUp' : 'stepDown']();
1204
+ e.preventDefault();
1205
+ }
1206
+ };
1207
+ spinEvents.keydown = function(e){
1208
+ if(o.list || e.isDefaultPrevented() || $.attr(this, 'list')){return;}
1209
+ var stepped = true;
1210
+ var code = e.keyCode;
1211
+ if (code == 38) {
1212
+ step.stepUp();
1213
+ } else if (code == 40) {
1214
+ step.stepDown();
1215
+ } else {
1216
+ stepped = false;
1217
+ }
1218
+ if(stepped){
1219
+ e.preventDefault();
1220
+ }
1221
+ };
1222
+
1223
+ spinElement.attr({'autocomplete': 'off', role: 'spinbutton'}).on(spinEvents);
1224
+ }
1225
+
1226
+
1227
+ if(!o.splitInput){
1228
+ $(document).on('wslocalechange',function(){
1229
+ if(o.value){
1230
+ that.value(o.value);
1231
+ }
1232
+
1233
+ if(placeholderFormat[that.type] && o.placeholder){
1234
+ that.placeholder(o.placeholder);
1235
+ }
1236
+ });
1237
+ } else {
1238
+ $(document).onTrigger('wslocalechange',function(){
1239
+ that.reorderInputs();
1240
+ });
1241
+ }
1242
+
1243
+ $('.step-up', this.buttonWrapper)
1244
+ .on({
1245
+ 'mousepressstart mousepressend': mousePress,
1246
+ 'mousedown mousepress': function(e){
1247
+ step.stepUp();
1248
+ }
1249
+ })
1250
+ ;
1251
+ $('.step-down', this.buttonWrapper)
1252
+ .on({
1253
+ 'mousepressstart mousepressend': mousePress,
1254
+ 'mousedown mousepress': function(e){
1255
+ step.stepDown();
1256
+ }
1257
+ })
1258
+ ;
1259
+ initChangeEvents();
1260
+ }
1261
+ };
1262
+
1263
+ ['readonly', 'disabled'].forEach(function(name){
1264
+ spinBtnProto[name] = function(val){
1265
+ if(this.options[name] != val || !this._init){
1266
+ this.options[name] = !!val;
1267
+ if(name == 'readonly' && this.options.noInput){
1268
+ this.element
1269
+ .prop(name, true)
1270
+ .attr({'aria-readonly': this.options[name]})
1271
+ ;
1272
+ } else {
1273
+ this.element.prop(name, this.options[name]);
1274
+ }
1275
+ this.buttonWrapper[this.options[name] ? 'addClass' : 'removeClass']('ws-'+name);
1276
+ }
1277
+ };
1278
+ });
1279
+
1280
+
1281
+ $.fn.spinbtnUI = function(opts){
1282
+ opts = $.extend({
1283
+ monthNames: 'monthNames',
1284
+ size: 1,
1285
+ startView: 0
1286
+ }, opts);
1287
+ return this.each(function(){
1288
+ $.webshims.objectCreate(spinBtnProto, {
1289
+ element: {
1290
+ value: $(this)
1291
+ }
1292
+ }, opts);
1293
+ });
1294
+ };
1295
+ })();
1296
+
1297
+ (function(){
1298
+ var picker = {};
1299
+ var disable = {
1300
+
1301
+ };
1302
+
1303
+ var getDateArray = function(date){
1304
+ var ret = [date.getFullYear(), addZero(date.getMonth() + 1), addZero(date.getDate())];
1305
+ ret.month = ret[0]+'-'+ret[1];
1306
+ ret.date = ret[0]+'-'+ret[1]+'-'+ret[2];
1307
+ return ret;
1308
+ };
1309
+ var today = getDateArray(new Date());
1310
+
1311
+ var _setFocus = function(element, _noFocus){
1312
+ var setFocus, that;
1313
+ element = $(element || this.activeButton);
1314
+ this.activeButton.attr({tabindex: '-1', 'aria-selected': 'false'});
1315
+ this.activeButton = element.attr({tabindex: '0', 'aria-selected': 'true'});
1316
+ this.index = this.buttons.index(this.activeButton[0]);
1317
+
1318
+ clearTimeout(this.timer);
1319
+
1320
+ if(!this.popover.openedByFocus && !_noFocus){
1321
+ that = this;
1322
+ setFocus = function(noTrigger){
1323
+ clearTimeout(that.timer);
1324
+ that.timer = setTimeout(function(){
1325
+ if(element[0]){
1326
+ element[0].focus();
1327
+ if(noTrigger !== true && !element.is(':focus')){
1328
+ setFocus(true);
1329
+ }
1330
+ }
1331
+ }, that.popover.isVisible ? 99 : 360);
1332
+ };
1333
+ this.popover.activateElement(element);
1334
+ setFocus();
1335
+ }
1336
+
1337
+ };
1338
+
1339
+ var _initialFocus = function(){
1340
+ var sel;
1341
+ if(this.popover.navedInitFocus){
1342
+ sel = this.popover.navedInitFocus.sel || this.popover.navedInitFocus;
1343
+ if((!this.activeButton || !this.activeButton[0]) && this.buttons[sel]){
1344
+ this.activeButton = this.buttons[sel]();
1345
+ } else if(sel){
1346
+ this.activeButton = $(sel, this.element);
1347
+ }
1348
+
1349
+ if(!this.activeButton[0] && this.popover.navedInitFocus.alt){
1350
+ this.activeButton = this.buttons[this.popover.navedInitFocus.alt]();
1351
+ }
1352
+ }
1353
+
1354
+ if(!this.activeButton || !this.activeButton[0]){
1355
+ this.activeButton = this.buttons.filter('.checked-value');
1356
+ }
1357
+
1358
+ if(!this.activeButton[0]){
1359
+ this.activeButton = this.buttons.filter('.this-value');
1360
+ }
1361
+ if(!this.activeButton[0]){
1362
+ this.activeButton = this.buttons.eq(0);
1363
+ }
1364
+
1365
+ this.setFocus(this.activeButton, this.opts.noFocus);
1366
+ };
1367
+
1368
+
1369
+ webshims.ListBox = function (element, popover, opts){
1370
+ this.element = $('ul', element);
1371
+ this.popover = popover;
1372
+ this.opts = opts || {};
1373
+ this.buttons = $('button:not(:disabled)', this.element);
1374
+
1375
+
1376
+ this.ons(this);
1377
+ this._initialFocus();
1378
+ };
1379
+
1380
+ webshims.ListBox.prototype = {
1381
+ setFocus: _setFocus,
1382
+ _initialFocus: _initialFocus,
1383
+ prev: function(){
1384
+ var index = this.index - 1;
1385
+ if(index < 0){
1386
+ if(this.opts.prev){
1387
+ this.popover.navedInitFocus = 'last';
1388
+ this.popover.actionFn(this.opts.prev);
1389
+ this.popover.navedInitFocus = false;
1390
+ }
1391
+ } else {
1392
+ this.setFocus(this.buttons.eq(index));
705
1393
  }
706
- if(typeof props == 'string'){
707
- props = props.split(listReg);
1394
+ },
1395
+ next: function(){
1396
+ var index = this.index + 1;
1397
+ if(index >= this.buttons.length){
1398
+ if(this.opts.next){
1399
+ this.popover.navedInitFocus = 'first';
1400
+ this.popover.actionFn(this.opts.next);
1401
+ this.popover.navedInitFocus = false;
1402
+ }
1403
+ } else {
1404
+ this.setFocus(this.buttons.eq(index));
1405
+ }
1406
+ },
1407
+ ons: function(that){
1408
+ this.element
1409
+ .on({
1410
+ 'keydown': function(e){
1411
+ var handled;
1412
+ var key = e.keyCode;
1413
+ if(e.ctrlKey){return;}
1414
+ if(key == 36 || key == 33){
1415
+ that.setFocus(that.buttons.eq(0));
1416
+ handled = true;
1417
+ } else if(key == 34 || key == 35){
1418
+ that.setFocus(that.buttons.eq(that.buttons.length - 1));
1419
+ handled = true;
1420
+ } else if(key == 38 || key == 37){
1421
+ that.prev();
1422
+ handled = true;
1423
+ } else if(key == 40 || key == 39){
1424
+ that.next();
1425
+ handled = true;
1426
+ }
1427
+ if(handled){
1428
+ return false;
1429
+ }
1430
+ }
1431
+ })
1432
+ ;
1433
+ }
1434
+ };
1435
+
1436
+ webshims.Grid = function (element, popover, opts){
1437
+ this.element = $('tbody', element);
1438
+ this.popover = popover;
1439
+ this.opts = opts || {};
1440
+ this.buttons = $('button:not(:disabled,.othermonth)', this.element);
1441
+
1442
+ this.ons(this);
1443
+
1444
+ this._initialFocus();
1445
+ if(this.popover.openedByFocus){
1446
+ this.popover.activeElement = this.activeButton;
1447
+ }
1448
+ };
1449
+
1450
+
1451
+
1452
+ webshims.Grid.prototype = {
1453
+ setFocus: _setFocus,
1454
+ _initialFocus: _initialFocus,
1455
+
1456
+ first: function(){
1457
+ this.setFocus(this.buttons.eq(0));
1458
+ },
1459
+ last: function(){
1460
+ this.setFocus(this.buttons.eq(this.buttons.length - 1));
1461
+ },
1462
+ upPage: function(){
1463
+ $('.ws-picker-header > button:not(:disabled)', this.popover.element).trigger('click');
1464
+ },
1465
+ downPage: function(){
1466
+ this.activeButton.filter(':not([data-action="changeInput"])').trigger('click');
1467
+ },
1468
+ ons: function(that){
1469
+ this.element
1470
+ .on({
1471
+ 'keydown': function(e){
1472
+ var handled;
1473
+ var key = e.keyCode;
1474
+
1475
+ if(e.shiftKey){return;}
1476
+
1477
+ if((e.ctrlKey && key == 40)){
1478
+ handled = 'downPage';
1479
+ } else if((e.ctrlKey && key == 38)){
1480
+ handled = 'upPage';
1481
+ } else if(key == 33 || (e.ctrlKey && key == 37)){
1482
+ handled = 'prevPage';
1483
+ } else if(key == 34 || (e.ctrlKey && key == 39)){
1484
+ handled = 'nextPage';
1485
+ } else if(e.keyCode == 36 || e.keyCode == 33){
1486
+ handled = 'first';
1487
+ } else if(e.keyCode == 35){
1488
+ handled = 'last';
1489
+ } else if(e.keyCode == 38){
1490
+ handled = 'up';
1491
+ } else if(e.keyCode == 37){
1492
+ handled = 'prev';
1493
+ } else if(e.keyCode == 40){
1494
+ handled = 'down';
1495
+ } else if(e.keyCode == 39){
1496
+ handled = 'next';
1497
+ }
1498
+ if(handled){
1499
+ that[handled]();
1500
+ return false;
1501
+ }
1502
+ }
1503
+ })
1504
+ ;
1505
+ }
1506
+ };
1507
+ $.each({
1508
+ prevPage: {get: 'last', action: 'prev'},
1509
+ nextPage: {get: 'first', action: 'next'}
1510
+ }, function(name, val){
1511
+ webshims.Grid.prototype[name] = function(){
1512
+ if(this.opts[val.action]){
1513
+ this.popover.navedInitFocus = {
1514
+ sel: 'button[data-id="'+ this.activeButton.attr('data-id') +'"]:not(:disabled,.othermonth)',
1515
+ alt: val.get
1516
+ };
1517
+ this.popover.actionFn(this.opts[val.action]);
1518
+ this.popover.navedInitFocus = false;
708
1519
  }
709
- if(desc.initAttr){
710
- initProp.createTmpCache(name);
1520
+ };
1521
+ });
1522
+
1523
+ $.each({
1524
+ up: {traverse: 'prevAll', get: 'last', action: 'prev', reverse: true},
1525
+ down: {traverse: 'nextAll', get: 'first', action: 'next'}
1526
+ }, function(name, val){
1527
+ webshims.Grid.prototype[name] = function(){
1528
+ var cellIndex = this.activeButton.closest('td').prop('cellIndex');
1529
+ var sel = 'td:nth-child('+(cellIndex + 1)+') button:not(:disabled,.othermonth)';
1530
+ var button = this.activeButton.closest('tr')[val.traverse]();
1531
+
1532
+ if(val.reverse){
1533
+ button = $(button.get().reverse());
711
1534
  }
712
- props.forEach(function(prop){
713
- if(!modifyProps[name][prop]){
714
- modifyProps[name][prop] = [];
715
- havePolyfill[prop] = true;
1535
+ button = button.find(sel)[val.get]();
1536
+
1537
+ if(!button[0]){
1538
+ if(this.opts[val.action]){
1539
+ this.popover.navedInitFocus = sel+':'+val.get;
1540
+ this.popover.actionFn(this.opts[val.action]);
1541
+ this.popover.navedInitFocus = false;
716
1542
  }
717
- if(desc.set){
718
- if(only){
719
- desc.set.only = only;
720
- }
721
- modifyProps[name][prop].push(desc.set);
1543
+ } else {
1544
+ this.setFocus(button.eq(0));
1545
+ }
1546
+ };
1547
+ });
1548
+
1549
+ $.each({
1550
+ prev: {traverse: 'prevAll',get: 'last', reverse: true},
1551
+ next: {traverse: 'nextAll', get: 'first'}
1552
+ }, function(name, val){
1553
+ webshims.Grid.prototype[name] = function(){
1554
+ var sel = 'button:not(:disabled,.othermonth)';
1555
+ var button = this.activeButton.closest('td')[val.traverse]('td');
1556
+ if(val.reverse){
1557
+ button = $(button.get().reverse());
1558
+ }
1559
+ button = button.find(sel)[val.get]();
1560
+ if(!button[0]){
1561
+ button = this.activeButton.closest('tr')[val.traverse]('tr');
1562
+ if(val.reverse){
1563
+ button = $(button.get().reverse());
722
1564
  }
723
-
724
- if(desc.initAttr){
725
- initProp.content(name, prop);
1565
+ button = button.find(sel)[val.get]();
1566
+ }
1567
+
1568
+ if(!button[0]){
1569
+ if(this.opts[name]){
1570
+ this.popover.navedInitFocus = val.get;
1571
+ this.popover.actionFn(this.opts[name]);
1572
+ this.popover.navedInitFocus = false;
726
1573
  }
727
- });
728
- initProp.flushTmpCache();
1574
+ } else {
1575
+ this.setFocus(button.eq(0));
1576
+ }
1577
+ };
1578
+ });
1579
+
1580
+ picker.getWeek = function(date){
1581
+ var onejan = new Date(date.getFullYear(),0,1);
1582
+ return Math.ceil((((date - onejan) / 86400000) + onejan.getDay()+1)/7);
1583
+ };
1584
+ picker.getYearList = function(value, data){
1585
+ var j, i, val, disabled, lis, prevDisabled, nextDisabled, classStr, classArray, start;
1586
+
1587
+
1588
+ var size = data.options.size;
1589
+ var max = data.options.max.split('-');
1590
+ var min = data.options.min.split('-');
1591
+ var currentValue = data.options.value.split('-');
1592
+ var xthCorrect = 0;
1593
+ var enabled = 0;
1594
+ var str = '';
1595
+ var rowNum = 0;
1596
+
1597
+ if(data.options.useDecadeBase == 'max' && max[0]){
1598
+ xthCorrect = 11 - (max[0] % 12);
1599
+ } else if(data.options.useDecadeBase == 'min' && min[0]){
1600
+ xthCorrect = 11 - (min[0] % 12);
1601
+ }
1602
+
1603
+ value = value[0] * 1;
1604
+ start = value - ((value + xthCorrect) % (12 * size));
1605
+
1606
+
1607
+
1608
+ for(j = 0; j < size; j++){
1609
+ if(j){
1610
+ start += 12;
1611
+ } else {
1612
+ prevDisabled = picker.isInRange([start-1], max, min) ? {'data-action': 'setYearList','value': start-1} : false;
1613
+ }
729
1614
 
730
- });
731
- },
732
- defineNodeNamesBooleanProperty: function(elementNames, prop, descs){
733
- if(!descs){
734
- descs = {};
1615
+ str += '<div class="year-list picker-list ws-index-'+ j +'"><div class="ws-picker-header"><button disabled="disabled">'+ start +' – '+(start + 11)+'</button></div>';
1616
+ lis = [];
1617
+ for(i = 0; i < 12; i++){
1618
+ val = start + i ;
1619
+ classArray = [];
1620
+ if( !picker.isInRange([val], max, min) ){
1621
+ disabled = ' disabled=""';
1622
+ } else {
1623
+ disabled = '';
1624
+ enabled++;
1625
+ }
1626
+
1627
+ if(val == today[0]){
1628
+ classArray.push('this-value');
1629
+ }
1630
+
1631
+ if(currentValue[0] == val){
1632
+ classArray.push('checked-value');
1633
+ }
1634
+
1635
+ classStr = classArray.length ? ' class="'+ (classArray.join(' ')) +'"' : '';
1636
+
1637
+ if(i && !(i % 3)){
1638
+ rowNum++;
1639
+ lis.push('</tr><tr class="ws-row-'+ rowNum +'">');
1640
+ }
1641
+ 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>');
1642
+ }
1643
+ if(j == size - 1){
1644
+ nextDisabled = picker.isInRange([val+1], max, min) ? {'data-action': 'setYearList','value': val+1} : false;
1645
+ }
1646
+ 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>';
735
1647
  }
736
- if($.isFunction(descs)){
737
- descs.set = descs;
1648
+
1649
+ return {
1650
+ enabled: enabled,
1651
+ main: str,
1652
+ next: nextDisabled,
1653
+ prev: prevDisabled,
1654
+ type: 'Grid'
1655
+ };
1656
+ };
1657
+
1658
+
1659
+ picker.getMonthList = function(value, data){
1660
+
1661
+ var j, i, name, val, disabled, lis, fullyDisabled, prevDisabled, nextDisabled, classStr, classArray;
1662
+ var o = data.options;
1663
+ var size = o.size;
1664
+ var max = o.max.split('-');
1665
+ var min = o.min.split('-');
1666
+ var currentValue = o.value.split('-');
1667
+ var enabled = 0;
1668
+ var rowNum = 0;
1669
+ var str = '';
1670
+
1671
+ value = value[0] - Math.floor((size - 1) / 2);
1672
+ for(j = 0; j < size; j++){
1673
+ if(j){
1674
+ value++;
1675
+ } else {
1676
+ prevDisabled = picker.isInRange([value-1], max, min) ? {'data-action': 'setMonthList','value': value-1} : false;
1677
+ }
1678
+ if(j == size - 1){
1679
+ nextDisabled = picker.isInRange([value+1], max, min) ? {'data-action': 'setMonthList','value': value+1} : false;
1680
+ }
1681
+ lis = [];
1682
+
1683
+ if( !picker.isInRange([value, '01'], max, min) && !picker.isInRange([value, '12'], max, min)){
1684
+ disabled = ' disabled=""';
1685
+ fullyDisabled = true;
1686
+ } else {
1687
+ fullyDisabled = false;
1688
+ disabled = '';
1689
+ }
1690
+
1691
+ if(o.minView >= 1){
1692
+ disabled = ' disabled=""';
1693
+ }
1694
+
1695
+ str += '<div class="month-list picker-list ws-index-'+ j +'"><div class="ws-picker-header">';
1696
+
1697
+ str += o.selectNav ?
1698
+ '<select data-action="setMonthList" class="year-select">'+ picker.createYearSelect(value, max, min).join('') +'</select>' :
1699
+ '<button data-action="setYearList"'+disabled+' value="'+ value +'" tabindex="-1">'+ value +'</button>';
1700
+ str += '</div>';
1701
+
1702
+ for(i = 0; i < 12; i++){
1703
+ val = curCfg.date.monthkeys[i+1];
1704
+ name = (curCfg.date[o.monthNames] || curCfg.date.monthNames)[i];
1705
+ classArray = [];
1706
+ if(fullyDisabled || !picker.isInRange([value, val], max, min) ){
1707
+ disabled = ' disabled=""';
1708
+ } else {
1709
+ disabled = '';
1710
+ enabled++;
1711
+ }
1712
+
1713
+ if(value == today[0] && today[1] == val){
1714
+ classArray.push('this-value');
1715
+ }
1716
+
1717
+ if(currentValue[0] == value && currentValue[1] == val){
1718
+ classArray.push('checked-value');
1719
+ }
1720
+
1721
+ classStr = (classArray.length) ? ' class="'+ (classArray.join(' ')) +'"' : '';
1722
+ if(i && !(i % 3)){
1723
+ rowNum++;
1724
+ lis.push('</tr><tr class="ws-row-'+ rowNum +'">');
1725
+ }
1726
+
1727
+ 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>');
1728
+
1729
+ }
1730
+
1731
+ str += '<div class="picker-grid"><table role="grid" aria-label="'+value+'"><tbody><tr class="ws-row-0">'+ (lis.join(''))+ '</tr></tbody></table></div></div>';
738
1732
  }
739
- webshims.defineNodeNamesProperty(elementNames, prop, {
740
- attr: {
741
- set: function(val){
742
- this.setAttribute(prop, val);
743
- if(descs.set){
744
- descs.set.call(this, true);
1733
+
1734
+ return {
1735
+ enabled: enabled,
1736
+ main: str,
1737
+ prev: prevDisabled,
1738
+ next: nextDisabled,
1739
+ type: 'Grid'
1740
+ };
1741
+ };
1742
+
1743
+
1744
+ picker.getDayList = function(value, data){
1745
+
1746
+ var j, i, k, day, nDay, name, val, disabled, lis, prevDisabled, nextDisabled, addTr, week, rowNum;
1747
+
1748
+ var lastMotnh, curMonth, otherMonth, dateArray, monthName, fullMonthName, buttonStr, date2, classArray;
1749
+ var o = data.options;
1750
+ var size = o.size;
1751
+ var max = o.max.split('-');
1752
+ var min = o.min.split('-');
1753
+ var currentValue = o.value.split('-');
1754
+ var monthNames = curCfg.date[o.monthNamesHead] || curCfg.date[o.monthNames] || curCfg.date.monthNames;
1755
+ var enabled = 0;
1756
+ var str = [];
1757
+ var date = new Date(value[0], value[1] - 1, 1);
1758
+
1759
+ date.setMonth(date.getMonth() - Math.floor((size - 1) / 2));
1760
+
1761
+ for(j = 0; j < size; j++){
1762
+ date.setDate(1);
1763
+ lastMotnh = date.getMonth();
1764
+ rowNum = 0;
1765
+ if(!j){
1766
+ date2 = new Date(date.getTime());
1767
+ date2.setDate(-1);
1768
+ dateArray = getDateArray(date2);
1769
+ prevDisabled = picker.isInRange(dateArray, max, min) ? {'data-action': 'setDayList','value': dateArray[0]+'-'+dateArray[1]} : false;
1770
+ }
1771
+
1772
+ dateArray = getDateArray(date);
1773
+
1774
+ str.push('<div class="day-list picker-list ws-index-'+ j +'"><div class="ws-picker-header">');
1775
+ if( o.selectNav ){
1776
+ 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>'];
1777
+ if(curCfg.date.showMonthAfterYear){
1778
+ monthName.reverse();
1779
+ }
1780
+ str.push( monthName.join(' ') );
1781
+ }
1782
+
1783
+ fullMonthName = [curCfg.date.monthNames[(dateArray[1] * 1) - 1], dateArray[0]];
1784
+ monthName = [monthNames[(dateArray[1] * 1) - 1], dateArray[0]];
1785
+ if(curCfg.date.showMonthAfterYear){
1786
+ monthName.reverse();
1787
+ fullMonthName.reverse();
1788
+ }
1789
+
1790
+ if(!data.options.selectNav) {
1791
+ str.push(
1792
+ '<button data-action="setMonthList"'+ (o.minView >= 2 ? ' disabled="" ' : '') +' value="'+ dateArray.date +'" tabindex="-1">'+ monthName.join(' ') +'</button>'
1793
+ );
1794
+ }
1795
+
1796
+
1797
+ str.push('</div><div class="picker-grid"><table role="grid" aria-label="'+ fullMonthName.join(' ') +'"><thead><tr>');
1798
+
1799
+ if(data.options.showWeek){
1800
+ str.push('<th class="week-header">'+ curCfg.date.weekHeader +'</th>');
1801
+ }
1802
+ for(k = curCfg.date.firstDay; k < curCfg.date.dayNamesShort.length; k++){
1803
+ str.push('<th class="day-'+ k +'"><abbr title="'+ curCfg.date.dayNames[k] +'">'+ curCfg.date.dayNamesShort[k] +'</abbr></th>');
1804
+ }
1805
+ k = curCfg.date.firstDay;
1806
+ while(k--){
1807
+ str.push('<th class="day-'+ k +'"><abbr title="'+ curCfg.date.dayNames[k] +'">'+ curCfg.date.dayNamesShort[k] +'</abbr></th>');
1808
+ }
1809
+ str.push('</tr></thead><tbody><tr class="ws-row-0">');
1810
+
1811
+ if(data.options.showWeek) {
1812
+ week = picker.getWeek(date);
1813
+ str.push('<td class="week-cell">'+ week +'</td>');
1814
+ }
1815
+
1816
+ for (i = 0; i < 99; i++) {
1817
+ addTr = (i && !(i % 7));
1818
+ curMonth = date.getMonth();
1819
+ otherMonth = lastMotnh != curMonth;
1820
+ day = date.getDay();
1821
+ classArray = [];
1822
+
1823
+ if(addTr && otherMonth ){
1824
+ str.push('</tr>');
1825
+ break;
1826
+ }
1827
+ if(addTr){
1828
+ rowNum++;
1829
+ str.push('</tr><tr class="ws-row-'+ rowNum +'">');
1830
+ if(data.options.showWeek) {
1831
+ week++;
1832
+ str.push('<td class="week-cell">'+ week +'</td>');
745
1833
  }
746
- },
747
- get: function(){
748
- var ret = this.getAttribute(prop);
749
- return (ret == null) ? undefined : prop;
750
1834
  }
751
- },
752
- removeAttr: {
753
- value: function(){
754
- this.removeAttribute(prop);
755
- if(descs.set){
756
- descs.set.call(this, false);
1835
+
1836
+ if(!i){
1837
+
1838
+ if(day != curCfg.date.firstDay){
1839
+ nDay = day - curCfg.date.firstDay;
1840
+ if(nDay < 0){
1841
+ nDay += 7;
1842
+ }
1843
+ date.setDate(date.getDate() - nDay);
1844
+ day = date.getDay();
1845
+ curMonth = date.getMonth();
1846
+ otherMonth = lastMotnh != curMonth;
757
1847
  }
758
1848
  }
759
- },
760
- reflect: true,
761
- propType: 'boolean',
762
- initAttr: descs.initAttr || false
763
- });
764
- },
765
- contentAttr: function(elem, name, val){
766
- if(!elem.nodeName){return;}
767
- var attr;
768
- if(val === undefined){
769
- attr = (elem.attributes[name] || {});
770
- val = attr.specified ? attr.value : null;
771
- return (val == null) ? undefined : val;
1849
+
1850
+ dateArray = getDateArray(date);
1851
+ buttonStr = '<td role="presentation" class="day-'+ day +'"><button data-id="day-'+ date.getDate() +'" role="gridcell" data-action="changeInput" value="'+ (dateArray.join('-')) +'"';
1852
+
1853
+ if(otherMonth){
1854
+ classArray.push('othermonth');
1855
+ } else {
1856
+ classArray.push('day-'+date.getDate());
1857
+ }
1858
+
1859
+ if(dateArray[0] == today[0] && today[1] == dateArray[1] && today[2] == dateArray[2]){
1860
+ classArray.push('this-value');
1861
+ }
1862
+
1863
+ if(currentValue[0] == dateArray[0] && dateArray[1] == currentValue[1] && dateArray[2] == currentValue[2]){
1864
+ classArray.push('checked-value');
1865
+ }
1866
+
1867
+ if(classArray.length){
1868
+ buttonStr += ' class="'+ classArray.join(' ') +'"';
1869
+ }
1870
+
1871
+ if(!picker.isInRange(dateArray, max, min) || (data.options.disableDays && $.inArray(day, data.options.disableDays) != -1)){
1872
+ buttonStr += ' disabled=""';
1873
+ }
1874
+
1875
+ str.push(buttonStr+' tabindex="-1">'+ date.getDate() +'</button></td>');
1876
+
1877
+ date.setDate(date.getDate() + 1);
1878
+ }
1879
+ str.push('</tbody></table></div></div>');
1880
+ if(j == size - 1){
1881
+ dateArray = getDateArray(date);
1882
+ dateArray[2] = 1;
1883
+ nextDisabled = picker.isInRange(dateArray, max, min) ? {'data-action': 'setDayList','value': dateArray.date} : false;
1884
+ }
1885
+ }
1886
+
1887
+
1888
+ return {
1889
+ enabled: 9,
1890
+ main: str.join(''),
1891
+ prev: prevDisabled,
1892
+ next: nextDisabled,
1893
+ type: 'Grid'
1894
+ };
1895
+ };
1896
+
1897
+ picker.isInRange = function(values, max, min){
1898
+ var i;
1899
+ var ret = true;
1900
+ for(i = 0; i < values.length; i++){
1901
+
1902
+ if(min[i] && min[i] > values[i]){
1903
+ ret = false;
1904
+ break;
1905
+ } else if( !(min[i] && min[i] == values[i]) ){
1906
+ break;
1907
+ }
1908
+ }
1909
+ if(ret){
1910
+ for(i = 0; i < values.length; i++){
1911
+
1912
+ if((max[i] && max[i] < values[i])){
1913
+ ret = false;
1914
+ break;
1915
+ } else if( !(max[i] && max[i] == values[i]) ){
1916
+ break;
1917
+ }
1918
+ }
1919
+ }
1920
+ return ret;
1921
+ };
1922
+
1923
+ picker.createMonthSelect = function(value, max, min, monthNames){
1924
+ if(!monthNames){
1925
+ monthNames = curCfg.date.monthNames;
1926
+ }
1927
+
1928
+ var selected;
1929
+ var i = 0;
1930
+ var options = [];
1931
+ var tempVal = value[1]-1;
1932
+ for(; i < monthNames.length; i++){
1933
+ selected = tempVal == i ? ' selected=""' : '';
1934
+ if(selected || picker.isInRange([value[0], i+1], max, min)){
1935
+ options.push('<option value="'+ value[0]+'-'+addZero(i+1) + '"'+selected+'>'+ monthNames[i] +'</option>');
1936
+ }
772
1937
  }
1938
+ return options;
1939
+ };
1940
+
1941
+ picker.createYearSelect = function(value, max, min, valueAdd){
773
1942
 
774
- if(typeof val == 'boolean'){
775
- if(!val){
776
- elem.removeAttribute(name);
1943
+ var temp;
1944
+ var goUp = true;
1945
+ var goDown = true;
1946
+ var options = ['<option selected="">'+ value + '</option>'];
1947
+ var i = 0;
1948
+ if(!valueAdd){
1949
+ valueAdd = '';
1950
+ }
1951
+ while(i < 8 && (goUp || goDown)){
1952
+ i++;
1953
+ temp = value-i;
1954
+ if(goUp && picker.isInRange([temp], max, min)){
1955
+ options.unshift('<option value="'+ (temp+valueAdd) +'">'+ temp +'</option>');
777
1956
  } else {
778
- elem.setAttribute(name, name);
1957
+ goUp = false;
1958
+ }
1959
+ temp = value + i;
1960
+ if(goDown && picker.isInRange([temp], max, min)){
1961
+ options.push('<option value="'+ (temp+valueAdd) +'">'+ temp +'</option>');
1962
+ } else {
1963
+ goDown = false;
779
1964
  }
780
- } else {
781
- elem.setAttribute(name, val);
782
1965
  }
783
- },
1966
+ return options;
1967
+ };
1968
+
1969
+ var actions = {
1970
+ changeInput: function(val, popover, data){
1971
+ popover.stopOpen = true;
1972
+ data.element.getShadowFocusElement().focus();
1973
+ setTimeout(function(){
1974
+ popover.stopOpen = false;
1975
+ }, 9);
1976
+ popover.hide();
1977
+ data.setChange(val);
1978
+ }
1979
+ };
784
1980
 
785
- // set current Lang:
786
- // - webshims.activeLang(lang:string);
787
- // get current lang
788
- // - webshims.activeLang();
789
- // get current lang
790
- // webshims.activeLang({
791
- // register: moduleName:string,
792
- // callback: callback:function
793
- // });
794
- // get/set including removeLang
795
- // - webshims.activeLang({
796
- // module: moduleName:string,
797
- // callback: callback:function,
798
- // langObj: languageObj:array/object
799
- // });
800
- activeLang: (function(){
801
- var callbacks = [];
802
- var registeredCallbacks = {};
803
- var currentLang;
804
- var shortLang;
805
- var notLocal = /:\/\/|^\.*\//;
806
- var loadRemoteLang = function(data, lang, options){
807
- var langSrc;
808
- if(lang && options && $.inArray(lang, options.availabeLangs || []) !== -1){
809
- data.loading = true;
810
- langSrc = options.langSrc;
811
- if(!notLocal.test(langSrc)){
812
- langSrc = webshims.cfg.basePath+langSrc;
1981
+ (function(){
1982
+ var retNames = function(name){
1983
+ return 'get'+name+'List';
1984
+ };
1985
+ var retSetNames = function(name){
1986
+ return 'set'+name+'List';
1987
+ };
1988
+ var stops = {
1989
+ date: 'Day',
1990
+ week: 'Day',
1991
+ month: 'Month'
1992
+ };
1993
+
1994
+ $.each({'setYearList' : ['Year', 'Month', 'Day'], 'setMonthList': ['Month', 'Day'], 'setDayList': ['Day']}, function(setName, names){
1995
+ var getNames = names.map(retNames);
1996
+ var setNames = names.map(retSetNames);
1997
+ actions[setName] = function(val, popover, data, startAt){
1998
+ val = ''+val;
1999
+ var o = data.options;
2000
+ var values = val.split('-');
2001
+ if(!startAt){
2002
+ startAt = 0;
813
2003
  }
814
- webshims.loader.loadScript(langSrc+lang+'.js', function(){
815
- if(data.langObj[lang]){
816
- data.loading = false;
817
- callLang(data, true);
818
- } else {
819
- $(function(){
820
- if(data.langObj[lang]){
821
- callLang(data, true);
2004
+ $.each(getNames, function(i, item){
2005
+ if(i >= startAt){
2006
+ var content = picker[item](values, data);
2007
+
2008
+ if( values.length < 2 || content.enabled > 1 || stops[data.type] === names[i]){
2009
+ popover.element
2010
+ .attr({'data-currentview': setNames[i]})
2011
+ .addClass('ws-size-'+o.size)
2012
+ .data('pickercontent', {
2013
+ data: data,
2014
+ content: content,
2015
+ values: values
2016
+ })
2017
+ ;
2018
+ popover.bodyElement.html(content.main);
2019
+ if(content.prev){
2020
+ popover.prevElement
2021
+ .attr(content.prev)
2022
+ .prop({disabled: false})
2023
+ ;
2024
+ } else {
2025
+ popover.prevElement
2026
+ .removeAttr('data-action')
2027
+ .prop({disabled: true})
2028
+ ;
2029
+ }
2030
+ if(content.next){
2031
+ popover.nextElement
2032
+ .attr(content.next)
2033
+ .prop({disabled: false})
2034
+ ;
2035
+ } else {
2036
+ popover.nextElement
2037
+ .removeAttr('data-action')
2038
+ .prop({disabled: true})
2039
+ ;
822
2040
  }
823
- data.loading = false;
824
- });
2041
+ if(webshims[content.type]){
2042
+ new webshims[content.type](popover.bodyElement.children(), popover, content);
2043
+ }
2044
+ popover.element.trigger('pickerchange');
2045
+ return false;
2046
+ }
825
2047
  }
826
2048
  });
827
- return true;
2049
+ };
2050
+ });
2051
+ })();
2052
+
2053
+ picker.commonInit = function(data, popover){
2054
+ var actionfn = function(e){
2055
+ if(!$(this).is('.othermonth') || $(this).css('cursor') == 'pointer'){
2056
+ popover.actionFn({
2057
+ 'data-action': $.attr(this, 'data-action'),
2058
+ value: $(this).val() || $.attr(this, 'value')
2059
+ });
828
2060
  }
829
2061
  return false;
830
2062
  };
831
- var callRegister = function(module){
832
- if(registeredCallbacks[module]){
833
- registeredCallbacks[module].forEach(function(data){
834
- data.callback();
2063
+ var id = new Date().getTime();
2064
+ var generateList = function(o, max, min){
2065
+ var options = [];
2066
+ var label = '';
2067
+ var labelId = '';
2068
+ o.options = data.getOptions() || {};
2069
+ $('div.ws-options', popover.contentElement).remove();
2070
+ $.each(o.options[0], function(val, label){
2071
+ var disabled = picker.isInRange(val.split('-'), o.maxS, o.minS) ?
2072
+ '' :
2073
+ ' disabled="" '
2074
+ ;
2075
+ options.push('<li role="presentation"><button value="'+ val +'" '+disabled+' data-action="changeInput" tabindex="-1" role="option">'+ (label || data.formatValue(val, false)) +'</button></li>');
2076
+ });
2077
+ if(options.length){
2078
+ id++;
2079
+ if(o.options[1]){
2080
+ labelId = 'datalist-'+id;
2081
+ label = '<h5 id="'+labelId+'">'+ o.options[1] +'</h5>';
2082
+ labelId = ' aria-labelledbyid="'+ labelId +'" ';
2083
+ }
2084
+ new webshims.ListBox($('<div class="ws-options">'+label+'<ul role="listbox" '+ labelId +'>'+ options.join('') +'</div>').insertAfter(popover.bodyElement)[0], popover, {noFocus: true});
2085
+ }
2086
+ };
2087
+ var updateContent = function(){
2088
+ if(popover.isDirty){
2089
+ var o = data.options;
2090
+ o.maxS = o.max.split('-');
2091
+ o.minS = o.min.split('-');
2092
+
2093
+ $('button', popover.buttonRow).each(function(){
2094
+ var text;
2095
+ if($(this).is('.ws-empty')){
2096
+ text = curCfg.date.clear;
2097
+ if(!text){
2098
+ text = formcfg[''].date.clear || 'clear';
2099
+ webshims.warn("could not get clear text from form cfg");
2100
+ }
2101
+ } else if($(this).is('.ws-current')){
2102
+ text = (curCfg[data.type] || {}).currentText;
2103
+ if(!text){
2104
+ text = (formcfg[''][[data.type]] || {}).currentText || 'current';
2105
+ webshims.warn("could not get currentText from form cfg");
2106
+ }
2107
+ $.prop(this, 'disabled', !picker.isInRange(today[data.type].split('-'), o.maxS, o.minS));
2108
+ }
2109
+ if(text){
2110
+ $(this).text(text).attr({'aria-label': text});
2111
+ if(webshims.assumeARIA){
2112
+ $.attr(this, 'aria-label', text);
2113
+ }
2114
+ }
2115
+
835
2116
  });
2117
+ popover.nextElement.attr({'aria-label': curCfg.date.nextText});
2118
+ $('> span', popover.nextElement).html(curCfg.date.nextText);
2119
+ popover.prevElement.attr({'aria-label': curCfg.date.prevText});
2120
+ $('> span', popover.prevElement).html(curCfg.date.prevText);
2121
+
2122
+ generateList(o, o.maxS, o.minS);
2123
+
2124
+ }
2125
+ $('button.ws-empty', popover.buttonRow).prop('disabled', $.prop(data.orig, 'required'));
2126
+ popover.isDirty = false;
2127
+ };
2128
+
2129
+ popover.actionFn = function(obj){
2130
+ if(actions[obj['data-action']]){
2131
+ actions[obj['data-action']](obj.value, popover, data, 0);
2132
+ } else {
2133
+ webshims.warn('no action for '+ obj['data-action']);
836
2134
  }
837
2135
  };
838
- var callLang = function(data, _noLoop){
839
- if(data.activeLang != currentLang && data.activeLang !== shortLang){
840
- var options = modules[data.module].options;
841
- if( data.langObj[currentLang] || (shortLang && data.langObj[shortLang]) ){
842
- data.activeLang = currentLang;
843
- data.callback(data.langObj[currentLang] || data.langObj[shortLang], currentLang);
844
- callRegister(data.module);
845
- } else if( !_noLoop &&
846
- !loadRemoteLang(data, currentLang, options) &&
847
- !loadRemoteLang(data, shortLang, options) &&
848
- data.langObj[''] && data.activeLang !== '' ) {
849
- data.activeLang = '';
850
- data.callback(data.langObj[''], currentLang);
851
- callRegister(data.module);
2136
+
2137
+ 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>');
2138
+ popover.nextElement = $('button.ws-next', popover.contentElement);
2139
+ popover.prevElement = $('button.ws-prev', popover.contentElement);
2140
+ popover.bodyElement = $('div.ws-picker-body', popover.contentElement);
2141
+ popover.buttonRow = $('div.ws-button-row', popover.contentElement);
2142
+
2143
+ popover.isDirty = true;
2144
+
2145
+ popover.contentElement
2146
+ .on('click', 'button[data-action]', actionfn)
2147
+ .on('change', 'select[data-action]', actionfn)
2148
+ ;
2149
+
2150
+ popover.contentElement.on({
2151
+ keydown: function(e){
2152
+ if(e.keyCode == 9){
2153
+ var tabbable = $('[tabindex="0"]:not(:disabled)', this).filter(':visible');
2154
+ var index = tabbable.index(e.target);
2155
+ if(e.shiftKey && index <= 0){
2156
+ tabbable.last().focus();
2157
+ return false;
2158
+ }
2159
+ if(!e.shiftKey && index >= tabbable.length - 1){
2160
+ tabbable.first().focus();
2161
+ return false;
2162
+ }
2163
+ } else if(e.keyCode == 27){
2164
+ data.element.getShadowFocusElement().focus();
2165
+ popover.hide();
2166
+ return false;
2167
+ }
2168
+ }
2169
+ });
2170
+
2171
+ $(data.options.orig).on('input', function(){
2172
+ var currentView;
2173
+ if(data.options.updateOnInput && popover.isVisible && data.options.value && (currentView = popover.element.attr('data-currentview'))){
2174
+ actions[currentView]( data.options.value , popover, data, 0);
2175
+ }
2176
+ });
2177
+
2178
+ data._propertyChange = (function(){
2179
+ var timer;
2180
+ var update = function(){
2181
+ if(popover.isVisible){
2182
+ updateContent();
2183
+ }
2184
+ };
2185
+ return function(prop){
2186
+ if(prop == 'value'){return;}
2187
+ popover.isDirty = true;
2188
+ if(popover.isVisible){
2189
+ clearTimeout(timer);
2190
+ timer = setTimeout(update, 9);
852
2191
  }
2192
+ };
2193
+ })();
2194
+
2195
+ popover.activeElement = $([]);
2196
+
2197
+ popover.activateElement = function(element){
2198
+ element = $(element);
2199
+ if(element[0] != popover.activeElement[0]){
2200
+ popover.activeElement.removeClass('ws-focus');
2201
+ element.addClass('ws-focus');
853
2202
  }
2203
+ popover.activeElement = element;
854
2204
  };
2205
+ popover.element.on({
2206
+ wspopoverbeforeshow: function(){
2207
+ data.element.triggerHandler('wsupdatevalue');
2208
+ updateContent();
2209
+ }
2210
+ });
855
2211
 
2212
+ $(document).onTrigger('wslocalechange', data._propertyChange);
2213
+ };
2214
+
2215
+ picker._common = function(data){
2216
+ var popover = webshims.objectCreate(webshims.wsPopover, {}, {prepareFor: data.element});
2217
+ var opener = $('<button type="button" class="ws-popover-opener"><span /></button>').appendTo(data.buttonWrapper);
2218
+ var options = data.options;
2219
+ var init = false;
856
2220
 
857
- var activeLang = function(lang){
858
-
859
- if(typeof lang == 'string' && lang !== currentLang){
860
- currentLang = lang;
861
- shortLang = currentLang.split('-')[0];
862
- if(currentLang == shortLang){
863
- shortLang = false;
2221
+ var show = function(){
2222
+ if(!options.disabled && !options.readonly && !popover.isVisible){
2223
+ if(!init){
2224
+ picker.commonInit(data, popover);
864
2225
  }
865
- $.each(callbacks, function(i, data){
866
- callLang(data);
867
- });
868
- } else if(typeof lang == 'object'){
869
2226
 
870
- if(lang.register){
871
- if(!registeredCallbacks[lang.register]){
872
- registeredCallbacks[lang.register] = [];
873
- }
874
- registeredCallbacks[lang.register].push(lang);
875
- lang.callback();
2227
+ if(!init || data.options.restartView) {
2228
+ actions.setYearList( options.defValue || options.value, popover, data, data.options.startView);
876
2229
  } else {
877
- if(!lang.activeLang){
878
- lang.activeLang = '';
879
- }
880
- callbacks.push(lang);
881
- callLang(lang);
2230
+ actions[popover.element.attr('data-currentview') || 'setYearList']( options.defValue || options.value, popover, data, 0);
882
2231
  }
2232
+
2233
+ init = true;
2234
+ popover.show(data.element);
883
2235
  }
884
- return currentLang;
885
2236
  };
886
2237
 
887
- return activeLang;
888
- })()
889
- });
890
-
891
- $.each({
892
- defineNodeNamesProperty: 'defineNodeNameProperty',
893
- defineNodeNamesProperties: 'defineNodeNameProperties',
894
- createElements: 'createElement'
895
- }, function(name, baseMethod){
896
- webshims[name] = function(names, a, b, c){
897
- if(typeof names == 'string'){
898
- names = names.split(listReg);
899
- }
900
- var retDesc = {};
901
- names.forEach(function(nodeName){
902
- retDesc[nodeName] = webshims[baseMethod](nodeName, a, b, c);
903
- });
904
- return retDesc;
905
- };
906
- });
907
-
908
- webshims.isReady('webshimLocalization', true);
909
- });
910
- //html5a11y
911
- (function($, document){
912
- //if we support basic styleing or do not support ARIA (assumed) abort
913
- if(!Modernizr.localstorage || ('hidden' in document.createElement('a'))){return;}
914
-
915
- var elemMappings = {
916
- article: "article",
917
- aside: "complementary",
918
- section: "region",
919
- nav: "navigation",
920
- address: "contentinfo"
921
- };
922
- var addRole = function(elem, role){
923
- var hasRole = elem.getAttribute('role');
924
- if (!hasRole) {
925
- elem.setAttribute('role', role);
926
- }
927
- };
928
-
929
- $.webshims.addReady(function(context, contextElem){
930
- $.each(elemMappings, function(name, role){
931
- var elems = $(name, context).add(contextElem.filter(name));
932
- for (var i = 0, len = elems.length; i < len; i++) {
933
- addRole(elems[i], role);
2238
+ options.containerElements.push(popover.element[0]);
2239
+
2240
+ if(!options.startView){
2241
+ options.startView = 0;
934
2242
  }
935
- });
936
- if (context === document) {
937
- var header = document.getElementsByTagName('header')[0];
938
- var footers = document.getElementsByTagName('footer');
939
- var footerLen = footers.length;
940
- if (header && !$(header).closest('section, article')[0]) {
941
- addRole(header, 'banner');
2243
+ if(!options.minView){
2244
+ options.minView = 0;
942
2245
  }
943
- if (!footerLen) {
944
- return;
2246
+ if(options.startView < options.minView){
2247
+ options.minView = options.startView;
2248
+ webshims.warn("wrong config for minView/startView.");
945
2249
  }
946
- var footer = footers[footerLen - 1];
947
- if (!$(footer).closest('section, article')[0]) {
948
- addRole(footer, 'contentinfo');
2250
+ if(!options.size){
2251
+ options.size = 1;
949
2252
  }
950
- }
951
- });
952
-
953
- })(jQuery, document);
954
-
955
- jQuery.webshims.register('form-datalist', function($, webshims, window, document, undefined){
956
- "use strict";
957
- var doc = document;
958
-
959
- /*
960
- * implement propType "element" currently only used for list-attribute (will be moved to dom-extend, if needed)
961
- */
962
- webshims.propTypes.element = function(descs){
963
- webshims.createPropDefault(descs, 'attr');
964
- if(descs.prop){return;}
965
- descs.prop = {
966
- get: function(){
967
- var elem = descs.attr.get.call(this);
968
- if(elem){
969
- elem = document.getElementById(elem);
970
- if(elem && descs.propNodeName && !$.nodeName(elem, descs.propNodeName)){
971
- elem = null;
972
- }
973
- }
974
- return elem || null;
975
- },
976
- writeable: false
977
- };
978
- };
979
-
980
-
981
- /*
982
- * Implements datalist element and list attribute
983
- */
984
-
985
- (function(){
986
- var formsCFG = $.webshims.cfg.forms;
987
- var listSupport = Modernizr.input.list;
988
- if(listSupport && !formsCFG.customDatalist){return;}
989
-
990
- var initializeDatalist = function(){
991
-
992
-
993
- if(!listSupport){
994
- webshims.defineNodeNameProperty('datalist', 'options', {
995
- prop: {
996
- writeable: false,
997
- get: function(){
998
- var elem = this;
999
- var select = $('select', elem);
1000
- var options;
1001
- if(select[0]){
1002
- options = select[0].options;
1003
- } else {
1004
- options = $('option', elem).get();
1005
- if(options.length){
1006
- webshims.warn('you should wrap your option-elements for a datalist in a select element to support IE and other old browsers.');
1007
- }
1008
- }
1009
- return options;
2253
+
2254
+ popover.element
2255
+ .addClass(data.type+'-popover input-picker')
2256
+ .attr({role: 'application'})
2257
+ .on({
2258
+ wspopoverhide: function(){
2259
+ popover.openedByFocus = false;
2260
+ },
2261
+ focusin: function(e){
2262
+ if(popover.activateElement){
2263
+ popover.openedByFocus = false;
2264
+ popover.activateElement(e.target);
1010
2265
  }
1011
- }
1012
- });
1013
- }
1014
-
1015
- var inputListProto = {
1016
- //override autocomplete
1017
- autocomplete: {
1018
- attr: {
1019
- get: function(){
1020
- var elem = this;
1021
- var data = $.data(elem, 'datalistWidget');
1022
- if(data){
1023
- return data._autocomplete;
1024
- }
1025
- return ('autocomplete' in elem) ? elem.autocomplete : elem.getAttribute('autocomplete');
1026
- },
1027
- set: function(value){
1028
- var elem = this;
1029
- var data = $.data(elem, 'datalistWidget');
1030
- if(data){
1031
- data._autocomplete = value;
1032
- if(value == 'off'){
1033
- data.hideList();
1034
- }
1035
- } else {
1036
- if('autocomplete' in elem){
1037
- elem.autocomplete = value;
1038
- } else {
1039
- elem.setAttribute('autocomplete', value);
1040
- }
1041
- }
2266
+ },
2267
+ focusout: function(){
2268
+ if(popover.activeElement){
2269
+ popover.activeElement.removeClass('ws-focus');
1042
2270
  }
1043
2271
  }
1044
- }
1045
- };
2272
+ })
2273
+ ;
1046
2274
 
1047
- // if(formsCFG.customDatalist && (!listSupport || !('selectedOption') in $('<input />')[0])){
1048
- // //currently not supported x-browser (FF4 has not implemented and is not polyfilled )
1049
- // inputListProto.selectedOption = {
1050
- // prop: {
1051
- // writeable: false,
1052
- // get: function(){
1053
- // var elem = this;
1054
- // var list = $.prop(elem, 'list');
1055
- // var ret = null;
1056
- // var value, options;
1057
- // if(!list){return ret;}
1058
- // value = $.prop(elem, 'value');
1059
- // if(!value){return ret;}
1060
- // options = $.prop(list, 'options');
1061
- // if(!options.length){return ret;}
1062
- // $.each(options, function(i, option){
1063
- // if(value == $.prop(option, 'value')){
1064
- // ret = option;
1065
- // return false;
1066
- // }
1067
- // });
1068
- // return ret;
1069
- // }
1070
- // }
1071
- // };
1072
- // }
1073
-
1074
- if(!listSupport){
1075
- inputListProto['list'] = {
1076
- attr: {
1077
- get: function(){
1078
- var val = webshims.contentAttr(this, 'list');
1079
- return (val == null) ? undefined : val;
1080
- },
1081
- set: function(value){
1082
- var elem = this;
1083
- webshims.contentAttr(elem, 'list', value);
1084
- webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
2275
+ labelWidth(popover.element.children('div.ws-po-outerbox').attr({role: 'group'}), options.labels, true);
2276
+ labelWidth(opener, options.labels, true);
2277
+
2278
+ opener
2279
+ .attr({
2280
+ 'tabindex': options.labels.length ? 0 : '-1'
2281
+ })
2282
+ .on({
2283
+ mousedown: function(){
2284
+ stopPropagation.apply(this, arguments);
2285
+ popover.preventBlur();
2286
+ },
2287
+ click: function(){
2288
+ if(popover.isVisible && popover.activeElement){
2289
+ popover.openedByFocus = false;
2290
+ popover.activeElement.focus();
1085
2291
  }
2292
+ show();
1086
2293
  },
1087
- initAttr: true,
1088
- reflect: true,
1089
- propType: 'element',
1090
- propNodeName: 'datalist'
2294
+ focus: function(){
2295
+ popover.preventBlur();
2296
+ }
2297
+ })
2298
+ ;
2299
+
2300
+ (function(){
2301
+ var mouseFocus = false;
2302
+ var resetMouseFocus = function(){
2303
+ mouseFocus = false;
1091
2304
  };
1092
- } else {
1093
- //options only return options, if option-elements are rooted: but this makes this part of HTML5 less backwards compatible
1094
- if(!($('<datalist><select><option></option></select></datalist>').prop('options') || []).length ){
1095
- webshims.defineNodeNameProperty('datalist', 'options', {
1096
- prop: {
1097
- writeable: false,
1098
- get: function(){
1099
- var options = this.options || [];
1100
- if(!options.length){
1101
- var elem = this;
1102
- var select = $('select', elem);
1103
- if(select[0] && select[0].options && select[0].options.length){
1104
- options = select[0].options;
1105
- }
1106
- }
1107
- return options;
1108
- }
1109
- }
1110
- });
1111
- }
1112
- inputListProto['list'] = {
1113
- attr: {
1114
- get: function(){
1115
- var val = webshims.contentAttr(this, 'list');
1116
- if(val != null){
1117
- this.removeAttribute('list');
1118
- } else {
1119
- val = $.data(this, 'datalistListAttr');
1120
- }
1121
-
1122
- return (val == null) ? undefined : val;
1123
- },
1124
- set: function(value){
1125
- var elem = this;
1126
- $.data(elem, 'datalistListAttr', value);
1127
- webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
2305
+ data.inputElements.on({
2306
+ focus: function(){
2307
+ if(!popover.stopOpen && (data.options.openOnFocus || (mouseFocus && options.openOnMouseFocus))){
2308
+ popover.openedByFocus = !options.noInput;
2309
+ show();
2310
+ } else {
2311
+ popover.preventBlur();
1128
2312
  }
1129
2313
  },
1130
- initAttr: true,
1131
- reflect: true,
1132
- propType: 'element',
1133
- propNodeName: 'datalist'
1134
- };
1135
- }
1136
-
1137
-
1138
- webshims.defineNodeNameProperties('input', inputListProto);
1139
-
1140
- if($.event.customEvent){
1141
- $.event.customEvent.updateDatalist = true;
1142
- $.event.customEvent.updateInput = true;
1143
- $.event.customEvent.datalistselect = true;
1144
- }
1145
- webshims.addReady(function(context, contextElem){
1146
- contextElem
1147
- .filter('datalist > select, datalist, datalist > option, datalist > select > option')
1148
- .closest('datalist')
1149
- .triggerHandler('updateDatalist')
1150
- ;
1151
-
1152
- });
1153
-
1154
-
2314
+ mousedown: function(){
2315
+ mouseFocus = true;
2316
+ setTimeout(resetMouseFocus, 9);
2317
+ if(data.element.is(':focus')){
2318
+ popover.openedByFocus = !options.noInput;
2319
+ show();
2320
+ }
2321
+ popover.preventBlur();
2322
+ }
2323
+ });
2324
+ })();
2325
+ data.popover = popover;
1155
2326
  };
1156
2327
 
2328
+ picker.month = picker._common;
2329
+ picker.date = picker.month;
1157
2330
 
1158
- /*
1159
- * ShadowList
1160
- */
1161
- var listidIndex = 0;
2331
+ webshims.picker = picker;
2332
+ })();
2333
+
2334
+ (function(){
2335
+
2336
+ var stopCircular, isCheckValidity;
1162
2337
 
1163
- var noDatalistSupport = {
1164
- submit: 1,
1165
- button: 1,
1166
- reset: 1,
1167
- hidden: 1,
2338
+ var modernizrInputTypes = Modernizr.inputtypes;
2339
+ var inputTypes = {
1168
2340
 
1169
- //ToDo
1170
- range: 1,
1171
- date: 1
1172
- };
1173
- var globStoredOptions = {};
1174
- var getStoredOptions = function(name){
1175
- if(!name){return [];}
1176
- if(globStoredOptions[name]){
1177
- return globStoredOptions[name];
1178
- }
1179
- var data;
1180
- try {
1181
- data = JSON.parse(localStorage.getItem('storedDatalistOptions'+name));
1182
- } catch(e){}
1183
- globStoredOptions[name] = data || [];
1184
- return data || [];
1185
- };
1186
- var storeOptions = function(name, val){
1187
- if(!name){return;}
1188
- val = val || [];
1189
- try {
1190
- localStorage.setItem( 'storedDatalistOptions'+name, JSON.stringify(val) );
1191
- } catch(e){}
1192
2341
  };
2342
+ var copyProps = [
2343
+ 'disabled',
2344
+ 'readonly',
2345
+ 'value',
2346
+ 'min',
2347
+ 'max',
2348
+ 'step',
2349
+ 'title',
2350
+ 'placeholder'
2351
+ ];
1193
2352
 
1194
- var getText = function(elem){
1195
- return (elem.textContent || elem.innerText || $.text([ elem ]) || '');
1196
- };
2353
+ //
2354
+ var copyAttrs = ['data-placeholder', 'tabindex'];
2355
+
2356
+ $.each(copyProps.concat(copyAttrs), function(i, name){
2357
+ var fnName = name.replace(/^data\-/, '');
2358
+ webshims.onNodeNamesPropertyModify('input', name, function(val){
2359
+ if(!stopCircular){
2360
+ var shadowData = webshims.data(this, 'shadowData');
2361
+ if(shadowData && shadowData.data && shadowData.nativeElement === this && shadowData.data[fnName]){
2362
+ shadowData.data[fnName](val);
2363
+ }
2364
+ }
2365
+ });
2366
+ });
1197
2367
 
1198
- var shadowListProto = {
1199
- _create: function(opts){
1200
-
1201
- if(noDatalistSupport[$.prop(opts.input, 'type')]){return;}
1202
- var datalist = opts.datalist;
1203
- var data = $.data(opts.input, 'datalistWidget');
1204
- if(datalist && data && data.datalist !== datalist){
1205
- data.datalist = datalist;
1206
- data.id = opts.id;
2368
+ if(options.replaceUI && 'valueAsNumber' in document.createElement('input')){
2369
+ var reflectFn = function(val){
2370
+ if(webshims.data(this, 'hasShadow')){
2371
+ $.prop(this, 'value', $.prop(this, 'value'));
2372
+ }
2373
+ };
2374
+
2375
+ webshims.onNodeNamesPropertyModify('input', 'valueAsNumber', reflectFn);
2376
+ webshims.onNodeNamesPropertyModify('input', 'valueAsDate', reflectFn);
2377
+ }
2378
+
2379
+ var extendType = (function(){
2380
+ return function(name, data){
2381
+ inputTypes[name] = data;
2382
+ data.attrs = $.merge([], copyAttrs, data.attrs);
2383
+ data.props = $.merge([], copyProps, data.props);
2384
+ };
2385
+ })();
2386
+
2387
+ var isVisible = function(){
2388
+ return $.css(this, 'display') != 'none';
2389
+ };
2390
+ var sizeInput = function(data){
2391
+ var init;
2392
+ var updateStyles = function(){
2393
+ $.style( data.orig, 'display', '' );
2394
+ var hasButtons, marginR, marginL;
2395
+ var correctWidth = 0.6;
2396
+ if(!init || data.orig.offsetWidth){
2397
+ hasButtons = data.buttonWrapper && data.buttonWrapper.filter(isVisible).length;
2398
+ marginR = $.css( data.orig, 'marginRight');
2399
+ data.element.css({
2400
+ marginLeft: $.css( data.orig, 'marginLeft'),
2401
+ marginRight: hasButtons ? 0 : marginR
2402
+ });
1207
2403
 
1208
- data.shadowList.prop('className', 'datalist-polyfill '+ (data.datalist.className || '') + ' '+ data.datalist.id +'-shadowdom');
1209
- if(formsCFG.positionDatalist){
1210
- data.shadowList.insertAfter(opts.input);
1211
- } else {
1212
- data.shadowList.appendTo('body');
1213
- }
1214
- $(data.datalist)
1215
- .off('updateDatalist.datalistWidget')
1216
- .on('updateDatalist.datalistWidget', $.proxy(data, '_resetListCached'))
1217
- ;
1218
- data._resetListCached();
1219
- return;
1220
- } else if(!datalist){
1221
- if(data){
1222
- data.destroy();
2404
+ if(hasButtons){
2405
+ marginL = (parseInt(data.buttonWrapper.css('marginLeft'), 10) || 0);
2406
+ data.element.css({paddingRight: ''});
2407
+
2408
+ if(marginL < 0){
2409
+ marginR = (parseInt(marginR, 10) || 0) + ((data.buttonWrapper.outerWidth() + marginL) * -1);
2410
+ data.buttonWrapper.css('marginRight', marginR);
2411
+ data.element
2412
+ .css({paddingRight: ''})
2413
+ .css({
2414
+ paddingRight: (parseInt( data.element.css('paddingRight'), 10) || 0) + data.buttonWrapper.outerWidth()
2415
+ })
2416
+ ;
2417
+ } else {
2418
+ data.buttonWrapper.css('marginRight', marginR);
2419
+ correctWidth = data.buttonWrapper.outerWidth(true) + 0.6;
2420
+ }
1223
2421
  }
1224
- return;
1225
- } else if(data && data.datalist === datalist){
1226
- return;
2422
+
2423
+ data.element.outerWidth( $(data.orig).outerWidth() - correctWidth );
1227
2424
  }
1228
- listidIndex++;
1229
- var that = this;
1230
- this.hideList = $.proxy(that, 'hideList');
1231
- this.timedHide = function(){
1232
- clearTimeout(that.hideTimer);
1233
- that.hideTimer = setTimeout(that.hideList, 9);
1234
- };
1235
- this.datalist = datalist;
1236
- this.id = opts.id;
1237
- this.hasViewableData = true;
1238
- this._autocomplete = $.attr(opts.input, 'autocomplete');
1239
- $.data(opts.input, 'datalistWidget', this);
1240
- this.shadowList = $('<div class="datalist-polyfill '+ (this.datalist.className || '') + ' '+ this.datalist.id +'-shadowdom' +'" />');
1241
-
1242
- if(formsCFG.positionDatalist || $(opts.input).hasClass('position-datalist')){
1243
- this.shadowList.insertAfter(opts.input);
1244
- } else {
1245
- this.shadowList.appendTo('body');
1246
- }
1247
-
1248
- this.index = -1;
1249
- this.input = opts.input;
1250
- this.arrayOptions = [];
1251
-
1252
- this.shadowList
1253
- .delegate('li', 'mouseenter.datalistWidget mousedown.datalistWidget click.datalistWidget', function(e){
1254
- var items = $('li:not(.hidden-item)', that.shadowList);
1255
- var select = (e.type == 'mousedown' || e.type == 'click');
1256
- that.markItem(items.index(e.currentTarget), select, items);
1257
- if(e.type == 'click'){
1258
- that.hideList();
1259
- if(formsCFG.customDatalist){
1260
- $(opts.input).trigger('datalistselect');
1261
- }
1262
- }
1263
- return (e.type != 'mousedown');
1264
- })
1265
- .on('focusout', this.timedHide)
1266
- ;
1267
-
1268
- opts.input.setAttribute('autocomplete', 'off');
1269
-
1270
- $(opts.input)
1271
- .attr({
1272
- //role: 'combobox',
1273
- 'aria-haspopup': 'true'
1274
- })
1275
- .on({
1276
- 'input.datalistWidget': function(){
1277
- if(!that.triggeredByDatalist){
1278
- that.changedValue = false;
1279
- that.showHideOptions();
1280
- }
1281
- },
1282
- 'keydown.datalistWidget': function(e){
1283
- var keyCode = e.keyCode;
1284
- var activeItem;
1285
- var items;
1286
- if(keyCode == 40 && !that.showList()){
1287
- that.markItem(that.index + 1, true);
1288
- return false;
1289
- }
1290
-
1291
- if(!that.isListVisible){return;}
1292
-
1293
-
1294
- if(keyCode == 38){
1295
- that.markItem(that.index - 1, true);
1296
- return false;
1297
- }
1298
- if(!e.shiftKey && (keyCode == 33 || keyCode == 36)){
1299
- that.markItem(0, true);
1300
- return false;
1301
- }
1302
- if(!e.shiftKey && (keyCode == 34 || keyCode == 35)){
1303
- items = $('li:not(.hidden-item)', that.shadowList);
1304
- that.markItem(items.length - 1, true, items);
1305
- return false;
1306
- }
1307
- if(keyCode == 13 || keyCode == 27){
1308
- if (keyCode == 13){
1309
- activeItem = $('li.active-item:not(.hidden-item)', that.shadowList);
1310
- that.changeValue( $('li.active-item:not(.hidden-item)', that.shadowList) );
1311
- }
1312
- that.hideList();
1313
- if(formsCFG.customDatalist && activeItem && activeItem[0]){
1314
- $(opts.input).trigger('datalistselect');
1315
- }
1316
- return false;
1317
- }
1318
- },
1319
- 'focus.datalistWidget': function(){
1320
- if($(this).hasClass('list-focus')){
1321
- that.showList();
1322
- }
1323
- },
1324
- 'mousedown.datalistWidget': function(){
1325
- if($(this).is(':focus')){
1326
- that.showList();
1327
- }
1328
- },
1329
- 'blur.datalistWidget': this.timedHide
1330
- })
1331
- ;
1332
-
2425
+ init = true;
2426
+ $.style( data.orig, 'display', 'none' );
2427
+ };
2428
+ $(document).onTrigger('updateshadowdom', updateStyles);
2429
+ };
2430
+
2431
+
2432
+ var implementType = function(){
2433
+ var type = $.prop(this, 'type');
2434
+
2435
+ var i, opts, data, optsName, labels;
2436
+ if(inputTypes[type] && webshims.implement(this, 'inputwidgets')){
2437
+ data = {};
2438
+ optsName = type;
1333
2439
 
1334
- $(this.datalist)
1335
- .off('updateDatalist.datalistWidget')
1336
- .on('updateDatalist.datalistWidget', $.proxy(this, '_resetListCached'))
1337
- ;
2440
+ //todo: do we need deep extend?
1338
2441
 
1339
- this._resetListCached();
2442
+ labels = $(this).jProp('labels');
1340
2443
 
1341
- if(opts.input.form && (opts.input.name || opts.input.id)){
1342
- $(opts.input.form).on('submit.datalistWidget'+opts.input.id, function(){
1343
- if(!$(opts.input).hasClass('no-datalist-cache') && that._autocomplete != 'off'){
1344
- var val = $.prop(opts.input, 'value');
1345
- var name = (opts.input.name || opts.input.id) + $.prop(opts.input, 'type');
1346
- if(!that.storedOptions){
1347
- that.storedOptions = getStoredOptions( name );
1348
- }
1349
- if(val && that.storedOptions.indexOf(val) == -1){
1350
- that.storedOptions.push(val);
1351
- storeOptions(name, that.storedOptions );
1352
- }
2444
+ opts = $.extend({}, options.widgets, options[type], $($.prop(this, 'form')).data(type) || {}, $(this).data(type) || {}, {
2445
+ orig: this,
2446
+ type: type,
2447
+ labels: labels,
2448
+ options: {},
2449
+ input: function(val){
2450
+ opts._change(val, 'input');
2451
+ },
2452
+ change: function(val){
2453
+ opts._change(val, 'change');
2454
+ },
2455
+ _change: function(val, trigger){
2456
+ stopCircular = true;
2457
+ $.prop(opts.orig, 'value', val);
2458
+ stopCircular = false;
2459
+ if(trigger){
2460
+ $(opts.orig).trigger(trigger);
1353
2461
  }
1354
- });
1355
- }
1356
- $(window).on('unload.datalist'+this.id+' beforeunload.datalist'+this.id, function(){
1357
- that.destroy();
2462
+ },
2463
+ containerElements: []
1358
2464
  });
1359
- },
1360
- destroy: function(){
1361
- var autocomplete = $.attr(this.input, 'autocomplete');
1362
- $(this.input)
1363
- .off('.datalistWidget')
1364
- .removeData('datalistWidget')
1365
- ;
1366
- this.shadowList.remove();
1367
- $(document).off('.datalist'+this.id);
1368
- $(window).off('.datalist'+this.id);
1369
- if(this.input.form && this.input.id){
1370
- $(this.input.form).off('submit.datalistWidget'+this.input.id);
1371
- }
1372
- this.input.removeAttribute('aria-haspopup');
1373
- if(autocomplete === undefined){
1374
- this.input.removeAttribute('autocomplete');
1375
- } else {
1376
- $(this.input).attr('autocomplete', autocomplete);
1377
- }
1378
- },
1379
- _resetListCached: function(e){
1380
- var that = this;
1381
- var forceShow;
1382
- this.needsUpdate = true;
1383
- this.lastUpdatedValue = false;
1384
- this.lastUnfoundValue = '';
1385
-
1386
- if(!this.updateTimer){
1387
- if(window.QUnit || (forceShow = (e && document.activeElement == that.input))){
1388
- that.updateListOptions(forceShow);
1389
- } else {
1390
- webshims.ready('WINDOWLOAD', function(){
1391
- that.updateTimer = setTimeout(function(){
1392
- that.updateListOptions();
1393
- that = null;
1394
- listidIndex = 1;
1395
- }, 200 + (100 * listidIndex));
1396
- });
1397
- }
2465
+
2466
+
2467
+ for(i = 0; i < copyProps.length; i++){
2468
+ opts[copyProps[i]] = $.prop(this, copyProps[i]);
1398
2469
  }
1399
- },
1400
- maskHTML: function(str){
1401
- return str.replace(/</g, '&lt;').replace(/>/g, '&gt;');
1402
- },
1403
- updateListOptions: function(_forceShow){
1404
- this.needsUpdate = false;
1405
- clearTimeout(this.updateTimer);
1406
- this.updateTimer = false;
1407
- this.shadowList
1408
- .css({
1409
- fontSize: $.css(this.input, 'fontSize'),
1410
- fontFamily: $.css(this.input, 'fontFamily')
1411
- })
1412
- ;
1413
- this.searchStart = formsCFG.customDatalist && $(this.input).hasClass('search-start');
1414
-
1415
- var list = [];
1416
-
1417
- var values = [];
1418
- var allOptions = [];
1419
- var rElem, rItem, rOptions, rI, rLen, item;
1420
- for(rOptions = $.prop(this.datalist, 'options'), rI = 0, rLen = rOptions.length; rI < rLen; rI++){
1421
- rElem = rOptions[rI];
1422
- if(rElem.disabled){return;}
1423
- rItem = {
1424
- value: $(rElem).val() || '',
1425
- text: $.trim($.attr(rElem, 'label') || getText(rElem)),
1426
- className: rElem.className || '',
1427
- style: $.attr(rElem, 'style') || ''
1428
- };
1429
- if(!rItem.text){
1430
- rItem.text = rItem.value;
1431
- } else if(rItem.text != rItem.value){
1432
- rItem.className += ' different-label-value';
2470
+
2471
+ for(i = 0; i < copyAttrs.length; i++){
2472
+ optsName = copyAttrs[i].replace(/^data\-/, '');
2473
+ if(optsName == 'placeholder' || !opts[optsName]){
2474
+ opts[optsName] = $.attr(this, copyAttrs[i]) || opts[optsName];
1433
2475
  }
1434
- values[rI] = rItem.value;
1435
- allOptions[rI] = rItem;
1436
2476
  }
1437
2477
 
1438
- if(!this.storedOptions){
1439
- this.storedOptions = ($(this.input).hasClass('no-datalist-cache') || this._autocomplete == 'off') ? [] : getStoredOptions((this.input.name || this.input.id) + $.prop(this.input, 'type'));
1440
- }
2478
+ data.shim = inputTypes[type]._create(opts);
1441
2479
 
1442
- this.storedOptions.forEach(function(val, i){
1443
- if(values.indexOf(val) == -1){
1444
- allOptions.push({value: val, text: val, className: 'stored-suggest', style: ''});
1445
- }
2480
+ webshims.addShadowDom(this, data.shim.element, {
2481
+ data: data.shim || {}
1446
2482
  });
1447
2483
 
1448
- for(rI = 0, rLen = allOptions.length; rI < rLen; rI++){
1449
- item = allOptions[rI];
1450
- list[rI] = '<li class="'+ item.className +'" style="'+ item.style +'" tabindex="-1" role="listitem"><span class="option-label">'+ this.maskHTML(item.text) +'</span> <span class="option-value">'+ this.maskHTML(item.value) +'</span></li>';
1451
- }
2484
+ data.shim.options.containerElements.push(data.shim.element[0]);
1452
2485
 
1453
- this.arrayOptions = allOptions;
1454
- this.shadowList.html('<div class="datalist-outer-box"><div class="datalist-box"><ul role="list">'+ list.join("\n") +'</ul></div></div>');
2486
+ labelWidth($(this).getShadowFocusElement(), labels);
2487
+ $.attr(this, 'required', $.attr(this, 'required'));
2488
+ $(this).on('change', function(e){
2489
+ if(!stopCircular){
2490
+ data.shim.value($.prop(this, 'value'));
2491
+ }
2492
+ });
1455
2493
 
1456
- if($.fn.bgIframe){
1457
- this.shadowList.bgIframe();
1458
- }
2494
+ (function(){
2495
+ var has = {
2496
+ focusin: true,
2497
+ focus: true
2498
+ };
2499
+ var timer;
2500
+ var hasFocusTriggered = false;
2501
+ var hasFocus = false;
2502
+
2503
+ $(data.shim.options.containerElements)
2504
+ .on({
2505
+ 'focusin focus focusout blur': function(e){
2506
+ e.stopImmediatePropagation();
2507
+ hasFocus = has[e.type];
2508
+ clearTimeout(timer);
2509
+ timer = setTimeout(function(){
2510
+ if(hasFocus != hasFocusTriggered){
2511
+ hasFocusTriggered = hasFocus;
2512
+ $(opts.orig).triggerHandler(hasFocus ? 'focus' : 'blur');
2513
+ $(opts.orig).trigger(hasFocus ? 'focusin' : 'focusout');
2514
+ }
2515
+ hasFocusTriggered = hasFocus;
2516
+ }, 0);
2517
+ }
2518
+ })
2519
+ ;
2520
+ })();
2521
+
1459
2522
 
1460
- if(_forceShow || this.isListVisible){
1461
- this.showHideOptions();
1462
- }
1463
- },
1464
- showHideOptions: function(_fromShowList){
1465
- var value = $.prop(this.input, 'value').toLowerCase();
1466
- //first check prevent infinite loop, second creates simple lazy optimization
1467
- if(value === this.lastUpdatedValue || (this.lastUnfoundValue && value.indexOf(this.lastUnfoundValue) === 0)){
1468
- return;
1469
- }
1470
-
1471
- this.lastUpdatedValue = value;
1472
- var found = false;
1473
- var startSearch = this.searchStart;
1474
- var lis = $('li', this.shadowList);
1475
- if(value){
1476
- this.arrayOptions.forEach(function(item, i){
1477
- var search;
1478
- if(!('lowerText' in item)){
1479
- if(item.text != item.value){
1480
- item.lowerText = item.value.toLowerCase() + item.text.toLowerCase();
1481
- } else {
1482
- item.lowerText = item.text.toLowerCase();
2523
+ data.shim.element.on('change input', stopPropagation);
2524
+
2525
+ if(Modernizr.formvalidation){
2526
+ $(opts.orig).on('firstinvalid', function(e){
2527
+ if(!webshims.fromSubmit && isCheckValidity){return;}
2528
+ $(opts.orig).off('invalid.replacedwidgetbubble').on('invalid.replacedwidgetbubble', function(evt){
2529
+ if(!e.isInvalidUIPrevented() && !evt.isDefaultPrevented()){
2530
+ webshims.validityAlert.showFor( e.target );
2531
+ e.preventDefault();
2532
+ evt.preventDefault();
1483
2533
  }
1484
- }
1485
- search = item.lowerText.indexOf(value);
1486
- search = startSearch ? !search : search !== -1;
1487
- if(search){
1488
- $(lis[i]).removeClass('hidden-item');
1489
- found = true;
1490
- } else {
1491
- $(lis[i]).addClass('hidden-item');
1492
- }
2534
+ $(opts.orig).off('invalid.replacedwidgetbubble');
2535
+ });
1493
2536
  });
1494
- } else if(lis.length) {
1495
- lis.removeClass('hidden-item');
1496
- found = true;
1497
- }
1498
-
1499
- this.hasViewableData = found;
1500
- if(!_fromShowList && found){
1501
- this.showList();
1502
- }
1503
- if(!found){
1504
- this.lastUnfoundValue = value;
1505
- this.hideList();
1506
2537
  }
1507
- },
1508
- setPos: function(){
1509
- this.shadowList.css({marginTop: 0, marginLeft: 0, marginRight: 0, marginBottom: 0});
1510
- var css = (formsCFG.positionDatalist) ? $(this.input).position() : webshims.getRelOffset(this.shadowList, this.input);
1511
- css.top += $(this.input).outerHeight();
1512
- css.width = $(this.input).outerWidth() - (parseInt(this.shadowList.css('borderLeftWidth'), 10) || 0) - (parseInt(this.shadowList.css('borderRightWidth'), 10) || 0);
1513
- this.shadowList.css({marginTop: '', marginLeft: '', marginRight: '', marginBottom: ''}).css(css);
1514
- return css;
1515
- },
1516
- showList: function(){
1517
- if(this.isListVisible){return false;}
1518
- if(this.needsUpdate){
1519
- this.updateListOptions();
1520
- }
1521
- this.showHideOptions(true);
1522
- if(!this.hasViewableData){return false;}
1523
- this.isListVisible = true;
1524
- var that = this;
1525
-
1526
- that.setPos();
1527
- that.shadowList.addClass('datalist-visible').find('li.active-item').removeClass('active-item');
1528
-
1529
- $(window).unbind('.datalist'+that.id);
1530
- $(document)
1531
- .off('.datalist'+that.id)
1532
- .on('mousedown.datalist'+that.id +' focusin.datalist'+that.id, function(e){
1533
- if(e.target === that.input || that.shadowList[0] === e.target || $.contains( that.shadowList[0], e.target )){
1534
- clearTimeout(that.hideTimer);
1535
- setTimeout(function(){
1536
- clearTimeout(that.hideTimer);
1537
- }, 9);
1538
- } else {
1539
- that.timedHide();
1540
- }
1541
- })
1542
- .on('updateshadowdom.datalist'+that.id, function(){
1543
- that.setPos();
1544
- })
1545
- ;
1546
- return true;
1547
- },
1548
- hideList: function(){
1549
- if(!this.isListVisible){return false;}
1550
- var that = this;
1551
- var triggerChange = function(e){
1552
- if(that.changedValue){
1553
- $(that.input).trigger('change');
1554
- }
1555
- that.changedValue = false;
1556
- };
1557
2538
 
1558
- that.shadowList.removeClass('datalist-visible list-item-active');
1559
- that.index = -1;
1560
- that.isListVisible = false;
1561
- if(that.changedValue){
1562
- that.triggeredByDatalist = true;
1563
- webshims.triggerInlineForm && webshims.triggerInlineForm(that.input, 'input');
1564
- if($(that.input).is(':focus')){
1565
- $(that.input).one('blur', triggerChange);
1566
- } else {
1567
- triggerChange();
1568
- }
1569
- that.triggeredByDatalist = false;
1570
- }
1571
- $(document).unbind('.datalist'+that.id);
1572
- $(window)
1573
- .off('.datalist'+that.id)
1574
- .one('resize.datalist'+that.id, function(){
1575
- that.shadowList.css({top: 0, left: 0});
1576
- })
1577
- ;
1578
- return true;
1579
- },
1580
- scrollIntoView: function(elem){
1581
- var ul = $('ul', this.shadowList);
1582
- var div = $('div.datalist-box', this.shadowList);
1583
- var elemPos = elem.position();
1584
- var containerHeight;
1585
- elemPos.top -= (parseInt(ul.css('paddingTop'), 10) || 0) + (parseInt(ul.css('marginTop'), 10) || 0) + (parseInt(ul.css('borderTopWidth'), 10) || 0);
1586
- if(elemPos.top < 0){
1587
- div.scrollTop( div.scrollTop() + elemPos.top - 2);
1588
- return;
1589
- }
1590
- elemPos.top += elem.outerHeight();
1591
- containerHeight = div.height();
1592
- if(elemPos.top > containerHeight){
1593
- div.scrollTop( div.scrollTop() + (elemPos.top - containerHeight) + 2);
1594
- }
1595
- },
1596
- changeValue: function(activeItem){
1597
- if(!activeItem[0]){return;}
1598
- var newValue = $('span.option-value', activeItem).text();
1599
- var oldValue = $.prop(this.input, 'value');
1600
- if(newValue != oldValue){
1601
- $(this.input)
1602
- .prop('value', newValue)
1603
- .triggerHandler('updateInput')
1604
- ;
1605
- this.changedValue = true;
1606
- }
1607
- },
1608
- markItem: function(index, doValue, items){
1609
- var activeItem;
1610
- var goesUp;
1611
2539
 
1612
- items = items || $('li:not(.hidden-item)', this.shadowList);
1613
- if(!items.length){return;}
1614
- if(index < 0){
1615
- index = items.length - 1;
1616
- } else if(index >= items.length){
1617
- index = 0;
2540
+ if(data.shim.buttonWrapper && data.shim.buttonWrapper.filter(isVisible).length){
2541
+ data.shim.element.addClass('has-input-buttons');
1618
2542
  }
1619
- items.removeClass('active-item');
1620
- this.shadowList.addClass('list-item-active');
1621
- activeItem = items.filter(':eq('+ index +')').addClass('active-item');
1622
2543
 
1623
- if(doValue){
1624
- this.changeValue(activeItem);
1625
- this.scrollIntoView(activeItem);
2544
+ if(opts.calculateWidth){
2545
+ sizeInput(data.shim);
1626
2546
  }
1627
- this.index = index;
2547
+ $(this).css({display: 'none'});
1628
2548
  }
1629
2549
  };
1630
2550
 
1631
- //init datalist update
1632
- initializeDatalist();
2551
+ if(!modernizrInputTypes.range || options.replaceUI){
2552
+ extendType('range', {
2553
+ _create: function(opts, set){
2554
+ return $('<span />').insertAfter(opts.orig).rangeUI(opts).data('rangeUi');
2555
+ }
2556
+ });
2557
+ }
2558
+
2559
+ if(Modernizr.formvalidation){
2560
+ ['input', 'form'].forEach(function(name){
2561
+ var desc = webshims.defineNodeNameProperty(name, 'checkValidity', {
2562
+ prop: {
2563
+ value: function(){
2564
+ isCheckValidity = true;
2565
+ var ret = desc.prop._supvalue.apply(this, arguments);
2566
+ isCheckValidity = false;
2567
+ return ret;
2568
+ }
2569
+ }
2570
+ });
2571
+ });
2572
+ }
2573
+
2574
+
2575
+ ['number', 'time', 'month', 'date'].forEach(function(name){
2576
+ if(!modernizrInputTypes[name] || options.replaceUI){
2577
+ extendType(name, {
2578
+ _create: function(opts, set){
2579
+
2580
+ if(opts.splitInput && !splitInputs[name]){
2581
+ webshims.warn('splitInput not supported for '+ name);
2582
+ opts.splitInput = false;
2583
+ }
2584
+ var markup = opts.splitInput ?
2585
+ '<span class="ws-'+name+' ws-input" role="group"></span>' :
2586
+ '<input class="ws-'+name+'" type="text" />';
2587
+ var data = $(markup) //role="spinbutton"???
2588
+ .insertAfter(opts.orig)
2589
+ .spinbtnUI(opts)
2590
+ .data('wsspinner')
2591
+ ;
2592
+ if(webshims.picker && webshims.picker[name]){
2593
+ webshims.picker[name](data);
2594
+ }
2595
+ data.buttonWrapper.addClass('input-button-size-'+(data.buttonWrapper.children().filter(isVisible).length));
2596
+ return data;
2597
+ }
2598
+ });
2599
+ }
2600
+ });
2601
+
2602
+
2603
+ webshims.addReady(function(context, contextElem){
2604
+ $('input', context)
2605
+ .add(contextElem.filter('input'))
2606
+ .each(implementType)
2607
+ ;
2608
+ });
1633
2609
  })();
1634
-
1635
- });
2610
+ });
2611
+