MediaWiki:Common.js

From Teltonika Networks Wiki
Revision as of 07:52, 26 March 2018 by Giedrius (talk | contribs) (Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: $('#mw-head').append('<div id="menu-toggle" onclick="mobileMenu()"><div class="bar1"></div><div clas...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
$('#mw-head').append('<div id="menu-toggle" onclick="mobileMenu()"><div class="bar1"></div><div class="bar2"></div><div class="bar3"></div></div>');

$('#mw-panel').append('<div id="menu-toggle" onclick="mobileMenu()"><div class="bar1"></div><div class="bar2"></div><div class="bar3"></div></div>');

function mobileMenu() {
    if ($(".open")[0]) {
        $("#mw-panel").removeClass("open");
    } else {
        $("#mw-panel").addClass("open");
    }
}

var list = document.getElementById("p-views").getElementsByTagName("a");
for (i = 0; i < list.length; i++) {
    var node = document.createElement("li");
    var textnode = document.createElement("a");
    textnode.innerText = list[i].innerText;
    textnode.href = list[i].href;
    node.appendChild(textnode);
    document.getElementById("p-cactions").getElementsByTagName("ul")[0].appendChild(node);
}


var mainList = document.getElementById("p-namespaces").getElementsByTagName("a");
for (i = 0; i < mainList.length; i++) {
    var node = document.createElement("li");
    var textnode = document.createElement("a");
    textnode.innerText = mainList[i].innerText;
    textnode.href = mainList[i].href;
    node.appendChild(textnode);
    document.getElementById("p-cactions").getElementsByTagName("ul")[0].appendChild(node);
}


var mainListFirstElement = document.getElementById("p-namespaces").getElementsByTagName("a")[0];
var myString = mainListFirstElement.innerText;
myString = myString.substring(0, myString.lastIndexOf(" "));


var span = document.getElementById("p-namespaces").getElementsByTagName("span")[0];
console.log(span);

var textnodeHref = document.createElement("a");
if (myString.length > 0) {
    textnodeHref.innerText = myString;
} else {
    textnodeHref.innerText = mainListFirstElement.innerText;
}
textnodeHref.href = mainListFirstElement.href;
textnodeHref.title = mainListFirstElement.title;
span.appendChild(textnodeHref);