1 |
dpavlin |
570 |
/* |
2 |
|
|
simple yet powerful implementation of show/hide effect |
3 |
|
|
with history navigation (back/forward/default) |
4 |
|
|
|
5 |
|
|
Dobrica Pavlinusic <dpavlin@rot13.org> 2004-09-12 |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
var changed_display_ids = []; |
9 |
|
|
var changed_display_pos = 0; |
10 |
|
|
var id_cache = []; |
11 |
|
|
|
12 |
|
|
var debug_on = true; |
13 |
|
|
function debug(text) { |
14 |
|
|
if (debug_on) debug_on = confirm(text); |
15 |
|
|
} |
16 |
|
|
|
17 |
|
|
function element_id(id) { |
18 |
|
|
//debug("id: "+id); |
19 |
dpavlin |
577 |
|
20 |
dpavlin |
570 |
if (id_cache[id]) { |
21 |
|
|
//debug("from cache "+id+" == "+id_cache[id]); |
22 |
|
|
return id_cache[id]; |
23 |
|
|
} else { |
24 |
|
|
var el = self.document.getElementById(id); |
25 |
|
|
//debug("getElementById("+id+") == "+el); |
26 |
|
|
if (el) { |
27 |
|
|
id_cache[id] = el; |
28 |
|
|
return el; |
29 |
|
|
} |
30 |
|
|
//} else debug("can't find element "+id); |
31 |
|
|
} |
32 |
|
|
return null; |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
function toggle_display(name,dont_save) { |
36 |
|
|
var el = element_id(name); |
37 |
|
|
if (el) { |
38 |
|
|
//debug("toggle "+name+" == "+el.id+" current: '"+el.style.display+"'"); |
39 |
|
|
|
40 |
|
|
if (el.style.display=='none') |
41 |
|
|
el.style.display = ''; |
42 |
|
|
else |
43 |
|
|
el.style.display = 'none'; |
44 |
|
|
|
45 |
|
|
if (! dont_save) changed_display_ids[changed_display_pos++] = name; |
46 |
|
|
} |
47 |
|
|
|
48 |
dpavlin |
577 |
// if in iframe, ask parent to resize me |
49 |
|
|
if (parent.iframe_resize) parent.iframe_resize(self.name); |
50 |
|
|
|
51 |
dpavlin |
570 |
return false; |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
function default_display() { |
55 |
|
|
if (changed_display_pos == 0) return null; |
56 |
|
|
|
57 |
|
|
for (var i = 0; i < changed_display_pos; i++) { |
58 |
|
|
toggle_display( changed_display_ids[i], 1 ); |
59 |
|
|
} |
60 |
|
|
changed_display_pos = 0; |
61 |
|
|
return false; |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
function back_display() { |
65 |
|
|
if (changed_display_pos == 0) { |
66 |
|
|
return; |
67 |
|
|
} |
68 |
|
|
toggle_display( changed_display_ids[--changed_display_pos], 1 ); |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
function forward_display() { |
72 |
|
|
if (changed_display_pos == changed_display_ids.length) { |
73 |
|
|
return; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
toggle_display( changed_display_ids[changed_display_pos++], 1 ); |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
function reset_changed() { |
80 |
|
|
changed_display_ids.length = 0; |
81 |
|
|
changed_display_pos = 0; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
function set_display(name,display) { |
85 |
|
|
var el = element_id(name); |
86 |
|
|
|
87 |
|
|
if (el) el.style.display = display |
88 |
|
|
else alert("can't set_display("+name+","+display+")"); |
89 |
|
|
|
90 |
|
|
return false; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
function show_display(show) { |
94 |
|
|
for (var i = 0; i < show.length; i++) { |
95 |
|
|
set_display(show[i],''); |
96 |
|
|
} |
97 |
|
|
reset_changed(); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
function hide_display(hide) { |
101 |
|
|
for (var i = 0; i < hide.length; i++) { |
102 |
|
|
set_display(hide[i],'none'); |
103 |
|
|
} |
104 |
|
|
reset_changed(); |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
function show_hide_display(show,hide) { |
108 |
|
|
show_display(show); |
109 |
|
|
hide_display(hide); |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
function outline_display(name) { |
113 |
|
|
|
114 |
|
|
var el = element_id(name); |
115 |
|
|
|
116 |
|
|
//debug("outline "+name); |
117 |
|
|
|
118 |
|
|
if (el) { |
119 |
|
|
el.style.backgroundColor = "#ffff66"; |
120 |
|
|
//el.style.border = "1px dashed #c0c0c0"; |
121 |
|
|
|
122 |
|
|
if (el.style.display=='none') toggle_display(el.id); |
123 |
|
|
|
124 |
|
|
// recursivly show elements to root |
125 |
|
|
while (el.parentNode) { |
126 |
|
|
el=el.parentNode; |
127 |
|
|
if (el.style && el.style.display=='none') toggle_display(el.id); |
128 |
|
|
} |
129 |
|
|
} |
130 |
|
|
} |