html5forms-rails 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/CHANGELOG.md +5 -0
  2. data/Gemfile +11 -0
  3. data/README.md +208 -0
  4. data/Rakefile +49 -0
  5. data/VERSION +1 -0
  6. data/demos/html5-form-demo.html +79 -0
  7. data/html5forms-rails.gemspec +142 -0
  8. data/lib/html5forms.rb +6 -0
  9. data/vendor/assets/images/colorpicker/blank.gif +0 -0
  10. data/vendor/assets/images/colorpicker/colorpicker_background.png +0 -0
  11. data/vendor/assets/images/colorpicker/colorpicker_hex.png +0 -0
  12. data/vendor/assets/images/colorpicker/colorpicker_hsb_b.png +0 -0
  13. data/vendor/assets/images/colorpicker/colorpicker_hsb_h.png +0 -0
  14. data/vendor/assets/images/colorpicker/colorpicker_hsb_s.png +0 -0
  15. data/vendor/assets/images/colorpicker/colorpicker_indic.gif +0 -0
  16. data/vendor/assets/images/colorpicker/colorpicker_overlay.png +0 -0
  17. data/vendor/assets/images/colorpicker/colorpicker_rgb_b.png +0 -0
  18. data/vendor/assets/images/colorpicker/colorpicker_rgb_g.png +0 -0
  19. data/vendor/assets/images/colorpicker/colorpicker_rgb_r.png +0 -0
  20. data/vendor/assets/images/colorpicker/colorpicker_select.gif +0 -0
  21. data/vendor/assets/images/colorpicker/colorpicker_submit.png +0 -0
  22. data/vendor/assets/images/colorpicker/custom_background.png +0 -0
  23. data/vendor/assets/images/colorpicker/custom_hex.png +0 -0
  24. data/vendor/assets/images/colorpicker/custom_hsb_b.png +0 -0
  25. data/vendor/assets/images/colorpicker/custom_hsb_h.png +0 -0
  26. data/vendor/assets/images/colorpicker/custom_hsb_s.png +0 -0
  27. data/vendor/assets/images/colorpicker/custom_indic.gif +0 -0
  28. data/vendor/assets/images/colorpicker/custom_rgb_b.png +0 -0
  29. data/vendor/assets/images/colorpicker/custom_rgb_g.png +0 -0
  30. data/vendor/assets/images/colorpicker/custom_rgb_r.png +0 -0
  31. data/vendor/assets/images/colorpicker/custom_submit.png +0 -0
  32. data/vendor/assets/images/colorpicker/select.png +0 -0
  33. data/vendor/assets/images/colorpicker/select2.png +0 -0
  34. data/vendor/assets/images/colorpicker/slider.png +0 -0
  35. data/vendor/assets/images/h5f/form_validation.png +0 -0
  36. data/vendor/assets/images/html5form-shim/asterisk.png +0 -0
  37. data/vendor/assets/images/html5form-shim/down.png +0 -0
  38. data/vendor/assets/images/html5form-shim/fail.png +0 -0
  39. data/vendor/assets/images/html5form-shim/ok.png +0 -0
  40. data/vendor/assets/images/html5forms/jscolor/arrow.gif +0 -0
  41. data/vendor/assets/images/html5forms/jscolor/cross.gif +0 -0
  42. data/vendor/assets/images/html5forms/jscolor/hs.png +0 -0
  43. data/vendor/assets/images/html5forms/jscolor/hv.png +0 -0
  44. data/vendor/assets/images/html5forms/slider/slider-1.png +0 -0
  45. data/vendor/assets/images/html5forms/slider/slider-disabled-1.png +0 -0
  46. data/vendor/assets/images/html5forms/slider/slider-disabled.png +0 -0
  47. data/vendor/assets/images/html5forms/slider/slider.png +0 -0
  48. data/vendor/assets/javascripts/colorpicker.js +484 -0
  49. data/vendor/assets/javascripts/colorpicker.min.js +9 -0
  50. data/vendor/assets/javascripts/h5f.js +328 -0
  51. data/vendor/assets/javascripts/h5f.min.js +4 -0
  52. data/vendor/assets/javascripts/html5forms/EventHelpers.min.js +15 -0
  53. data/vendor/assets/javascripts/html5forms/autocomplete.min.js +1 -0
  54. data/vendor/assets/javascripts/html5forms/cssQuery-p.min.js +6 -0
  55. data/vendor/assets/javascripts/html5forms/dev/EventHelpers.js +486 -0
  56. data/vendor/assets/javascripts/html5forms/dev/autocomplete.js +387 -0
  57. data/vendor/assets/javascripts/html5forms/dev/cssQuery-p.js +6 -0
  58. data/vendor/assets/javascripts/html5forms/dev/html5.js +121 -0
  59. data/vendor/assets/javascripts/html5forms/dev/html5Forms.js +892 -0
  60. data/vendor/assets/javascripts/html5forms/dev/html5Widgets.js +1417 -0
  61. data/vendor/assets/javascripts/html5forms/dev/jscolor.js +840 -0
  62. data/vendor/assets/javascripts/html5forms/dev/slider.js +797 -0
  63. data/vendor/assets/javascripts/html5forms/dev/timer.js +137 -0
  64. data/vendor/assets/javascripts/html5forms/dev/visibleIf.js +1100 -0
  65. data/vendor/assets/javascripts/html5forms/html5.min.js +2 -0
  66. data/vendor/assets/javascripts/html5forms/html5Forms.min.js +1 -0
  67. data/vendor/assets/javascripts/html5forms/html5Widgets.min.js +20 -0
  68. data/vendor/assets/javascripts/html5forms/jscolor.min.js +10 -0
  69. data/vendor/assets/javascripts/html5forms/slider.min.js +25 -0
  70. data/vendor/assets/javascripts/html5forms/timer.min.js +1 -0
  71. data/vendor/assets/javascripts/html5forms/visibleIf.min.js +19 -0
  72. data/vendor/assets/javascripts/html5forms.fallback.js +115 -0
  73. data/vendor/assets/javascripts/html5forms.fallback.min.js +11 -0
  74. data/vendor/assets/javascripts/jquery.html5form-shim.js +402 -0
  75. data/vendor/assets/javascripts/jquery.html5form.min.js +4 -0
  76. data/vendor/assets/javascripts/jquery.placehold.min.js +7 -0
  77. data/vendor/assets/javascripts/ui.spinner.js +649 -0
  78. data/vendor/assets/javascripts/ui.spinner.min.js +7 -0
  79. data/vendor/assets/javascripts/webforms2/webforms2-msie.js +1 -0
  80. data/vendor/assets/javascripts/webforms2/webforms2-p.js +14 -0
  81. data/vendor/assets/javascripts/webforms2/webforms2.js +14 -0
  82. data/vendor/assets/javascripts/webforms2/webforms2_src.js +3195 -0
  83. data/vendor/assets/stylesheets/colorpicker.css +161 -0
  84. data/vendor/assets/stylesheets/h5f.css +86 -0
  85. data/vendor/assets/stylesheets/html5form-shim.css +109 -0
  86. data/vendor/assets/stylesheets/html5forms/number.css +35 -0
  87. data/vendor/assets/stylesheets/html5forms/slider.css +169 -0
  88. data/vendor/assets/stylesheets/html5forms/slider_ie.css +41 -0
  89. data/vendor/assets/stylesheets/html5forms/visibleIf.css +23 -0
  90. data/vendor/assets/stylesheets/html5forms.layout.css +116 -0
  91. data/vendor/assets/stylesheets/ui.spinner.css +3 -0
  92. data/vendor/assets/stylesheets/webforms2.css +42 -0
  93. metadata +221 -0
