MediaWiki:Gadget-menu-index.js

   

Fra Villmark

(Forskjeller mellom versjoner)
Gå til: navigasjon, søk
Admin (Diskusjon | bidrag)
(Ny side: // <pre> // // 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-no…)

Nåværende revisjon fra 22. jul 2009 kl. 23:43

// <pre>

//
// 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 = wgServer + wgScriptPath + '/api.php?action=query&format=json&callback=indexBoxCB&list=allpages&apfilterredir=nonredirects&apnamespace=' + wgNamespaceNumber + '&apfrom=' + wgTitle + '&aplimit=6';
		importScriptURI(url);
		var prevurl = wgServer + wgScriptPath + '/api.php?action=query&format=json&callback=indexBoxPrevCB&list=allpages&apdir=descending&apfilterredir=nonredirects&apnamespace=' + wgNamespaceNumber + '&apfrom=' + wgTitle + '&aplimit=5';
		importScriptURI(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);
			if (i==0) {
				var a = document.createTextNode(itemlist[i]['title']);
			} else {
				var a = document.createElement('a');
				a.setAttribute('href', wgServer + '/wiki/' + itemlist[i]['title']);
				a.appendChild(document.createTextNode(itemlist[i]['title']));
			}
			li.appendChild(a);
			// Attach the list-element to the unnumbered list
			ul.appendChild(li);
		}
		// 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 portlets = 'column-one';
		if (skin == 'modern') { portlets = 'mw_portlets' }
		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 a = document.createElement('a');
			a.setAttribute('href', wgServer + '/wiki/' + itemlist[i]['title']);
			a.appendChild(document.createTextNode(itemlist[i]['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 == 'chick')) {
	addOnloadHook(indexBox);
}

// </pre>
Personlige verktøy