Jump to content

User:Jsimlo/shortcuts.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jsimlo (talk | contribs) at 15:52, 13 September 2006. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<pre>

 var shortcutsVersion      = "0.0.1";
 var shortcutsReleaseDate  = "2006-09-01 17:23";

 function shortcutsMakeLink (name, url)
 {
   var ntxt = document.createTextNode (name);
   var na   = document.createElement ('a');
   var nli  = document.createElement ('li');

   na.setAttribute ('href', '/wiki/' + url); 
   nli.setAttribute ('class', 'n-shortcut');

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

   return nli;
 }

 function makePortlet (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');

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

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

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

   return nportlet;
 }

 function shortcutsMyLinks ()
 {
   var sidecol = document.getElementById ('column-one');

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

 function shortcutsStartSection (name)
 {
   shortcutsLinks[shortcutsLinks.length] = new Array ('name': name, 'links': new Array ());
 }

 function shortcutsAddLink (name, article)
 {
   var links = shortcutsLinks[shortcutsLinks.length - 1];

   links[links.length] = new Array ('name': name, 'article': article);
 }

 /**
  * Initialization stuff..
  */
 var shortcutsLinks = new Array ();
 shortcutsStartSection ('shortcuts');

 if (window.addEventListener)
   window.addEventListener("load", shortcutsMyLinks, false);
 else if (window.attachEvent)
   window.attachEvent("onload", shortcutsMyLinks);

//</pre>