// <syntaxhighlight lang="javascript">
/*
(Script under development - partially functional)
ViewAsOutline-NavBox.js = view navigation footers as outlines
What it does: converts navigation footers on the current view of
the current page into pastable wikicode outline format. That is, as bullet list
entries with asterisks and square brackets, ready to be copied into an edit window.
Brief comments are provided within the source code below. For extensive explanatory
notes on what the source code does and how it works, see the Script's workshop on
the talk page.
*/
// ============== Set up ==============
// Start off with a bodyguard function to reserve the aliases mw and $
( function ( mw, $ ) {
// we can now rely on mw and $ within the safety of our “bodyguard” function, to mean
// "mediawiki" and "jQuery", respectively
// ============== ready() event listener/handler ==============
// below is jQuery short-hand for $(document).ready(function() { ... });
// it makes the rest of the script wait until the page's DOM is loaded and ready
$(function() {
// Load dependencies
mw.loader.using( , function () {
// ============== activation filters ==============
// Only activate on Vector skin
if ( mw.config.get( 'skin' ) === 'vector' ) {
// End of set up
// =================== Prep work =====================
// Variable declarations, etc., go here
// ================= Core program =================
// CONVERSION FOR NAVBOXES
// Force the navboxes to show
$( ".navbox" ).find( 'tr' ).css( 'display', 'table-row' );
// Revert list items to li format by removing hlist class
//$( ".navbox" ).find( "td" ).removeClass( "hlist" );
$( ".navbox" ).find( "*" ).removeClass( "hlist" );
// add hlist class back into the navbar, so the vte links are not affected
$( ".navbar" ).addClass ( "hlist" );
// Make the ul's targettable by adding a class to them
$( ".navbox-list" ).find( "ul" ).addClass( "navbox-ul" );
$( ".navbox-abovebelow" ).find( "ul" ).addClass( "abovebelow-ul" );
// Make the bullets go bye bye
$( ".navbox-ul" ).css( {"list-style-type":"none", "list-style-image":"none"} );
$( ".abovebelow-ul" ).css( {"list-style-type":"none", "list-style-image":"none"} );
// Make the bullets go bye bye (this works too)
// $( ".navbox-ul" ).css( "list-style-type", "none" );
// $( ".navbox-ul" ).css( "list-style-image", "none" );
// Make the links targettable by adding a class to them
$( ".navbox-list" ).find( "a" ).addClass( "navbox-a" );
// Development note: navbox-lists, ULs, and even LIs are nested; leave nesting in place
// and regex-out the brackets to leave the right number of asterisks
// wrap the page names with *] - links go between the double square brackets
var navboxAElements = document.getElementsByClassName("navbox-a");
var i;
for (i = 0; i < navboxAElements.length; i++) {
navboxAElements.outerHTML = navboxAElements.outerHTML.replace(/(<a.*?(<\/a>))/g,'* ]');
}
// add heading delimiters to the row titles
$( ".navbox-group" ).prepend( "== " ).append( " ==" );
/*
// convert table to unordered list
// This is causing an unexpected result: clones wikicommons template for some reason
$('table').replaceWith( $('table').html()
.replace(/<tbody/gi, "<ul id='table'")
.replace(/<tr/gi, "<li")
.replace(/<\/tr>/gi, "</li>")
.replace(/<td/gi, "<span")
.replace(/<\/td>/gi, "</span>")
.replace(/<\/tbody/gi, "<\/ul")
);
*/
// CONVERSION FOR SIDEBARS
// Force sections to show
$( ".NavContent" ).css( "display", "block" );
// Revert list items to li format by removing hlist class
$( ".sidebar" ).find( "*" ).removeClass( " hlist" );
// Make the ul's targettable by adding a class to them
$( ".NavContent" ).find( "ul" ).addClass( "NavContent-ul" );
// Make the bullets go bye bye
$( ".NavContent-ul" ).css( {"list-style-type":"none", "list-style-image":"none"} );
// Realign the text to the left
$( ".NavHead" ).css( "text-align", "left" );
$( ".NavContent" ).css( "text-align", "left" );
// Make the links targettable by adding a class to them
$( ".sidebar" ).find( "a" ).not( ".NavToggle" ).addClass( "vbox-a" );
// wrap the page names with *] - links go between the double square brackets
var vboxAElements = document.getElementsByClassName( "vbox-a" );
var i;
for (i = 0; i < vboxAElements.length; i++) {
//vboxAElements.outerHTML = vboxAElements.outerHTML.replace(/(<a.*?(<\/a>))/g,'* ]');
vboxAElements = vboxAElements.prepend( "* [[" );
vboxAElements = vboxAElements.append( "]]" );
}
}
});
} );
}( mediaWiki, jQuery ) );
// </syntaxhighlight>