User:Jsimlo/shortcuts.js: Difference between revisions

Content deleted Content added
version 1.1.0: added initialization through addOnloadHook ()
maintenance: more info TypeError: Cannot read property 'appendChild' of null
 
(3 intermediate revisions by 3 users not shown)
Line 1:
/**********************************************************************
//<pre><nowiki>
 
/**********************************************************************
* *
* Changes to this file affect other users. *
Line 9 ⟶ 7:
 
 
var shortcutsVersion = "'1.1.0"2';
var shortcutsReleaseDate = "2007'2012-0211-03"04';
var shortcutsLinks = new Array ()[];
 
 
/***********************************************************
Line 20 ⟶ 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 28 ⟶ 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'];
Line 43 ⟶ 41:
* Creates and returns an li element with the desired link.
*/
function shortcutsMakeLink (name, urlpageName)
{
var ntxt = document.createTextNode (name);
Line 49 ⟶ 47:
var nli = document.createElement ('li');
 
na.setAttribute ('href', '/wiki/'mw.util.getUrl( +pageName url); );
nli.setAttribute ('class', 'n-shortcut');
 
Line 70 ⟶ 68:
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++)
Line 94 ⟶ 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 = 0; i < shortcutsLinks.length; i++)
Line 108 ⟶ 119:
function shortcutsInitialize ()
{
if( $.isFunction( window.shortcutsInit ) ) { shortcutsInit(); }
shortcutsMain ();
}
Line 115 ⟶ 126:
* INITIALIZATION
***********************************************************/
shortcutsStartSection (mw.config.get('wgUserName') ? mw.config.get('wgUserName') : 'shortcuts');
 
addOnloadHook $(shortcutsInitialize);
var shortcutsLinks = new Array ();
shortcutsStartSection (wgUserName ? wgUserName : 'shortcuts');
 
addOnloadHook (shortcutsInitialize);
 
//</nowiki></pre>