Jump to content

MediaWiki:Common.js: Difference between revisions

From The Austrian Economics Wiki, the global repository of classical-liberal thought
new collapse code
new collapse try
Line 5: Line 5:
     importScript("MediaWiki:Common.js/edit.js")
     importScript("MediaWiki:Common.js/edit.js")
}
}
( function( $ ) {
// CONFIG
var config = window.ShowHideConfig = $.extend( true, {
autoCollapse: 2,
userLang: true,
brackets: '[]',
linkBefore: false,
// German
de: {
show: "anzeigen",
hide: "verbergen",
showAll: "alle anzeigen",
hideAll: "alle verbergen"
},
// English
en: {
show: "show",
hide: "hide",
showAll: "show all",
hideAll: "hide all"
},
// Spanish
es: {
show: "Mostrar",
hide: "Ocultar",
showAll: "Mostrar todo",
hideAll: "Ocultar todo"
},
// French
fr: {
show: "montrer",
hide: "cacher",
showAll: "montrer tous",
hideAll: "cacher tous"
},
// Japanese
ja: {
show: "表示",
hide: "非表示",
showAll: "すべて表示",
hideAll: "すべて非表示"
},
// Dutch
nl: {
show: "tonen",
hide: "verbergen",
showAll: "alles tonen",
hideAll: "alles verbergen"
},
// Polish
pl: {
show: "Pokaż",
hide: "Ukryj",
showAll: "Pokaż wszystko",
hideAll: "Ukryj wszystko"
},
// Russian
ru: {
show: "Открыть",
hide: "Скрыть",
showAll: "Открыть все",
hideAll: "Скрыть все"
}
// Make a post on the talkpage if you have i18n updates
}, window.ShowHideConfig || {} );
// i18n function
function msg( name ) {
if ( config.userLang && wgUserLanguage in config && name in config[wgUserLanguage] ) {
return config[wgUserLanguage][name];
}
if ( wgContentLanguage in config && name in config[wgContentLanguage] ) {
return config[wgContentLanguage][name];
}
return config.en[name];
}
// common
$.fn.onLink = function( fn ) {
return this.bind( 'click keypress', function(e) {
if ( e.type === 'click' || ( e.type === 'keypress' && ( e.keyCode === 13 || e.charCode === 32 ) ) ) {
fn.call(this, e);
}
} );
};
/** Collapsible tables using jQuery
*
*  Description: Allows tables to be collapsed, showing only the header.
*/
function collapseTable( node, state ) {
var $table = $( node ),
$button = $table.find( 'tr:first > th:first .collapseLink' );
if ( !$table.length || !$button.length ) {
return false;
}
if ( typeof state === 'boolean' ) {
$table.toggleClass( 'collapsed', !state );
} else {
$table.toggleClass( 'collapsed' );
}
var hidden = $table.hasClass( 'collapsed' );
$table.find( '> * > tr:not(:first):not(.nocollapse)' )[hidden?"hide":"show"]();
$button.text( msg( hidden ? "show" : "hide" ) );
return true;
}
function createCollapseButtons() {
var NavigationBoxes = [];
$( 'table.collapsible' ).each( function () {
NavigationBoxes.push(this);
var $buttonLink = $( '<span tabIndex=0 class=collapseLink />' ).text( msg( "hide" ) ).css({ cursor: "pointer" }).onLink( function( e ) { collapseTable( $(this).closest('table') ); } ),
$button = $( "<span class=collapseButton />" ).css( {
"float": "right",
textAlign: "right",
fontWeight: "normal",
width: "6em",
marginLeft: "-100%"
} );
$button.append( document.createTextNode(config.brackets.substr(0, config.brackets.length/2)), $buttonLink, config.brackets.substr(config.brackets.length/2) );
var $header = $( this ).find( 'tr:first > th:first' ).prepend($button);
} );
// if more Navigation Bars found than Default: hide all
if ( $( NavigationBoxes ).filter( '.autocollapse' ).length >= config.autoCollapse ) {
$( NavigationBoxes ).filter( '.autocollapse' ).each( function () { collapseTable( this, false ); } );
} else {
$( NavigationBoxes ).filter( '.collapsed' ).each( function () { collapseTable( this, false ); } );
}
}
$( createCollapseButtons );
/** Dynamic Navigation Bars with jQuery
*
*  Base Description: See Wikipedia:Wikipedia:NavFrame.
*/
// shows and hides content and picture (if available) of navigation bars
function toggleNavigationBar( node ) {
var $navFrame = $( node ),
$navToggle = $navFrame.find( '.NavHead:first .collapseLink' );
if ( !$navFrame.length || !$navToggle.length ) {
return false;
}
$navFrame.toggleClass( 'NavVisible' );
$navFrame.find( '.NavPic, .NavContent' ).not( $navFrame.find( '.NavFrame .NavPic' ) ).not( $navFrame.find( '.NavFrame .NavContent' ) ).slideToggle();
$navToggle.text( msg( $navFrame.hasClass( 'NavVisible' ) ? "hide" : "show" ) );
return true;
}
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton() {
var NavFrames = $( '.NavFrame' ).addClass( 'NavVisible' ).each( function () {
var $navHead = $( this ).find( '.NavHead:first' ),
$buttonLink = $( '<span tabIndex=0 class=collapseLink />' ).text( msg( "hide" ) ).onLink( function ( e ) { toggleNavigationBar( $( this ).closest( '.NavFrame' ) ); } ),
$button = $( '<span class="NavToggle collapseButton" />' );
$navHead.filter( 'legend' ).append( ' - ' );
if ( config.brackets ) {
$button.append( document.createTextNode(config.brackets.substr(0, config.brackets.length/2)), $buttonLink, config.brackets.substr(config.brackets.length/2) );
} else {
$button.append( $buttonLink );
}
$navHead[config.linkBefore?"prepend":"append"]($button);
} );
// if more Navigation Bars found than Default: hide all
if ( NavFrames.length >= config.autoCollapse ) {
NavFrames.not( '.noautocollapse' ).each( function () { toggleNavigationBar(this); } );
} else {
NavFrames.filter( '.collapsed' ).each( function () { toggleNavigationBar(this); } );
}
return true;
}
$( createNavigationBarToggleButton );
$( function () {
$( '.NavGlobal' ).each( function () {
$( '<span class=NavGlobalShow />' ).append(
document.createTextNode( '[' ),
$( '<span tabIndex=0 class=collapseLink />' ).text( msg( "showAll" ) ).onLink( function ( e ) {
$( '.NavFrame' ).each( function () { if ( !$( this ).hasClass( 'NavVisible' ) ) toggleNavigationBar(this); } );
} ),
']'
).appendTo( this );
$( this ).append( ' ' );
$('<span class=NavGlobalHide />').append(
document.createTextNode( '[' ),
$( '<span tabIndex=0 class=collapseLink />' ).text( msg( "hideAll" ) ).onLink( function ( e ) {
$( '.NavFrame' ).each( function () { if ( $( this ).hasClass( 'NavVisible' ) ) toggleNavigationBar(this); } );
} ),
']'
).appendTo( this );
} );
} );
} )( jQuery );
/*


/*
/*
Line 297: Line 91:
*/
*/
self.proofreadpage_disable_wheelzoom=true;
self.proofreadpage_disable_wheelzoom=true;
/** Collapsible tables *********************************************************
*
*  Description: Allows tables to be collapsed, showing only the header. See
*                        http://www.mediawiki.org/wiki/Manual:Collapsible_tables.
*  Maintainers: [[en:User:R. Koot]]
*/
var autoCollapse = 2;
var collapseCaption = 'hide';
var expandCaption = 'show';
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 );
/** 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 );
        };
})();

Revision as of 12:25, 12 August 2011

/* Import more specific scripts if necessary */

