User:Whiteknight/perpage.js

From Wikibooks, open books for an open world
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac);
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5;
  • Konqueror: simply click the Reload button, or press F5;
  • Opera users may need to completely clear their cache in Tools→Preferences.
//Per-Book javascript. 
//adapted from http://en.wikinews.org/wiki/User:Matt/public/pagecss.js
/*
  Imports stylesheets and script pages that are specific to a given book or namespace.  
  Also, provides links in the form of tabs to the stylesheet and script pages that correspond
  to the particular page. Allows significant customization for individual pages and individual
  books. Currently does not support per-namespace stylesheets, or scripts for the main
  namespace.
*/

var pagejs_base = "User:Whiteknight/Javascripts/";
var nsjs_base = "User:Whiteknight/Javascripts/ns/";
var pagecss_base = "User:Whiteknight/Stylesheets/";
 
function WKAddPerPageTabs() {
  if(wgPageName.match(pagejs_base) ||
     wgPageName.match(pagecss_base)) {
    var bookpath = "/wiki/" + wgPageName.split("/")[2];
    add_toolbox_link(bookpath, 'book', 'ca-gobook');
  } else {
    var scriptpath = "/wiki/" + pagejs_base  + wgBookName;
    var stylepath =  "/wiki/" + pagecss_base + wgBookName;
    add_toolbox_link(stylepath, 'style',  'ca-addstyle');
    add_toolbox_link(scriptpath, 'script', 'ca-addscript');
  }
}

import_style(pagecss_base + wgBookName);
import_script(pagejs_base + wgBookName);
if(wgCanonicalNamespace != "") import_script(nsjs_base + wgCanonicalNamespace);
$(WKAddPerPageTabs);