Index: trunk/phase3/skins/common/wikibits.js |
— | — | @@ -136,42 +136,6 @@ |
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
140 | | -window.showTocToggle = function() { |
141 | | - if ( document.createTextNode ) { |
142 | | - // Uses DOM calls to avoid document.write + XHTML issues |
143 | | - |
144 | | - var linkHolder = document.getElementById( 'toctitle' ); |
145 | | - var existingLink = document.getElementById( 'togglelink' ); |
146 | | - if ( !linkHolder || existingLink ) { |
147 | | - // Don't add the toggle link twice |
148 | | - return; |
149 | | - } |
150 | | - |
151 | | - var outerSpan = document.createElement( 'span' ); |
152 | | - outerSpan.className = 'toctoggle'; |
153 | | - |
154 | | - var toggleLink = document.createElement( 'a' ); |
155 | | - toggleLink.id = 'togglelink'; |
156 | | - toggleLink.className = 'internal'; |
157 | | - toggleLink.href = '#'; |
158 | | - addClickHandler( toggleLink, function( evt ) { toggleToc(); return killEvt( evt ); } ); |
159 | | - |
160 | | - toggleLink.appendChild( document.createTextNode( mediaWiki.msg( 'hidetoc' ) ) ); |
161 | | - |
162 | | - outerSpan.appendChild( document.createTextNode( '[' ) ); |
163 | | - outerSpan.appendChild( toggleLink ); |
164 | | - outerSpan.appendChild( document.createTextNode( ']' ) ); |
165 | | - |
166 | | - linkHolder.appendChild( document.createTextNode( ' ' ) ); |
167 | | - linkHolder.appendChild( outerSpan ); |
168 | | - |
169 | | - var cookiePos = document.cookie.indexOf( "hidetoc=" ); |
170 | | - if ( cookiePos > -1 && document.cookie.charAt( cookiePos + 8 ) == 1 ) { |
171 | | - toggleToc(); |
172 | | - } |
173 | | - } |
174 | | -}; |
175 | | - |
176 | 140 | window.changeText = function( el, newText ) { |
177 | 141 | // Safari work around |
178 | 142 | if ( el.innerText ) { |
— | — | @@ -192,25 +156,6 @@ |
193 | 157 | return false; // Don't follow the link (IE) |
194 | 158 | }; |
195 | 159 | |
196 | | -window.toggleToc = function() { |
197 | | - var tocmain = document.getElementById( 'toc' ); |
198 | | - var toc = document.getElementById('toc').getElementsByTagName('ul')[0]; |
199 | | - var toggleLink = document.getElementById( 'togglelink' ); |
200 | | - |
201 | | - if ( toc && toggleLink && toc.style.display == 'none' ) { |
202 | | - changeText( toggleLink, mediaWiki.msg( 'hidetoc' ) ); |
203 | | - toc.style.display = 'block'; |
204 | | - document.cookie = "hidetoc=0"; |
205 | | - tocmain.className = 'toc'; |
206 | | - } else { |
207 | | - changeText( toggleLink, mediaWiki.msg( 'showtoc' ) ); |
208 | | - toc.style.display = 'none'; |
209 | | - document.cookie = "hidetoc=1"; |
210 | | - tocmain.className = 'toc tochidden'; |
211 | | - } |
212 | | - return false; |
213 | | -}; |
214 | | - |
215 | 160 | window.mwEditButtons = []; |
216 | 161 | window.mwCustomEditButtons = []; // eg to add in MediaWiki:Common.js |
217 | 162 | |
— | — | @@ -1099,6 +1044,4 @@ |
1100 | 1045 | |
1101 | 1046 | if ( ie6_bugs ) { |
1102 | 1047 | importScriptURI( stylepath + '/common/IEFixes.js' ); |
1103 | | -} |
1104 | | - |
1105 | | -showTocToggle(); |
| 1048 | +} |
\ No newline at end of file |
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js |
— | — | @@ -15,10 +15,10 @@ |
16 | 16 | // Any initialisation after the DOM is ready |
17 | 17 | $(function () { |
18 | 18 | |
19 | | - // Shortcut |
| 19 | + // Shortcut to client profile return |
20 | 20 | var profile = $.client.profile(); |
21 | 21 | |
22 | | - // Set tooltipAccessKeyPrefix |
| 22 | + /* Set tooltipAccessKeyPrefix */ |
23 | 23 | |
24 | 24 | // Opera on any platform |
25 | 25 | if ( profile.name == 'opera' ) { |
— | — | @@ -49,15 +49,15 @@ |
50 | 50 | mw.util.tooltipAccessKeyPrefix = 'alt-shift-'; |
51 | 51 | } |
52 | 52 | |
53 | | - // Enable CheckboxShiftClick |
| 53 | + /* Enable CheckboxShiftClick */ |
54 | 54 | $( 'input[type=checkbox]:not(.noshiftselect)' ).checkboxShiftClick(); |
55 | 55 | |
56 | | - // Emulate placeholder if not supported by browser |
| 56 | + /* Emulate placeholder if not supported by browser */ |
57 | 57 | if ( !( 'placeholder' in document.createElement( 'input' ) ) ) { |
58 | 58 | $( 'input[placeholder]' ).placeholder(); |
59 | 59 | } |
60 | 60 | |
61 | | - // Fill $content var |
| 61 | + /* Fill $content var */ |
62 | 62 | if ( $( '#bodyContent' ).length ) { |
63 | 63 | mw.util.$content = $( '#bodyContent' ); |
64 | 64 | } else if ( $( '#article' ).length ) { |
— | — | @@ -65,6 +65,25 @@ |
66 | 66 | } else { |
67 | 67 | mw.util.$content = $( '#content' ); |
68 | 68 | } |
| 69 | + |
| 70 | + /* Table of Contents toggle */ |
| 71 | + var $tocContainer = $( '#toc' ), |
| 72 | + $tocTitle = $( '#toctitle' ), |
| 73 | + $tocToggleLink = $( '#togglelink' ); |
| 74 | + // Only add it if there is a TOC and there is no toggle added already |
| 75 | + if ( $tocContainer.size() && $tocTitle.size() && !$tocToggleLink.size() ) { |
| 76 | + var hideTocCookie = $.cookie( 'mw_hidetoc' ), |
| 77 | + $tocToggleLink = $( '<a href="#" class="internal" id="togglelink">' ).text( mw.msg( 'hidetoc' ) ).click( function(e){ |
| 78 | + e.preventDefault(); |
| 79 | + mw.util.toggleToc( $(this) ); |
| 80 | + } ); |
| 81 | + $tocTitle.append( $tocToggleLink.wrap( '<span class="toctoggle">' ).parent().prepend( ' [' ).append( '] ' ) ); |
| 82 | + |
| 83 | + if ( hideTocCookie == '1' ) { |
| 84 | + // Cookie says user want toc hidden |
| 85 | + $tocToggleLink.click(); |
| 86 | + } |
| 87 | + } |
69 | 88 | } ); |
70 | 89 | |
71 | 90 | return true; |
— | — | @@ -118,6 +137,32 @@ |
119 | 138 | }, |
120 | 139 | |
121 | 140 | /** |
| 141 | + * Hide/show the table of contents element |
| 142 | + * |
| 143 | + * @param text String CSS to be appended |
| 144 | + * @return the CSS stylesheet |
| 145 | + */ |
| 146 | + 'toggleToc' : function( $toggleLink ) { |
| 147 | + var $tocList = $( '#toc ul:first' ), |
| 148 | + |
| 149 | + if ( $tocList.is( ':hidden' ) ) { |
| 150 | + $tocList.slideDown( 'fast' ); |
| 151 | + $toggleLink.text( mw.msg( 'hidetoc' ) ); |
| 152 | + $.cookie( 'mw_hidetoc', null, { |
| 153 | + expires: 30, |
| 154 | + path: '/' |
| 155 | + } ); |
| 156 | + } else { |
| 157 | + $tocList.slideUp( 'fast' ); |
| 158 | + $toggleLink.text( mw.msg( 'showtoc' ) ); |
| 159 | + $.cookie( 'mw_hidetoc', '1', { |
| 160 | + expires: 30, |
| 161 | + path: '/' |
| 162 | + } ); |
| 163 | + } |
| 164 | + }, |
| 165 | + |
| 166 | + /** |
122 | 167 | * Get the full URL to a page name |
123 | 168 | * |
124 | 169 | * @param str Page name to link to |
Index: trunk/phase3/resources/Resources.php |
— | — | @@ -350,7 +350,7 @@ |
351 | 351 | ), |
352 | 352 | 'mediawiki.util' => array( |
353 | 353 | 'scripts' => 'resources/mediawiki.util/mediawiki.util.js', |
354 | | - 'dependencies' => array( 'jquery.checkboxShiftClick', 'jquery.client', 'jquery.placeholder', 'jquery.makeCollapsible' ), |
| 354 | + 'dependencies' => array( 'jquery.checkboxShiftClick', 'jquery.client', 'jquery.cookie', 'jquery.placeholder', 'jquery.makeCollapsible' ), |
355 | 355 | 'debugScripts' => 'resources/mediawiki.util/mediawiki.util.test.js', |
356 | 356 | ), |
357 | 357 | 'mediawiki.action.history' => array( |