-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmartInputField.js
1334 lines (1128 loc) · 38.8 KB
/
smartInputField.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
/*
# smartInputField
by Efraim Meulenberg
[HOSTED EXAMPLE](http://tornadotwins.com/github/smartInputField)
Requires jQuery
'Slider' requires rangeslider by André Ruffert (http://rangeslider.js.org/)
'ColorPicker' requires Iris (http://automattic.github.io/Iris/)
The inputField class creates interactive fields that are useful for realtime editing of css properties
or any other toolbar use.
Currently an inputField can be a 'size' element (a number input that can differentiate between pixels and percentage),
and a dropdown element. To create a new 'size' input field:
var sizer = new inputField(
{
'container': '#thingyHere', //jquery reference or jquery search string for the container
'id': 'editWidth', //id-name to use (optional)
'disabled': true, //start the field off disabled or not (optional)
'onoff': true, //add ability to turn the field on or off (optional)
'value': '85%', //default value (in pixels "90px" or percent "90%") (optional)
'type': 'size', //type of input field ('size', 'slider' or 'dropdown')
'placeholder': "Width", //placeholder name (in case no value is specified) (optional)
'callback': function (value) //callback function that's called on-change and on enable/disable
{
console.log('Size callback says:');
console.log(value);
}
});
To create a dropdown menu, use the following:
var dropdown = new inputField(
{
'container': '#droppyHere', //jquery reference or jquery search string for the container
'id': 'editAlignment', //id-name to use (optional)
'disabled': false, //start the field off disabled or not (optional)
'type': 'dropdown', //type of input field ('size', 'slider' or 'dropdown')
'onoff': true, //add ability to turn the field on or off (optional)
'options': //The <options> (value, label) to add to the dropdown
{
'left': "Left",
'right': "Right",
'center': "Center" //callback function that's called on-change and on enable/disable
},
'callback': function (value)
{
console.log('dropdown callback says:');
console.log(value);
}
});
To create a range-slider, use the following:
var slider = new inputField(
{
type: 'slider', //type of input field ('size', 'slider' or 'dropdown')
container: '#holder',
id: 'editRoundCorners',
disabled: false,
onoff: true,
min: 0, //minimum value of the range slider
max: 50, //maximum value of the range slider
value: 5, //start value of the range slider
callback: function(value)
{
switch(value)
{
console.log('RangeSlider callback says:');
console.log(value);
}
}
});
To create a color picker, use the following:
var clrPickr = new inputField(
{
type: 'color',
container: '#clrPickr',
id: 'colorPickerId',
disabled: false,
onoff: true,
value: '#f7ad0c',
callback: function(value)
{
console.log('ColorPicker callback says:');
console.log(value);
}
});
The following methods can be use to influence the inputField at realtime:
inputField.getValue() //return the value of the input field
inputField.disable() //disable the input field
inputField.enable() //enable the input field
inputField.setValue(v, force) //set the value of the field to v, force(optional) is a bool to let the callback function know or not
inputField.setErrorMessage(html) //create an error message underneath the field
TODO: Add support for dynamically added options to the dropdown type
*/
function inputField (options = {})
{
this.constructor = function(options)
{
if(options.container) { this.setContainer(options.container); }
if(options.placeholder) { this.setPlaceHolder(options.placeholder); }
if(options.type) { this.setType(options.type); }
if(options.options) { this.addDropdownOptions(options.options); }
if(options.id) { this.setId(options.id); }
if(options.name) { this.setName(options.name); }
if(typeof options.disabled !== "undefined") { this.setDisabled(options.disabled); }
if(options.callback) { this.setCallback(options.callback); }
if(typeof options.value !== 'undefined') { this.setStartValue(options.value); }
if(options.onoff) { this.setOnOff(options.onoff); }
if(typeof options.min !== 'undefined') { this.setMin(options.min); }
if(typeof options.max !== 'undefined') { this.setMax(options.max); }
if(typeof options.step !== 'undefined') { this.setStep(options.step); }
//start it up!
this.create();
};
this.onoff = false;
this.setOnOff = function(v)
{
this.onoff = v;
};
this.ison = true;
this.createOnOff = function()
{
//Create the checkbox container
var c = $('<div/>');
c.addClass('checkbox');
//Create the checkbox object
var o = $('<input/>');
o.attr('type', 'checkbox');
o.attr('id', this.id+"_onoff");
if(this.ison && (!this.disabled))
{
o.prop('checked', true);
}
else
{
o.prop('checked', false);
}
var that = this;
o.off('change').on('change', function()
{
if($(this).prop('checked'))
{
that.turnOff();
}
else
{
that.turnOn();
}
});
//Create the checkbox label
var l = $('<label/>');
l.attr('for', this.id+"_onoff");
//Put the label and the checkbox in the container
c.append(o);
c.append(l);
return c;
};
this.turnOn = function()
{
this.disable(true);
this.ison = true;
};
this.turnOff = function()
{
this.enable(true);
this.ison = false;
};
this.startValue = null;
this.setStartValue = function (v)
{
this.startValue = v;
}
this.callback = null;
this.setCallback = function(a)
{
this.callback = a;
}
//HTML id attribute
this.id = null;
this.setId = function (id)
{
this.id = id;
};
//HTML name attribute
this.name = null;
this.setName = function (name)
{
this.name = name;
};
//HTML disabled attribute
this.disabled = false;
this.setDisabled = function (d)
{
this.disabled = d;
};
this.getValue = function()
{
switch(this.type)
{
case "size":
//if the box is empty, return null
if(!this.element.val())
{
return null;
}
//return the value, either in percent or in pixels
if(this.valueInPercent)
{
return this.element.val()+"%";
}
else
{
return this.element.val()+"px";
}
break;
case "slider":
//return the value, either in percent or in pixels
if(this.valueInPercent)
{
return this.element.val()+"%";
}
else
{
return this.element.val()+"px";
}
break;
case "dropdown":
//return the value of the selected item
return $("#"+this.id+" option:selected").val();
break;
//used by 'text' type, 'color' type, etc
default:
return this.element.val();
break;
}
};
//Set the value of the element
this.setValue = function(v, callback=true)
{
switch(this.type)
{
case 'slider':
var hasPx = v.indexOf('px') >= 0;
var hasPc = v.indexOf('%') >= 0;
//force value to an integer
v = parseInt(v, 10);
//console.log('updating slider value: '+v);
this.element.val(v).change();
this.element.rangeslider('update');
if(hasPc)
{
this.setSizeToPercent(v);
}
else
{
this.setSizeToPixels(v);
}
break;
case "size":
var hasPx = v.indexOf('px') >= 0;
var hasPc = v.indexOf('%') >= 0;
//force value to an integer
v = parseInt(v, 10);
this.element.val(v);
if(hasPc)
{
this.setSizeToPercent(v);
}
else
{
this.setSizeToPixels(v);
}
break;
case "dropdown":
//if the option exist, this will select it
this.element.val(v);
if(this.element.val() !== v)
{
console.warn('Setting dropdown value failed: '+v);
}
break;
case "color":
var updatedColor = this.rgbToHex(v);
this.element.val( updatedColor );
$("#"+this.id+"_colorShower").css( 'background-color', updatedColor );
if(this.callback && this.created && callback)
{
this.callback(updatedColor);
}
//skip the callback at the end
return;
break;
//used by type=text, type=color etc
default:
this.element.val(v);
break;
}
if(this.callback && this.created && callback)
{
this.callback(this.getValue());
}
};
this.rgbToHex = function(rgb)
{
if (/^#[0-9A-F]{6}$/i.test(rgb))
{
return rgb;
}
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
function hex(x)
{
return ("0" + parseInt(x).toString(16)).slice(-2);
}
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
this.valueInPercent = false;
this.valueInPixels = false;
this.setSizeToPercent = function (v=null)
{
if(this.created)
{
//If we're not given a value, use the value already there
//This way, we can use this function from setValue as well as button click events
if(!v)
{
v = this.getValue();
}
//Set errrrr'thing to percentage
this.container.find('#'+this.id+"_pc").removeClass('subBtn_off');
this.container.find('#'+this.id+"_pc").addClass('subBtn_on');
this.container.find('#'+this.id+"_px").removeClass('subBtn_on');
this.container.find('#'+this.id+"_px").addClass('subBtn_off');
this.valueInPercent = true;
this.valueInPixels = false;
}
};
this.setSizeToPixels = function (v)
{
if(this.created)
{
//If we're not given a value, use the value already there
//This way, we can use this function from setValue as well as button click events
if(!v)
{
v = this.getValue();
}
//Set errrrr'thing to pixels
this.container.find('#'+this.id+"_pc").removeClass('subBtn_on');
this.container.find('#'+this.id+"_pc").addClass('subBtn_off');
this.container.find('#'+this.id+"_px").removeClass('subBtn_off');
this.container.find('#'+this.id+"_px").addClass('subBtn_on');
this.valueInPercent = false;
this.valueInPixels = true;
}
};
/**
* What type of input is this?
* The type has to be set before this.create() is called.
* By default, it's a text input field.
*/
this.type = "text";
this.setType = function(t)
{
switch (t)
{
case "text":
this.type = "text";
break;
case "size":
this.type = "size";
break;
case "dropdown":
this.type = "dropdown";
break;
case "slider":
this.type = "slider";
break;
case 'color':
this.type = 'color';
break;
case 'colour':
this.type = 'color';
break;
}
};
this.placeholder = null;
this.setPlaceHolder = function(v)
{
this.placeholder = v;
};
//True when the DOM element has been created, false before
this.created = false;
//jQuery reference to the main element after creation
this.element = null;
//jQuery reference to this element's error container
this.errorElement = null;
/**
* create() starts off the creation process. Called by the constructor
*/
this.create = function()
{
//Don't create anything without a specified container
if(!this.container) { return; }
//Don't create twice
if(this.created) { return; }
switch (this.type)
{
case "dropdown":
this.createDropdown();
break;
case "size":
this.createSize();
break;
case "slider":
this.createSlider();
break;
case "text":
this.createText();
break;
case "color":
this.createColorPicker();
break;
}
};
//holds options for a dropdown element
this.options = {};
this.addDropdownOptions = function(options)
{
this.options = options;
};
//private function that adds options to a $('<select/>')
this.addOptionsToSelect = function(select)
{
$.each(this.options, function(value, name)
{
select.append( $("<option value='"+value+"'/>").text(name) );
});
return select;
};
/**
* Creates a Dropdown element
*/
this.createDropdown = function()
{
//Don't create anything without a specified container
if(!this.container) { return; }
//Don't create twice
if(this.created) { return; }
var select = $('<select/>');
if(this.name) { select.attr('name', this.name); }
if(this.disabled) { select.prop('disabled', 'disabled'); }
if(!this.id)
{
this.id = this.createRandomString();
}
select.attr('id', this.id);
if(! ($.isEmptyObject(this.options)) )
{
select = this.addOptionsToSelect(select);
}
if(this.onoff)
{
select.css('width', 'calc(100% - 41px)');
select.css('float', 'left');
}
else
{
select.css('width', 'calc(100% - 6px)');
}
select.css('margin', '3px');
//check if we need an on/off switch
if(this.onoff)
{
var oo = this.createOnOff();
this.container.append(oo);
}
this.container.append(select);
//<div class="error_msg" data-linked-to="f_align">Bla</div>
this.container.append('<div class="error_msg" id="error_'+this.id+'" />')
this.element = $('#'+this.id);
this.errorElement = $('#error_'+this.id);
var that = this;
//make sure any specified callback gets called if we're given one
if(this.callback)
{
$(document).on('change','#'+this.id,function()
{
that.callback(that.getValue());
});
}
this.created = true;
};
/**
* Displays an error message for this element. Only works if creation is done.
*/
this.setErrorMessage = function(html)
{
if(this.created)
{
this.errorElement.html(html);
}
};
this.rangeMin = 0;
this.setMin = function(min)
{
this.rangeMin = Number(min);
};
this.rangeMax = 50;
this.setMax = function(max)
{
this.rangeMax = Number(max);
};
this.rangeStep = 1;
this.setStep = function(step)
{
this.rangeStep = Number(step);
};
/**
* Creates a range 'slider' element that works in all major browsers & mobile
*/
this.createSlider = function()
{
/*
<div class="checkbox">
<input type="checkbox" id="slidy_onoff">
<label for="slidy_onoff"></label>
</div>
<div class="slider-container">
<div class="slider-aligner">
<input
id="slidy"
type="range"
min="0"
max="50"
step="1"
value="0"
data-orientation="horizontal"
>
</div>
</div>
<div class="slider-pxpc-container">
<button class="inputSubButton subBtn_off" id="slidy_px">px</button>
<button class="inputSubButton subBtn_on" id="slidy_pc">%</button>
</div>
*/
//Don't create anything without a specified container
if(!this.container) { return; }
//Don't create twice
if(this.created) { return; }
var input = $('<input />');
if(this.name) { input.attr('name', this.name); }
if(this.disabled) { input.prop('disabled', 'disabled'); }
if(!this.id)
{
this.id = this.createRandomString();
}
input.attr('id', this.id);
input.attr('type', 'range');
input.attr('data-orientation', 'horizontal');
//min and max are set now, but startvalue (value) is set after creation
input.attr('min', this.rangeMin);
input.attr('max', this.rangeMax);
input.attr('step', this.rangeStep);
slider_aligner = $('<div/>');
slider_aligner.addClass('slider-aligner');
slider_container = $('<div/>');
slider_container.addClass('slider-container');
if(this.onoff)
{
slider_container.css('width', 'calc(100% - 129px)');
}
else
{
slider_container.css('width', 'calc(100% - 89px)');
}
slider_aligner.append(input);
slider_container.append(slider_aligner);
this.container.append(slider_container);
var that = this;
var button_container = $('<div/>');
button_container.addClass('slider-pxpc-container');
//percent button
var pcBtn = $('<button/>');
pcBtn.addClass('inputSubButton');
pcBtn.addClass('subBtn_off');
pcBtn.attr('id', this.id+"_pc");
pcBtn.text('%');
pcBtn.off('click').on('click', function ()
{
if(that.disabled) { return; }
that.setSizeToPercent();
if(that.callback)
{
that.callback(that.getValue());
}
});
//pixel button
var pxBtn = $('<button/>');
pxBtn.addClass('inputSubButton');
pxBtn.addClass('subBtn_on'); //use pixels by default
pxBtn.attr('id', this.id+"_px");
pxBtn.text('px');
pxBtn.off('click').on('click', function ()
{
if(that.disabled) { return; }
that.setSizeToPixels();
if(that.callback)
{
that.callback(that.getValue());
}
});
//use pixels by default
this.valueInPixels = true;
button_container.append(pcBtn);
button_container.append(pxBtn);
this.container.append(button_container);
//check if we need an on/off switch
if(this.onoff)
{
var oo = this.createOnOff();
this.container.prepend(oo);
}
//add an error message container
this.container.append('<div class="error_msg" id="error_'+this.id+'" />')
this.errorElement = $('#error_'+this.id);
//keep a reference to the element in memory
this.element = $('#'+this.id);
//activate the element as range
this.element.rangeslider(
{
polyfill: false,
onInit: function ()
{
var $handle = $('.rangeslider__handle', this.$range);
that.updateRangeHandle($handle[0], this.value);
}
});
this.element.on('input', function (e)
{
var $handle = $('.rangeslider__handle', e.target.nextSibling);
that.updateRangeHandle($handle[0], this.value);
});
//make sure any specified callback gets called if we're given one
if(this.callback)
{
$(document).on('change','#'+this.id,function()
{
that.callback(that.getValue());
});
}
//let all other functions know we're past the creation phase
this.created = true;
//if there was a start value, apply it (now that creation is done)
if(this.startValue)
{
this.setValue(this.startValue, false);
}
if(this.disabled)
{
this.disable();
}
};
/**
* Updates the number on the Range Slider's handle when it's being used
*/
this.updateRangeHandle = function (el, val)
{
el.textContent = val;
};
this.cpVisible = false; //color picker visible?
this.createColorPicker = function()
{
//Don't create anything without a specified container
if(!this.container) { return; }
//Don't create twice
if(this.created) { return; }
/*
//given this.container
<div id="colorPicker">
<div id="00_container" class="colorContainer">
<div id="00_colorShower" class="colorShower">
<div id="00_arrow" class="colorArrowDown"></div>
</div>
//this.element
<input type="text" id='00' value="#ffa500" />
</div>
<div id="00_colorPickerContainer" class="colorPickerContainer">
</div>
</div>
*/
var input = $('<input />');
if(this.name) { input.attr('name', this.name); }
if(this.disabled) { input.prop('disabled', 'disabled'); }
if(this.placeholder){ input.attr('placeholder', this.placeholder); }
if(!this.id)
{
this.id = this.createRandomString();
}
input.attr('id', this.id);
input.attr('type', 'text');
input.val(this.startValue);
//create colorContainer
var cc = $('<div/>');
cc.attr('id', this.id+"_container");
cc.addClass('colorContainer');
//make room for an on/off checkbox if we need it
if(this.onoff)
{
cc.css('margin-left', '38px');
}
//create colorShower
var cs = $('<div/>');
cs.attr('id', this.id+"_colorShower");
cs.addClass('colorShower');
//create dropdown arrow
var ca = $('<div/>');
ca.attr('id', this.id+'_arrow');
ca.addClass('colorArrowDown');
//create the floating container that holds the hidden colorpicker
var cpc = $('<div/>');
cpc.attr('id', this.id+"_colorPickerContainer");
cpc.addClass('colorPickerContainer');
//make room for an on/off checkbox if we need it
if(this.onoff)
{
cpc.css('margin-left', '38px');
}
cs.append(ca);
cc.append(cs);
cc.append(input);
//check if we need an on/off switch
if(this.onoff)
{
var oo = this.createOnOff();
this.container.append(oo);
}
//add it to the DOM
this.container.append(cc);
this.container.append(cpc);
//add an error message container
this.container.append('<div class="error_msg" id="error_'+this.id+'" />')
this.errorElement = $('#error_'+this.id);
this.element = $('#'+this.id);
var that = this;
this.element.iris(
{
//don't hide just yet
hide: false,
target: $('#'+that.id+'_colorPickerContainer'),
color: that.element.val(),
//callback function
change: function(event, ui)
{
// event = standard jQuery event, produced by whichever control was changed.
// ui = standard jQuery UI object, with a color member containing a Color.js object
// change the color-shower's color
$("#"+that.id+"_colorShower").css( 'background-color', ui.color.toString());
if(that.callback)
{
that.callback(ui.color.toString());
}
}
});
//INIT: Now hide it, so that we can use toggle from there on
this.element.iris('hide');
$("#"+this.id+"_colorShower").css( 'background-color', this.element.val() );
this.cpVisible = false;
//Toggle the colorpicker plugin when we click on the colorshower
$('#'+this.id+'_colorShower').off('click').on('click', function ()
{
if(that.disabled) { return; }
if(that.cpVisible)
{
that.element.iris('hide');
$('#'+that.id+'_arrow').removeClass('colorArrowUp').addClass('colorArrowDown');
that.cpVisible = false;
}
else
{
that.element.iris('show');
$('#'+that.id+'_arrow').removeClass('colorArrowDown').addClass('colorArrowUp');
that.cpVisible = true;
}
});
//Don't show the colorpicker when we click on the input (to avoid annoyance when pasting hex code)
this.element.off('click').on('click', function()
{
return;
});
//Trigger the color change whenever a value changes (avoid having to press enter)
this.element.off('change').on('change', function ()
{
that.element.iris({color: that.element.val()});
});
//make sure any specified callback gets called if we're given one
if(this.callback)
{
$(document).on('change keydown paste input','#'+this.id,function()
{
that.callback(that.getValue());
});
}
//let all other functions know we're past the creation phase
this.created = true;
};
this.createText = function()
{
//Don't create anything without a specified container
if(!this.container) { return; }
//Don't create twice
if(this.created) { return; }
var input = $('<input />');
if(this.name) { input.attr('name', this.name); }
if(this.disabled) { input.prop('disabled', 'disabled'); }
if(this.placeholder){ input.attr('placeholder', this.placeholder); }
if(!this.id)
{
this.id = this.createRandomString();
}
input.attr('id', this.id);
input.attr('type', 'text');
var that = this;
cont = $('<div/>');
cont.addClass('sizeInput-container');
if(this.onoff)
{
cont.css('width', 'calc(100% - 41px)');
cont.css('float', 'left');
}
else
{
cont.css('width', 'calc(100% - 6px)');
}
cont.css('margin', '3px');
cont.append(input);
//check if we need an on/off switch
if(this.onoff)
{
var oo = this.createOnOff();
this.container.append(oo);
}
//add it to the DOM
this.container.append(cont);