if (wgAction == "edit" || wgAction == "submit" || wgPageName == "Special:Upload") //scripts specific to editing pages {

   importScript("MediaWiki:Common.js/edit.js")

}

/*

* scripts imported from en.wikisource.org and wikisource.org
*/

/* messages are configurable here */ self.ws_messages = { 'optlist':'Display options', 'hide_page_numbers':'Hide page links', 'show_page_numbers':'Show page links', 'layout':'Layout', 'author':'Author', 'translator':'Translator', 'editor':'Editor', 'publisher':'Publisher', 'place':'Place', 'volume':'Volume', 'school':'School', 'book':'Book', 'collection':'Collection', 'journal':'Journal or magazine', 'phdthesis':'Thesis, report', 'dictionary':'Dictionary', 'progress':'Progress', 'progress_T':'Done', 'progress_V':'To be validated', 'progress_C':'To be proofread', 'progress_MS':'Ready for Match & Split', 'progress_OCR':'Needs an OCR text layer', 'progress_X':'Source file is an excerpt of a larger volume, or a mixture of several sources', 'progress_L':'Source file is incorrect (missing pages, unordered pages, etc)', '▲':'Return to the top of the page.',


'corr_list':"List of corrections performed on this page" , 'corr_link':"Corrections" , 'corr_one':"One typo </a> has been corrected." , 'corr_many':" typos</a> have been corrected." , 'corr_close':"Close." ,

'iwtrans':'Its text comes from', 'iwtrans2':'Its text comes from other Wikisource subdomains.' }

