3 // our global vars |
3 // our global vars |
4 // the delay between the slide in/out, and a little inertia |
4 // the delay between the slide in/out, and a little inertia |
5 |
5 |
6 /* |
6 /* |
7 pseudocode: |
7 pseudocode: |
8 oninit(): |
8 oninit(): |
9 i = 0 |
9 i = 0 |
10 for every div with class "slideblock", do |
10 for every div with class "slideblock", do |
11 if ( cookie['mdgSliderState_' || i] == 'closed' ) |
11 if ( cookie['mdgSliderState_' || i] == 'closed' ) |
12 div.hide() |
12 div.hide() |
13 |
13 |
14 div.trigger.addEvent onclick(): |
14 div.trigger.addEvent onclick(): |
15 if ( div.hidden ) |
15 if ( div.hidden ) |
16 div.show() |
16 div.show() |
17 cookie['mdgSliderState_' || i] = 'open' |
17 cookie['mdgSliderState_' || i] = 'open' |
18 else |
18 else |
19 div.hide() |
19 div.hide() |
20 cookie['mdgSliderState_' || i] = 'closed |
20 cookie['mdgSliderState_' || i] = 'closed |
21 |
21 |
22 i++ |
22 i++ |
23 |
23 |
24 */ |
24 */ |
25 |
25 |
26 |
26 |
27 var sliders_initted = false; |
27 var sliders_initted = false; |
28 |
28 |
29 var initSliders = function() |
29 var initSliders = function() |
30 { |
30 { |
31 if ( KILL_SWITCH || IE ) |
31 if ( KILL_SWITCH || IE ) |
32 return false; |
32 return false; |
33 |
33 |
34 var divs = getElementsByClassName(document, "div", "slideblock"); |
34 var divs = getElementsByClassName(document, "div", "slideblock"); |
35 var divs2 = getElementsByClassName(document, "div", "slideblock2"); |
35 var divs2 = getElementsByClassName(document, "div", "slideblock2"); |
36 for ( var i = 0; i < divs2.length; i++ ) |
36 for ( var i = 0; i < divs2.length; i++ ) |
37 { |
37 { |
38 divs.push(divs2[i]); |
38 divs.push(divs2[i]); |
39 } |
39 } |
40 delete divs2; |
40 delete divs2; |
41 |
41 |
42 if ( divs.length < 1 ) |
42 if ( divs.length < 1 ) |
43 return false; |
43 return false; |
44 |
44 |
45 for ( var i = 0; i < divs.length; i++ ) |
45 for ( var i = 0; i < divs.length; i++ ) |
46 { |
46 { |
47 var div = divs[i]; |
47 var div = divs[i]; |
48 // set a unique id for this slider |
48 // set a unique id for this slider |
49 div.metaid = i; |
49 div.metaid = i; |
50 |
50 |
51 var cookiename = 'mdgSliderState_' + i; |
51 var cookiename = 'mdgSliderState_' + i; |
52 if ( readCookie(cookiename) == 'closed' ) |
52 if ( readCookie(cookiename) == 'closed' ) |
53 { |
53 { |
54 div.style.display = 'none'; |
54 div.style.display = 'none'; |
55 } |
55 } |
56 |
56 |
57 var el = div.previousSibling; |
57 var el = div.previousSibling; |
58 if ( !el ) |
58 if ( !el ) |
59 continue; |
59 continue; |
60 while ( el.tagName == undefined ) |
60 while ( el.tagName == undefined ) |
61 { |
61 { |
62 el = el.previousSibling; |
62 el = el.previousSibling; |
63 if ( !el ) |
63 if ( !el ) |
64 break; |
64 break; |
65 } |
65 } |
66 if ( !el ) |
66 if ( !el ) |
67 continue; |
67 continue; |
68 var toggler = el.getElementsByTagName('a')[0]; |
68 var toggler = el.getElementsByTagName('a')[0]; |
69 if ( !toggler ) |
69 if ( !toggler ) |
70 continue; |
70 continue; |
71 toggler.onclick = function() |
71 toggler.onclick = function() |
72 { |
72 { |
73 load_component(['jquery', 'jquery-ui']); |
73 load_component(['jquery', 'jquery-ui']); |
74 |
74 |
75 var mydiv = this.parentNode.nextSibling; |
75 var mydiv = this.parentNode.nextSibling; |
76 while ( mydiv.tagName != 'DIV' ) |
76 while ( mydiv.tagName != 'DIV' ) |
77 mydiv = mydiv.nextSibling; |
77 mydiv = mydiv.nextSibling; |
78 if ( mydiv.style.display == 'none' ) |
78 if ( mydiv.style.display == 'none' ) |
79 { |
79 { |
80 $(mydiv).show('blind'); |
80 $(mydiv).show('blind'); |
81 var cookiename = 'mdgSliderState_' + mydiv.metaid; |
81 var cookiename = 'mdgSliderState_' + mydiv.metaid; |
82 createCookie(cookiename, 'open', 365); |
82 createCookie(cookiename, 'open', 365); |
83 } |
83 } |
84 else |
84 else |
85 { |
85 { |
86 $(mydiv).hide('blind'); |
86 $(mydiv).hide('blind'); |
87 var cookiename = 'mdgSliderState_' + mydiv.metaid; |
87 var cookiename = 'mdgSliderState_' + mydiv.metaid; |
88 createCookie(cookiename, 'closed', 365); |
88 createCookie(cookiename, 'closed', 365); |
89 } |
89 } |
90 |
90 |
91 return false; |
91 return false; |
92 } |
92 } |
93 } |
93 } |
94 } |
94 } |
95 |
95 |
96 addOnloadHook(initSliders); |
96 addOnloadHook(initSliders); |
97 |
97 |