Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
(Created page with "→Any JavaScript here will be loaded for all users on every page load.: if (mwCustomEditButtons) { mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": ...") |
m |
||
(7 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
addOnloadHook(function(){ | |||
if (skin == "vector") { | |||
var head = document.getElementById('head'); | |||
if(head) removeKeys(head.getElementsByTagName('a')); | |||
var panel = document.getElementById('panel'); | |||
if(panel) removeKeys(panel.getElementsByTagName('a')); | |||
} else { | |||
var columnOne = document.getElementById('column-one'); | |||
if (!columnOne) columnOne = document.getElementById('mw_portlets'); | |||
if (!columnOne) return; | |||
removeKeys(columnOne.getElementsByTagName('a')); | |||
var cactions = document.getElementById('p-cactions'); | |||
if(cactions) removeKeys(cactions.getElementsByTagName('a')); | |||
var personal = document.getElementById('p-personal'); | |||
if(personal) removeKeys(personal.getElementsByTagName('a')); | |||
} | |||
removeKeys(document.getElementsByTagName('input')); | |||
removeKeys(document.getElementsByTagName('label')); | |||
}) | |||
function removeKeys(nodeList){ | |||
var el; | |||
for (var i = 0; i < nodeList.length; i++) { | |||
el = nodeList[i]; | |||
if (!el.accessKey) continue; | |||
if (!window.removeAccessKeys || removeAccessKeys.indexOf(el.accessKey) >= 0) { | |||
el.accessKey = ''; //el.setAttribute('accessKey', ''); | |||
if (el.title) el.title = el.title.replace(tooltipAccessKeyRegexp, ''); | |||
} | |||
} | |||
} | |||
if (mwCustomEditButtons) | if (mwCustomEditButtons) | ||
Line 44: | Line 78: | ||
"tagClose": "]]", | "tagClose": "]]", | ||
"sampleText": "Needs work"} | "sampleText": "Needs work"} | ||
} | |||
/*------------------*/ | |||
/* Clean-up sidebar */ | |||
/*------------------*/ | |||
// From: http://www.mediawiki.org/wiki/Manual:Interface/Sidebar | |||
function ModifySidebar(action, section, name, link) { | |||
try { | |||
switch (section) { | |||
case "languages": | |||
var target = "p-lang"; | |||
break; | |||
case "toolbox": | |||
var target = "p-tb"; | |||
break; | |||
case "navigation": | |||
var target = "p-navigation"; | |||
break; | |||
default: | |||
var target = "p-" + section; | |||
break; | |||
} | |||
if (action == "add") { | |||
var node = document.getElementById(target) | |||
.getElementsByTagName('div')[0] | |||
.getElementsByTagName('ul')[0]; | |||
var aNode = document.createElement('a'); | |||
var liNode = document.createElement('li'); | |||
aNode.appendChild(document.createTextNode(name)); | |||
aNode.setAttribute('href', link); | |||
liNode.appendChild(aNode); | |||
liNode.className='plainlinks'; | |||
node.appendChild(liNode); | |||
} | |||
if (action == "remove") { | |||
var list = document.getElementById(target) | |||
.getElementsByTagName('div')[0] | |||
.getElementsByTagName('ul')[0]; | |||
var listelements = list.getElementsByTagName('li'); | |||
for (var i = 0; i < listelements.length; i++) { | |||
if (listelements[i].getElementsByTagName('a')[0].innerHTML == name || | |||
listelements[i].getElementsByTagName('a')[0].href == link) { | |||
list.removeChild(listelements[i]); | |||
} | |||
} | |||
} | |||
} catch(e) { | |||
// lets just ignore what's happened | |||
return; | |||
} | |||
} | |||
// For anonymous users | |||
function CustomizeModificationsOfSidebar() | |||
{ | |||
// SYNTAX: | |||
// ModifySidebar("action", "section", "name", "link"); | |||
// action "add" to add a link; "remove to remove a link | |||
// section "navigation", "toolbox", "languages" or any other existing customized section; | |||
// name contains the text of the link | |||
// link contains the URL of the link | |||
// Remove these entries from the toolbox | |||
//ModifySidebar("remove", "toolbox", "What links here", ""); | |||
ModifySidebar("remove", "toolbox", "Permanent link", ""); | |||
ModifySidebar("remove", "toolbox", "Special pages", ""); | |||
ModifySidebar("remove", "toolbox", "Related changes", ""); | |||
ModifySidebar("remove", "toolbox", "Upload file", ""); | |||
} | |||
// For logged in users | |||
function ReducedSidebar() | |||
{ | |||
//ModifySidebar("remove", "toolbox", "What links here", ""); | |||
ModifySidebar("remove", "toolbox", "Permanent link", ""); | |||
ModifySidebar("remove", "toolbox", "Related changes", ""); | |||
} | |||
// Anonymous users don't have the direct links, logged in users do. | |||
if (!isArray(wgUserGroups)) { | |||
addOnloadHook(CustomizeModificationsOfSidebar); | |||
} | |||
function userIsInGroup (group) { | |||
//are they in a given local group? | |||
if (wgUserGroups) { | |||
if (!group || group.length == 0) group = '*'; | |||
if (wgUserGroups.join (' ').indexOf (group) != -1){ | |||
return true; | |||
} | |||
else{ | |||
return false; | |||
} | |||
} | |||
return false; | |||
} | |||
if (userIsInGroup('user')){ | |||
addOnloadHook(ReducedSidebar); | |||
} | |||
function isObject(obj) { | |||
if (typeof obj == "object" && obj != null) | |||
return true; | |||
else | |||
return false; | |||
} | |||
function isArray(obj) { | |||
if (isObject(obj)) { | |||
if (obj.constructor.toString().indexOf("Array") == -1) | |||
return false; | |||
else | |||
return true; | |||
} | |||
else | |||
return false; | |||
} | |||
Array.prototype.Contains = function(element,strict) { | |||
for(i in this) { | |||
if(this[i] == element && !strict) return true; | |||
else if(this[i] === element) return true; | |||
} | |||
return false; | |||
} | } |
Latest revision as of 14:26, 12 September 2010
/* Any JavaScript here will be loaded for all users on every page load. */
addOnloadHook(function(){
if (skin == "vector") {
var head = document.getElementById('head');
if(head) removeKeys(head.getElementsByTagName('a'));
var panel = document.getElementById('panel');
if(panel) removeKeys(panel.getElementsByTagName('a'));
} else {
var columnOne = document.getElementById('column-one');
if (!columnOne) columnOne = document.getElementById('mw_portlets');
if (!columnOne) return;
removeKeys(columnOne.getElementsByTagName('a'));
var cactions = document.getElementById('p-cactions');
if(cactions) removeKeys(cactions.getElementsByTagName('a'));
var personal = document.getElementById('p-personal');
if(personal) removeKeys(personal.getElementsByTagName('a'));
}
removeKeys(document.getElementsByTagName('input'));
removeKeys(document.getElementsByTagName('label'));
})
function removeKeys(nodeList){
var el;
for (var i = 0; i < nodeList.length; i++) {
el = nodeList[i];
if (!el.accessKey) continue;
if (!window.removeAccessKeys || removeAccessKeys.indexOf(el.accessKey) >= 0) {
el.accessKey = ''; //el.setAttribute('accessKey', '');
if (el.title) el.title = el.title.replace(tooltipAccessKeyRegexp, '');
}
}
}
if (mwCustomEditButtons)
{
mwCustomEditButtons[mwCustomEditButtons.length] = {
"imageFile": "http://modelling3e4.connectmv.com/extensions/toolbar_images/button_tt.png",
"speedTip": "Insert teletype text here",
"tagOpen": "<tt>",
"tagClose": "</tt>",
"sampleText": "Insert teletype text here"}
mwCustomEditButtons[mwCustomEditButtons.length] = {
"imageFile": "http://modelling3e4.connectmv.com/extensions/toolbar_images/button_comment.png",
"speedTip": "Comment visible only for editors",
"tagOpen": "<!-- ",
"tagClose": " -->",
"sampleText": "Insert comment here"}
mwCustomEditButtons[mwCustomEditButtons.length] = {
"imageFile": "http://modelling3e4.connectmv.com/extensions/toolbar_images/button_source_code.png",
"speedTip": "Colour-coded source code",
"tagOpen": "<syntaxhighlight lang=\"matlab\">\n",
"tagClose": "\n</syntaxhighlight>",
"sampleText": "Place source code here; replace lang if necessary"}
mwCustomEditButtons[mwCustomEditButtons.length] = {
"imageFile": "http://modelling3e4.connectmv.com/extensions/toolbar_images/button_definition.png",
"speedTip": "Insert definition(s)",
"tagOpen": "; ",
"tagClose": "\n: ",
"sampleText": "Words to define here (definition goes after the colon)"}
mwCustomEditButtons[mwCustomEditButtons.length] = {
"imageFile": "http://modelling3e4.connectmv.com/extensions/toolbar_images/button_table.png",
"speedTip": "Insert a table",
"tagOpen": "{| class=\"wikitable\"\n|-\n",
"tagClose": "\n|}",
"sampleText": "! header 1\n! header 2\n! header 3\n|-\n| row 1, cell 1\n| row 1, cell 2\n| row 1, cell 3\n|-\n| row 2, cell 1\n| row 2, cell 2\n| row 2, cell 3"}
mwCustomEditButtons[mwCustomEditButtons.length] = {
"imageFile": "http://modelling3e4.connectmv.com/extensions/toolbar_images/button_category.png",
"speedTip": "Insert a category for this page",
"tagOpen": "[[Category: ",
"tagClose": "]]",
"sampleText": "Needs work"}
}
/*------------------*/
/* Clean-up sidebar */
/*------------------*/
// From: http://www.mediawiki.org/wiki/Manual:Interface/Sidebar
function ModifySidebar(action, section, name, link) {
try {
switch (section) {
case "languages":
var target = "p-lang";
break;
case "toolbox":
var target = "p-tb";
break;
case "navigation":
var target = "p-navigation";
break;
default:
var target = "p-" + section;
break;
}
if (action == "add") {
var node = document.getElementById(target)
.getElementsByTagName('div')[0]
.getElementsByTagName('ul')[0];
var aNode = document.createElement('a');
var liNode = document.createElement('li');
aNode.appendChild(document.createTextNode(name));
aNode.setAttribute('href', link);
liNode.appendChild(aNode);
liNode.className='plainlinks';
node.appendChild(liNode);
}
if (action == "remove") {
var list = document.getElementById(target)
.getElementsByTagName('div')[0]
.getElementsByTagName('ul')[0];
var listelements = list.getElementsByTagName('li');
for (var i = 0; i < listelements.length; i++) {
if (listelements[i].getElementsByTagName('a')[0].innerHTML == name ||
listelements[i].getElementsByTagName('a')[0].href == link) {
list.removeChild(listelements[i]);
}
}
}
} catch(e) {
// lets just ignore what's happened
return;
}
}
// For anonymous users
function CustomizeModificationsOfSidebar()
{
// SYNTAX:
// ModifySidebar("action", "section", "name", "link");
// action "add" to add a link; "remove to remove a link
// section "navigation", "toolbox", "languages" or any other existing customized section;
// name contains the text of the link
// link contains the URL of the link
// Remove these entries from the toolbox
//ModifySidebar("remove", "toolbox", "What links here", "");
ModifySidebar("remove", "toolbox", "Permanent link", "");
ModifySidebar("remove", "toolbox", "Special pages", "");
ModifySidebar("remove", "toolbox", "Related changes", "");
ModifySidebar("remove", "toolbox", "Upload file", "");
}
// For logged in users
function ReducedSidebar()
{
//ModifySidebar("remove", "toolbox", "What links here", "");
ModifySidebar("remove", "toolbox", "Permanent link", "");
ModifySidebar("remove", "toolbox", "Related changes", "");
}
// Anonymous users don't have the direct links, logged in users do.
if (!isArray(wgUserGroups)) {
addOnloadHook(CustomizeModificationsOfSidebar);
}
function userIsInGroup (group) {
//are they in a given local group?
if (wgUserGroups) {
if (!group || group.length == 0) group = '*';
if (wgUserGroups.join (' ').indexOf (group) != -1){
return true;
}
else{
return false;
}
}
return false;
}
if (userIsInGroup('user')){
addOnloadHook(ReducedSidebar);
}
function isObject(obj) {
if (typeof obj == "object" && obj != null)
return true;
else
return false;
}
function isArray(obj) {
if (isObject(obj)) {
if (obj.constructor.toString().indexOf("Array") == -1)
return false;
else
return true;
}
else
return false;
}
Array.prototype.Contains = function(element,strict) {
for(i in this) {
if(this[i] == element && !strict) return true;
else if(this[i] === element) return true;
}
return false;
}