User:The Transhumanist/ViewAsOutline-Templates.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:The Transhumanist/ViewAsOutline-Templates. |
// <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( ['mediawiki.util'], 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[i].outerHTML = navboxAElements[i].outerHTML.replace(/(<a.*?(<\/a>))/g,'* [[$1]]');
}
// 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[i].outerHTML = vboxAElements[i].outerHTML.replace(/(<a.*?(<\/a>))/g,'* [[$1]]');
vboxAElements[i] = vboxAElements[i].prepend( "* [[" );
vboxAElements[i] = vboxAElements[i].append( "]]" );
}
}
});
} );
}( mediaWiki, jQuery ) );
// </syntaxhighlight>