MediaWiki:Vector.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Wendl (Diskussion | Beiträge) |
Wendl (Diskussion | Beiträge) |
||
Zeile 204: | Zeile 204: | ||
function modifyURL(elem){ | function modifyURL(elem){ | ||
var t = elem; | var t = elem; | ||
while(!$(t).hasClass("mw-headline"){ | while(!$(t).hasClass("mw-headline")){ | ||
t = t.firstChild | t = t.firstChild; | ||
} | } | ||
console.log(t); | console.log(t); |
Version vom 12. November 2022, 01:18 Uhr
/* Das folgende JavaScript wird für Benutzer der Vector-Benutzeroberfläche geladen. */ //--------------------------------------------- Parameters // ------------ Parameter var scroll_x; var scroll_y; // ------------ Start addScrollButton(); modifySearch(); incrementInlist(); categoryImprovements(); handleLiveChatButtons(); handleExpandables(); handleInfoButtons(); // Listen for URL Change window.addEventListener('hashchange', function() { onFocusHeadline(); }) //--------------------------------------------- Scroll Actions //--------------------------------------------- Add Scroll to top button function addScrollButton(){ window.addEventListener("scroll", function(event) { scroll_y = this.scrollY; scroll_x = this.scrollX; if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { $(sc_t).fadeIn(); } else { $(sc_t).fadeOut(); } }); sc_t = document.createElement("div"); sc_t.id = "scroll-top-button"; document.querySelector("body").append(sc_t); sc_t.addEventListener("click", topFunction); } function topFunction() { $("html, body").animate({ scrollTop: "0" }); } function scrollToAnchorByURL(){ var url = window.location.href; if(url.includes("#")){ var id = url.split("#")[1]; var anchor = $("#"+id); scrollToElement(anchor); } } function scrollToElement(elem){ $('html,body').animate({scrollTop: elem.offset().top}); } //--------------------------------------------- Search Field function modifySearch(){ document.querySelector("#searchInput").placeholder = "Suche…"; } //--------------------------------------------- Link Styling (Inactive via CSS) function addCustomStyles(){ var links = document.querySelectorAll("a"); for(var i=0; i<links.length;i++){ var link = links[i]; if(link.getElementsByTagName("img").length==0){ link.classList.add("adbk-link"); } } } //--------------------------------------------- Inlist Incrementor function incrementInlist(){ var inlists = document.querySelectorAll(".inlist"); for (var i = 0; i < inlists.length; i++){ var inlist = inlists[i]; addListClasses(inlist); handleInlist(inlist, 0); } } function addListClasses(inlist_div){ var l = inlist_div.querySelectorAll("ul"); for(var i=0;i<l.length;i++){ l[i].classList.add("inlist-list"); } l = inlist_div.querySelectorAll("ol"); for(var i=0;i<l.length;i++){ l[i].classList.add("inlist-list"); } } function handleInlist(inlist, p_listindex){ var list = inlist.getElementsByClassName("inlist-list"); var children = list[0].children; for (var i = 0; i < children.length; i ++){ var listindex = p_listindex + i + 1; var li = children[i]; if(li.getElementsByClassName("inlist-list").length > 0){ handleInlist(li, listindex*10); } var str = listindex.toString(); var str_n = ""; for (var c = 0; c < str.length; c++){ str_n = str_n + "." + str.charAt(c); } str_n = str_n.slice(1) li.setAttribute('data-listindex', str_n); } } //--------------------------------------------- Infobutton-URL function handleInfoButtons(){ var infobuttons = document.querySelectorAll("#infobutton-url"); for (var i = 0; i < infobuttons.length; i++){ infobuttons[i].addEventListener("click", function(event) { var infobutton = getParentByClass(event.target, "infobutton-url"); var url = infobutton.getAttribute('data-url'); window.open(url); }) } } function getParentByClass(elem, _class){ var t = elem; while (!$(t).hasClass(_class)) { t = t.parentElement; } return t; } //--------------------------------------------- Category Improvements function categoryImprovements(){ var head = document.getElementById("firstHeading") var head_str = head.innerHTML; var head_arr = head_str.split(":"); var head_new = ""; for(var i=0;i<head_arr.length;i++){ head_new = head_new + head_arr[i] + ": "; } head.innerHTML = cutLast(cutLast(head_new)); } //--------------------------------------------- Rocket.Chat Livechat (function(w, d, s, u) { w.RocketChat = function(c) { w.RocketChat._.push(c) }; w.RocketChat._ = []; w.RocketChat.url = u; var h = d.getElementsByTagName(s)[0], j = d.createElement(s); j.async = true; j.src = 'https://chat.adbk-nuernberg.de/livechat/rocketchat-livechat.min.js?_=201903270000'; //h.parentNode.insertBefore(j, h); document.body.appendChild(j); })(window, document, 'script', 'https://chat.adbk-nuernberg.de/livechat'); function openLiveChat() { newwindow=window.open("https://chat.adbk-nuernberg.de/livechat?mode=popout","chat.adbk-nuernberg.de",'height=700,width=480'); if (window.focus) {newwindow.focus()} return false; } function handleLiveChatButtons(){ var liveChatButtons = document.querySelectorAll(".livechat"); for (var i = 0; i < liveChatButtons.length; i++){ var liveChatButton = liveChatButtons[i]; liveChatButton.addEventListener("click", openLiveChat, false); } } //--------------------------------------------- Expandable function handleExpandables(){ var expandables = document.querySelectorAll(".expandable"); for (var i = 0; i < expandables.length; i++){ var title = expandables[i].querySelector("#expandable-title"); title.addEventListener("click", function(event) { toggleTitle(event.target); modifyURL(event.target); }, false); } } function modifyURL(elem){ var t = elem; while(!$(t).hasClass("mw-headline")){ t = t.firstChild; } console.log(t); } function onFocusHeadline(){ close_all_expandables() var url = window.location.href; var sectionName = url.split("#")[1]; var section = document.getElementById(sectionName); var bubbleList = []; while (section.tagName != "BODY") { bubbleList.push(section); section = section.parentElement; } for (var i = 0; i < bubbleList.length; i++){ try { if($(bubbleList[i]).hasClass("expandable")){ toggle_expandable(bubbleList[i]); } } catch (err) {} } } function close_all_expandables(){ var expandables = document.querySelectorAll(".expandable"); for (var i = 0; i < expandables.length; i++){ close_expandable(expandables[i]); } } function close_expandable(elem){ var content = elem.querySelector("#expandable-content"); var title = elem.querySelector("#expandable-title"); title.classList.remove('arrow-down'); title.classList.add('arrow-right'); content.dataset.visible = "false"; content.style.display = "none"; } function open_expandable(elem){ var content = elem.querySelector("#expandable-content"); var title = elem.querySelector("#expandable-title"); title.classList.add('arrow-down'); title.classList.remove('arrow-right'); content.dataset.visible = "true"; content.style.display = "inherit"; scrollToAnchorByURL(); } function toggle_expandable(elem){ var content = elem.querySelector("#expandable-content"); var visible = content.getAttribute('data-visible'); if (visible == "true") { close_expandable(elem) } else { open_expandable(elem) } } function toggleTitle(elem){ var t = elem; while (t.id != "expandable-title") { t = t.parentElement; } var c = t.parentElement.querySelector("#expandable-content"); var v = c.getAttribute('data-visible'); if (v == "true") { t.classList.remove('arrow-down'); t.classList.add('arrow-right'); c.dataset.visible = "false"; c.parentElement.querySelector("#expandable-content").style.display = "none"; } else { t.classList.add('arrow-down'); t.classList.remove('arrow-right'); c.dataset.visible = "true"; c.parentElement.querySelector("#expandable-content").style.display = "inherit"; } } //--------------------------------------------- Functions function cutFirst(str){ return str.slice(1) } function cutLast(str){ return str.slice(0, -1) }