2 |
2 |
3 var userpage_blocks = []; |
3 var userpage_blocks = []; |
4 |
4 |
5 var userpage_onload = function() |
5 var userpage_onload = function() |
6 { |
6 { |
7 var wrapper = document.getElementById('userpage_wrap'); |
7 var wrapper = document.getElementById('userpage_wrap'); |
8 var links = document.getElementById('userpage_links'); |
8 var links = document.getElementById('userpage_links'); |
9 |
9 |
10 if ( !wrapper ) |
10 if ( !wrapper ) |
11 return false; |
11 return false; |
12 |
12 |
13 wrapper.className = 'userpage_wrap'; |
13 wrapper.className = 'userpage_wrap'; |
14 links.className = 'userpage_links'; |
14 links.className = 'userpage_links'; |
15 |
15 |
16 var blocks = wrapper.getElementsByTagName('div'); |
16 var blocks = wrapper.getElementsByTagName('div'); |
17 var first_block = false; |
17 var first_block = false; |
18 for ( var i = 0; i < blocks.length; i++ ) |
18 for ( var i = 0; i < blocks.length; i++ ) |
19 { |
19 { |
20 var block = blocks[i]; |
20 var block = blocks[i]; |
21 if ( /^tab:/.test(block.id) ) |
21 if ( /^tab:/.test(block.id) ) |
22 { |
22 { |
23 $dynano(block).addClass('userpage_block'); |
23 $dynano(block).addClass('userpage_block'); |
24 var block_id = block.id.substr(4); |
24 var block_id = block.id.substr(4); |
25 userpage_blocks.push(block_id); |
25 userpage_blocks.push(block_id); |
26 if ( !first_block ) |
26 if ( !first_block ) |
27 { |
27 { |
28 // this is the first block on the page, memorize it |
28 // this is the first block on the page, memorize it |
29 first_block = block_id; |
29 first_block = block_id; |
30 } |
30 } |
31 } |
31 } |
32 } |
32 } |
33 // init links |
33 // init links |
34 var as = links.getElementsByTagName('a'); |
34 var as = links.getElementsByTagName('a'); |
35 for ( var i = 0; i < as.length; i++ ) |
35 for ( var i = 0; i < as.length; i++ ) |
36 { |
36 { |
37 var a = as[i]; |
37 var a = as[i]; |
38 if ( a.href.indexOf('#') > -1 ) |
38 if ( a.href.indexOf('#') > -1 ) |
39 { |
39 { |
40 var hash = a.href.substr(a.href.indexOf('#')); |
40 var hash = a.href.substr(a.href.indexOf('#')); |
41 var blockid = hash.substr(5); |
41 var blockid = hash.substr(5); |
42 a.blockid = blockid; |
42 a.blockid = blockid; |
43 a.onclick = function() |
43 a.onclick = function() |
44 { |
44 { |
45 userpage_select_block(this.blockid); |
45 userpage_select_block(this.blockid); |
46 return false; |
46 return false; |
47 } |
47 } |
48 a.id = 'userpage_blocklink_' + blockid; |
48 a.id = 'userpage_blocklink_' + blockid; |
49 } |
49 } |
50 } |
50 } |
51 if ( $_REQUEST['tab'] ) |
51 if ( $_REQUEST['tab'] ) |
52 { |
52 { |
53 userpage_select_block($_REQUEST['tab'], true); |
53 userpage_select_block($_REQUEST['tab'], true); |
54 } |
54 } |
55 else |
55 else |
56 { |
56 { |
57 userpage_select_block(first_block, true); |
57 userpage_select_block(first_block, true); |
58 } |
58 } |
59 } |
59 } |
60 |
60 |
61 addOnloadHook(userpage_onload); |
61 addOnloadHook(userpage_onload); |
62 |
62 |
63 /** |
63 /** |
66 * @param bool If true, omits transition effects. |
66 * @param bool If true, omits transition effects. |
67 */ |
67 */ |
68 |
68 |
69 function userpage_select_block(block, nofade) |
69 function userpage_select_block(block, nofade) |
70 { |
70 { |
71 // memorize existing scroll position, reset the hash, then scroll back to where we were |
71 // memorize existing scroll position, reset the hash, then scroll back to where we were |
72 // a little hackish and might cause a flash, but it's better than hiding the tabs on each click |
72 // a little hackish and might cause a flash, but it's better than hiding the tabs on each click |
73 var currentScroll = getScrollOffset(); |
73 var currentScroll = getScrollOffset(); |
74 |
74 |
75 var current_block = false; |
75 var current_block = false; |
76 nofade = true; |
76 nofade = true; |
77 for ( var i = 0; i < userpage_blocks.length; i++ ) |
77 for ( var i = 0; i < userpage_blocks.length; i++ ) |
78 { |
78 { |
79 var div = document.getElementById('tab:' + userpage_blocks[i]); |
79 var div = document.getElementById('tab:' + userpage_blocks[i]); |
80 if ( div ) |
80 if ( div ) |
81 { |
81 { |
82 if ( div.style.display != 'none' ) |
82 if ( div.style.display != 'none' ) |
83 { |
83 { |
84 current_block = userpage_blocks[i]; |
84 current_block = userpage_blocks[i]; |
85 if ( nofade || aclDisableTransitionFX ) |
85 if ( nofade || aclDisableTransitionFX ) |
86 { |
86 { |
87 div.style.display = 'none'; |
87 div.style.display = 'none'; |
88 } |
88 } |
89 } |
89 } |
90 } |
90 } |
91 var a = document.getElementById('userpage_blocklink_' + userpage_blocks[i]); |
91 var a = document.getElementById('userpage_blocklink_' + userpage_blocks[i]); |
92 if ( a ) |
92 if ( a ) |
93 { |
93 { |
94 if ( $dynano(a.parentNode).hasClass('userpage_tab_active') ) |
94 if ( $dynano(a.parentNode).hasClass('userpage_tab_active') ) |
95 { |
95 { |
96 $dynano(a.parentNode).rmClass('userpage_tab_active'); |
96 $dynano(a.parentNode).rmClass('userpage_tab_active'); |
97 } |
97 } |
98 } |
98 } |
99 } |
99 } |
100 if ( nofade || !current_block || aclDisableTransitionFX ) |
100 if ( nofade || !current_block || aclDisableTransitionFX ) |
101 { |
101 { |
102 var div = document.getElementById('tab:' + block); |
102 var div = document.getElementById('tab:' + block); |
103 div.style.display = 'block'; |
103 div.style.display = 'block'; |
104 } |
104 } |
105 else |
105 else |
106 { |
106 { |
107 // DISABLED: see "nofade = true;" above. |
107 // DISABLED: see "nofade = true;" above. |
108 // do this in a slightly fancier fashion |
108 // do this in a slightly fancier fashion |
109 load_component(['jquery', 'jquery-ui']); |
109 load_component(['jquery', 'jquery-ui']); |
110 $('#tab:' + current_block).hide("blind", {}, 500, function() |
110 $('#tab:' + current_block).hide("blind", {}, 500, function() |
111 { |
111 { |
112 $('#tab:' + block).show("blind", {}, 500); |
112 $('#tab:' + block).show("blind", {}, 500); |
113 }); |
113 }); |
114 } |
114 } |
115 var a = document.getElementById('userpage_blocklink_' + block); |
115 var a = document.getElementById('userpage_blocklink_' + block); |
116 $dynano(a.parentNode).addClass('userpage_tab_active'); |
116 $dynano(a.parentNode).addClass('userpage_tab_active'); |
117 |
117 |
118 window.location.hash = 'tab:' + block; |
118 window.location.hash = 'tab:' + block; |
119 setScrollOffset(currentScroll); |
119 setScrollOffset(currentScroll); |
120 } |
120 } |