User:Jsimlo/shortcuts.js: Difference between revisions

Content deleted Content added
No edit summary
maintenance: more info TypeError: Cannot read property 'appendChild' of null
 
(11 intermediate revisions by 4 users not shown)
Line 1:
/**********************************************************************
//<pre>
* *
* Changes to this file affect other users. *
* Please discuss on the talk page before editing. *
* *
**********************************************************************/
 
 
var shortcutsVersion = "0'1.01.3"2';
var shortcutsReleaseDate = "2006'2012-0911-01 18:25"04';
var shortcutsLinks = new Array ()[];
 
/***********************************************************
Line 11 ⟶ 18:
* Starts a new section of links. Function for external use.
*/
function window.shortcutsStartSection = function (name)
{
shortcutsLinks[shortcutsLinks.length] = { 'name': name, 'links': new Array ()[] };
}
 
Line 19 ⟶ 26:
* Adds new link into the current section of links. Function for external use.
*/
function window.shortcutsAddLink = function (name, article)
{
var links = shortcutsLinks[shortcutsLinks.length - 1]['links'];
 
links[links.length] = { 'name': name, 'article': article };
Line 34 ⟶ 41:
* Creates and returns an li element with the desired link.
*/
function shortcutsMakeLink (name, urlpageName)
{
var ntxt = document.createTextNode (name);
Line 40 ⟶ 47:
var nli = document.createElement ('li');
 
na.setAttribute ('href', '/wiki/'mw.util.getUrl( +pageName url); );
nli.setAttribute ('class', 'n-shortcut');
 
Line 53 ⟶ 60:
* Creates and returns a portlet populated by list of links.
*/
function makePortletshortcutsMakePortlet (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 in= 0; i < links.length; i++)
nul.appendChild (
shortcutsMakeLink (links[i]['name'], links[i]['article'])
);
 
Line 85 ⟶ 100:
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 in= 0; i < shortcutsLinks.length; i++)
if (shortcutsLinks[i]['links'].length > 0)
sidecol.appendChild (
makePortletshortcutsMakePortlet (shortcutsLinks[i]['name'], shortcutsLinks[i]['links'])
);
}
 
/**
* Initializes the onload events.
*/
function shortcutsInitialize ()
{
if( $.isFunction( window.shortcutsInit ) ) { shortcutsInit(); }
shortcutsMain ();
}
 
Line 97 ⟶ 126:
* INITIALIZATION
***********************************************************/
shortcutsStartSection (mw.config.get('wgUserName') ? mw.config.get('wgUserName') : 'shortcuts');
 
$(shortcutsInitialize);
var shortcutsLinks = new Array ();
shortcutsStartSection ('shortcuts');
 
if (window.addEventListener)
{
window.addEventListener ("load", shortcutsMain, false);
window.addEventListener ("load", shortcutsInit, false);
}
else if (window.attachEvent)
{
window.attachEvent ("onload", shortcutsMain);
window.attachEvent ("onload", shortcutsInit);
}
 
//</pre>