Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/**
* Dynamic Navigation Bars (experimental)
*
* Description: See [[Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
*/
var collapseCaption = 'hide';
var expandCaption = 'show';
// Set up the words in your language
var navigationBarHide = '[' + collapseCaption + ']';
var navigationBarShow = '[' + expandCaption + ']';
/**
* Shows and hides content and picture (if available) of navigation bars.
*
* @param {number} indexNavigationBar The index of navigation bar to be toggled
* @param {jQuery.Event} event Event object
* @return {boolean}
*/
function toggleNavigationBar( indexNavigationBar, event ) {
var navToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
var navFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
var navChild;
/**************************/
/* Adapt a list structure and use it as a navigational aid **************************************
*
* Description: Gives a list some additional structuring and a collapse/expand functionality
* Maintainers: [[User:Jeblad]]
*/
// build an opaque function object
(function(mw, $, undefined){
// get the locally stored objects, clear out the objects on errors
var max = 128;
var values = {};
try {
values = JSON.parse( window.localStorage.getItem("navbox-items-value") || '{}' );
}
catch (e) {
try {
window.localStorage.setItem("navbox-items-value", '{}' );
} catch(e) {}
}
// private method for local storage
function store(key, idx, state) {
// only check whats the state
if (state === undefined)
return (values[key] ? values[key][idx] : null);
// build a copy where we start with our value and skip any later duplicates
var obj = {};
obj[key] = [];
obj[key][idx] = state;
var count = 0;
for (var x in values) {
if (x === key) {
if (!obj[x]) obj[x] = [];
for (var y in values[x])
if (!obj[x][y])
obj[x][y]=values[x][y];
}
else
obj[x]=values[x];
if (max<count++)
continue;
}
values = obj;
// rebuild indexes for local storage
var a = [];
for (var x in values) {
var b = [];
for (var y in values[x])
b.push('"'+values[x][y]+'"');
a.push('"'+x+'":['+b.join(',')+']');
}
try {
window.localStorage.setItem("navbox-items-value", '{'+a.join(',')+'}' );
} catch(e) {}
// return our set state
return state;
}
// worker process
$(function() {
// cache our navboxes
var navbox = $('div.statbox');
// we're running so remove no-script class
navbox
.removeClass('no-script');
// identify lead ins
navbox
.find('dd')
.find('ul,ol')
.each(function(i, el) {
var obj = el.previousSibling;
while (obj && !/\S/.test(obj.nodeValue))
obj = obj.previousSibling;
if (obj)
$(el)
.addClass('lead-in');
});
// is collapsible navigation enabled?
if (mw.config.get('wgVectorEnabledModules') && mw.config.get('wgVectorEnabledModules')['collapsiblenav']) {
// identify collapsible navigations
navbox
.addClass('collapsible');
// identify collapsed state and set up handlers
navbox
.find('dt')
.each(function(i, el){
var obj = el.nextSibling;
while (obj && obj.nodeType != 1)
obj = obj.nextSibling;
if (obj && obj.nodeName) {
$(el)
.addClass(function(index, currentClass){
var matches = $(el).closest('.navbox').attr('class').match(/navbox-([-\w]+)/);
var idx = $(this).closest('dl').prevAll('dl').length; // not sure
if (matches && 1<matches.length && store(matches[1], idx) == 'expanded') {
$(el)
.nextUntil('dt')
.css('display', 'block');
return 'expanded';
}
else return 'collapsed';
})
.wrapInner('<span class="title"/>')
.click(function(){
var matches = $(this).closest('.navbox').attr('class').match(/navbox-([-\w]+)/);
var idx = $(this).closest('dl').prevAll('dl').length; // not sure
$(this)
.closest('dt')
.toggleClass('collapsed expanded')
.each(function(i, el){
if (matches && 1<matches.length)
store(matches[1], idx, $(el).hasClass('collapsed') ? 'collapsed' : 'expanded');
})
.nextUntil('dt')
.slideToggle();
});
}
})
}
});
})(mediaWiki, jQuery);
if ( !navFrame || !navToggle ) {
return false;
}
// If shown now
if ( navToggle.firstChild.data === navigationBarHide ) {
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
if ( $( navChild ).hasClass( 'NavContent' ) ) {
navChild.style.display = 'none';
}
}
navToggle.firstChild.data = navigationBarShow;
// If hidden now
} else if ( navToggle.firstChild.data === navigationBarShow ) {
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
if ( $( navChild ).hasClass( 'NavContent' ) ) {
navChild.style.display = 'block';
}
}
navToggle.firstChild.data = navigationBarHide;
}
event.preventDefault();
}
/**
* Adds show/hide-button to navigation bars.
*
* @param {jQuery} $content
*/
function createNavigationBarToggleButton( $content ) {
var j, navChild, navToggle, navToggleText, isCollapsed,
indexNavigationBar = 0;
// Iterate over all < div >-elements
var $divs = $content.find( 'div.NavFrame:not(.mw-collapsible)' );
$divs.each( function ( i, navFrame ) {
indexNavigationBar++;
navToggle = document.createElement( 'a' );
navToggle.className = 'NavToggle';
navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
navToggle.setAttribute( 'href', '#' );
$( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );
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"
* to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make
* the content visible without JavaScript support), the new recommended way is to add the class
* "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' ) {
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 );
} );
}
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
// AutoWikiBrowser
mw.loader.load( '//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js/load.js&action=raw&ctype=text/javascript' );
// Translation progress (experimental)
// var ratio = GoogleTranslate.getTranslatedRatio();
// document.getElementsByClassName('template-notice-text')[0].innerHTML += ' Translation progress: ' + Math.round(100*ratio) + '%';