_ _    _ _____  ___   __                       
 __      _(_) | _(_)___ / ( _ ) / /_   ___ ___  _ __ ___  
 \ \ /\ / / | |/ / | |_ \ / _ \| '_ \ / __/ _ \| '_ ` _ \ 
  \ V  V /| |   <| |___) | (_) | (_) | (_| (_) | | | | | |
   \_/\_/ |_|_|\_\_|____/ \___/ \___(_)___\___/|_| |_| |_|

User:The Transhumanist/ViewAsOutline-CategoryTree.js

The issue of User:The Transhumanist/ViewAsOutline-CategoryTree.js is a topic that has generated great interest and controversy in recent times. With different approaches and perspectives, User:The Transhumanist/ViewAsOutline-CategoryTree.js has been the subject of debate and research in various areas of knowledge. From its impact on society to its implications at the individual level, User:The Transhumanist/ViewAsOutline-CategoryTree.js has captured the attention of academics, specialists and ordinary people. In this article, we will explore different aspects related to User:The Transhumanist/ViewAsOutline-CategoryTree.js, analyzing its relevance and unraveling its possible consequences. Additionally, we will examine how User:The Transhumanist/ViewAsOutline-CategoryTree.js has shaped and will continue to shape the current landscape, offering a comprehensive view of this important topic.
// <syntaxhighlight lang="javascript">

/*

(Script under development - not yet functional)

ViewAsOutline-CategoryTree.js = Convert CategoryTree into outline on screen, ready for copying/pasting

What it does: it's a utility for viewing a CategoryTree as an outline in wikicode (as you would see it in an editor)

When completed,
this script will provide 4 menu items to affect a displayed category tree: one for expanding, one for collapsing, 
one for turning wikicodification on, and another for turning wikicodification off. Wikicodification means adding 
the heading delimiters and list item wikicoding that you would see in an editor (even though we're not in an editor),
for easy copying/pasting into an editor.

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 (not ready yet).

*/

// ============== 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() {
        
		// ============== activation filters ==============
        // Only activate on Vector skin
        if ( mw.config.get( 'skin' ) === 'vector' ) {

	        // Run this script only if "Category tree " is in the page title
			if (document.title.indexOf("Category tree ") != -1) {

				// End of set up
			
        	    // =================== Prep work =====================
				
				// Variable declarations, etc., go here

            	// ================= Core program ================= 

                $( function() {
                    VAOCTExpand();
                    VAOCTCollapse();
                    VAOCTWikicodify();
                    VAOCTDeWikicodify();
				} );
			}
        }

        // ======================== Subroutines ===========================
        // Functions (aka subroutines) are activated only when they are called.
    	// Below are the functions called in the core control structure of the program above.
    	// They are placed at the end of the program, so that the script's flow 
    	// is easier to follow.

       	// ============ Function to expand unexpanded categories in the tree ==============

       	function VAOCTExpand() {
			// Create linked menu item
			var portletlink = mw.util.addPortletLink('p-tb', '#', 'CatTree expand', 'ct-expand', 'Expand all categories');
			// Bind click handler
			$(portletlink).click( function(e) {
				e.preventDefault();     // prevents any default action -- we want only the following actions to run:

				// Do some stuff when clicked...
				//$('.CategoryTreeToggle').click();
				$('.CategoryTreeToggle').click();

			});     // end of function(e) (click handler)
       	}

       	// ============ Function to collapse expanded categories in the tree ==============

       	function VAOCTCollapse() {
			// Create linked menu item
			var portletlink = mw.util.addPortletLink('p-tb', '#', 'CatTree collapse', 'ct-collapse', 'Collapse all categories');
			// Bind click handler
			$(portletlink).click( function(e) {
				e.preventDefault();     // prevents any default action -- we want only the following actions to run:

				// Do some stuff when clicked...
				$('.CategoryTreeToggle').click();

			});     // end of function(e) (click handler)
       	}

       	// ============ Function to insert/show list wikicode on-screen for links to articles ==============

       	function VAOCTWikicodify() {
			// Create linked menu item
			var portletlink = mw.util.addPortletLink('p-tb', '#', 'CT Wikicodify', 'ct-wiki', 'Add list wikicode');
			// Bind click handler
			$(portletlink).click( function(e) {
				e.preventDefault();     // prevents any default action -- we want only the following actions to run:

				// Do some stuff when clicked...
				// Add brackets enclosed in classed spans, except for entries that already have them.
				var cont = document.getElementById('mw-content-text');
            	// wrap the page names in spanned wikicodes, and add Brackets class to prevent matching same entries again
            	cont.outerHTML = cont.outerHTML.replace(/(<a class=\")(CategoryTreeLabel  CategoryTreeLabelNs0.*?<\/a>)/g,'<span class="OpeningBrackets">* ]</span>');				
				// Show hidden brackets
				$('.OpeningBrackets').show();
				$('.ClosingBrackets').show();

			});     // end of function(e) (click handler)
       	}

       	// ============ Function to hide list wikicode ==============

       	function VAOCTDeWikicodify() {
			// Create linked menu item
			var portletlink = mw.util.addPortletLink('p-tb', '#', 'CT Dewikicodify', 'ct-dewiki', 'Remove list wikicode');
			// Bind click handler
			$(portletlink).click( function(e) {
				e.preventDefault();     // prevents any default action -- we want only the following actions to run:

				// Do some stuff when clicked...
				//$('.CategoryTreeSection').find('.CategoryTreeLabelPage').parent().hide();
				$('.OpeningBrackets').hide();
				$('.ClosingBrackets').hide();

			});     // end of function(e) (click handler)
       	}

    } );
}( mediaWiki, jQuery ) );

// </syntaxhighlight>