bug 782828
[phpmyadmin/crack.git] / libraries / left.js
blob603dbd6d3a35d117c9a78150b576ef7f82ae3595
1 /* $Id$ */
4 // These scripts were originally found on cooltype.com.
5 // Modified 01/01/1999 by Tobias Ratschiller for linuxapps.com
7 // Modified 7th June 2000 by Brian Birtles for Mozilla 5.0
8 // compatibility for phpMyAdmin
10 // Rewritten and put in a libray 2nd May 2001 by Loïc Chapeaux
12 // Test passed with:
13 // - Mozilla 0.8.1 to 1.0-RC1 for Windows (js enabled & disabled)
14 // - IE5, 5.01, 5.5, 6.0 for Windows
15 // - Netscape 4.75 to 4.78 for Windows
17 // Test failed (crappy DOM implementations) with:
18 // - Opera 5.02 for windows: 'getElementsByTagName' is unsupported
19 // - Opera 5.10 to 6.01 for windows, Opera 5+ for Linux: 'style.display' can't
20 //   be changed
21 // - Konqueror 2+, 3: 'style.display' can't be changed
24 var isExpanded   = false;
26 var imgOpened    = new Image(9,9);
27 imgOpened.src    = 'images/minus.png';
28 var imgClosed    = new Image(9,9);
29 imgClosed.src    = 'images/plus.png';
32 /**
33  * Do reloads the frame if the window has been resized under Netscape4+
34  *
35  * @access  private
36  */
37 function reDo() {
38   if (innerWidth != origWidth || innerHeight != origHeight)
39     location.reload(true);
40 } // end of the 'reDo()' function
42 /**
43  * Positioned element resize bug under NS4+
44  */
45 if (isNS4) {
46   var origWidth  = innerWidth;
47   var origHeight = innerHeight;
48   onresize       = reDo;
52 /**
53  * Gets the id of the first collapsible room
54  *
55  * @param  string  the name of the first collapsible room
56  *
57  * @return  integer  the index number corresponding to this room
58  *
59  * @access  public
60  */
61 function nsGetIndex(el) {
62   var ind       = null;
63   var theLayers = document.layers;
64   var layersCnt = theLayers.length;
65   for (var i = 0; i < layersCnt; i++) {
66     if (theLayers[i].id == el) {
67       ind = i;
68       break;
69     }
70   }
71   return ind;
72 } // end of the 'nsGetIndex()' function
75 /**
76  * Positions layers under NS4+
77  *
78  * @access  public
79  */
80 function nsArrangeList() {
81   if (typeof(firstInd) != 'undefined' && firstInd != null) {
82     var theLayers = document.layers;
83     var layersCnt = theLayers.length;
84     var nextY     = theLayers[firstInd].pageY + theLayers[firstInd].document.height;
85     for (var i = firstInd + 1; i < layersCnt; i++) {
86       if (theLayers[i].visibility != 'hide') {
87         theLayers[i].pageY = nextY;
88         nextY              += theLayers[i].document.height;
89       }
90     }
91   }
92 } // end of the 'nsArrangeList()' function
95 /**
96  * Expand databases at startup
97  *
98  * @access  public
99  */
100 function nsShowAll() {
101   var theLayers = document.layers;
102   var layersCnt = theLayers.length;
103   for (i = firstInd; i < layersCnt; i++) {
104     theLayers[i].visibility = 'show';
105   }
106 } // end of the 'nsShowAll()' function
110  * Collapses databases at startup
112  * @access  public
113  */
114 function initIt()
116   if (!capable || !isServer)
117     return;
119   var tempColl    = null;
120   var tempCollCnt = null;
121   var i           = 0;
123   if (isDOM) {
124     tempColl    = document.getElementsByTagName('DIV');
125     tempCollCnt = tempColl.length;
126     for (i = 0; i < tempCollCnt; i++) {
127       if (tempColl[i].id == expandedDb)
128         tempColl[i].style.display = 'block';
129       else if (tempColl[i].className == 'child')
130         tempColl[i].style.display = 'none';
131     }
132   } // end of the DOM case
133   else if (isIE4) {
134     tempColl    = document.all.tags('DIV');
135     tempCollCnt = tempColl.length;
136     for (i = 0; i < tempCollCnt; i++) {
137       if (tempColl(i).id == expandedDb)
138         tempColl(i).style.display = 'block';
139       else if (tempColl(i).className == 'child')
140         tempColl(i).style.display = 'none';
141     }
142   } // end of the IE4 case
143   else if (isNS4) {
144     var theLayers  = document.layers;
145     var layersCnt  = theLayers.length;
146     for (i = 0; i < layersCnt; i++) {
147       if (theLayers[i].id == expandedDb)
148         theLayers[i].visibility   = 'show';
149       else if (theLayers[i].id.indexOf('Child') != -1)
150         theLayers[i].visibility   = 'hide';
151       else
152         theLayers[i].visibility   = 'show';
153     }
154     nsArrangeList();
155   } // end of the NS4 case
156 } // end of the 'initIt()' function
160  * Collapses/expands a database when the user require this to be done
162  * @param  string  the name of the database to act on
163  * @param  boolean whether to expand or to collapse the database content
165  * @access  public
166  */
167 function expandBase(el, unexpand)
169   if (!capable)
170     return;
172   var whichEl = null;
173   var whichIm = null;
175   if (isDOM) {
176     whichEl = document.getElementById(el + 'Child');
177     whichIm = document.getElementById(el + 'Img');
178     if (whichEl.style.display == 'none' && whichIm) {
179       whichEl.style.display  = 'block';
180       whichIm.src            = imgOpened.src;
181     }
182     else if (unexpand) {
183       whichEl.style.display  = 'none';
184       whichIm.src            = imgClosed.src;
185     }
186   } // end of the DOM case
187   else if (isIE4) {
188     whichEl = document.all(el + 'Child');
189     whichIm = document.images.item(el + 'Img');
190     if (whichEl.style.display == 'none') {
191       whichEl.style.display  = 'block';
192       whichIm.src            = imgOpened.src;
193     }
194     else if (unexpand) {
195       whichEl.style.display  = 'none';
196       whichIm.src            = imgClosed.src;
197     }
198   } // end of the IE4 case
199   else if (isNS4) {
200     whichEl = document.layers[el + 'Child'];
201     whichIm = document.layers[el + 'Parent'].document.images['imEx'];
202     if (whichEl.visibility == 'hide') {
203       whichEl.visibility  = 'show';
204       whichIm.src         = imgOpened.src;
205     }
206     else if (unexpand) {
207       whichEl.visibility  = 'hide';
208       whichIm.src         = imgClosed.src;
209     }
210     nsArrangeList();
211   } // end of the NS4 case
212 } // end of the 'expandBase()' function
216  * Hilight/un-hilight a database when the mouse pass over/out it
218  * @param  string  the name of the database to act on
219  * @param  boolean the color to be used
221  * @access  public
222  */
223 function hilightBase(el, theColor)
225   if (!isDOM && !isIE4) {
226     return null;
227   }
229   var whichDb     = null;
230   var whichTables = null;
232   if (isDOM) {
233     whichDb       = document.getElementById(el + 'Parent');
234     whichTables   = document.getElementById(el + 'Child');
235   }
236   else if (isIE4) {
237     whichDb       = document.all(el + 'Parent');
238     whichTables   = document.all(el + 'Child');
239   }
241   if (typeof(whichDb.style) == 'undefined') {
242     return null;
243   }
244   else if (whichTables) {
245     whichDb.style.backgroundColor     = theColor;
246     whichTables.style.backgroundColor = theColor;
247   }
248   else {
249     whichDb.style.backgroundColor     = theColor;
250   }
252   return true;
253 } // end of the 'hilightBase()' function
255 window.onload = initIt;