MediaWiki:Common.js

From DominionStrategy Wiki
(Difference between revisions)
Jump to: navigation, search
m
m
Line 2: Line 2:
  
 
// ADDING PORTLET LINKS
 
// ADDING PORTLET LINKS
function portlets(){
+
function add_portlet_links(){
var PortletList = {
+
var PortletLinks = {
 
/*
 
/*
PortletList[ string portletID ] = Array(
+
PortletLinks[ string linkID ] = Array(
 
boolean left,    // true if added on the left-side, false if right
 
boolean left,    // true if added on the left-side, false if right
 
string label,
 
string label,
Line 20: Line 20:
 
Add a portlet link to page
 
Add a portlet link to page
 
PARAMS
 
PARAMS
regexp/string page: RegExp or exact match string of page titles to add portlet
+
regexp/string page: RegExp or exact match string of page titles to add portlet link
string id        : portletID of the added portlet
+
string id        : linkID of the added portlet link
 
*/
 
*/
  
function add_portlet_link(page,id){
+
function add(page,id){
 
if(typeof page == "string"){
 
if(typeof page == "string"){
 
if(wgPageName != page) return false
 
if(wgPageName != page) return false
 
}else if(!page.test(wgPageName)) return false
 
}else if(!page.test(wgPageName)) return false
 
 
var portlet = PortletsList[id]
+
var link = PortletLinks[id]
if(!portlet) return false
+
if(!link) return false
var vector = portlet[0] ? 'p-namespaces' : 'p-views'
+
var vector = link[0] ? 'p-namespaces' : 'p-views'
return mw.util.addPortletLink( vector , portlet[3] , portlet[1] , portlet[2] , portlet[4] , $('#'+vector+' li').children[3] )
+
return mw.util.addPortletLink( vector , link[3] , link[1] , id , link[2] , link[4] , $('#'+vector+' li')[link[5]-1] )
 
}
 
}
  
 
// Register adding portlets
 
// Register adding portlets
add_portlet_link('Help:Discussion','ca-new-section')
+
add('Help:Discussion','ca-new-section')
 
}
 
}
$(document).ready( portlets )
+
$(document).ready( add_portlet_links )

Revision as of 05:29, 13 November 2012

/* Any JavaScript here will be loaded for all users on every page load. */

// ADDING PORTLET LINKS
function add_portlet_links(){
	var PortletLinks = {
	/*
		PortletLinks[ string linkID ] = Array(
			boolean left,     // true if added on the left-side, false if right
			string label,
			string tooltip,
			string href,
			string accesskey,
			integer position  // insert position, counting from left
		)
	*/
		"ca-new-section":[false,"New Section","Add a new section","?action=edit&section=new","e",3]
	}

	/*
		Add a portlet link to page
		PARAMS
			regexp/string page: RegExp or exact match string of page titles to add portlet link
			string id         : linkID of the added portlet link
	*/

	function add(page,id){
		if(typeof page == "string"){
			if(wgPageName != page) return false
		}else if(!page.test(wgPageName)) return false
		
		var link = PortletLinks[id]
		if(!link) return false
		var vector = link[0] ? 'p-namespaces' : 'p-views'
		return mw.util.addPortletLink( vector , link[3] , link[1] , id , link[2] , link[4] , $('#'+vector+' li')[link[5]-1] )
	}

	// Register adding portlets
	add('Help:Discussion','ca-new-section')
}
$(document).ready( add_portlet_links )
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox