Sətir 96: |
Sətir 96: |
| } | | } |
| }); | | }); |
− |
| |
− | /* Test if an element has a certain class **************************************
| |
− | *
| |
− | * Description: Uses regular expressions and caching for better performance.
| |
− | * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
| |
− | */
| |
− |
| |
− | var hasClass = (function () {
| |
− | var reCache = {};
| |
− | return function (element, className) {
| |
− | return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
| |
− | };
| |
− | })();
| |
− |
| |
| | | |
| /** Interwiki links to featured articles *************************************** | | /** Interwiki links to featured articles *************************************** |
Sətir 118: |
Sətir 104: |
| * Maintainers: [[User:R. Koot]] | | * Maintainers: [[User:R. Koot]] |
| */ | | */ |
| + | |
| + | /** |
| + | * NAVFRAME |
| + | */ |
| | | |
| //Messages | | //Messages |
Sətir 127: |
Sətir 117: |
| var zeroSectionTip = 'Girişi redaktə et'; | | var zeroSectionTip = 'Girişi redaktə et'; |
| | | |
− | var NavigationBarHide = '[bağla]'; | + | var NavigationBarHide = '[gizlət]'; |
− | var NavigationBarShow = '[bax]'; | + | var NavigationBarShow = '[göstər]'; |
| var NavigationBarShowDefault = 2; | | var NavigationBarShowDefault = 2; |
| | | |
Sətir 162: |
Sətir 152: |
| | | |
| | | |
− | /** Collapsible tables *********************************************************
| + | var NavigationBarShowDefault; |
− | *
| + | if ( typeof NavigationBarShowDefault === 'undefined' ) { |
− | * Description: Allows tables to be collapsed, showing only the header. See
| + | NavigationBarShowDefault = 1; |
− | * [[Wikipedia:NavFrame]].
| + | } |
− | * Maintainers: [[User:R. Koot]]
| + | |
− | */
| + | // table.collapsible |
| + | 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 |
| + | if( $toggle.parent()[0].style.color ) { |
| + | $toggle.find( 'a' ).css( 'color', 'inherit' ); |
| + | } |
| + | } |
| + | } ); |
| + | } |
| + | |
| + | mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup ); |
| + | |
| + | /** |
| + | * Dynamic Navigation Bars (experimental) |
| + | * |
| + | * Description: See [[Wikipedia:NavFrame]]. |
| + | * Maintainers: UNMAINTAINED |
| + | */ |
| | | |
− | var autoCollapse = 2;
| + | var collapseCaption = 'gizlə'; |
− | var collapseCaption = "bağla";
| + | var expandCaption = 'göstər'; |
− | var expandCaption = "bax";
| + | |
− | | + | // Set up the words in your language |
− | function collapseTable( tableIndex ) | + | var navigationBarHide = '[' + collapseCaption + ']'; |
− | {
| + | var navigationBarShow = '[' + expandCaption + ']'; |
− | var Button = document.getElementById( "collapseButton" + tableIndex );
| + | |
− | var Table = document.getElementById( "collapsibleTable" + tableIndex );
| + | /** |
− | var i;
| + | * Shows and hides content and picture (if available) of navigation bars. |
− | if ( !Table || !Button ) {
| + | * |
− | return false;
| + | * @param {number} indexNavigationBar The index of navigation bar to be toggled |
− | }
| + | * @param {jQuery.Event} event Event object |
− |
| + | */ |
− | var Rows = Table.getElementsByTagName( "tr" );
| + | function toggleNavigationBar( indexNavigationBar, event ) { |
− |
| + | var navToggle = document.getElementById( 'NavToggle' + indexNavigationBar ); |
− | if ( Button.firstChild.data == collapseCaption ) {
| + | var navFrame = document.getElementById( 'NavFrame' + indexNavigationBar ); |
− | for ( i = 1; i < Rows.length; i++ ) {
| + | var navChild; |
− | Rows[i].style.display = "none";
| + | |
− | }
| + | if ( !navFrame || !navToggle ) { |
− | Button.firstChild.data = expandCaption;
| + | return false; |
− | } else {
| + | } |
− | for ( i = 1; i < Rows.length; i++ ) {
| + | |
− | Rows[i].style.display = Rows[0].style.display;
| + | // If shown now |
− | }
| + | if ( navToggle.firstChild.data === navigationBarHide ) { |
− | Button.firstChild.data = collapseCaption;
| + | for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) { |
− | }
| + | if ( $( navChild ).hasClass( 'NavContent' ) ) { |
− | } | + | navChild.style.display = 'none'; |
− | | + | } |
− | function createCollapseButtons()
| + | } |
− | {
| + | navToggle.firstChild.data = navigationBarShow; |
− | var tableIndex = 0;
| + | |
− | var NavigationBoxes = {};
| + | // If hidden now |
− | var Tables = document.getElementsByTagName( "table" );
| + | } else if ( navToggle.firstChild.data === navigationBarShow ) { |
− | var i;
| + | for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) { |
− | for ( i = 0; i < Tables.length; i++ ) {
| + | if ( $( navChild ).hasClass( 'NavContent' ) ) { |
− | if ( hasClass( Tables[i], "collapsible" ) ) {
| + | navChild.style.display = 'block'; |
− | NavigationBoxes[ tableIndex ] = Tables[i];
| + | } |
− | Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
| + | } |
− |
| + | navToggle.firstChild.data = navigationBarHide; |
− | var Button = document.createElement( "span" );
| + | } |
− | var ButtonLink = document.createElement( "a" );
| + | |
− | var ButtonText = document.createTextNode( collapseCaption );
| + | event.preventDefault(); |
− | | + | } |
− | Button.style.styleFloat = "right";
| + | |
− | Button.style.cssFloat = "right";
| + | /** |
− | Button.style.fontWeight = "normal";
| + | * Adds show/hide-button to navigation bars. |
− | Button.style.textAlign = "right";
| + | * |
− | Button.style.width = "6em";
| + | * @param {jQuery} $content |
− |
| + | */ |
− | ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
| + | function createNavigationBarToggleButton( $content ) { |
− | ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
| + | var i, j, navChild, navToggle, navToggleText, isCollapsed, |
− | ButtonLink.appendChild( ButtonText );
| + | indexNavigationBar = 0; |
− |
| + | // Iterate over all < div >-elements |
− | Button.appendChild( document.createTextNode( "[" ) );
| + | var $divs = $content.find( 'div.NavFrame:not(.mw-collapsible)' ); |
− | Button.appendChild( ButtonLink );
| + | $divs.each( function ( i, navFrame ) { |
− | Button.appendChild( document.createTextNode( "]" ) );
| + | indexNavigationBar++; |
− |
| + | navToggle = document.createElement( 'a' ); |
− | var Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
| + | navToggle.className = 'NavToggle'; |
− | /* only add button and increment count if there is a header row to work with */
| + | navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar ); |
− | if (Header) {
| + | navToggle.setAttribute( 'href', '#' ); |
− | Header.insertBefore( Button, Header.childNodes[0] );
| + | $( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) ); |
− | tableIndex++;
| + | |
− | }
| + | isCollapsed = $( navFrame ).hasClass( 'collapsed' ); |
− | }
| + | /** |
− | }
| + | * Check if any children are already hidden. This loop is here for backwards compatibility: |
− |
| + | * the old way of making NavFrames start out collapsed was to manually add style="display:none" |
− | for ( i = 0; i < tableIndex; i++ ) {
| + | * to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make |
− | if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
| + | * the content visible without JavaScript support), the new recommended way is to add the class |
− | collapseTable( i );
| + | * "collapsed" to the NavFrame itself, just like with collapsible tables. |
− | }
| + | */ |
− | }
| + | for ( navChild = navFrame.firstChild; navChild !== null && !isCollapsed; navChild = navChild.nextSibling ) { |
− | }
| + | if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) { |
− |
| + | if ( navChild.style.display === 'none' ) { |
− | $( createCollapseButtons );
| + | isCollapsed = true; |
| + | } |
| + | } |
| + | } |
| + | if ( isCollapsed ) { |
| + | for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) { |
| + | if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) { |
| + | navChild.style.display = 'none'; |
| + | } |
| + | } |
| + | } |
| + | navToggleText = document.createTextNode( isCollapsed ? navigationBarShow : navigationBarHide ); |
| + | navToggle.appendChild( navToggleText ); |
| + | |
| + | // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) |
| + | for ( j = 0; j < navFrame.childNodes.length; j++ ) { |
| + | if ( $( navFrame.childNodes[j] ).hasClass( 'NavHead' ) ) { |
| + | navToggle.style.color = navFrame.childNodes[j].style.color; |
| + | navFrame.childNodes[j].appendChild( navToggle ); |
| + | } |
| + | } |
| + | navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar ); |
| + | } ); |
| + | } |
| | | |
− | /** Dynamic Navigation Bars (experimental) *************************************
| + | mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton ); |
− | *
| |
− | * Description: See [[Wikipedia:NavFrame]].
| |
− | * Maintainers: UNMAINTAINED
| |
− | */
| |
− |
| |
− | // set up the words in your language
| |
− | var NavigationBarHide = '[' + collapseCaption + ']';
| |
− | var NavigationBarShow = '[' + expandCaption + ']';
| |
− |
| |
− | // set up max count of Navigation Bars on page,
| |
− | // if there are more, all will be hidden
| |
− | // NavigationBarShowDefault = 0; // all bars will be hidden
| |
− | // NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
| |
− | var NavigationBarShowDefault = autoCollapse;
| |
− |
| |
− |
| |
− | // shows and hides content and picture (if available) of navigation bars
| |
− | // Parameters:
| |
− | // indexNavigationBar: the index of navigation bar to be toggled
| |
− | function toggleNavigationBar(indexNavigationBar)
| |
− | {
| |
− | var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
| |
− | var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
| |
− |
| |
− | if (!NavFrame || !NavToggle) {
| |
− | return false;
| |
− | }
| |
− |
| |
− | // if shown now
| |
− | if (NavToggle.firstChild.data == NavigationBarHide) {
| |
− | for (
| |
− | var NavChild = NavFrame.firstChild;
| |
− | NavChild != null;
| |
− | NavChild = NavChild.nextSibling
| |
− | ) {
| |
− | if ( hasClass( NavChild, 'NavPic' ) ) {
| |
− | NavChild.style.display = 'none';
| |
− | }
| |
− | if ( hasClass( NavChild, 'NavContent') ) {
| |
− | NavChild.style.display = 'none';
| |
− | }
| |
− | }
| |
− | NavToggle.firstChild.data = NavigationBarShow;
| |
− |
| |
− | // if hidden now
| |
− | } else if (NavToggle.firstChild.data == NavigationBarShow) {
| |
− | for (
| |
− | var NavChild = NavFrame.firstChild;
| |
− | NavChild != null;
| |
− | NavChild = NavChild.nextSibling
| |
− | ) {
| |
− | if (hasClass(NavChild, 'NavPic')) {
| |
− | NavChild.style.display = 'block';
| |
− | }
| |
− | if (hasClass(NavChild, 'NavContent')) {
| |
− | NavChild.style.display = 'block';
| |
− | }
| |
− | }
| |
− | NavToggle.firstChild.data = NavigationBarHide;
| |
− | }
| |
− | }
| |
− |
| |
− | // adds show/hide-button to navigation bars
| |
− | function createNavigationBarToggleButton()
| |
− | {
| |
− | var indexNavigationBar = 0;
| |
− | // iterate over all < div >-elements
| |
− | var divs = document.getElementsByTagName("div");
| |
− | for(
| |
− | var i=0;
| |
− | NavFrame = divs[i];
| |
− | i++
| |
− | ) {
| |
− | // if found a navigation bar
| |
− | if (hasClass(NavFrame, "NavFrame")) {
| |
− |
| |
− | indexNavigationBar++;
| |
− | var NavToggle = document.createElement("a");
| |
− | NavToggle.className = 'NavToggle';
| |
− | NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
| |
− | NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
| |
− |
| |
− | var NavToggleText = document.createTextNode(NavigationBarHide);
| |
− | NavToggle.appendChild(NavToggleText);
| |
− | // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
| |
− | for(
| |
− | var j=0;
| |
− | j < NavFrame.childNodes.length;
| |
− | j++
| |
− | ) {
| |
− | if (hasClass(NavFrame.childNodes[j], "NavHead")) {
| |
− | NavFrame.childNodes[j].appendChild(NavToggle);
| |
− | }
| |
− | }
| |
− | NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
| |
− | }
| |
− | }
| |
− | // if more Navigation Bars found than Default: hide all
| |
− | if (NavigationBarShowDefault < indexNavigationBar) {
| |
− | for(
| |
− | var i=1;
| |
− | i<=indexNavigationBar;
| |
− | i++
| |
− | ) {
| |
− | toggleNavigationBar(i);
| |
− | }
| |
− | }
| |
− |
| |
− | }
| |
− |
| |
− | $( createNavigationBarToggleButton );
| |
| | | |
| /** "Technical restrictions" title fix ***************************************** | | /** "Technical restrictions" title fix ***************************************** |