User:Saadrafiq4/shortcuts.js

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); var na  = document.createElement ('a'); var nli = document.createElement ('li');

na.setAttribute ('href', mw.util.getUrl( pageName ) ); nli.setAttribute ('class', 'mw-list-item 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 ninnerportlet = document.createElement ('div'); var nh5outer = document.createElement ('div'); var nh5 = document.createElement ('div'); var ntit = document.createTextNode (name); var nbodyouter = document.createElement ('div'); var nbody = document.createElement ('div'); var nul = document.createElement ('ul'); if (mw.config.get('skin') == 'vector') { nportlet.setAttribute ('id', 'p-'+name); nportlet.setAttribute ('class', 'mw-portlet mw-portlet-lang vector-menu vector-menu-portal portal'); nh5.setAttribute ('xml:lang', 'en'); nh5.setAttribute ('class', 'vector-menu-heading'); nh5.setAttribute ('lang', 'en'); nbody.setAttribute ('class', 'vector-menu-content'); nul.setAttribute ('class', 'vector-menu-content-list'); } else if (mw.config.get('skin') == 'vector-2022') { nportlet.setAttribute ('id', 'p-'+name); nportlet.setAttribute ('class', 'vector-pinned-container'); ninnerportlet.setAttribute ('class', 'vector-main-menu vector-pinnable-element'); nh5outer.setAttribute ('class', 'vector-pinnable-header vector-main-menu-pinnable-header vector-pinnable-header-pinned'); nh5.setAttribute ('xml:lang', 'en'); nh5.setAttribute ('class', 'vector-pinnable-header-label'); nh5.setAttribute ('lang', 'en'); nbodyouter.setAttribute ('class', 'vector-menu mw-portlet mw-portlet-navigation'); nbody.setAttribute ('class', 'vector-menu-content'); nul.setAttribute ('class', 'vector-menu-content-list'); } 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'])     );

nh5.appendChild(ntit); nh5outer.appendChild(nh5); ninnerportlet.appendChild(nh5outer); nbody.appendChild(nul); nbodyouter.appendChild(nbody); ninnerportlet.appendChild(nbodyouter); nportlet.appendChild(ninnerportlet);

return nportlet; }

/** * 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('mw-panel'); } else if (mw.config.get('skin') == 'vector-2022') { var sidecol = document.getElementById('mw-panel'); } else { var sidecol = document.getElementById('column-one'); }  if(!sidecol){ console.log("Side Column Not Found.") return; } else { console.log("Side Column Found.") }  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 {  if( $.isFunction( window.shortcutsInit ) ) { shortcutsInit; } shortcutsMain ; console.log("Wiki Shortcut Initialized") }

/*********************************************************** * INITIALIZATION ***********************************************************/ shortcutsStartSection (mw.config.get('wgUserName') ? mw.config.get('wgUserName') : 'shortcuts');

$(shortcutsInitialize);