author | Dan |
Fri, 22 May 2009 13:49:02 -0400 | |
changeset 1001 | 79770fb4132a |
parent 699 | c7d737202d59 |
child 1227 | bdac73ed481e |
permissions | -rw-r--r-- |
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
1 |
/* |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
2 |
* Expandable fieldsets |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
3 |
*/ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
4 |
|
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
5 |
var expander_onload = function() |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
6 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
7 |
var sets = document.getElementsByTagName('fieldset'); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
8 |
if ( sets.length < 1 ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
9 |
return false; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
10 |
var init_us = []; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
11 |
for ( var index = 0; index < sets.length; index++ ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
12 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
13 |
var mode = sets[index].getAttribute('enano:expand'); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
14 |
if ( mode == 'closed' || mode == 'open' ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
15 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
16 |
init_us.push(sets[index]); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
17 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
18 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
19 |
for ( var k = 0; k < init_us.length; k++ ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
20 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
21 |
expander_init_element(init_us[k]); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
22 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
23 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
24 |
|
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
25 |
function expander_init_element(el) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
26 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
27 |
// get the legend tag |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
28 |
var legend = el.getElementsByTagName('legend')[0]; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
29 |
if ( !legend ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
30 |
return false; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
31 |
// existing content |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
32 |
var existing_inner = legend.innerHTML; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
33 |
// blank the innerHTML and replace it with a link |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
34 |
legend.innerHTML = ''; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
35 |
var button = document.createElement('a'); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
36 |
button.className = 'expander expander-open'; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
37 |
button.innerHTML = existing_inner; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
38 |
button.href = '#'; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
39 |
|
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
40 |
legend.appendChild(button); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
41 |
|
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
42 |
button.onclick = function() |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
43 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
44 |
try |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
45 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
46 |
expander_handle_click(this); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
47 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
48 |
catch(e) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
49 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
50 |
console.debug('Exception caught: ', e); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
51 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
52 |
return false; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
53 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
54 |
|
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
55 |
if ( el.getAttribute('enano:expand') == 'closed' ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
56 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
57 |
expander_close(el); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
58 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
59 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
60 |
|
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
61 |
function expander_handle_click(el) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
62 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
63 |
if ( el.parentNode.parentNode.tagName != 'FIELDSET' ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
64 |
return false; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
65 |
var parent = el.parentNode.parentNode; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
66 |
if ( parent.getAttribute('enano:expand') == 'closed' ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
67 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
68 |
expander_open(parent); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
69 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
70 |
else |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
71 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
72 |
expander_close(parent); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
73 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
74 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
75 |
|
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
76 |
function expander_close(el) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
77 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
78 |
var children = el.childNodes; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
79 |
for ( var i = 0; i < children.length; i++ ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
80 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
81 |
var child = children[i]; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
82 |
if ( child.tagName == 'LEGEND' ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
83 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
84 |
var a = child.getElementsByTagName('a')[0]; |
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
582
diff
changeset
|
85 |
$dynano(a).rmClass('expander-open'); |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
582
diff
changeset
|
86 |
$dynano(a).addClass('expander-closed'); |
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
87 |
continue; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
88 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
89 |
if ( child.style ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
90 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
91 |
child.expander_meta_old_state = child.style.display; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
92 |
child.style.display = 'none'; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
93 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
94 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
95 |
el.expander_meta_padbak = el.style.padding; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
96 |
el.setAttribute('enano:expand', 'closed'); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
97 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
98 |
|
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
99 |
function expander_open(el) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
100 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
101 |
var children = el.childNodes; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
102 |
for ( var i = 0; i < children.length; i++ ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
103 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
104 |
var child = children[i]; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
105 |
if ( child.tagName == 'LEGEND' ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
106 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
107 |
var a = child.getElementsByTagName('a')[0]; |
699
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
582
diff
changeset
|
108 |
$dynano(a).rmClass('expander-closed'); |
c7d737202d59
Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents:
582
diff
changeset
|
109 |
$dynano(a).addClass('expander-open'); |
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
110 |
continue; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
111 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
112 |
if ( child.expander_meta_old_state && child.style ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
113 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
114 |
child.style.display = child.expander_meta_old_state; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
115 |
child.expander_meta_old_state = null; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
116 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
117 |
else |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
118 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
119 |
if ( child.style ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
120 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
121 |
child.style.display = null; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
122 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
123 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
124 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
125 |
if ( el.expander_meta_padbak ) |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
126 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
127 |
el.style.padding = el.expander_meta_padbak; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
128 |
el.expander_meta_padbak = null; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
129 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
130 |
else |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
131 |
{ |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
132 |
el.style.padding = null; |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
133 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
134 |
el.setAttribute('enano:expand', 'open'); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
135 |
} |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
136 |
|
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
diff
changeset
|
137 |
addOnloadHook(expander_onload); |