@@ -0,0 +1,797 @@
1
+ /*
2
+ Unobtrusive Slider Control by frequency decoder v2.6 (http://www.frequency-decoder.com/)
3
+
4
+ Released under a creative commons Attribution-Share Alike 3.0 Unported license (http://creativecommons.org/licenses/by-sa/3.0/)
5
+
6
+ You are free:
7
+
8
+ * to copy, distribute, display, and perform the work
9
+ * to make derivative works
10
+ * to make commercial use of the work
11
+
12
+ Under the following conditions:
13
+
14
+ by Attribution.
15
+ --------------
16
+ You must attribute the work in the manner specified by the author or licensor.
17
+
18
+ sa
19
+ --
20
+ Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one.
21
+
22
+ * For any reuse or distribution, you must make clear to others the license terms of this work.
23
+ * Any of these conditions can be waived if you get permission from the copyright holder.
24
+ */
25
+
26
+ var fdSliderController = (function() {
27
+ var sliders = {},
28
+ uniqueid = 0,
29
+ mouseWheelEnabled = true;
30
+
31
+ var removeMouseWheelSupport = function() {
32
+ mouseWheelEnabled = false;
33
+ };
34
+ var addEvent = function(obj, type, fn) {
35
+ if( obj.attachEvent ) {
36
+ obj["e"+type+fn] = fn;
37
+ obj[type+fn] = function(){obj["e"+type+fn]( window.event );};
38
+ obj.attachEvent( "on"+type, obj[type+fn] );
39
+ } else { obj.addEventListener( type, fn, true ); }
40
+ };
41
+ var removeEvent = function(obj, type, fn) {
42
+ if( obj.detachEvent ) {
43
+ try {
44
+ obj.detachEvent( "on"+type, obj[type+fn] );
45
+ obj[type+fn] = null;
46
+ } catch(err) { };
47
+ } else { obj.removeEventListener( type, fn, true ); }
48
+ };
49
+ var stopEvent = function(e) {
50
+ if(e == null) e = document.parentWindow.event;
51
+ if(e.stopPropagation) {
52
+ e.stopPropagation();
53
+ e.preventDefault();
54
+ };
55
+
56
+ /*@cc_on@*/
57
+ /*@if(@_win32)
58
+ e.cancelBubble = true;
59
+ e.returnValue = false;
60
+ /*@end@*/
61
+
62
+ return false;
63
+ };
64
+ var joinNodeLists = function() {
65
+ if(!arguments.length) { return []; };
66
+ var nodeList = [];
67
+ for (var i = 0; i < arguments.length; i++) {
68
+ for (var j = 0, item; item = arguments[i][j]; j++) { nodeList[nodeList.length] = item; };
69
+ };
70
+ return nodeList;
71
+ };
72
+
73
+ // Function by Artem B. with a minor change by f.d.
74
+ var parseCallbacks = function(cbs) {
75
+ if(cbs == null) { return {}; };
76
+ var func,
77
+ type,
78
+ cbObj = {},
79
+ parts,
80
+ obj;
81
+ for(var i = 0, fn; fn = cbs[i]; i++) {
82
+ type = fn.match(/(fd_slider_cb_(update|create|destroy|redraw|move|focus|blur|enable|disable)_)([^\s|$]+)/i)[1];
83
+ fn = fn.replace(new RegExp("^"+type), "").replace(/-/g, ".");
84
+ type = type.replace(/^fd_slider_cb_/i, "").replace(/_$/, "");
85
+
86
+ try {
87
+ if(fn.indexOf(".") != -1) {
88
+ parts = fn.split('.');
89
+ obj = window;
90
+ for (var x = 0, part; part = obj[parts[x]]; x++) {
91
+ if(part instanceof Function) {
92
+ (function() {
93
+ var method = part;
94
+ func = function (data) { method.apply(obj, [data]) };
95
+ })();
96
+ } else {
97
+ obj = part;
98
+ };
99
+ };
100
+ } else {
101
+ func = window[fn];
102
+ };
103
+
104
+ if(!(func instanceof Function)) continue;
105
+ if(!(type in cbObj)) { cbObj[type] = []; };
106
+ cbObj[type][cbObj[type].length] = func;
107
+ } catch (err) {};
108
+ };
109
+ return cbObj;
110
+ };
111
+
112
+ var parseClassNames = function(cbs) {
113
+ if(cbs == null) { return ""; };
114
+ var cns = [];
115
+ for(var i = 0, cn; cn = cbs[i]; i++) {
116
+ cns[cns.length] = cn.replace(/^fd_slider_cn_/, "");
117
+ };
118
+ return cns.join(" ");
119
+ };
120
+ var createSlider = function(options) {
121
+ if(!options || !options.inp || !options.inp.id) { return false; };
122
+ destroySingleSlider(options.inp.id);
123
+ sliders[options.inp.id] = new fdSlider(options);
124
+ return true;
125
+ };
126
+ var init = function( elem ) {
127
+ var ranges = /fd_range_([-]{0,1}[0-9]+(d[0-9]+){0,1}){1}_([-]{0,1}[0-9]+(d[0-9]+){0,1}){1}/i,
128
+ increment = /fd_inc_([-]{0,1}[0-9]+(d[0-9]+){0,1}){1}/,
129
+ kIncrement = /fd_maxinc_([-]{0,1}[0-9]+(d[0-9]+){0,1}){1}/,
130
+ callbacks = /((fd_slider_cb_(update|create|destroy|redraw|move|focus|blur|enable|disable)_)([^\s|$]+))/ig,
131
+ classnames = /(fd_slider_cn_([a-zA-Z0-9_\-]+))/ig,
132
+ inputs = elem && elem.tagName && elem.tagName.search(/input|select/i) != -1 ? [elem] : joinNodeLists(document.getElementsByTagName('input'), document.getElementsByTagName('select')),
133
+ range,
134
+ tmp,
135
+ options;
136
+
137
+ for(var i = 0, inp; inp = inputs[i]; i++) {
138
+ if((inp.tagName.toLowerCase() == "input" && inp.type == "text" && (inp.className.search(ranges) != -1 || inp.className.search(/fd_slider/) != -1)) || (inp.tagName.toLowerCase() == "select" && inp.className.search(/fd_slider/) != -1)) {
139
+ // If we haven't been passed a specific id and the slider exists then continue
140
+ if(!elem && inp.id && document.getElementById("fd-slider-"+inp.id)) { continue; };
141
+
142
+ // Create an id if necessary
143
+ if(!inp.id) { inp.id == "sldr" + uniqueid++; };
144
+
145
+ options = {
146
+ inp: inp,
147
+ inc: inp.className.search(increment) != -1 ? inp.className.match(increment)[0].replace("fd_inc_", "").replace("d",".") : "1",
148
+ maxInc: inp.className.search(kIncrement) != -1 ? inp.className.match(kIncrement)[0].replace("fd_maxinc_", "").replace("d",".") : false,
149
+ range: [0,100],
150
+ callbacks: parseCallbacks(inp.className.match(callbacks)),
151
+ classNames: parseClassNames(inp.className.match(classnames)),
152
+ tween: inp.className.search(/fd_tween/i) != -1,
153
+ vertical: inp.className.search(/fd_vertical/i) != -1,
154
+ hideInput: inp.className.search(/fd_hide_input/i) != -1,
155
+ clickJump: inp.className.search(/fd_jump/i) != -1,
156
+ fullARIA: inp.className.search(/fd_full_aria/i) != -1,
157
+ noMouseWheel: inp.className.search(/fd_disable_mousewheel/i) != -1
158
+ };
159
+
160
+ if(inp.tagName.toLowerCase() == "select") {
161
+ options.range = [0, inp.options.length - 1];
162
+ } else if(inp.className.search(ranges) != -1) {
163
+ range = inp.className.match(ranges)[0].replace("fd_range_", "").replace(/d/g,".").split("_");
164
+ options.range = [range[0], range[1]];
165
+ };
166
+
167
+ createSlider(options);
168
+ };
169
+ };
170
+
171
+ return true;
172
+ };
173
+ var destroySingleSlider = function(id) {
174
+ if(id in sliders) {
175
+ sliders[id].destroy();
176
+ delete sliders[id];
177
+ return true;
178
+ };
179
+ return false;
180
+ };
181
+ var destroyAllsliders = function(e) {
182
+ for(slider in sliders) { sliders[slider].destroy(); };
183
+ };
184
+ var unload = function(e) {
185
+ destroyAllsliders();
186
+ sliders = null;
187
+ removeEvent(window, "unload", unload);
188
+ removeEvent(window, "resize", resize);
189
+ removeOnloadEvent();
190
+ };
191
+ var resize = function(e) {
192
+ for(slider in sliders) { sliders[slider].onResize(); };
193
+ };
194
+ var removeOnloadEvent = function() {
195
+ removeEvent(window, "load", init);
196
+ /*@cc_on@*/
197
+ /*@if(@_win32)
198
+ removeEvent(window, "load", function() { setTimeout(onload, 200) });
199
+ /*@end@*/
200
+ };
201
+ function fdSlider(options) {
202
+
203
+ var inp = options.inp,
204
+ disabled = false,
205
+ tagName = inp.tagName.toLowerCase(),
206
+ min = +options.range[0],
207
+ max = +options.range[1],
208
+ range = Math.abs(max - min),
209
+ inc = tagName == "select" ? 1 : +options.inc||1,
210
+ maxInc = options.maxInc && options.maxInc != 'undefined' ? options.maxInc : inc * 2;
211
+ // alert(options.maxInc + "," + maxInc)
212
+
213
+ var precision = options.inc.search(".") != -1 ? options.inc.substr(options.inc.indexOf(".")+1, options.inc.length - 1).length : 0,
214
+ steps = Math.ceil(range / inc),
215
+ useTween = !!options.tween,
216
+ fullARIA = !!options.fullARIA,
217
+ hideInput = !!options.hideInput,
218
+ clickJump = useTween ? false : !!options.clickJump,
219
+ vertical = !!options.vertical,
220
+ callbacks = options.callbacks,
221
+ classNames = options.classNames,
222
+ noMWheel = !!options.noMouseWheel,
223
+ timer = null,
224
+ kbEnabled = true,
225
+ sliderH = 0,
226
+ sliderW = 0,
227
+ tweenX = 0,
228
+ tweenB = 0,
229
+ tweenC = 0,
230
+ tweenD = 0,
231
+ frame = 0,
232
+ x = 0,
233
+ y = 0,
234
+ maxPx = 0,
235
+ handlePos = 0,
236
+ destPos = 0,
237
+ mousePos = 0,
238
+ deltaPx = 0,
239
+ stepPx = 0,
240
+ self = this,
241
+ changeList = {},
242
+ initVal = null,
243
+ outerWrapper,
244
+ wrapper,
245
+ handle,
246
+ bar;
247
+
248
+ if(max < min) {
249
+ inc = -inc;
250
+ maxInc = -maxInc;
251
+ };
252
+
253
+ function disableSlider(noCallback) {
254
+ if(disabled && !noCallback) { return; };
255
+
256
+ try {
257
+ removeEvent(outerWrapper, "mouseover", onMouseOver);
258
+ removeEvent(outerWrapper, "mouseout", onMouseOut);
259
+ removeEvent(outerWrapper, "mousedown", onMouseDown);
260
+ removeEvent(handle, "focus", onFocus);
261
+ removeEvent(handle, "blur", onBlur);
262
+ if(!window.opera) {
263
+ removeEvent(handle, "keydown", onKeyDown);
264
+ removeEvent(handle, "keypress", onKeyPress);
265
+ } else {
266
+ removeEvent(handle, "keypress", onKeyDown);
267
+ };
268
+ removeEvent(handle, "mousedown", onHandleMouseDown);
269
+ removeEvent(handle, "mouseup", onHandleMouseUp);
270
+
271
+ if(mouseWheelEnabled && !noMWheel) {
272
+ if (window.addEventListener && !window.devicePixelRatio) window.removeEventListener('DOMMouseScroll', trackMouseWheel, false);
273
+ else {
274
+ removeEvent(document, "mousewheel", trackMouseWheel);
275
+ removeEvent(window, "mousewheel", trackMouseWheel);
276
+ };
277
+ };
278
+ } catch(err) {};
279
+
280
+ clearTimeout(timer);
281
+ outerWrapper.className = outerWrapper.className.replace("slider-disabled", "") + " slider-disabled";
282
+ outerWrapper.setAttribute("aria-disabled", true);
283
+ inp.disabled = disabled = true;
284
+
285
+ if(!noCallback) {
286
+ callback("disable");
287
+ };
288
+ };
289
+
290
+ function enableSlider(noCallback) {
291
+ if(!disabled && !noCallback) return;
292
+ addEvent(outerWrapper, "mouseover", onMouseOver);
293
+ addEvent(outerWrapper, "mouseout", onMouseOut);
294
+ addEvent(outerWrapper, "mousedown", onMouseDown);
295
+ if(!window.opera) {
296
+ addEvent(handle, "keydown", onKeyDown);
297
+ addEvent(handle, "keypress", onKeyPress);
298
+ } else {
299
+ addEvent(handle, "keypress", onKeyDown);
300
+ };
301
+ addEvent(handle, "focus", onFocus);
302
+ addEvent(handle, "blur", onBlur);
303
+ addEvent(handle, "mousedown", onHandleMouseDown);
304
+ addEvent(handle, "mouseup", onHandleMouseUp);
305
+
306
+ outerWrapper.className = outerWrapper.className.replace("slider-disabled", "");
307
+ outerWrapper.setAttribute("aria-disabled", false);
308
+ inp.disabled = disabled = false;
309
+
310
+ if(!noCallback) {
311
+ callback("enable");
312
+ };
313
+ };
314
+
315
+ function destroySlider() {
316
+ try {
317
+ disableSlider();
318
+ outerWrapper.parentNode.removeChild(outerWrapper);
319
+ } catch(err) {};
320
+
321
+ wrapper = bar = handle = outerWrapper = timer = null;
322
+ callback("destroy");
323
+ callbacks = null;
324
+ };
325
+
326
+ function redraw() {
327
+ locate();
328
+ // Internet Explorer requires the try catch
329
+ try {
330
+ var sW = outerWrapper.offsetWidth,
331
+ sH = outerWrapper.offsetHeight,
332
+ hW = handle.offsetWidth,
333
+ hH = handle.offsetHeight,
334
+ bH = bar.offsetHeight,
335
+ bW = bar.offsetWidth;
336
+
337
+ maxPx = vertical ? sH - hH : sW - hW;
338
+ stepPx = maxPx / steps;
339
+ deltaPx = maxPx / Math.ceil(range / maxInc);
340
+
341
+
342
+ sliderW = sW;
343
+ sliderH = sH;
344
+
345
+ valueToPixels();
346
+ } catch(err) { };
347
+ callback("redraw");
348
+ };
349
+
350
+ function callback(type) {
351
+ var cbObj = {"elem":inp, "value":tagName == "select" ? inp.options[inp.selectedIndex].value : inp.value};
352
+ if(type in callbacks) {
353
+ for(var i = 0, func; func = callbacks[type][i]; i++) {
354
+ func(cbObj);
355
+ };
356
+ };
357
+ };
358
+
359
+ function onFocus(e) {
360
+ outerWrapper.className = outerWrapper.className.replace('focused','') + ' focused';
361
+ if(mouseWheelEnabled && !noMWheel) {
362
+ addEvent(window, 'DOMMouseScroll', trackMouseWheel);
363
+ addEvent(document, 'mousewheel', trackMouseWheel);
364
+ if(!window.opera) addEvent(window, 'mousewheel', trackMouseWheel);
365
+ };
366
+ callback("focus");
367
+ };
368
+
369
+ function onBlur(e) {
370
+ outerWrapper.className = outerWrapper.className.replace(/focused|fd-fc-slider-hover|fd-slider-hover/g,'');
371
+ if(mouseWheelEnabled && !noMWheel) {
372
+ removeEvent(document, 'mousewheel', trackMouseWheel);
373
+ removeEvent(window, 'DOMMouseScroll', trackMouseWheel);
374
+ if(!window.opera) removeEvent(window, 'mousewheel', trackMouseWheel);
375
+ };
376
+ callback("blur");
377
+ };
378
+
379
+ function trackMouseWheel(e) {
380
+ if(!kbEnabled) return;
381
+ e = e || window.event;
382
+ var delta = 0;
383
+
384
+ if (e.wheelDelta) {
385
+ delta = e.wheelDelta/120;
386
+ if (window.opera && window.opera.version() < 9.2) delta = -delta;
387
+ } else if(e.detail) {
388
+ delta = -e.detail/3;
389
+ };
390
+
391
+ if(vertical) { delta = -delta; };
392
+
393
+ if(delta) {
394
+ var xtmp = vertical ? handle.offsetTop : handle.offsetLeft;
395
+ xtmp = (delta < 0) ? Math.ceil(xtmp + deltaPx) : Math.floor(xtmp - deltaPx);
396
+ pixelsToValue(Math.min(Math.max(xtmp, 0), maxPx));
397
+ }
398
+ return stopEvent(e);
399
+ };
400
+
401
+ function onKeyPress(e) {
402
+ e = e || document.parentWindow.event;
403
+ if ((e.keyCode >= 33 && e.keyCode <= 40) || !kbEnabled || e.keyCode == 45 || e.keyCode == 46) {
404
+ return stopEvent(e);
405
+ };
406
+ return true;
407
+ };
408
+
409
+ function onKeyDown(e) {
410
+ if(!kbEnabled) return true;
411
+
412
+ e = e || document.parentWindow.event;
413
+ var kc = e.keyCode != null ? e.keyCode : e.charCode;
414
+
415
+ if ( kc < 33 || (kc > 40 && (kc != 45 && kc != 46))) return true;
416
+
417
+ var value = tagName == "input" ? parseFloat(inp.value) : inp.selectedIndex;
418
+ if(isNaN(value) || value < Math.min(min,max)) value = Math.min(min,max);
419
+
420
+ if( kc == 37 || kc == 40 || kc == 46 || kc == 34) {
421
+ // left, down, ins, page down
422
+ value -= (e.ctrlKey || kc == 34 ? maxInc : inc)
423
+ } else if( kc == 39 || kc == 38 || kc == 45 || kc == 33) {
424
+ // right, up, del, page up
425
+ value += (e.ctrlKey || kc == 33 ? maxInc : inc)
426
+ } else if( kc == 35 ) {
427
+ // max
428
+ value = max;
429
+ } else if( kc == 36 ) {
430
+ // min
431
+ value = min;
432
+ };
433
+
434
+ valueToPixels(value);
435
+ callback("update");
436
+
437
+ // Opera doesn't let us cancel key events so the up/down arrows and home/end buttons will scroll the screen - which sucks
438
+ return stopEvent(e);
439
+ };
440
+
441
+ function onMouseOver( e ) {
442
+ /*@cc_on@*/
443
+ /*@if(@_jscript_version <= 5.6)
444
+ if(this.className.search(/focused/) != -1) {
445
+ this.className = this.className.replace("fd-fc-slider-hover", "") +' fd-fc-slider-hover';
446
+ return;
447
+ }
448
+ /*@end@*/
449
+ this.className = this.className.replace(/fd\-slider\-hover/g,"") +' fd-slider-hover';
450
+ };
451
+
452
+ function onMouseOut( e ) {
453
+ /*@cc_on@*/
454
+ /*@if(@_jscript_version <= 5.6)
455
+ if(this.className.search(/focused/) != -1) {
456
+ this.className = this.className.replace("fd-fc-slider-hover", "");
457
+ return;
458
+ }
459
+ /*@end@*/
460
+ this.className = this.className.replace(/fd\-slider\-hover/g,"");
461
+ };
462
+
463
+ function onHandleMouseUp(e) {
464
+ e = e || window.event;
465
+ removeEvent(document, 'mousemove', trackMouse);
466
+ removeEvent(document, 'mouseup', onHandleMouseUp);
467
+
468
+ kbEnabled = true;
469
+
470
+ // Opera fires the blur event when the mouseup event occurs on a button, so we attept to force a focus
471
+ if(window.opera) try { setTimeout(function() { onfocus(); }, 0); } catch(err) {};
472
+ document.body.className = document.body.className.replace(/slider-drag-vertical|slider-drag-horizontal/g, "");
473
+
474
+ return stopEvent(e);
475
+ };
476
+
477
+ function onHandleMouseDown(e) {
478
+ e = e || window.event;
479
+ mousePos = vertical ? e.clientY : e.clientX;
480
+ handlePos = parseInt(vertical ? handle.offsetTop : handle.offsetLeft)||0;
481
+ kbEnabled = false;
482
+
483
+ clearTimeout(timer);
484
+ timer = null;
485
+
486
+ addEvent(document, 'mousemove', trackMouse);
487
+ addEvent(document, 'mouseup', onHandleMouseUp);
488
+
489
+ // Force a "focus" on the button on mouse events
490
+ if(window.devicePixelRatio || (document.all && !window.opera)) try { setTimeout(function() { handle.focus(); }, 0); } catch(err) {};
491
+
492
+ document.body.className += " slider-drag-" + (vertical ? "vertical" : "horizontal");
493
+ };
494
+
495
+ function onMouseUp( e ) {
496
+ e = e || window.event;
497
+ removeEvent(document, 'mouseup', onMouseUp);
498
+ if(!useTween) {
499
+ clearTimeout(timer);
500
+ timer = null;
501
+ kbEnabled = true;
502
+ };
503
+ return stopEvent(e);
504
+ };
505
+
506
+ function trackMouse( e ) {
507
+ e = e || window.event;
508
+ pixelsToValue(snapToNearestValue(handlePos + (vertical ? e.clientY - mousePos : e.clientX - mousePos)));
509
+ };
510
+
511
+ function onMouseDown( e ) {
512
+ e = e || window.event;
513
+ var targ;
514
+ if (e.target) targ = e.target;
515
+ else if (e.srcElement) targ = e.srcElement;
516
+ if (targ.nodeType == 3) targ = targ.parentNode;
517
+
518
+ if(targ.className.search("fd-slider-handle") != -1) { return true; };
519
+
520
+ try { setTimeout(function() { handle.focus(); }, 0); } catch(err) { };
521
+
522
+ clearTimeout(timer);
523
+ locate();
524
+
525
+ timer = null;
526
+ kbEnabled = false;
527
+
528
+ var posx = 0,
529
+ sLft = 0,
530
+ sTop = 0;
531
+
532
+ // Internet Explorer doctype woes
533
+ if (document.documentElement && document.documentElement.scrollTop) {
534
+ sTop = document.documentElement.scrollTop;
535
+ sLft = document.documentElement.scrollLeft;
536
+ } else if (document.body) {
537
+ sTop = document.body.scrollTop;
538
+ sLft = document.body.scrollLeft;
539
+ };
540
+
541
+ if (e.pageX) posx = vertical ? e.pageY : e.pageX;
542
+ else if (e.clientX) posx = vertical ? e.clientY + sTop : e.clientX + sLft;
543
+ posx -= vertical ? y + Math.round(handle.offsetHeight / 2) : x + Math.round(handle.offsetWidth / 2);
544
+ posx = snapToNearestValue(posx);
545
+
546
+ if(useTween) {
547
+ tweenTo(posx);
548
+ } else if(clickJump) {
549
+ pixelsToValue(posx);
550
+ } else {
551
+ addEvent(document, 'mouseup', onMouseUp);
552
+ destPos = posx;
553
+ onTimer();
554
+ };
555
+ };
556
+
557
+ function incrementHandle(numOfSteps) {
558
+ var value = tagName == "input" ? parseFloat(inp.value) : inp.selectedIndex;
559
+ if(isNaN(value) || value < Math.min(min,max)) value = Math.min(min,max);
560
+ value += inc * numOfSteps;
561
+ valueToPixels(value);
562
+ };
563
+
564
+ function snapToNearestValue(px) {
565
+ var rem = px % stepPx;
566
+ if(rem && rem >= (stepPx / 2)) { px += (stepPx - rem); }
567
+ else { px -= rem; };
568
+ return Math.min(Math.max(parseInt(px, 10), 0), maxPx);
569
+ };
570
+
571
+ function locate(){
572
+ var curleft = 0,
573
+ curtop = 0,
574
+ obj = outerWrapper;
575
+
576
+ // Try catch for IE's benefit
577
+ try {
578
+ while (obj.offsetParent) {
579
+ curleft += obj.offsetLeft;
580
+ curtop += obj.offsetTop;
581
+ obj = obj.offsetParent;
582
+ };
583
+ } catch(err) {};
584
+ x = curleft;
585
+ y = curtop;
586
+ };
587
+
588
+ function onTimer() {
589
+ var xtmp = vertical ? handle.offsetTop : handle.offsetLeft;
590
+ xtmp = Math.round((destPos < xtmp) ? Math.max(destPos, Math.floor(xtmp - deltaPx)) : Math.min(destPos, Math.ceil(xtmp + deltaPx)));
591
+ pixelsToValue(xtmp);
592
+ if(xtmp != destPos) timer = setTimeout(onTimer, steps > 20 ? 50 : 100);
593
+ else kbEnabled = true;
594
+ };
595
+
596
+ var tween = function(){
597
+ frame++;
598
+ var c = tweenC,
599
+ d = 20,
600
+ t = frame,
601
+ b = tweenB,
602
+ x = Math.ceil((t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b);
603
+
604
+ pixelsToValue(t == d ? tweenX : x);
605
+ callback("move");
606
+ if(t!=d) timer = setTimeout(tween, 20);
607
+ else {
608
+ clearTimeout(timer);
609
+ timer = null;
610
+ kbEnabled = true;
611
+ };
612
+ };
613
+
614
+ function tweenTo(tx){
615
+ kbEnabled = false;
616
+ tweenX = parseInt(tx, 10);
617
+ tweenB = parseInt(vertical ? handle.style.top : handle.style.left, 10);
618
+ tweenC = tweenX - tweenB;
619
+ tweenD = 20;
620
+ frame = 0;
621
+ if(!timer) timer = setTimeout(tween, 20);
622
+ };
623
+
624
+ function pixelsToValue(px) {
625
+ //jslog.debug(DebugHelpers.getStackTrace())
626
+ handle.style[vertical ? "top" : "left"] = px + "px";
627
+ var val = min + (Math.round(px / stepPx) * inc);
628
+ setInputValue((tagName == "select" || inc == 1) ? Math.round(val) : val);
629
+ };
630
+
631
+ function valueToPixels(val) {
632
+ var value = isNaN(val) ? tagName == "input" ? parseFloat(inp.value) : inp.selectedIndex : val;
633
+ if(isNaN(value) || value < Math.min(min,max)) value = Math.min(min,max);
634
+ else if(value > Math.max(min,max)) value = Math.max(min,max);
635
+ setInputValue(value);
636
+ handle.style[vertical ? "top" : "left"] = Math.round(((value - min) / inc) * stepPx) + "px";
637
+ };
638
+
639
+ function setInputValue(val) {
640
+ val = isNaN(val) ? min : val;
641
+ if(tagName == "select") {
642
+ try {
643
+ val = parseInt(val, 10);
644
+ if(inp.selectedIndex == val) return;
645
+ inp.options[val].selected = true;
646
+ } catch (err) {};
647
+ } else {
648
+ val = (min + (Math.round((val - min) / inc) * inc)).toFixed(precision);
649
+ if(inp.value == val) return;
650
+ inp.value = val;
651
+ };
652
+ updateAriaValues();
653
+ callback("update");
654
+ };
655
+
656
+ function findLabel() {
657
+ var label;
658
+ if(inp.parentNode && inp.parentNode.tagName.toLowerCase() == "label") label = inp.parentNode;
659
+ else {
660
+ var labelList = document.getElementsByTagName('label');
661
+ // loop through label array attempting to match each 'for' attribute to the id of the current element
662
+ for(var i = 0, lbl; lbl = labelList[i]; i++) {
663
+ // Internet Explorer requires the htmlFor test
664
+ if((lbl['htmlFor'] && lbl['htmlFor'] == inp.id) || (lbl.getAttribute('for') == inp.id)) {
665
+ label = lbl;
666
+ break;
667
+ };
668
+ };
669
+ };
670
+ if(label && !label.id) { label.id = inp.id + "_label"; };
671
+ return label;
672
+ };
673
+
674
+ function updateAriaValues() {
675
+ handle.setAttribute("aria-valuenow", tagName == "select" ? inp.options[inp.selectedIndex].value : inp.value);
676
+ handle.setAttribute("aria-valuetext", tagName == "select" ? inp.options[inp.selectedIndex].text : inp.value);
677
+ };
678
+
679
+ function onChange( e ) {
680
+ valueToPixels();
681
+ callback("update");
682
+ return true;
683
+ };
684
+
685
+ (function() {
686
+ if(hideInput) { inp.className += " fd_hide_slider_input"; }
687
+ else { addEvent(inp, 'change', onChange); };
688
+
689
+ outerWrapper = document.createElement('div');
690
+ outerWrapper.className = "fd-slider" + (vertical ? "-vertical " : " ") + classNames;
691
+ outerWrapper.id = "fd-slider-" + inp.id;
692
+
693
+ wrapper = document.createElement('span');
694
+ wrapper.className = "fd-slider-inner";
695
+
696
+ bar = document.createElement('span');
697
+ bar.className = "fd-slider-bar";
698
+
699
+ if(fullARIA) {
700
+ handle = document.createElement('span');
701
+ handle.setAttribute(!/*@cc_on!@*/false ? "tabIndex" : "tabindex", "0");
702
+ } else {
703
+ handle = document.createElement('button');
704
+ handle.setAttribute("type", "button");
705
+ };
706
+
707
+ handle.className = "fd-slider-handle";
708
+ handle.appendChild(document.createTextNode(String.fromCharCode(160)));
709
+
710
+ outerWrapper.appendChild(wrapper);
711
+ outerWrapper.appendChild(bar);
712
+ outerWrapper.appendChild(handle);
713
+
714
+ inp.parentNode.insertBefore(outerWrapper, inp);
715
+
716
+ /*@cc_on@*/
717
+ /*@if(@_win32)
718
+ handle.unselectable = "on";
719
+ bar.unselectable = "on";
720
+ wrapper.unselectable = "on";
721
+ outerWrapper.unselectable = "on";
722
+ /*@end@*/
723
+
724
+ // Add ARIA accessibility info programmatically
725
+ handle.setAttribute("role", "slider");
726
+ handle.setAttribute("aria-valuemin", min);
727
+ handle.setAttribute("aria-valuemax", max);
728
+
729
+ var lbl = findLabel();
730
+ if(lbl) {
731
+ handle.setAttribute("aria-labelledby", lbl.id);
732
+ handle.id = "fd-slider-handle-" + inp.id;
733
+ /*@cc_on
734
+ /*@if(@_win32)
735
+ lbl.setAttribute("htmlFor", handle.id);
736
+ @else @*/
737
+ lbl.setAttribute("for", handle.id);
738
+ /*@end
739
+ @*/
740
+ };
741
+
742
+ // Are there page instructions - the creation of the instructions has been left up to you fine reader...
743
+ if(document.getElementById("fd_slider_describedby")) {
744
+ handle.setAttribute("aria-describedby", "fd_slider_describedby"); // aaa:describedby
745
+ };
746
+
747
+ if(inp.getAttribute("disabled") == true) {
748
+ disableSlider(true);
749
+ } else {
750
+ enableSlider(true);
751
+ };
752
+
753
+ updateAriaValues();
754
+ callback("create");
755
+ redraw();
756
+ })();
757
+
758
+ return {
759
+ onResize: function(e) { if(outerWrapper.offsetHeight != sliderH || outerWrapper.offsetWidth != sliderW) { redraw(); }; },
760
+ destroy: function() { destroySlider(); },
761
+ reset: function() { valueToPixels(); },
762
+ increment: function(n) { incrementHandle(n); },
763
+ disable: function() { disableSlider(); },
764
+ enable: function() { enableSlider(); }
765
+ };
766
+ };
767
+
768
+ addEvent(window, "load", init);
769
+ addEvent(window, "unload", unload);
770
+ addEvent(window, "resize", resize);
771
+ /*@cc_on@*/
772
+ /*@if(@_win32)
773
+ var onload = function(e) {
774
+ for(slider in sliders) { sliders[slider].reset(); }
775
+ };
776
+ addEvent(window, "load", function() { setTimeout(onload, 200) });
777
+ /*@end@*/
778
+
779
+ return {
780
+ create: function(elem) { init(elem) },
781
+ createSlider: function(opts) { createSlider(opts); },
782
+ destroyAll: function() { destroyAllsliders(); },
783
+ destroySlider: function(id) { return destroySingleSlider(id); },
784
+ redrawAll: function() { resize(); },
785
+ increment: function(id, numSteps) { if(!(id in sliders)) { return false; }; sliders[id].increment(numSteps); },
786
+ addEvent: addEvent,
787
+ removeEvent: removeEvent,
788
+ stopEvent: stopEvent,
789
+ updateSlider: function(id) { if(!(id in sliders)) { return false; }; sliders[id].reset(); },
790
+ disableMouseWheel: function() { removeMouseWheelSupport(); },
791
+ removeOnLoadEvent: function() { removeOnloadEvent(); },
792
+ disableSlider: function(id) { if(!(id in sliders)) { return false; }; sliders[id].disable(); },
793
+ enableSlider: function(id) { if(!(id in sliders)) { return false; }; sliders[id].enable(); }
794
+ }
795
+ })();
796
+
797
+