User:Pyrospirit/shortcuts.js

var shortcutsVersion = "1.1.0"; var shortcutsReleaseDate = "2007-02-03";

/***********************************************************
 * INTERFACE

/** function shortcutsStartSection (name) { shortcutsLinks[shortcutsLinks.length] = {'name': name, 'links': new Array }; }
 * Starts a new section of links. Function for external use.

/** function shortcutsAddLink (name, article) { var links = shortcutsLinks[shortcutsLinks.length - 1]['links'];
 * Adds new link into the current section of links. Function for external use.

links[links.length] = {'name': name, 'article': article}; }

/***********************************************************
 * IMPLEMENTATION

/** function shortcutsMakeLink (name, url) { url = url.replace(/ /, "_");
 * Link maker.
 * Creates and returns an li element with the desired link.

var ntxt = document.createTextNode(name); var na = document.createElement('a'); var nli = document.createElement('li'); var fullUrl = wgArticlePath.replace(/\$1/, url);

na.setAttribute('href', fullUrl); nli.setAttribute('class', 'n-shortcut');

na.appendChild(ntxt); nli.appendChild(na);

return nli; }

/** function shortcutsMakePortlet (name, links) { var nportlet = document.createElement('div'); var nh5 = document.createElement('h5'); var ntit = document.createTextNode(name); var nbody = document.createElement('div'); var nul = document.createElement('ul');
 * Portlet maker.
 * Creates and returns a portlet populated by list of links.

nportlet.setAttribute('id', 'p-' + name); nportlet.setAttribute('class', 'portlet'); nbody.setAttribute('class', 'pBody'); nul.setAttribute('id', 'p-' + name);

for (var i = 0; i < links.length; i++) { var item = shortcutsMakeLink(links[i]['name'], links[i]['article']); nul.appendChild(item); }

nh5.appendChild(ntit); nportlet.appendChild(nh5); nbody.appendChild(nul); nportlet.appendChild(nbody);

return nportlet; }

/** function shortcutsMain { var sidecol = document.getElementById ('column-one');
 * Main function.
 * Enumerates all non-empty sections, and adds new portlets beneath the old ones.

for (var i = 0; i < shortcutsLinks.length; i++) { if (shortcutsLinks[i]['links'].length > 0) { var portlet = shortcutsMakePortlet(shortcutsLinks[i]['name'],                                              shortcutsLinks[i]['links']); sidecol.appendChild(portlet); }   } }

/** function shortcutsInitialize { shortcutsInit; shortcutsMain; }
 * Initializes the onload events.

/***********************************************************
 * INITIALIZATION

var shortcutsLinks = new Array; shortcutsStartSection(wgUserName ? wgUserName : 'shortcuts');

$(shortcutsInitialize);