author | Dan |
Thu, 14 Feb 2008 21:56:28 -0500 | |
changeset 422 | ca37fcd08c4e |
parent 362 | 02d315d1cc58 |
child 582 | a38876c0793c |
permissions | -rw-r--r-- |
1 | 1 |
// Sliding drawers on the sidebar |
2 |
||
3 |
// our global vars |
|
4 |
// the delay between the slide in/out, and a little inertia |
|
5 |
||
6 |
var sliders_initted = false; |
|
7 |
||
8 |
function initSliders() |
|
9 |
{ |
|
10 |
sliders_initted = true; |
|
57
b354deeaa4c4
Vastly improved compatibility with older versions of IE, particularly 5.0, through the use of a kill switch that turns off all AJAX functions
Dan
parents:
1
diff
changeset
|
11 |
if ( KILL_SWITCH ) |
b354deeaa4c4
Vastly improved compatibility with older versions of IE, particularly 5.0, through the use of a kill switch that turns off all AJAX functions
Dan
parents:
1
diff
changeset
|
12 |
return false; |
1 | 13 |
// detect whether the user has ie or not, how we get the height is different |
14 |
var useragent = navigator.userAgent.toLowerCase(); |
|
15 |
var ie = ((useragent.indexOf('msie') != -1) && (useragent.indexOf('opera') == -1) && (useragent.indexOf('webtv') == -1)); |
|
16 |
||
17 |
if(ie) |
|
18 |
return; |
|
19 |
||
20 |
var divs = getElementsByClassName(document, "div", "slideblock"); |
|
21 |
||
22 |
for(var i=0; i<divs.length; i++) |
|
23 |
{ |
|
24 |
// set a unique id for this slider |
|
25 |
divs[i].metaid = i; |
|
26 |
||
27 |
// get the original height |
|
28 |
var baseheight = (ie) ? divs[i].offsetHeight + "px" : document.defaultView.getComputedStyle(divs[i], null).getPropertyValue('height', null); |
|
29 |
||
30 |
// use cookies to toggle whether to display it or not |
|
31 |
var id = ( divs[i].parentNode.firstChild.nextSibling ) ? divs[i].parentNode.firstChild.nextSibling.firstChild : divs[i].parentNode.parentNode.firstChild.nextSibling.firstChild; |
|
32 |
||
362
02d315d1cc58
Started localization on User CP. Localized pagination, password strength, and various other small widgets. Fixed bug in path manager causing return of fullpage from get_page_id_from_url() even when namespace is Special.
Dan
parents:
57
diff
changeset
|
33 |
if ( !id.nextSibling ) |
02d315d1cc58
Started localization on User CP. Localized pagination, password strength, and various other small widgets. Fixed bug in path manager causing return of fullpage from get_page_id_from_url() even when namespace is Special.
Dan
parents:
57
diff
changeset
|
34 |
return; |
02d315d1cc58
Started localization on User CP. Localized pagination, password strength, and various other small widgets. Fixed bug in path manager causing return of fullpage from get_page_id_from_url() even when namespace is Special.
Dan
parents:
57
diff
changeset
|
35 |
|
1 | 36 |
if(id.innerHTML || id.nextSibling.length < 1) id = id.innerHTML; |
37 |
else id = id.nextSibling.innerHTML; // Gecko fix |
|
38 |
||
39 |
var cookieName = 'mdgSliderState_'+i; // id.replace(' ', '_'); |
|
40 |
//alert(cookieName + ': ' + readCookie(cookieName)); |
|
41 |
if(readCookie(cookieName)=='closed') |
|
42 |
{ |
|
43 |
divs[i].style.display = "none"; |
|
44 |
} |
|
45 |
else |
|
46 |
{ |
|
47 |
divs[i].style.display = "block"; |
|
48 |
} |
|
49 |
||
50 |
// "save" our div height, because once it's display is set to none we can't get the original height again |
|
51 |
var d = new div(); |
|
52 |
d.el = divs[i]; |
|
53 |
d.ht = baseheight.substring(0, baseheight.indexOf("p")); |
|
54 |
||
55 |
// store our saved version |
|
56 |
divheights[i] = d; |
|
57 |
} |
|
58 |
} |
|
59 |
||
60 |
// this is one of our divs, it just has a DOM reference to the element and the original height |
|
61 |
function div(_el, _ht) |
|
62 |
{ |
|
63 |
this.el = _el; |
|
64 |
this.ht = _ht; |
|
65 |
} |
|
66 |
||
67 |
function toggle(t) |
|
68 |
{ |
|
69 |
if(IE) |
|
70 |
return false; |
|
57
b354deeaa4c4
Vastly improved compatibility with older versions of IE, particularly 5.0, through the use of a kill switch that turns off all AJAX functions
Dan
parents:
1
diff
changeset
|
71 |
if ( KILL_SWITCH ) |
b354deeaa4c4
Vastly improved compatibility with older versions of IE, particularly 5.0, through the use of a kill switch that turns off all AJAX functions
Dan
parents:
1
diff
changeset
|
72 |
return false; |
1 | 73 |
if ( !sliders_initted ) |
74 |
initSliders(); |
|
75 |
// reset our inertia base and interval |
|
76 |
inertiabase = inertiabaseoriginal; |
|
77 |
clearInterval(slideinterval); |
|
78 |
||
79 |
// get our block |
|
80 |
block = t.parentNode.nextSibling; |
|
81 |
||
82 |
// for mozilla, it doesn't like whitespace between elements |
|
83 |
if(block.className == undefined) |
|
84 |
block = t.parentNode.nextSibling.nextSibling; |
|
85 |
||
86 |
if(block.style.display == "none") |
|
87 |
{ |
|
88 |
block.style.display = "block"; |
|
89 |
block.style.height = "1px"; |
|
90 |
||
91 |
// our goal and current height |
|
92 |
targetheight = divheight(block); |
|
93 |
heightnow = 1; |
|
94 |
||
95 |
// remember toggled state |
|
96 |
cookieName = 'mdgSliderState_'+block.metaid; // t.innerHTML.replace(' ', '_'); |
|
97 |
createCookie(cookieName, 'open', 3650); |
|
98 |
||
99 |
// our interval |
|
100 |
slideinterval = setInterval(slideout, slideintervalinc); |
|
101 |
} |
|
102 |
else |
|
103 |
{ |
|
104 |
// our goal and current height |
|
105 |
targetheight = 1; |
|
106 |
heightnow = divheight(block); |
|
107 |
||
108 |
// remember toggled state |
|
109 |
cookieName = 'mdgSliderState_'+block.metaid; // t.innerHTML.replace(' ', '_'); |
|
110 |
createCookie(cookieName, 'closed', 3650); |
|
111 |
||
112 |
// our interval |
|
113 |
slideinterval = setInterval(slidein, slideintervalinc); |
|
114 |
} |
|
115 |
} |
|
116 |
||
117 |
// this is our slidein function the interval uses, it keeps subtracting |
|
118 |
// from the height till it's 1px then it hides it |
|
119 |
function slidein() |
|
120 |
{ |
|
121 |
if(heightnow > targetheight) |
|
122 |
{ |
|
123 |
// reduce the height by intertiabase * inertiainc |
|
124 |
heightnow -= inertiabase; |
|
125 |
||
126 |
// increase the intertiabase by the amount to keep it changing |
|
127 |
inertiabase += inertiainc; |
|
128 |
||
129 |
// it's possible to exceed the height we want so we use a ternary - (condition) ? when true : when false; |
|
130 |
block.style.height = (heightnow > 1) ? heightnow + "px" : targetheight + "px"; |
|
131 |
} |
|
132 |
else |
|
133 |
{ |
|
134 |
// finished, so hide the div properly and kill the interval |
|
135 |
clearInterval(slideinterval); |
|
136 |
block.style.display = "none"; |
|
137 |
} |
|
138 |
} |
|
139 |
||
140 |
// this is the function our slideout interval uses, it keeps adding |
|
141 |
// to the height till it's fully displayed |
|
142 |
function slideout() |
|
143 |
{ |
|
144 |
block.style.display = 'block'; |
|
145 |
if(heightnow < targetheight) |
|
146 |
{ |
|
147 |
// increases the height by the inertia stuff |
|
148 |
heightnow += inertiabase; |
|
149 |
||
150 |
// increase the inertia stuff |
|
151 |
inertiabase += inertiainc; |
|
152 |
||
153 |
// it's possible to exceed the height we want so we use a ternary - (condition) ? when true : when false; |
|
154 |
block.style.height = (heightnow < targetheight) ? heightnow + "px" : targetheight + "px"; |
|
155 |
||
156 |
} |
|
157 |
else |
|
158 |
{ |
|
159 |
// finished, so make sure the height is what it's meant to be (inertia can make it off a little) |
|
160 |
// then kill the interval |
|
161 |
clearInterval(slideinterval); |
|
162 |
block.style.height = targetheight + "px"; |
|
163 |
} |
|
164 |
} |
|
165 |
||
166 |
// returns the height of the div from our array of such things |
|
167 |
function divheight(d) |
|
168 |
{ |
|
169 |
for(var i=0; i<divheights.length; i++) |
|
170 |
{ |
|
171 |
if(divheights[i].el == d) |
|
172 |
{ |
|
173 |
return divheights[i].ht; |
|
174 |
} |
|
175 |
} |
|
176 |
} |
|
177 |
||
178 |
/* |
|
179 |
the getElementsByClassName function I pilfered from this guy. It's |
|
180 |
a useful function that'll return any/all tags with a specific css class. |
|
181 |
||
182 |
Written by Jonathan Snook, http://www.snook.ca/jonathan |
|
183 |
Add-ons by Robert Nyman, http://www.robertnyman.com |
|
184 |
||
185 |
Modified to match all elements that match the class name plus an integer after the name |
|
186 |
This is used in Enano to allow sliding sidebar widgets that use their own CSS |
|
187 |
*/ |
|
188 |
function getElementsByClassName(oElm, strTagName, strClassName) |
|
189 |
{ |
|
190 |
// first it gets all of the specified tags |
|
191 |
var arrElements = (strTagName == "*" && document.all) ? document.all : oElm.getElementsByTagName(strTagName); |
|
192 |
||
193 |
// then it sets up an array that'll hold the results |
|
194 |
var arrReturnElements = new Array(); |
|
195 |
||
196 |
// some regex stuff you don't need to worry about |
|
197 |
strClassName = strClassName.replace(/\-/g, "\\-"); |
|
198 |
||
199 |
var oRegExp = new RegExp("(^|\\s)" + strClassName + "([0-9]*)(\\s|$)"); |
|
200 |
var oElement; |
|
201 |
||
202 |
// now it iterates through the elements it grabbed above |
|
203 |
for(var i=0; i<arrElements.length; i++) |
|
204 |
{ |
|
205 |
oElement = arrElements[i]; |
|
206 |
||
207 |
// if the class matches what we're looking for it ads to the results array |
|
208 |
if(oElement.className.match(oRegExp)) |
|
209 |
{ |
|
210 |
arrReturnElements.push(oElement); |
|
211 |
} |
|
212 |
} |
|
213 |
||
214 |
// then it kicks the results back to us |
|
215 |
return (arrReturnElements) |
|
216 |
} |
|
217 |