|
|
| (15 intermediate revisions by 3 users not shown) |
| Line 1: |
Line 1: |
| /** Collapsible tables ********************************************************* | | // Gadgets |
| *
| | |
| * Description: Allows tables to be collapsed, showing only the header. See | | //syntax highlighter |
| * http://www.mediawiki.org/wiki/Manual:Collapsible_tables.
| | mw.loader.load('//www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-DotsSyntaxHighlighter.js&action=raw&ctype=text/javascript'); |
| * Maintainers: [[en:User:R. Koot]]
| | |
| */
| | /* For Favicon */ |
|
| | jQuery("<link>", { |
| var autoCollapse = 2;
| | rel: "shortcut icon", |
| var collapseCaption = 'hide';
| | type: "image/x-icon", |
| var expandCaption = 'show';
| | href: "https://linguifex.com/assets/Linguifex4v1.png" |
|
| | }).appendTo("head"); |
| function collapseTable( tableIndex ) {
| |
| var Button = document.getElementById( 'collapseButton' + tableIndex );
| |
| var Table = document.getElementById( 'collapsibleTable' + tableIndex );
| |
|
| |
| if ( !Table || !Button ) {
| |
| return false;
| |
| }
| |
|
| |
| var Rows = Table.rows;
| |
|
| |
| if ( Button.firstChild.data == collapseCaption ) {
| |
| for ( var i = 1; i < Rows.length; i++ ) {
| |
| Rows[i].style.display = 'none';
| |
| }
| |
| Button.firstChild.data = expandCaption;
| |
| } else {
| |
| for ( var i = 1; i < Rows.length; i++ ) {
| |
| Rows[i].style.display = Rows[0].style.display;
| |
| }
| |
| Button.firstChild.data = collapseCaption;
| |
| }
| |
| }
| |
|
| |
| function createCollapseButtons() {
| |
| var tableIndex = 0;
| |
| var NavigationBoxes = new Object();
| |
| var Tables = document.getElementsByTagName( 'table' );
| |
|
| |
| for ( var i = 0; i < Tables.length; i++ ) {
| |
| if ( hasClass( Tables[i], 'collapsible' ) ) {
| |
|
| |
| /* only add button and increment count if there is a header row to work with */
| |
| var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
| |
| if ( !HeaderRow ) {
| |
| continue;
| |
| }
| |
| var Header = HeaderRow.getElementsByTagName( 'th' )[0];
| |
| if ( !Header ) {
| |
| continue;
| |
| }
| |
|
| |
| NavigationBoxes[tableIndex] = Tables[i];
| |
| Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
| |
|
| |
| var Button = document.createElement( 'span' );
| |
| var ButtonLink = document.createElement( 'a' );
| |
| var ButtonText = document.createTextNode( collapseCaption );
| |
|
| |
| Button.className = 'collapseButton'; // Styles are declared in [[MediaWiki:Common.css]]
| |
|
| |
| ButtonLink.style.color = Header.style.color;
| |
| ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
| |
| ButtonLink.setAttribute( 'href', "javascript:collapseTable(" + tableIndex + ");" );
| |
| ButtonLink.appendChild( ButtonText );
| |
|
| |
| Button.appendChild( document.createTextNode( '[' ) );
| |
| Button.appendChild( ButtonLink );
| |
| Button.appendChild( document.createTextNode( ']' ) );
| |
|
| |
| Header.insertBefore( Button, Header.childNodes[0] );
| |
| tableIndex++;
| |
| }
| |
| }
| |
|
| |
| for ( var i = 0; i < tableIndex; i++ ) {
| |
| if ( hasClass( NavigationBoxes[i], 'collapsed' ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], 'autocollapse' ) ) ) {
| |
| collapseTable( i );
| |
| } else if ( hasClass( NavigationBoxes[i], 'innercollapse' ) ) {
| |
| var element = NavigationBoxes[i];
| |
| while ( element = element.parentNode ) {
| |
| if ( hasClass( element, 'outercollapse' ) ) {
| |
| collapseTable( i );
| |
| break;
| |
| }
| |
| }
| |
| }
| |
| }
| |
| }
| |
|
| |
| addOnloadHook( createCollapseButtons );
| |
|
| |
|
| var NavigationBarHide = 'hide ▲';var NavigationBarShow = 'show ▼'; function NavToggleCategory(navFrame){ var table = navFrame.getElementsByTagName('table')[0]; if (table && table.className == "translations") return "translations"; var heading = navFrame.previousSibling; while (heading) { if (/[hH][4-6]/.test(heading.nodeName)) { if (heading.getElementsByTagName('span')[1]) heading = heading.getElementsByTagName('span')[1]; else heading = heading.getElementsByTagName('span')[0]; return $(heading).text().toLowerCase() // jQuery's .text() is inconsistent about whitespace: .replace(/^\s+|\s+$/g, '').replace(/\s+/g, ' ') // remove numbers added by the "Auto-number headings" pref: .replace(/^[1-9][0-9.]+ ?/, ''); } else if (/[hH][1-3]/.test(heading.nodeName)) break; heading = heading.previousSibling; } return "other boxes";};function createNavToggle(navFrame){ var navHead, navToggle, navContent; for (var j=0; j < navFrame.childNodes.length; j++) { var div = navFrame.childNodes[j]; switch (div.className) { case 'NavHead': navHead = div; break; case 'NavContent': navContent = div; break; } } if (!navHead || !navContent) return; // Step 1, don't react when a subitem is clicked. for (var i=0; i<navHead.childNodes.length; i++) { var child = navHead.childNodes[i]; if (child.nodeName == "A") { child.onclick = function (e) { if (e && e.stopPropagation) e.stopPropagation(); else window.event.cancelBubble = true; } } } // Step 2, toggle visibility when bar is clicked. // NOTE This function was chosen due to some funny behaviour in Safari. navToggle = newNode('a', {href: 'javascript:(function(){})()'}, ''); navHead.insertBefore(newNode('span', {'class': 'NavToggle'}, '[', navToggle, ']'), navHead.firstChild); navHead.style.cursor = "pointer"; navHead.onclick = VisibilityToggles.register(NavToggleCategory(navFrame), function show() { navToggle.innerHTML = NavigationBarHide; if (navContent) navContent.style.display = "block"; }, function hide() { navToggle.innerHTML = NavigationBarShow; if (navContent) navContent.style.display = "none"; });}; addOnloadHook( function (){ var divs = $(".NavFrame"); for (var i=0; i<divs.length; i++) { // NOTE: some templates use a class of NavFrame for the style, but for legacy reasons, are not NavFrames if (divs[i].className == "NavFrame") { createNavToggle(divs[i]); } } });
| |
|
| |
| /** Test if an element has a certain class ************************************** | | /** Test if an element has a certain class ************************************** |
| * | | * |
| Line 106: |
Line 24: |
| })(); | | })(); |
|
| |
|
| /* For Favicon */ | | mw.loader.using( [ 'mediawiki.util' ] ).done( function () { |
| <!-- document.write("<link rel='shortcut icon' href='http://conlang.wikkii.com/w/images/conlang/uploads/2/26/Favicon.png' type='image/x-icon'>"); -->
| | /* Begin of mw.loader.using callback */ |
| | /** |
| | * Collapsible tables; reimplemented with mw-collapsible |
| | * Styling is also in place to avoid FOUC |
| | * |
| | * Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]]. |
| | * @version 3.0.0 (2018-05-20) |
| | * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js |
| | * @author [[User:R. Koot]] |
| | * @author [[User:Krinkle]] |
| | * @author [[User:TheDJ]] |
| | * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which |
| | * is supported in MediaWiki core. Shimmable since MediaWiki 1.32 |
| | * |
| | * @param {jQuery} $content |
| | */ |
| | function makeCollapsibleMwCollapsible( $content ) { |
| | var $tables = $content |
| | .find( 'table.collapsible:not(.mw-collapsible)' ) |
| | .addClass( 'mw-collapsible' ); |
| | |
| | $.each( $tables, function ( index, table ) { |
| | // mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.'); |
| | if ( $( table ).hasClass( 'collapsed' ) ) { |
| | $( table ).addClass( 'mw-collapsed' ); |
| | // mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.'); |
| | } |
| | } ); |
| | if ( $tables.length > 0 ) { |
| | mw.loader.using( 'jquery.makeCollapsible' ).then( function () { |
| | $tables.makeCollapsible(); |
| | } ); |
| | } |
| | } |
| | mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible ); |
| | |
| | /** |
| | * Add support to mw-collapsible for autocollapse, innercollapse and outercollapse |
| | * |
| | * Maintainers: TheDJ |
| | */ |
| | function mwCollapsibleSetup( $collapsibleContent ) { |
| | var $element, |
| | $toggle, |
| | autoCollapseThreshold = 2; |
| | $.each( $collapsibleContent, function ( index, element ) { |
| | $element = $( element ); |
| | if ( $element.hasClass( 'collapsible' ) ) { |
| | $element.find( 'tr:first > th:first' ).prepend( $element.find( 'tr:first > * > .mw-collapsible-toggle' ) ); |
| | } |
| | if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) { |
| | $element.data( 'mw-collapsible' ).collapse(); |
| | } else if ( $element.hasClass( 'innercollapse' ) ) { |
| | if ( $element.parents( '.outercollapse' ).length > 0 ) { |
| | $element.data( 'mw-collapsible' ).collapse(); |
| | } |
| | } |
| | // because of colored backgrounds, style the link in the text color |
| | // to ensure accessible contrast |
| | $toggle = $element.find( '.mw-collapsible-toggle' ); |
| | if ( $toggle.length ) { |
| | // Make the toggle inherit text color (Updated for T333357 2023-04-29) |
| | if ( $toggle.parent()[ 0 ].style.color ) { |
| | $toggle.css( 'color', 'inherit' ); |
| | $toggle.find( '.mw-collapsible-text' ).css( 'color', 'inherit' ); |
| | } |
| | } |
| | } ); |
| | } |
| | |
| | mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup ); |
| | }); |