MediaWiki:Common.js

From Sccswiki
Revision as of 12:45, 24 October 2012 by WikiSysop (talk | contribs) (Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: $(document).ready(function(){ // find categories categories = []; $("#mw-normal-catlinks...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Note: After saving, 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: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Any JavaScript here will be loaded for all users on every page load. */
$(document).ready(function(){
    // find categories
    categories = [];
    $("#mw-normal-catlinks a").each(function(i) {
        // debug:
        // console.log($(this).html());
        categories.push($.trim($(this).html()));
    });
    //console.log(categories);
    
    // now go over all navigation links and hide all, where we don't have that category
    $("#p-navigation div ul li").each(function(i) {
        // debug:
        // console.log($(this).attr("class"));
        entry_classes = $.trim($(this).attr("class")).split(" ");
        //console.log(entry_classes);
        if(entry_classes.indexOf("nav1") != -1) {
            found = false;
            entry_classes.forEach(function(entry_class) {
                // ok.. we might consider hiding that..
                cat_name = entry_class.substring(4);
                if(categories.indexOf(cat_name) != -1) {
                    // that category we do have..
                    found = true;
                }
            });
            if(!found) {
                $(this).hide();
            }
        }
    });
})