-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComboBox.js
More file actions
1308 lines (1089 loc) · 41.6 KB
/
ComboBox.js
File metadata and controls
1308 lines (1089 loc) · 41.6 KB
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
if(!javaxt) var javaxt={};
if(!javaxt.dhtml) javaxt.dhtml={};
//******************************************************************************
//** ComboBox Class
//******************************************************************************
/**
* Form input with a pulldown list of options. By default, the options are
* accessed via a button or a "down arrow" key press. The list of options
* are automatically filtered as a user types in a value in the input field.
*
******************************************************************************/
javaxt.dhtml.ComboBox = function(parent, config) {
this.className = "javaxt.dhtml.ComboBox";
var me = this;
var input, button, mask;
var menuDiv, menuOptions, newOption;
var overflowDiv, overflowContainer;
var defaultConfig = {
/** Placeholder text to display in the input. No placeholder text is set
* by default.
*/
placeholder: false,
/** If true, the browser will spellcheck text in the input field. Default
* is false.
*/
spellcheck: false,
/** The number of menu items to that appear in the dropdown menu before
* overflow. Default is 5.
*/
maxVisibleRows: 5,
/** If true, will display a vertical scrollbar in the dropdown menu.
* Default is true.
*/
scrollbar: true,
/** If true, will display the dropdown menu whenever the input has focus
* (e.g. on mouse click). Default is true.
*/
showMenuOnFocus: true,
/** If true, the list of options in the dropdown menu are automatically
* filtered as a user types in a value in the input field. Default is
* true.
*/
typeAhead: true,
/** If true, will prevent user from typing or copy/pasting values in the
* input field. Default is false.
*/
readOnly: false,
/** A static list of options to put in the dropdown menu. Example:
<pre>
[
{
label: "Previous Year",
value: "prevYear"
},
{
label: "Current Year",
value: "currYear"
},
{
label: "Next Year",
value: "nextYear"
}
]
</pre>
* Use the add() method to add items dynamically.
*/
options: [],
/** If true, will display a static menu item at the bottom of the drop
* down menu. This extra menu option is commonly used to render a popup
* menu/dialog. The onAddNewOption() method can be overridden to handle
* when this item is selected. The addNewOptionText config option is
* used to set the text/label for this menu option. Default is false.
*/
addNewOption: false,
/** Text to display in the extra menu option when addNewOption is set to
* true. Default is "Add New..."
*/
addNewOptionText: "Add New...",
/** Style for individual elements within the component. Note that you can
* provide CSS class names instead of individual style definitions.
*/
style: {
width: "100%",
input: {
color: "#363636",
fontSize: "14px",
height: "24px",
lineHeight: "24px",
padding: "0px 4px",
verticalAlign: "middle",
transition: "border 0.2s linear 0s, box-shadow 0.2s linear 0s",
backgroundColor: "#fff",
border: "1px solid #ccc",
borderRight: "0 none",
boxShadow: "0 1px 1px rgba(0, 0, 0, 0.075) inset"
},
button: {
color: "#363636",
height: "24px",
width: "24px",
border: "1px solid #b4b4b4",
cursor: "pointer",
backgroundImage: "url(data:image/png;base64,iVBORw0KGgoAAAANSUh"+
"EUgAAABAAAAAQCAYAAAAf8/9hAAAAlklEQVQ4jWNgGAUowNvbW9PBwUEAjxJGHx"+
"8f/dDQUB4MGV9f3+TAwMD/AQEB97y8vOSxafb392+BqrlkbGzMhSLr7++/MTAw8"+
"D8OQ+CaYdjb21sT3flKAQEBj7AYgqHZz8+vBqsHPT09ldENCQgImIysOSAgoBZP"+
"GGEaQpJmfIYQrRmbITj9TAg4ODgIeHp6apGleegAAME5Y+rCcN+AAAAAAElFTkSuQmCC)",
backgroundPosition: "3px 3px",
backgroundRepeat: "no-repeat",
backgroundColor: "#e4e4e4"
},
menu: {
backgroundColor: "#ffffff",
border: "1px solid #ccc",
marginTop: "-1px",
overflow: "hidden",
boxShadow: "0 1px 4px 0 rgba(0, 0, 0, 0.15)"
},
option: {
color: "#363636",
whiteSpace: "nowrap",
height: "22px",
lineHeight: "22px",
padding: "0px 4px",
cursor: "default"
},
newOption: {
borderTop: "1px solid #ccc",
color: "#363636",
whiteSpace: "nowrap",
height: "24px",
lineHeight: "24px",
padding: "0px 4px",
cursor: "default"
},
/** If null or false, uses inline style. If "custom", uses,
* "iScrollHorizontalScrollbar", "iScrollVerticalScrollbar", and
* "iScrollIndicator" classes. You can also define custom class
* names by providing a style map like this:
<pre>
iscroll: {
horizontalScrollbar: "my-iScrollHorizontalScrollbar",
verticalScrollbar: "my-iScrollVerticalScrollbar",
indicator: "my-iScrollIndicator"
}
</pre>
*/
iscroll: null
}
};
//**************************************************************************
//** Constructor
//**************************************************************************
var init = function(){
if (isString(parent)) parent = document.getElementById(parent);
if (!parent) return;
//Clone the config so we don't modify the original config object
var clone = {};
merge(clone, config);
//Merge clone with default config
merge(clone, defaultConfig);
config = clone;
//Add noselect css rule before creating/styling any elements
javaxt.dhtml.utils.addNoSelectRule();
//Create main div
var mainDiv = createElement("div", parent);
mainDiv.className = "javaxt-combobox";
mainDiv.style.width = config.style.width;
mainDiv.style.position = "relative";
me.el = mainDiv;
//Create table with 2 columns
var table = createTable(mainDiv);
table.style.height = "";
var tr = table.addRow();
//Create input in the first column
var td = tr.addColumn();
td.style.width="100%";
input = createElement('input', td);
input.type = "text";
setStyle(input, "input");
if (config.readOnly===true){
config.spellcheck = false;
config.typeAhead = false;
input.setAttribute("readonly", "true");
}
if (config.spellcheck===true){} else input.setAttribute("spellcheck", "false");
if (config.placeholder) input.setAttribute("placeholder", config.placeholder);
input.onkeydown = function(e){
if (e.keyCode===9){
e.preventDefault();
}
};
input.onkeyup = function(e){
if (config.readOnly===true) return;
if (e.keyCode===9){ //tab
var d;
if (menuDiv.style.visibility !== "hidden"){
d = getFirstOption();
}
if (d) select(d, true);
else focusNext();
}
else if (e.keyCode===40){ //down arrow
me.showMenu();
var d = getFirstOption();
if (d) d.focus();
}
else{
if (config.typeAhead===true){
me.filter();
}
}
};
input.oninput = function(){
if (me.isDisabled()===true) return;
//if (config.readOnly===true) return;
var orgLabel = input.value;
var orgVal = input.data;
var foundMatch = false;
var filter = input.value.replace(/^\s*/, "").replace(/\s*$/, "").toLowerCase();
for (var i=0; i<menuOptions.childNodes.length; i++){
var div = menuOptions.childNodes[i];
var text = div.text;
if (!text) text = div.innerText;
if (isString(text)) text = text.toLowerCase();
if (text===filter){
foundMatch = true;
input.data = div.value;
break;
}
}
if (!foundMatch) input.data = null;
me.onChange(input.value, input.data, orgLabel, orgVal);
};
input.onpaste = input.oninput;
input.onpropertychange = input.oninput;
addShowHide(input);
if (config.showMenuOnFocus){
input.onclick = function(){
if (me.isDisabled()===true) return;
me.showMenu(true);
scroll();
this.focus();
};
}
//Create button in the second column
button = createElement('button', tr.addColumn());
//button.type = "button";
setStyle(button, "button");
button.onclick = function(e){
button.blur();
e.preventDefault();
if (menuDiv.style.visibility === "hidden"){
me.showMenu(true);
scroll();
}
else{
me.hideMenu();
}
};
//Create menu
var div = createElement('div', mainDiv, {
position: "relative",
width: "100%"
});
menuDiv = createElement('div', div);
menuDiv.setAttribute("desc", "menuDiv");
setStyle(menuDiv, "menu");
menuDiv.style.position = "absolute";
menuDiv.style.visibility = "hidden";
menuDiv.style.display = "block"; //<--Required to get size
menuDiv.style.width = "100%";
menuDiv.style.zIndex = 1;
menuDiv.style.boxSizing = "border-box";
//Create overflow divs
overflowContainer = createElement("div", {
position: "relative",
width: "100%",
height: "100%"
});
overflowDiv = overflowContainer.cloneNode();
overflowDiv.style.position = "absolute";
overflowDiv.style.overflow = "hidden";
overflowContainer.appendChild(overflowDiv);
//Create menu options
menuOptions = createElement("div", overflowDiv, {
position: "relative",
width: "100%"
});
if (config.options){
for (var i=0; i<config.options.length; i++){
var o = config.options[i];
me.add(o.label, o.value);
}
}
if (config.addNewOption===true){
var menuTable = createTable(menuDiv);
menuTable.style.height = "";
tr = menuTable.addRow();
td = tr.addColumn({
width: "100%",
height: "100%",
verticalAlign: "top"
});
td.appendChild(overflowContainer);
td = menuTable.addRow().addColumn();
newOption = createElement('div', td);
setStyle(newOption, "newOption");
var text = getText(config.addNewOptionText);
newOption.text = text;
newOption.innerHTML = text;
newOption.tabIndex = -1; //allows the div to have focus
var selectNewOption = function(){
me.hideMenu();
me.onAddNewOption();
};
newOption.onclick = selectNewOption;
newOption.onkeydown = function(e){
if (e.keyCode===9){
e.preventDefault();
}
};
newOption.onkeyup = function(e){
if (e.keyCode===9 || e.keyCode===13){ //tab or enter
selectNewOption();
}
else if (e.keyCode===38){ //up arrow
var previousSibling;
for (var i=menuOptions.childNodes.length-1; i>-1; i--){
var div = menuOptions.childNodes[i];
if (div.style.display !== "none"){
previousSibling = div;
break;
}
}
if (previousSibling) previousSibling.focus();
}
};
newOption.onselectstart = function () {return false;};
newOption.onmousedown = function () {return false;};
newOption.onmouseover = function(){
var div = this;
me.onMenuHover(text, div.value, div);
};
}
else{
menuDiv.appendChild(overflowContainer);
}
//Add event listener to hide menu if the client clicks outside of the menu div
var hideMenu = function(e){
if (!mainDiv.contains(e.target)){
me.hideMenu(false);
}
};
if (document.addEventListener) { // For all major browsers, except IE 8 and earlier
document.addEventListener("click", hideMenu);
}
else if (document.attachEvent) { // For IE 8 and earlier versions
document.attachEvent("onclick", hideMenu);
}
//Add public show/hide methods
addShowHide(me);
};
//**************************************************************************
//** isDisabled
//**************************************************************************
/** Returns true if the compnentent has been disabled.
*/
this.isDisabled = function(){
return me.el.disabled;
};
//**************************************************************************
//** enable
//**************************************************************************
/** Used to enable the input allowing users to interact with the component.
*/
this.enable = function(){
var outerDiv = me.el;
if (mask){
outerDiv.style.opacity = "";
mask.style.visibility = "hidden";
}
outerDiv.disabled = false;
};
//**************************************************************************
//** disable
//**************************************************************************
/** Used to disable the input preventing users from interacting with the
* component.
*/
this.disable = function(){
me.hideMenu();
var outerDiv = me.el;
outerDiv.style.opacity = "0.6";
if (mask){
mask.style.visibility = "visible";
}
else{
mask = createElement('div', {
width: "100%",
height: "100%",
position: "absolute",
zIndex: 1
});
mask.setAttribute("desc", "mask");
outerDiv.insertBefore(mask, outerDiv.firstChild);
}
outerDiv.disabled = true;
};
//**************************************************************************
//** reset
//**************************************************************************
/** Similar to the clear() method, this will clears the input value. However,
* unlike the clear() method, this method will retain all the items in the
* dropdown menu.
*/
this.reset = function(){
me.hideMenu();
//Remove everything that's not an input
var a = [];
var p = input.parentElement;
var c = p.childNodes;
for (var i=0; i<c.length; i++) if (c[i]!=input) a.push(c[i]);
for (var i=0; i<a.length; i++) p.removeChild(a[i]);
//Reset input
input.value = "";
input.data = null;
//Ensure the input is visible
input.show();
input.blur();
};
//**************************************************************************
//** setValue
//**************************************************************************
/** Used to set the value for the input.
* @param value A label or value found in the dropdown menu. This parameter
* is required.
* @param silent By default, if the input value is changed, it will fire.
* the onChange event. When silent is set to true, the input will NOT fire
* the onChange event. This parameter is optional.
*/
this.setValue = function(value, silent){
var setValue = function(text, value, div){
if (isElement(text)){
select(div, false, silent);
}
else{
input.value = text;
input.data = value;
if (silent===true) return;
input.oninput();
}
};
if (value==null || value==="") {
setValue("", null);
return;
};
//Try to match the value to one of the menu items using the menu data
for (var i=0; i<menuOptions.childNodes.length; i++){
var div = menuOptions.childNodes[i];
if (div.value===value){
var text = div.text;
if (!text) text = div.innerText;
setValue(text, div.value, div);
return;
}
}
//Try to match the value to one of the menu items using the menu text
var filter = getText(value).toLowerCase();
for (var i=0; i<menuOptions.childNodes.length; i++){
var div = menuOptions.childNodes[i];
var text = div.text;
if (!text) text = div.innerText;
if ((isString(text) && text.toLowerCase() === filter) || text === filter){
setValue(text, div.value, div);
return;
}
}
};
//**************************************************************************
//** getValue
//**************************************************************************
/** Returns the selected value associated with the input.
*/
this.getValue = function(){
return input.data;
};
//**************************************************************************
//** getText
//**************************************************************************
/** Returns the text displayed in the input.
*/
this.getText = function(){
return input.value;
};
//**************************************************************************
//** getOptions
//**************************************************************************
/** Returns an array of all the menu options currently available in the
* dropdown menu. Elements in the array will include a "text", "value",
* and "el" for each entry. Example:
<pre>
[
{
text: "United States",
value: "US",
el: div
},
{
text: "Mexico",
value: "MX",
el: div
},
...
]
</pre>
*/
this.getOptions = function(){
var arr = [];
for (var i=0; i<menuOptions.childNodes.length; i++){
var div = menuOptions.childNodes[i];
var text = div.text;
if (!text) text = div.innerText;
arr.push({
text: text,
value: div.value,
el: div
});
}
return arr;
};
//**************************************************************************
//** getInput
//**************************************************************************
/** Returns the DOM element for the input.
*/
this.getInput = function(){
return input;
};
//**************************************************************************
//** getButton
//**************************************************************************
/** Returns the DOM element for the button.
*/
this.getButton = function(){
return button;
};
//**************************************************************************
//** onChange
//**************************************************************************
/** Called when the input value changes
*/
this.onChange = function(label, value, prevLabel, prevValue){};
//**************************************************************************
//** onAddNewOption
//**************************************************************************
/** Called when a user clicks on the "new" menu option that appears at the
* bottom of the dropdown menu. See addNewOption config option.
*/
this.onAddNewOption = function(){};
//**************************************************************************
//** onMenuShow
//**************************************************************************
/** Called when the menu is made visible
*/
this.onMenuShow = function(){};
//**************************************************************************
//** onMenuHide
//**************************************************************************
/** Called when the menu is hidden
*/
this.onMenuHide = function(){};
//**************************************************************************
//** onMenuContext
//**************************************************************************
/** Called when a user attempts to render the context menu on a menu option
*/
this.onMenuContext = function(label, value, el){};
//**************************************************************************
//** onMenuHover
//**************************************************************************
/** Called when a user hovers over an item in the dropdown menu
*/
this.onMenuHover = function(label, value, el){};
//**************************************************************************
//** filter
//**************************************************************************
/** Used to filter items in the dropdown menu that start with the text in
* the input.
*/
this.filter = function(){
//Show menu
me.showMenu();
//Get input value
var filter = input.value.replace(/^\s*/, "").replace(/\s*$/, "").toLowerCase();
//Filter menu items
var numVisibleItems = 0;
var h = 0;
for (var i=0; i<menuOptions.childNodes.length; i++){
var div = menuOptions.childNodes[i];
var text = div.text;
if (!text) text = div.innerText;
if (isElement(text)){
if (isElement(input.text)){
//TODO: compare DOM elements
div.style.display = "none";
}
else{
div.style.display = "none";
}
}
else{
if (text.toLowerCase().indexOf(filter) === 0) {
div.style.display = "";
numVisibleItems++;
h = Math.max(div.offsetHeight, h);
}
else {
div.style.display = "none";
}
}
}
//Resize menu
resizeMenu(numVisibleItems, h);
};
//**************************************************************************
//** clear
//**************************************************************************
/** Clears the input and removes all items from the dropdown menu.
*/
this.clear = function(){
me.reset();
me.hideMenu();
removeOverflow();
menuDiv.style.height = "";
menuOptions.innerHTML = "";
};
//**************************************************************************
//** showMenu
//**************************************************************************
/** Renders the dropdown menu if it is hidden.
* @param removeFilter If true, expand the list and view all the options.
*/
this.showMenu = function(removeFilter){
if (menuDiv.style.visibility === "hidden"){
//Unhide all the options as needed
if (removeFilter===true){
for (var i=0; i<menuOptions.childNodes.length; i++){
menuOptions.childNodes[i].style.display = '';
}
}
//Check to see if the menu has anything to display
var numVisibleItems = 0;
var h = 0;
for (var i=0; i<menuOptions.childNodes.length; i++){
var div = menuOptions.childNodes[i];
if (div.style.display !== "none"){
numVisibleItems++;
h = Math.max(div.offsetHeight, h);
}
}
if (config.addNewOption===true){
numVisibleItems++;
h = Math.max(newOption.offsetHeight, h);
}
if (numVisibleItems>0){
//Update menu size
resizeMenu(numVisibleItems, h);
//Set zIndex
var highestElements = getHighestElements();
var zIndex = highestElements.zIndex;
if (!highestElements.contains(menuDiv)) zIndex++;
menuDiv.style.zIndex = zIndex;
//Show the menu
menuDiv.style.visibility = '';
//Hide bottom border
input.style.borderBottomColor =
button.style.borderBottomColor = "rgba(0,0,0,0)";
//Scroll to top
if (me.iScroll){
setTimeout(function () {
me.iScroll.scrollTo(0,0);
me.iScroll.refresh();
}, 0);
}
else{
overflowDiv.scrollTop = 0;
}
//Fire event
me.onMenuShow();
}
}
};
//**************************************************************************
//** hideMenu
//**************************************************************************
/** Hides the dropdown menu if it is visible.
*/
this.hideMenu = function(){
if (menuDiv.style.visibility !== "hidden"){
var hideInput = !input.isVisible();
//Restore input and button styles
input.style.borderBottomColor =
button.style.borderBottomColor = '';
setStyle(input, "input");
setStyle(button, "button");
input.style.width="100%";
//Hide menu
menuDiv.style.visibility = "hidden";
menuDiv.style.zIndex = 1;
//Focus or hide input
if (hideInput){
input.hide();
}
else{
if (arguments[0]!==false) input.focus();
}
//Fire event
me.onMenuHide();
}
};
//**************************************************************************
//** resizeMenu
//**************************************************************************
var resizeMenu = function(numVisibleItems, h){
if (numVisibleItems>0){
if (numVisibleItems>config.maxVisibleRows){
addOverflow();
var height = config.maxVisibleRows*h;
if (newOption){
menuDiv.style.height = height + "px";
height = height-newOption.offsetHeight;
overflowContainer.style.height =
//menuOptions.style.height =
height + "px";
}
else{
//menuOptions.style.height =
menuDiv.style.height = height + "px";
}
}
else{
removeOverflow();
overflowContainer.style.height = "100%"; //?
//menuOptions.style.height =
menuDiv.style.height = '';
}
}
else{
removeOverflow();
overflowContainer.style.height = "100%"; //?
//menuOptions.style.height =
menuDiv.style.height = '';
}
if (me.iScroll) me.iScroll.refresh();
};
//**************************************************************************
//** addOverflow
//**************************************************************************
var addOverflow = function(){
overflowDiv.style.position = "absolute";
if (config.scrollbar===true){
if (typeof IScroll !== 'undefined'){
if (!me.iScroll){
overflowDiv.style.overflowY = 'hidden';
me.iScroll = new IScroll(overflowDiv, {
scrollbars: config.style.iscroll ? "custom" : true,
mouseWheel: true,
fadeScrollbars: false,
hideScrollbars: false
});
if (config.style.iscroll) setStyle(me.iScroll, "iscroll");
}
if (me.iScroll) me.iScroll.refresh();
}
else{
overflowDiv.style.overflowY = 'scroll';
}
}
else{
overflowDiv.style.overflowY = 'hidden';
}
};
//**************************************************************************
//** removeOverflow
//**************************************************************************
var removeOverflow = function(){
overflowDiv.style.position = "relative";
if (config.addNewOption===true){
if (typeof IScroll !== 'undefined'){
//console.log("removeOverflow?");
}
else{
overflowDiv.style.overflowY = '';
}
}
};
//**************************************************************************
//** scroll
//**************************************************************************
/** Scrolls menu to the input value
*/
var scroll = function(){
var scrollToElement = function(el){
if (true) return;
if (me.iScroll){
setTimeout(function () {
me.iScroll.scrollToElement(el);
me.iScroll.refresh();
el.focus();
}, 100);
}
else{
overflowDiv.scrollTop = el.offsetTop;
el.focus();
}
};
//Scroll to a menu item that matches the text in the input
for (var i=0; i<menuOptions.childNodes.length; i++){
var div = menuOptions.childNodes[i];
var text = div.text;
if (!text) text = div.innerText;
if (text===input.value){