Added .gitignore
[moodle-linuxchix.git] / lib / dropdown.js
blobc922db52b469896cd63a3c31b91edb09b7c4fbc5
1 /****
2 Author: Jerome Mouneyrac
3 Bug Reference: http://tracker.moodle.org/browse/MDL-14439
4 IE and Opera fire the onchange when ever you move into a dropdwown list with the keyboard.
5 These functions fix this problem.
6 ****/
8 /*
9 global variables
11 Note:
12 if I didn't use global variables, we would need to pass them as parameter:
13 => in initSelect():
14 I would write "theSelect.onchange = selectChanged(...);"
15 This code causes a javascript error on IE. (not firefox)
16 so I had to write theSelect.onchange = selectChanged; It's why I use global variables .
17 Because I use global variables, I didn't put this code in javascript-static.js.
18 This file is loaded in javascript.php.
19 */
20 var select_formid;
21 var select_targetwindow;
23 //we redefine all user actions on the dropdown list
24 //onfocus, onchange, onkeydown, and onclick
25 function initSelect(formId,targetWindow)
27 //initialise global variables
28 select_formid=formId;
29 select_targetwindow=targetWindow;
31 var theSelect = document.getElementById(select_formid+"_jump");
33 theSelect.changed = false;
35 selectFocussed();
37 theSelect.onchange = selectChanged;
38 theSelect.onkeydown = selectKeyed;
39 theSelect.onclick = selectClicked;
41 return true;
44 function selectChanged(theElement)
46 var theSelect;
48 if (theElement && theElement.value)
50 theSelect = theElement;
52 else
54 theSelect = this;
57 if (!theSelect.changed)
59 return false;
62 //here is the onchange redirection
63 select_targetwindow.location=document.getElementById(select_formid).jump.options[document.getElementById(select_formid).jump.selectedIndex].value;
65 return true;
68 function selectClicked()
70 this.changed = true;
73 function selectFocussed()
75 this.initValue = this.value;
77 return true;
80 //we keep Firefox behaviors: onchange is fired when we press "Enter", "Esc", or "Tab"" keys.
81 //note that is probably not working on Mac (keyCode could be different)
82 function selectKeyed(e)
84 var theEvent;
85 var keyCodeTab = "9";
86 var keyCodeEnter = "13";
87 var keyCodeEsc = "27";
89 if (e)
91 theEvent = e;
93 else
95 theEvent = event;
98 if ((theEvent.keyCode == keyCodeEnter || theEvent.keyCode == keyCodeTab) && this.value != this.initValue)
100 this.changed = true;
101 selectChanged(this);
103 else if (theEvent.keyCode == keyCodeEsc)
105 this.value = this.initValue;
107 else
109 this.changed = false;
112 return true;