MediaWiki:Vector.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Wendl (Diskussion | Beiträge) (Der Seiteninhalt wurde durch einen anderen Text ersetzt: „→Das folgende JavaScript wird für Benutzer der Vector-Benutzeroberfläche geladen.: //----------------------------------------…“) Markierungen: Zurückgesetzt Ersetzt |
Wendl (Diskussion | Beiträge) Markierung: Zurückgesetzt |
||
Zeile 2: | Zeile 2: | ||
//--------------------------------------------- Parameters | //--------------------------------------------- Parameters | ||
var scroll_x; | var scroll_x; | ||
Zeile 14: | Zeile 10: | ||
console.log("Hallo"); | console.log("Hallo"); | ||
addScrollButton(); | |||
scrollToAnchorByURL(); | |||
modifySearch(); | |||
incrementInlist(); | |||
categoryImprovements(); | |||
//--------------------------------------------- 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" }); | |||
//document.body.scrollTop = 0; // For Safari | |||
//document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera | |||
} | |||
function scrollToElement(elem){ | |||
$('html,body').animate({scrollTop: elem.offset().top},'slow'); | |||
} | |||
function scrollToAnchorByURL(){ | |||
var url = window.location.href; | |||
if(url.contains("#"){ | |||
var id = url.split("#")[1]; | |||
var anchor = $("#"+id); | |||
scrollToElement(anchor); | |||
} | |||
} | |||
//--------------------------------------------- Search Field | |||
function modifySearch(){ | |||
document.querySelector("#searchInput").placeholder = "Suche…"; | |||
document.querySelector("#searchInput").focus(); | |||
} | |||
//--------------------------------------------- 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); | |||
} | |||
} | |||
//--------------------------------------------- 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)); | |||
} | |||
//--------------------------------------------- Functions | |||
function cutFirst(str){ | |||
return str.slice(1) | |||
} | |||
function cutLast(str){ | |||
return str.slice(0, -1) | |||
} |
Version vom 11. Januar 2022, 09:36 Uhr
/* Das folgende JavaScript wird für Benutzer der Vector-Benutzeroberfläche geladen. */ //--------------------------------------------- Parameters var scroll_x; var scroll_y; // ------------ Start console.log("Hallo"); addScrollButton(); scrollToAnchorByURL(); modifySearch(); incrementInlist(); categoryImprovements(); //--------------------------------------------- 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" }); //document.body.scrollTop = 0; // For Safari //document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera } function scrollToElement(elem){ $('html,body').animate({scrollTop: elem.offset().top},'slow'); } function scrollToAnchorByURL(){ var url = window.location.href; if(url.contains("#"){ var id = url.split("#")[1]; var anchor = $("#"+id); scrollToElement(anchor); } } //--------------------------------------------- Search Field function modifySearch(){ document.querySelector("#searchInput").placeholder = "Suche…"; document.querySelector("#searchInput").focus(); } //--------------------------------------------- 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); } } //--------------------------------------------- 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)); } //--------------------------------------------- Functions function cutFirst(str){ return str.slice(1) } function cutLast(str){ return str.slice(0, -1) }