Difference between revisions of "User:Gordon Wendt/monobook.js"
Jump to navigation
Jump to search
Gordon Wendt (talk | contribs) (trying again) |
Gordon Wendt (talk | contribs) (adding some links to test from the script author's page) |
||
Line 1: | Line 1: | ||
< | //<pre><nowiki> | ||
// [ | /********************************************************************** | ||
document. | * * | ||
* Changes to this file affect other users. * | |||
* Please discuss on the talk page before editing. * | |||
* * | |||
**********************************************************************/ | |||
var shortcutsVersion = "1.1.0"; | |||
var shortcutsReleaseDate = "2007-02-03"; | |||
/*********************************************************** | |||
* INTERFACE | |||
***********************************************************/ | |||
/** | |||
* Starts a new section of links. Function for external use. | |||
*/ | |||
function shortcutsStartSection (name) | |||
{ | |||
shortcutsLinks[shortcutsLinks.length] = { 'name': name, 'links': new Array () }; | |||
} | |||
/** | |||
* Adds new link into the current section of links. Function for external use. | |||
*/ | |||
function shortcutsAddLink (name, article) | |||
{ | |||
var links = shortcutsLinks[shortcutsLinks.length - 1]['links']; | |||
links[links.length] = { 'name': name, 'article': article }; | |||
} | |||
/*********************************************************** | |||
* IMPLEMENTATION | |||
***********************************************************/ | |||
/** | |||
* Link maker. | |||
* Creates and returns an li element with the desired link. | |||
*/ | |||
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; | |||
} | |||
/** | |||
* Portlet maker. | |||
* Creates and returns a portlet populated by list of links. | |||
*/ | |||
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'); | |||
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++) | |||
nul.appendChild ( | |||
shortcutsMakeLink (links[i]['name'], links[i]['article']) | |||
); | |||
nh5.appendChild (ntit); | |||
nportlet.appendChild (nh5); | |||
nbody.appendChild (nul); | |||
nportlet.appendChild (nbody); | |||
return nportlet; | |||
} | |||
function | /** | ||
* Main function. | |||
* Enumerates all non-empty sections, and adds new portlets beneath the old ones. | |||
*/ | |||
function shortcutsMain () | |||
{ | { | ||
var sidecol = document.getElementById ('column-one'); | |||
for (var i = 0; i < shortcutsLinks.length; i++) | |||
if (shortcutsLinks[i]['links'].length > 0) | |||
sidecol.appendChild ( | |||
shortcutsMakePortlet (shortcutsLinks[i]['name'], shortcutsLinks[i]['links']) | |||
); | |||
} | |||
/** | |||
* Initializes the onload events. | |||
*/ | |||
function shortcutsInitialize () | |||
{ | |||
shortcutsInit (); | |||
shortcutsMain (); | |||
} | } | ||
/*********************************************************** | |||
* INITIALIZATION | |||
***********************************************************/ | |||
var shortcutsLinks = new Array (); | |||
shortcutsStartSection (wgUserName ? wgUserName : 'shortcuts'); | |||
addOnloadHook (shortcutsInitialize); | |||
////////////////////////// | |||
////////////////////////// | |||
function shortcutsInit () | |||
{ | |||
shortcutsAddLink ('User:jsimlo/Sandbox', 'User:jsimlo/Sandbox'); | |||
shortcutsAddLink ('User:jsimlo/Wikify', 'User:jsimlo/Wikify'); | |||
shortcutsAddLink ('User:jsimlo/Shortcuts', 'User:jsimlo/Shortcuts'); | |||
shortcutsStartSection ('shortcuts'); | |||
shortcutsAddLink ('TED Notepad', 'TED Notepad'); | |||
shortcutsAddLink ('Nonogram', 'Nonogram'); | |||
} | |||
//</nowiki></pre> |
Revision as of 15:25, 10 June 2009
//<pre><nowiki>
/**********************************************************************
* *
* Changes to this file affect other users. *
* Please discuss on the talk page before editing. *
* *
**********************************************************************/
var shortcutsVersion = "1.1.0";
var shortcutsReleaseDate = "2007-02-03";
/***********************************************************
* INTERFACE
***********************************************************/
/**
* Starts a new section of links. Function for external use.
*/
function shortcutsStartSection (name)
{
shortcutsLinks[shortcutsLinks.length] = { 'name': name, 'links': new Array () };
}
/**
* Adds new link into the current section of links. Function for external use.
*/
function shortcutsAddLink (name, article)
{
var links = shortcutsLinks[shortcutsLinks.length - 1]['links'];
links[links.length] = { 'name': name, 'article': article };
}
/***********************************************************
* IMPLEMENTATION
***********************************************************/
/**
* Link maker.
* Creates and returns an li element with the desired link.
*/
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;
}
/**
* Portlet maker.
* Creates and returns a portlet populated by list of links.
*/
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');
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++)
nul.appendChild (
shortcutsMakeLink (links[i]['name'], links[i]['article'])
);
nh5.appendChild (ntit);
nportlet.appendChild (nh5);
nbody.appendChild (nul);
nportlet.appendChild (nbody);
return nportlet;
}
/**
* Main function.
* Enumerates all non-empty sections, and adds new portlets beneath the old ones.
*/
function shortcutsMain ()
{
var sidecol = document.getElementById ('column-one');
for (var i = 0; i < shortcutsLinks.length; i++)
if (shortcutsLinks[i]['links'].length > 0)
sidecol.appendChild (
shortcutsMakePortlet (shortcutsLinks[i]['name'], shortcutsLinks[i]['links'])
);
}
/**
* Initializes the onload events.
*/
function shortcutsInitialize ()
{
shortcutsInit ();
shortcutsMain ();
}
/***********************************************************
* INITIALIZATION
***********************************************************/
var shortcutsLinks = new Array ();
shortcutsStartSection (wgUserName ? wgUserName : 'shortcuts');
addOnloadHook (shortcutsInitialize);
//////////////////////////
//////////////////////////
function shortcutsInit ()
{
shortcutsAddLink ('User:jsimlo/Sandbox', 'User:jsimlo/Sandbox');
shortcutsAddLink ('User:jsimlo/Wikify', 'User:jsimlo/Wikify');
shortcutsAddLink ('User:jsimlo/Shortcuts', 'User:jsimlo/Shortcuts');
shortcutsStartSection ('shortcuts');
shortcutsAddLink ('TED Notepad', 'TED Notepad');
shortcutsAddLink ('Nonogram', 'Nonogram');
}
//</nowiki></pre>