Difference between revisions of "MediaWiki:Common.js"

From Introduction to Reactor Design: 3K4
Jump to navigation Jump to search
(Created page with "→‎Remove some of the annoying keyboard shortcuts: →‎Removes all access keys: addOnloadHook(function(){ if (skin == "vector") { var head = document.getElementById(...")
 
(Blanked the page)
Tag: Blanking
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
/* Remove some of the annoying keyboard shortcuts */


/* Removes all access keys*/   
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, '');
    }
  }
}
/* Any JavaScript here will be loaded for all users on every page load. */
if (mwCustomEditButtons)
{
    mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://learnche.mcmaster.ca/mediawiki/code/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://learnche.mcmaster.ca/mediawiki/code/extensions/toolbar_images/button_comment.png",
    "speedTip": "Comment: only seen by editors",
    "tagOpen": "<!-- ",
    "tagClose": " -->",
    "sampleText": "Insert comment here"}
    mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://learnche.mcmaster.ca/mediawiki/code/extensions/toolbar_images/button_source_code.png",
    "speedTip": "Colour-coded source code",
    "tagOpen": "<syntaxhighlight lang=\"python\">\n",
    "tagClose": "\n</syntaxhighlight>",
    "sampleText": "Place source code here; replace lang if necessary"}
    mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://learnche.mcmaster.ca/mediawiki/code/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://learnche.mcmaster.ca/mediawiki/code/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://learnche.mcmaster.ca/mediawiki/code/extensions/toolbar_images/button_category.png",
    "speedTip": "Insert a category for this page",
    "tagOpen": "[[Category: ",
    "tagClose": "]]",
    "sampleText": "Needs work"}
}
// 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;
    }
}
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", "");
    ModifySidebar("remove", "toolbox", "Printable version", "");
}
addOnloadHook(CustomizeModificationsOfSidebar);

Latest revision as of 17:59, 22 March 2022