User:Stigmj/monobook.js

// // An API-call to get a short list of pages, starting with the one you are on. // by no:User:Stigmj // function indexBox { var testobj = document.getElementById('tag-noindex'); if (!testobj) { var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&format=json&callback=indexBoxCB&list=allpages&apfilterredir=nonredirects&apnamespace=' + wgNamespaceNumber + '&apfrom=' + wgTitle + '&aplimit=6'; mw.loader.load(url); var prevurl = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&format=json&callback=indexBoxPrevCB&list=allpages&apdir=descending&apfilterredir=nonredirects&apnamespace=' + wgNamespaceNumber + '&apfrom=' + wgTitle + '&aplimit=5'; mw.loader.load(prevurl); } } // // A short callbackfunction to generate a dynamic index above the "navigation" menu in Monobook // by no:User:Stigmj // function indexBoxCB(obj) { if (obj['query']) { var itemlist = obj['query']['allpages']; // Create the container var idxobj = document.createElement('div'); idxobj.setAttribute('class', 'generated-sidebar portlet'); idxobj.setAttribute('id', 'p-index'); // Create the header of the container var idxhdr = document.createElement('h5'); idxhdr.appendChild(document.createTextNode('indeks')); // Create the body of the container var idxbody = document.createElement('div'); idxbody.setAttribute('class', 'pBody'); // Create the unnumbered list, which goes into the body var ul = document.createElement('ul'); for (var i=0; i<itemlist.length; i++) { // Create the list-elements var li = document.createElement('li'); li.setAttribute('id', 'idx-li-' + i);

var title = itemlist[i]['title'].split(':',2); if (title.length==2) title = title[1]; else title = title[0];

if (i==0) { var a = document.createTextNode(title); } else { var a = document.createElement('a'); a.setAttribute('href', wgServer + '/wiki/' + itemlist[i]['title']); a.setAttribute('title', itemlist[i]['title']); a.appendChild(document.createTextNode(title)); }			li.appendChild(a); // Attach the list-element to the unnumbered list ul.appendChild(li); }		switch (skin) { case 'modern': var portlets = 'mw_portlets'; idxbody.setAttribute('class', 'pBody'); idxobj.setAttribute('class', 'generated-sidebar portlet'); break; case 'vector': var portlets = 'panel'; idxbody.setAttribute('class', 'body'); idxobj.setAttribute('class', 'portal'); break default: var portlets = 'column-one'; idxbody.setAttribute('class', 'pBody'); idxobj.setAttribute('class', 'generated-sidebar portlet'); }		// Attach the unnumbered list to the body idxbody.appendChild(ul); // Attach the header to the container idxobj.appendChild(idxhdr); // Attach the body to the container idxobj.appendChild(idxbody); var colobj = document.getElementById(portlets); var navobj = document.getElementById('p-navigation'); // Insert the index-container before the navigation-container colobj.insertBefore(idxobj, navobj); // Check to see if dynamic menus are in use if (typeof wgGadgetDynamicMenus != 'undefined') { // Call up the rearranging importScript('MediaWiki:Gadget-dynamic-menus-test.js') }	} }

function indexBoxPrevCB(obj) { if (obj['query']) { var itemlist = obj['query']['allpages']; // Find the container var idxbody = document.getElementById('p-index'); // Find the list idxbody = idxbody.getElementsByTagName( "ul" )[0]; var ul = idxbody; // Find the first li-item in the list idxbody = idxbody.getElementsByTagName( "li" )[0]; for (var i=1; i<itemlist.length; i++) { // Create the list-elements var li = document.createElement('li'); li.setAttribute('id', 'idx-li-' + i); var title = itemlist[i]['title'].split(':',2); if (title.length==2) title = title[1]; else title = title[0]; var a = document.createElement('a'); a.setAttribute('href', wgServer + '/wiki/' + itemlist[i]['title']); a.setAttribute('title', itemlist[i]['title']); a.appendChild(document.createTextNode(title)); li.appendChild(a); // Attach the list-element to the unnumbered list ul.insertBefore(li, idxbody); idxbody = li; }	} } var isDiff = (document.location.search && (document.location.search.indexOf("diff=") != -1 || document.location.search.indexOf("oldid=") != -1));

if (wgNamespaceNumber>=0 && !isDiff && wgAction != 'edit' && wgAction != 'submit' && (skin == 'monobook' || skin == 'modern' || skin == 'vector' || skin == 'chick')) { addOnloadHook(indexBox); }