Content Type for www-urlencoded should match additions like "; charset=utf8" as well
[project/luci.git] / themes / openwrt.org / htdocs / luci-static / openwrt.org / Dropdowns.js
1 /*
2 Copyright (C) 2008  Alina Friedrichsen <x-alina@gmx.net>
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7 1. Redistributions of source code must retain the above copyright
8    notice, this list of conditions and the following disclaimer.
9 2. Redistributions in binary form must reproduce the above copyright
10    notice, this list of conditions and the following disclaimer in the
11    documentation and/or other materials provided with the distribution.
12
13 THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 SUCH DAMAGE.
24 */
25
26 function initDropdowns() {
27         var aSelects = XHTML1.getElementsByTagName("select");
28         var isIE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
29
30         function showPlaceholder(sel) {
31                 if( ! sel._ph ) {
32                         var box = sel.getBoundingClientRect();
33                         sel._dm = sel.currentStyle.display;
34                         sel._ph = document.createElement('input');
35                         sel.parentNode.insertBefore(sel._ph, sel);
36                         sel._ph.style.width  = ( box.right - box.left ) + 'px';
37                         sel._ph.style.height = ( box.bottom - box.top ) + 'px';
38                         sel._ph.style.margin = sel.currentStyle.margin;
39                 }
40
41                 sel._ph.value = sel.options[sel.selectedIndex].text;
42                 sel._ph.style.display = sel._dm;
43                 sel.style.display = 'none';
44         }
45
46         function hidePlaceholder(sel) {
47                 if( sel._ph ) sel._ph.style.display = 'none';
48                 sel.style.display = sel._dm;
49         }
50
51         function hideSelects() {
52                 for(var i = 0; i < aSelects.length; i++) {
53                         showPlaceholder(aSelects[i]);
54                 }
55         }
56
57         function showSelects() {
58                 for(var i = 0; i < aSelects.length; i++) {
59                         hidePlaceholder(aSelects[i]);
60                 }
61         }
62
63         function onmouseover(evt) {
64                 XHTML1.addClass(evt.currentTarget, "over");
65                 if( isIE6 ) hideSelects();
66         }
67
68         function onmouseout(evt) {
69                 XHTML1.removeClass(evt.currentTarget, "over");
70                 if( isIE6 ) showSelects();
71         }
72
73         function onfocus(evt) {
74                 for(var element = evt.currentTarget; element; element = element.parentNode) {
75                         if(XHTML1.isElement(element, "li")) {
76                                 XHTML1.addClass(element, "focus");
77                         }
78                 }
79                 if( isIE6 ) hideSelects();
80         }
81
82         function onblur(evt) {
83                 for(var element = evt.currentTarget; element; element = element.parentNode) {
84                         if(XHTML1.isElement(element, "li")) {
85                                 XHTML1.removeClass(element, "focus");
86                         }
87                 }
88                 if( isIE6 ) showSelects();
89         }
90
91         if(document.all) {
92                 var liElements = XHTML1.getElementsByTagName("li");
93                 for(var i = 0; i < liElements.length; i++) {
94                         var li = liElements[i];
95                         for(var element = li.parentNode; element; element = element.parentNode) {
96                                 if(XHTML1.isElement(element, "ul") && XHTML1.containsClass(element, "dropdowns")) {
97                                         XHTML1.addEventListener(li, "mouseover", onmouseover);
98                                         XHTML1.addEventListener(li, "mouseout", onmouseout);
99                                         break;
100                                 }
101                         }
102                 }
103         }
104
105         var aElements = XHTML1.getElementsByTagName("a");
106         for(var i = 0; i < aElements.length; i++) {
107                 var a = aElements[i];
108                 for(var element = a.parentNode; element; element = element.parentNode) {
109                         if(XHTML1.isElement(element, "ul") && XHTML1.containsClass(element, "dropdowns")) {
110                                 XHTML1.addEventListener(a, "focus", onfocus);
111                                 XHTML1.addEventListener(a, "blur", onblur);
112                                 break;
113                         }
114                 }
115         }
116 }
117
118 if(XHTML1.isDOMSupported()) {
119         XHTML1.addEventListener(window, "load", initDropdowns);
120 }