User:Porter21/ShowHide.js

function showHide { // Configuration var config = window.ShowHideConfig = $.extend(true, {     autoCollapse: 1,      userLang: false,      brackets: '[]',      linkBefore: false,      useSymbols: true,      symbolColor: '#000000',      symbolSize: '5px',      // English      en: {         show: 'show',         hide: 'hide',         showAll: 'show all',         hideAll: 'hide all'      }   }, window.ShowHideConfig || {}); var symbolShow = ''; var symbolHide = '';

// Function for multi-language support 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);         }      }); };

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(config.useSymbols ? (hidden ? symbolShow : symbolHide) : msg(hidden ? "show" : "hide")); return true; }

function createCollapseButtons { var NavigationBoxes = []; $('table.collapsible').each(function {         NavigationBoxes.push(this);         var   $buttonLink = $(' ').text((!config.useSymbols ? config.brackets.substr(0, config.brackets.length/2 : )) + msg('hide') + (!config.useSymbols ? config.brackets.substr(config.brackets.length/2) : )).css({ 'cursor': 'pointer' }).onLink(function(e) { collapseTable($(this).closest('table')); }),            $button = $(' ').css({ 'float': 'right', 'test-align': 'right', 'font-weight': 'normal', 'width': (config.useSymbols ? '20px' : '40px') });        $button.append($buttonLink);

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