MediaWiki:Common.js: Difference between revisions
(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...") |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
/* | /* Mobile Menu JS Start */ | ||
$('#mw-head').append('<div id="menu-toggle" onclick="mobileMenu()"><div class="bar1"></div><div class="bar2"></div><div class="bar3"></div></div>'); | $('#mw-head').append('<div id="menu-toggle" onclick="mobileMenu()"><div class="bar1"></div><div class="bar2"></div><div class="bar3"></div></div>'); | ||
Line 5: | Line 5: | ||
function mobileMenu() { | function mobileMenu() { | ||
if ($(".open")[0]) { | if ($(".open-toggle")[0]) { | ||
$("#mw-panel").removeClass("open"); | $("#mw-panel").removeClass("open-toggle"); | ||
} else { | } else { | ||
$("#mw-panel").addClass("open"); | $("#mw-panel").addClass("open-toggle"); | ||
} | } | ||
} | } | ||
$( window ).resize(function() { | |||
if ($(window).width() > 800) { | |||
$("#mw-panel").removeClass("open-toggle"); | |||
} | |||
}); | |||
/* Mobile Menu JS End */ | |||
var list = document.getElementById("p-views").getElementsByTagName("a"); | var list = document.getElementById("p-views").getElementsByTagName("a"); | ||
Line 21: | Line 29: | ||
document.getElementById("p-cactions").getElementsByTagName("ul")[0].appendChild(node); | document.getElementById("p-cactions").getElementsByTagName("ul")[0].appendChild(node); | ||
} | } | ||
var mainList = document.getElementById("p-namespaces").getElementsByTagName("a"); | var mainList = document.getElementById("p-namespaces").getElementsByTagName("a"); | ||
Line 32: | Line 39: | ||
document.getElementById("p-cactions").getElementsByTagName("ul")[0].appendChild(node); | document.getElementById("p-cactions").getElementsByTagName("ul")[0].appendChild(node); | ||
} | } | ||
var mainListFirstElement = document.getElementById("p-namespaces").getElementsByTagName("a")[0]; | var mainListFirstElement = document.getElementById("p-namespaces").getElementsByTagName("a")[0]; | ||
var myString = mainListFirstElement.innerText; | var myString = mainListFirstElement.innerText; | ||
myString = myString.substring(0, myString.lastIndexOf(" ")); | myString = myString.substring(0, myString.lastIndexOf(" ")); | ||
var span = document.getElementById("p-namespaces").getElementsByTagName("span")[0]; | var span = document.getElementById("p-namespaces").getElementsByTagName("span")[0]; | ||
var textnodeHref = document.createElement("a"); | var textnodeHref = document.createElement("a"); | ||
Line 51: | Line 55: | ||
textnodeHref.title = mainListFirstElement.title; | textnodeHref.title = mainListFirstElement.title; | ||
span.appendChild(textnodeHref); | span.appendChild(textnodeHref); | ||
var notNull= document.getElementById("p-views").getElementsByTagName("a"); | |||
if (notNull.length > 0) { | |||
document.getElementById("p-cactions").style.display = "block"; | |||
} |
Latest revision as of 12:19, 26 March 2018
/* Mobile Menu JS Start */ $('#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-toggle")[0]) { $("#mw-panel").removeClass("open-toggle"); } else { $("#mw-panel").addClass("open-toggle"); } } $( window ).resize(function() { if ($(window).width() > 800) { $("#mw-panel").removeClass("open-toggle"); } }); /* Mobile Menu JS End */ 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]; 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); var notNull= document.getElementById("p-views").getElementsByTagName("a"); if (notNull.length > 0) { document.getElementById("p-cactions").style.display = "block"; }