-
Notifications
You must be signed in to change notification settings - Fork 64
/
html5Widgets.js
1417 lines (1091 loc) · 37.9 KB
/
html5Widgets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* This notice must be untouched at all times.
*
* This javascript library contains helper routines to assist with event
* handling consinstently among browsers
*
* html5Widgets.js v.1.1 by Zoltan Hawryluk
* latest version and documentation available at http://www.useragentman.com/
*
* Changelog:
* version 1.0: initial release
* version 1.1: implemented oninput method for form elements for unsupported browsers
* fix IE9 to ensure backspace and delete keys fire an oninput event.
* version 1.2: Added Number Element Widget
*
* released under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*
*******************************************************************************/
var html5Widgets = new function(){
var me = this;
var delayEventTimeout = null;
me.inputNodes = new Array();
me.outputNodes = new Array();
me.formElements = null;
me.placeholderNodes = new Array();
me.dummyLink = document.createElement('input');
var quoteRe = /\"/g;
var dummyIDCount = 0;
var supportsNatively = new Object();
var isBadChrome = navigator.userAgent.indexOf('Chrome');
var valueRe = /this\.value/g;
var varRe = /([a-zA-Z][a-zA-Z0-9]*\.value)/g;
var isDebug;
var isIE9 = false;
/*@cc_on
@if (@_jscript_version == 9)
isIE9 = true;
@end
@*/
me.init = function(){
if (EventHelpers.hasPageLoadHappened(arguments)) {
return;
}
supportsNatively['oninput'] = EventHelpers.isSupported('input', 'form');
isDebug = CSSHelpers.isMemberOfClass(document.body, 'html5Widgets-debug')
// dummy link setup
me.type = 'text'
me.dummyLink.style.position = 'absolute';
me.dummyLink.style.top = '-200px';
document.body.appendChild(me.dummyLink)
var inputSupport = Modernizr.input
if (!inputSupport['placeholder']) {
setPlaceholders();
}
indexOutputNodes();
insertElements();
me.resolveOutputs();
/* document.getElementById('supports').innerHTML =
DebugHelpers.getProperties(Modernizr.inputtypes, 'inputtypes') + " " +
DebugHelpers.getProperties(Modernizr.input, 'input') + " " +
DebugHelpers.getProperties(Modernizr, 'Modernizr'); */
}
function supports_input_placeholder() {
var i = document.createElement('input');
return 'placeholder' in i;
}
function setPlaceholders() {
var nodes = [document.getElementsByTagName('input'), document.getElementsByTagName('textarea')];
for (var i=0; i<nodes.length; i++) {
for (var j=0; j<nodes[i].length; j++) {
var node = nodes[i][j];
if (DOMHelpers.getAttributeValue(node, 'placeholder')) {
me.placeholderNodes.push(new PlaceholderInput(node));
}
}
}
}
function getNextDummyID () {
dummyIDCount ++;
return "id" + dummyIDCount;
}
function indexOutputNodes () {
var outputElements = document.getElementsByTagName('output');
for (var i=0; i<outputElements.length; i++) {
var outputEl = outputElements[i];
if (outputEl.value != undefined && outputEl.onforminput != undefined) {
// this browser supports the output tag .. bail
supportsNatively["output"] = true;
break;
}
me.outputNodes.push(new OutputElement(outputEl))
}
me.formElements = document.getElementsByTagName('form');
}
function setOutputEvents(nodeName) {
var formElements = document.getElementsByTagName(nodeName);
for (var i=0; i<formElements.length; i++) {
var formElement = formElements[i];
// first - set event to resolve output tags
EventHelpers.addEvent(formElement, 'change', me.resolveOutputs);
EventHelpers.addEvent(formElement, 'keyup', me.resolveOutputs);
EventHelpers.addEvent(formElement, 'cut', me.resolveOutputs);
}
}
function insertElements(){
var inputSupport = Modernizr.inputtypes;
// Remove the onload event as we are creating the sliders with a JS call
if (window.fdSliderController) {
fdSliderController.removeOnLoadEvent();
}
var formElementTypes = ["input", "select", "textarea"];
for (var i=0; i<formElementTypes.length; i++) {
setOutputEvents(formElementTypes[i]);
}
var formElements = document.getElementsByTagName('input');
// leave if this browser supports the range type.
if (formElements.length <= 0) {
return;
}
for (var i = 0; i < formElements.length; i++) {
var formElement = formElements[i];
//var elType = getAttributeValue(formElement, 'type');
var elType = DOMHelpers.getAttributeValue(formElement, 'type');
//jslog.debug(elType)
if (!formElement.name) {
formElement.name = getNextDummyID();
}
switch (elType) {
case "range":
if (!inputSupport.range) {
me.inputNodes.push(new RangeElement(formElement));
}
break;
case "date":
case "week":
case "month":
case "datetime":
case "datetime-local":
// check to see if the browser supports the type.
if (!inputSupport[elType] || (window.html5Forms && html5Forms.forceJSDatePicker)) {
me.inputNodes.push(new CalendarElement(formElement, elType));
}
break;
case "color":
if (!inputSupport.color || isBadChrome) {
me.inputNodes.push(new ColorElement(formElement, elType));
}
break;
case "number":
if (!inputSupport.number) {
me.inputNodes.push(new NumberElement(formElement, elType));
}
break;
}
}
if (window.fdSliderController) {
fdSliderController.redrawAll();
}
if (window.jscolor) {
jscolor.init();
}
}
function delayedFireEvent(el, ev, callback){
if (!document.createEventObject ) {
me.fireEvent(el, ev);
if (callback) {
callback();
}
}
else {
if (delayEventTimeout != null) {
clearTimeout(delayEventTimeout)
}
delayEventTimeout = setTimeout(
function(){
EventHelpers.fireEvent(el, ev);
if (callback) {
callback();
}
}
, 1);
}
}
me.fireEvent = function(el, ev){
EventHelpers.fireEvent(el, ev);
}
me.resolveOutputs = function (e) {
// This resolves the onforminput events on the output nodes
for (var i=0; i<me.outputNodes.length; i++) {
var outputNode = me.outputNodes[i];
outputNode.resolve();
}
// This resolves the oninput events on the form nodes
if (!supportsNatively['oninput']) {
for (var i=0; i<me.formElements.length; i++) {
var formNode = me.formElements[i];
var oninput = DOMHelpers.getAttributeValue(formNode, 'oninput');
if (oninput) {
eval(me.getValueFormula(oninput, formNode));
}
}
} else if (isIE9 && e) {
// must deal with buggy implementation - delete and backspace don't fire
// the oninput event
var input = EventHelpers.getEventTarget(e);
switch (e.type) {
case "keyup":
var key = EventHelpers.getKey(e);
switch (key) {
case 8:
case 46:
case 88:
EventHelpers.fireEvent(input.form, 'input');
}
break;
case "cut":
delayedFireEvent(input.form, 'input');
break;
}
}
}
me.hideInput = function (node) {
node.style.position = 'absolute';
node.style.top = '-1000px';
node.style.left = '-1000px';
node.style.visibility = 'hidden'
}
me.getValueFormula = function(expr, parentForm) {
var formula = expr
if (formula == null) {
return null;
}
formula = formula
.replace(valueRe, 'value')
.replace(varRe, 'document.forms["' + parentForm.id + '"].$1');
return formula;
}
function showError(err) {
if (isDebug) {
alert(err);
}
throw(err);
}
/*
* Range Element
*/
function RangeElement(node){
var me = this,
parentForm,
hasFiredChangeEvent = false;
me.node = node;
me.sliderNode = null;
function init (){
parentForm = DOMHelpers.getAncestorByTagName(node, 'form');
var min = parseFloat(DOMHelpers.getAttributeValue(me.node, 'min'));
var max = parseFloat(DOMHelpers.getAttributeValue(me.node, 'max'));
if (!window.fdSliderController) {
showError("slider.js must be included in order for the range element to work in this browser. See documentation for more details.");
}
if (isNaN(min)) {
min = 0;
}
if (isNaN(max)) {
max = 100;
}
var step = DOMHelpers.getAttributeValue(me.node, 'step');
if (step == null) {
step = "1"
} else if (typeof(step) == 'number') {
step = step + "";
}
// Must add id if not there (Requirement of the script)
if (!me.node.id) {
me.node.id = "HTML5Form-slider" + getNextDummyID();
}
// Create an Object to hold the slider's initialisation data
var options = {
// A reference to the input
inp: me.node,
// A String containing the increment value (and the return precision, in this case 2 decimal places "x.20")
inc: step,
// Maximum keyboard increment (automatically uses double the normal increment if not given)
maxInc: step,
// Numeric range
range: [min, max],
// Callback functions
callbacks: {
"update": [me.changeEvent]
},
// String representing the classNames to give the created slider
classNames: "html5Widgets-slider fd_jump",
// Tween the handle onclick?
tween: false,
// Is this a vertical slider
vertical: false,
// Do we hide the associated input on slider creation
hideInput: false,
// Does the handle jump to the nearest click value point when the bar is clicked (tween cannot then be true)
clickJump: true,
// Full ARIA required
fullARIA: false,
// Do we disable the mouseWheel for this slider
noMouseWheel: false
};
// Create the slider
fdSliderController.createSlider(options);
//tweak styles
me.sliderNode = document.getElementById('fd-slider-' + me.node.id);
me.sliderNode.style.width = me.node.offsetWidth + "px";
elDisplay = me.node.style.display
if (elDisplay != 'block') {
me.sliderNode.style.display = 'inline-block';
//me.sliderNode.style.paddingTop = "0.9em";
}
html5Widgets.hideInput(me.node);
document.getElementById('fd-slider-' + me.node.id).style.zIndex = '0';
me.node.tabIndex = "-1";
me.node.type = "text";
// Event Handling
EventHelpers.addEvent(me.node, 'change', changeOriginalNodeEvent);
}
me.changeEvent = function (e){
var oninput = DOMHelpers.getAttributeValue(parentForm, 'oninput');
if (oninput) {
eval(html5Widgets.getValueFormula(oninput, parentForm));
}
/* The if statement is to prevent this to continuously fire in an endless loop */
if (!hasFiredChangeEvent) {
hasFiredChangeEvent = true;
delayedFireEvent(me.node, 'change', function () {
hasFiredChangeEvent = false;
});
}
}
function changeOriginalNodeEvent(e) {
fdSliderController.updateSlider(me.node.id);
}
init();
}
function CalendarElement (node, type) {
var me = this;
me.node = node;
me.type = type;
var badDateTimeValueRe =
/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}Z{0,1}$/;
var displayDateTimeValueRe =
/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$/;
var originalVisibilityState;
function init() {
if (!window.Calendar && isDebug) {
showError("jscalendar scripts and CSS must be included for date and time form elements to work. See documentation for more details. ")
}
// Must add id if not there (Requirement of the script)
if (!me.node.id) {
me.node.id = "HTML5Form-calendar" + getNextDummyID();
}
/*
* If this is the result of coming back to the page from history,
* then it may have an old reformatted version in it from a previous
* submit. Let's re-format it back.
*/
prepareForDisplay();
var formatString = "";
switch (me.type) {
case 'date':
formatString = "%Y-%m-%d";
break;
case 'month':
formatString = "%Y-%m";
break;
case 'week':
formatString = "%Y-W%W";
break;
case 'datetime':
placeUTCInfo();
case 'datetime-local':
case 'datetime':
formatString = "%Y-%m-%d %H:%M"
break;
}
/*
* Chrome, unfortunately, only implements type="date", and it's
* implementation displays the data in DD/MM/YYYY format. Even
* though it submits the data in YYYY-MM-DD format, this can
* be confusing to users if there is a, say, datetime widget
* with a date widget and they show different formats. In order
* to fix this, I change the type to "text" so that it uses the
* polyfill instead of the native one. Note that type="date"
* widgets in Chrome are only changed to type="text" when
* html5Forms.js's script tag has its
* data-webforms2-force-js-date-picker attribute set to "true".
*/
me.node.type = 'text';
//me.node.readOnly = true;
Calendar.setup(
{
eventName :"click",
showsTime : type.indexOf('time') >= 0,
cache : true,
inputField : me.node.id, // ID of the input field
ifFormat : formatString, // the date format
button : me.node.id // ID of the button
}
);
EventHelpers.addEvent(me.node, 'click', forceCalToTop);
EventHelpers.addEvent(me.node, 'focus', focusEvent)
EventHelpers.addEvent(me.node, 'keypress', openCalendar);
EventHelpers.addEvent(me.node, 'blur', closeCalendar);
EventHelpers.addEvent(me.node, 'keypress', keydownEvent)
//me.node.type = "text";
// this will call submitEvent() after the form has been validated by
// webforms2.js
if (window.$wf2) {
$wf2.callBeforeValidation.push(prepareForSubmission);
$wf2.callAfterValidation.push(validationEvent);
}
}
function placeUTCInfo() {
var label = document.createElement('span');
label.innerHTML = "UTC";
label.style.paddingLeft = "5px";
DOMHelpers.insertAfter(me.node, label);
var width = label.offsetWidth;
me.node.style.width = (me.node.offsetWidth - 5 - width) + 'px';
}
function prepareForSubmission() {
var splitVals;
switch (me.type) {
case "datetime":
case "datetime-local":
originalVisibilityState = me.node.style.visibility;
me.node.style.visibility = 'hidden';
if (me.node.value.match(displayDateTimeValueRe)) {
splitVals = me.node.value.split(' ');
me.node.value = splitVals[0] + "T" + splitVals[1];
}
switch (me.type) {
case "datetime-local":
break;
case "datetime":
if (me.node.value != "") {
me.node.value += "Z";
}
}
}
}
function prepareForDisplay() {
switch(me.type) {
case "datetime":
case "datetime-local":
if ( me.node.value.match(badDateTimeValueRe)) {
me.node.value = me.node.value.replace(/T/, ' ').replace(/Z/, '');
}
if (originalVisibilityState != null) {
me.node.style.visibility = originalVisibilityState;
}
}
}
function validationEvent(e, hasValidated) {
if (!hasValidated) {
prepareForDisplay();
}
}
function forceCalToTop(e) {
var cal = window.calendar;
cal.element.style.zIndex = 100;
}
function focusEvent(e) {
var el = EventHelpers.getEventTarget(e);
EventHelpers.fireEvent(el, 'click')
}
function openCalendar(e) {
var cal = window.calendar;
cal.element.style.zIndex = 100;
if (cal.open != undefined) {
cal.open();
}
//EventHelpers.fireEvent(this, 'blur');
//EventHelpers.fireEvent(this, 'focus');
}
function closeCalendar(e){
var cal = window.calendar;
if (cal) {
cal.hide();
}
}
function keydownEvent(e) {
var c = EventHelpers.getKey(e);
switch(c){
case 13:
html5Widgets.dummyLink.focus();
this.focus();
EventHelpers.preventDefault(e);
openCalendar(e);
break;
case 9:
closeCalendar(e);
break;
default:
EventHelpers.preventDefault(e);
break;
}
}
function submitEvent(e) {
prepareForSubmission();
}
init();
}
/*
* Output Element
*/
function OutputElement (node) {
var me = this;
me.node = node;
var value;
var valueFormula;
var parentForm;
function init () {
parentForm = DOMHelpers.getAncestorByTagName(node, 'form');
if (!parentForm.id) {
parentForm.id = getNextDummyID();
}
valueFormula = html5Widgets.getValueFormula(DOMHelpers.getAttributeValue(me.node, 'onforminput'), parentForm);
}
me.resolve = function () {
if (valueFormula == null) {
return;
} else {
eval(valueFormula);
me.node.innerHTML = value;
me.node.value = value;
}
}
init();
}
function ColorElement (node) {
var me = this;
/* note: color picker setPad() is what you are looking for */
me.node = node;
function init () {
if (!window.jscolor) {
showError('jscolor script must be included in order for the color input type to work in this browser. See documentation for more details.')
}
CSSHelpers.addClass(me.node, 'color');
CSSHelpers.addClass(me.node, '{hash:true,caps:false}');
me.node.type = "text";
}
init();
}
/*
* NumberElement: refactored from http://www.kethinov.com/jsstepper.php.
*/
function NumberElement (node) {
var me = this,
min = parseFloat(DOMHelpers.getAttributeValue(node, 'min')),
max = parseFloat(DOMHelpers.getAttributeValue(node, 'max')),
step = parseFloat(DOMHelpers.getAttributeValue(node, 'step'));
me.node = node;
if (isNaN(step)) {
// we don't have to create the up and down arraw widgets
return;
}
EventHelpers.addEvent(node, 'keyup', keyUpEvent);
function keyUpEvent() {
if (isNumeric(this.value)) {
/* if (this.value > max) this.value = max;
else if (this.value < min) this.value = this.min; */
} else if (this.value != '') {
var val = parseFloat(this.value);
if (isNaN(val)) {
this.value = '';
} else {
this.value = val;
}
}
}
function nearestValid(value, direction) {
var n = (value - min)/step,
r;
//alert(StringHelpers.sprintf("n: %s, value: %s, min: %s, step: %s", n, value, min, step))
if (n == parseInt(n)) {
r = value;
} else {
if (direction < 0) {
n = Math.floor(n + 1);
} else {
n = Math.ceil(n -1);
}
r = min + step * n;
}
if (r > max) {
r -= step;
} else if (r < min) {
r+= step
}
return r;
}
function buttonMouseDownEvent(e) {
var buttonType = this.className;
var stepMult = step;
if (buttonType == 'dnbutton') {
stepMult = -step;
}
var min = this.min;
var max = this.max;
if (
(stepMult < 0 && (node.value > min || isNaN(min))) ||
(stepMult > 0 && (node.value < max || isNaN(max)))
) {
setValue(me.node, nearestValid(parseFloat(node.value) + stepMult, stepMult));
}
var delayedOnce = false;
var date = new Date();
var curDate = null;
this.interval = setInterval(function() {
if (!delayedOnce) {
curDate = new Date();
if (curDate - date > 500) delayedOnce = true;
}
else if (
(stepMult < 0 && (node.value > min || isNaN(min))) ||
(stepMult > 0 && (node.value < max || isNaN(max)))
) {
setValue(me.node, nearestValid(parseFloat(node.value) + stepMult, stepMult));
}
}, 50);
EventHelpers.preventDefault(e);
}
function setValue(node, value) {
if (isNaN(value)) {
node.value = '';
} else {
node.value = value;
}
}
function buttonClickEvent(e) {
clearInterval(this.interval);
EventHelpers.preventDefault(e);
}
function buttonMouseUpEvent(e) {
clearInterval(this.interval);
EventHelpers.preventDefault(e);
}
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
function hasNativeSpinner() {
try {
return window.getComputedStyle(me.node, '-webkit-inner-spin-button').WebkitAppearance != undefined;
} catch (ex) {
return false;
}
}
function init () {
var upbutton = document.createElement('a');
upbutton.className = 'upbutton';
upbutton.appendChild(document.createTextNode("\u25B2"));
upbutton.targInput = node;
upbutton.max = max;
var dnbutton = document.createElement('a');
dnbutton.className = 'dnbutton';
dnbutton.appendChild(document.createTextNode("\u25BC"));
dnbutton.targInput = node;
dnbutton.min = min;
dnbutton.max = max;
EventHelpers.addEvent(upbutton, 'mousedown', buttonMouseDownEvent);
EventHelpers.addEvent(dnbutton, 'mousedown', buttonMouseDownEvent);
EventHelpers.addEvent(upbutton, 'click', buttonClickEvent);
EventHelpers.addEvent(upbutton, 'mouseup', buttonMouseUpEvent);
EventHelpers.addEvent(dnbutton, 'click', buttonClickEvent);
EventHelpers.addEvent(dnbutton, 'mouseup', buttonMouseUpEvent);
if (!hasNativeSpinner()) {
var controlsNode = document.createElement('div');
controlsNode.className = 'html5-numberControls';
controlsNode.appendChild(upbutton);
controlsNode.appendChild(dnbutton);
var wrapperNode = document.createElement('div')
wrapperNode.className = 'html5-numberWrapper';
wrapperNode.appendChild(controlsNode);
var parentNode = node.parentNode;
parentNode.insertBefore(wrapperNode, node);
var nodeWidth = node.offsetWidth;
var nodeStyle = CSSHelpers.getCurrentStyle(node);
node.style.width = (nodeWidth - upbutton.offsetWidth -9) + 'px';
wrapperNode.style.width = nodeWidth + 'px';
wrapperNode.style.marginTop = nodeStyle.marginTop;
wrapperNode.style.height = (node.offsetHeight) + 'px';
}
}
/* Finally: if the form field has a value onload that is not a number, remove it
if (!isNumeric(node.value)) {
node.value = '';
EventHelpers.fireEvent(node, 'change');
}*/
init();
}
function PlaceholderInput (node) {
var me = this;
me.node = node;
var form, defaultText;
function init () {
defaultText = DOMHelpers.getAttributeValue(node, 'placeholder');
form = DOMHelpers.getAncestorByTagName(node, 'form');
me.setPlaceholderText(true);
EventHelpers.addEvent(me.node, 'blur', blurEvent);
EventHelpers.addEvent(me.node, 'focus', focusEvent);
if (me.node.form) {
EventHelpers.addEvent(me.node.form, 'submit', removePlaceholderText);
}
if (window.$wf2) {
if ($wf2.callBeforeValidation != undefined) {
$wf2.callBeforeValidation.push(removePlaceholderText);
}
if ($wf2.callAfterValidation != undefined) {
$wf2.callAfterValidation.push(postValidationEvent);
}
}
}
me.setPlaceholderText = function (isLoadEvent) {
//jslog.debug(StringHelpers.sprintf('initiator: %s', this));
var isAutofocus = DOMHelpers.getAttributeValue(me.node, 'autofocus') != null;
if (me.node.value == "" || (isLoadEvent && me.node.value == defaultText)) {
CSSHelpers.addClass(me.node, 'html5-hasPlaceholderText');
me.node.value = defaultText;
}
if (isLoadEvent && isAutofocus && me.node.value == defaultText ) {
CSSHelpers.removeClass(me.node, 'html5-hasPlaceholderText');
me.node.value = '';
}
}
function focusEvent(e) {
CSSHelpers.addClass(me.node, 'html5-hasFocus');
removePlaceholderText();
}