User:Jsimlo/shortcuts.js: Difference between revisions

Content deleted Content added
No edit summary
 
maintenance: more info TypeError: Cannot read property 'appendChild' of null
 
(16 intermediate revisions by 4 users not shown)
Line 1:
/**********************************************************************
var shortcutsVersion = "0.0.1";
* *
var shortcutsReleaseDate = "2006-09-01 17:23";
* Changes to this file affect other users. *
* Please discuss on the talk page before editing. *
* *
**********************************************************************/
 
 
function shortcutsMakeLink (name, url)
var shortcutsVersion = '1.1.2';
var shortcutsReleaseDate = '2012-11-04';
var shortcutsLinks = [];
 
/***********************************************************
* INTERFACE
***********************************************************/
 
/**
* Starts a new section of links. Function for external use.
*/
window.shortcutsStartSection = function (name)
{
shortcutsLinks[shortcutsLinks.length] = { 'name': name, 'links': [] };
}
 
/**
* Adds new link into the current section of links. Function for external use.
*/
window.shortcutsAddLink = function (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, pageName)
{
var ntxt = document.createTextNode (name);
Line 8 ⟶ 47:
var nli = document.createElement ('li');
 
na.setAttribute ('href', '/wiki/'mw.util.getUrl( +pageName url); );
nli.setAttribute ('class', 'n-shortcut');
 
Line 17 ⟶ 56:
}
 
/**
function makePortlet (name, links)
* 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');
 
if (mw.config.get('skin') == 'vector') {
nportlet.setAttribute ('id', 'p-'+name);
nportlet.setAttribute ('classid', 'portletp-'+name);
nbody nportlet.setAttribute ('class', 'pBodyportal');
nul nh5.setAttribute ('idxml:lang', 'p-en'+name);
nh5.setAttribute ('lang', 'en');
nbody.setAttribute ('class', 'body');
} else {
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'])
);
 
Line 43 ⟶ 94:
}
 
/**
function shortcutsMyLinks ()
* Main function.
* Enumerates all non-empty sections, and adds new portlets beneath the old ones.
*/
function shortcutsMain ()
{
if (mw.config.get('skin') == 'vector') {
var sidecol = document.getElementById ('column-one');
var sidecol = document.getElementById ('panel');
} else {
var sidecol = document.getElementById ('column-one');
}
if(!sidecol) return;
 
for (var i = 0; i < shortcutsLinks.length; i++)
if (shortcutsLinks[i]['links'].length > 0)
sidecol.appendChild (
makePortletshortcutsMakePortlet (shortcutsLinks[i]['name'], shortcutsLinks[i]['links']);
);
}
if (window.addEventListener)
window.addEventListener("load", shortcutsMyLinks, false);
else if (window.attachEvent)
window.attachEvent("onload", shortcutsMyLinks);
 
/**
 
* Initializes the onload events.
function shortcutsStartSection (name)
*/
function shortcutsInitialize ()
{
if( $.isFunction( window.shortcutsInit ) ) { shortcutsInit(); }
shortcutsLinks[shortcutsLinks.length] = new Array ('name': name, 'links': new Array ());
shortcutsMain ();
}
 
/***********************************************************
function shortcutsAddLink (name, article)
* INITIALIZATION
{
***********************************************************/
var links = shortcutsLinks[shortcutsLinks.length - 1];
shortcutsStartSection (mw.config.get('wgUserName') ? mw.config.get('wgUserName') : 'shortcuts');
 
$(shortcutsInitialize);
links[links.length] = new Array ('name': name, 'article': article);
}
 
/**
* Initialization stuff..
*/
var shortcutsLinks = new Array ();
shortcutsStartSection ('shortcuts');