MediaWiki:Common.js
From DominionStrategy Wiki
(Difference between revisions)
m |
m |
||
Line 2: | Line 2: | ||
// ADDING PORTLET LINKS | // ADDING PORTLET LINKS | ||
− | function | + | function add_portlet_links(){ |
− | var | + | var PortletLinks = { |
/* | /* | ||
− | + | 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 : | + | string id : linkID of the added portlet link |
*/ | */ | ||
− | function | + | 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 | + | var link = PortletLinks[id] |
− | if(! | + | if(!link) return false |
− | var vector = | + | var vector = link[0] ? 'p-namespaces' : 'p-views' |
− | return mw.util.addPortletLink( vector , | + | 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('Help:Discussion','ca-new-section') | |
} | } | ||
− | $(document).ready( | + | $(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§ion=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 )