/* dynamic layouts from en.wikisource.org*/ self.ws_layouts = {

'Layout 1':{'text-wrap':"position:relative;margin-left:3em;margin-right:3em;", 
     '#text-container':"width:36em;margin:0px auto;font-family:Georgia,serif;" , 
     '#text':"text-align:justify;", 
     '.sidenote-right':"position:absolute; left:37em;width:16em;text-indent:0em;text-align:left;",
     '.sidenote-left':"position:absolute; right:37em;width:16em;text-indent:0em;text-align:right;",
     '.editsection':"display:none",
     '#headertemplate':"" },
'Layout 2':{'text-wrap':"", 
     '#text-container':"" , 
     '#text':"", 
     '.sidenote-right':"float:right;margin:0.5em;padding:3px;border:solid 1px gray;max-width:9em;text-indent:0em;text-align:left;",
     '.sidenote-left':"float:left;margin:0.5em;padding:3px;border:solid 1px gray;max-width:9em;text-indent:0em;text-align:left;",
     '.editsection':"display:none",
     '#headertemplate':"" },
'Layout 3':{'text-wrap':"margin-left:3em",
     '#text-container':"position:relative; min-width:60em; float:left; width:100%; margin-right:-23em;" , 
     '#text':"text-align:justify;margin-right:23em; text-indent:0em; padding-left:0px; padding-right:0px;width:auto;",
     '.sidenote-right':"position:absolute; right:-10em; width:9em; background-color:#eeeeee;text-indent:0em;text-align:left;",
     '.sidenote-left': "position:absolute; right:-10em; width:9em; background-color:#eeeeee;text-indent:0em;text-align:left;",
     '.editsection':"display:none",
     '#headertemplate':"position:absolute; top:0em; right:-23em; width:21em;float:right; text-align:left;" }

}


self.proofreadpage_add_container = true;

importScriptURI('http://wiki.mises.org/mediawiki/index.php?title=MediaWiki:Base.js&action=raw&ctype=text/javascript'); //importScriptURI('http://wiki.mises.org/mediawiki/index.php?title=MediaWiki:OCR.js&action=raw&ctype=text/javascript'); importScriptURI('http://wiki.mises.org/mediawiki/index.php?title=MediaWiki:DisplayFooter.js&action=raw&ctype=text/javascript'); importScriptURI('http://wiki.mises.org/mediawiki/index.php?title=MediaWiki:PageNumbers.js&action=raw&ctype=text/javascript'); importScriptURI('http://wiki.mises.org/mediawiki/index.php?title=MediaWiki:Corrections.js&action=raw&ctype=text/javascript'); importScriptURI('http://wiki.mises.org/mediawiki/index.php?title=MediaWiki:IndexForm.js&action=raw&ctype=text/javascript');

/* From en.wikisource.org Disabling mouse wheel until the problem is fixed. Users that have a configurations where zoom wheel works can override this, by adding "self.proofreadpage_disable_wheelzoom=false;" to their javascript.

  • /

self.proofreadpage_disable_wheelzoom=true;


/** Collapsible tables *********************************************************

*
*  Description: Allows tables to be collapsed, showing only the header. See
*                         http://www.mediawiki.org/wiki/Manual:Collapsible_tables.
*  Maintainers: 
*/

var autoCollapse = 2; var collapseCaption = 'hide'; var expandCaption = 'show';

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 );

/** 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 );
       };

})();