MediaWiki:Vector.js

Aus Wiki der Akademie der Bildenden Künste Nürnberg
Zur Navigation springen Zur Suche springen

Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Strg+F5
/* Das folgende JavaScript wird für Benutzer der Vector-Benutzeroberfläche geladen. */

//--------------------------------------------- Parameters

var scroll_x;
var scroll_y;


//--------------------------------------------- Scroll Actions

window.addEventListener("scroll", function(event) {
  scroll_y = this.scrollY;
  scroll_x = this.scrollX;

  if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
    sc_t.style.display = "block";
  } else {
    sc_t.style.display = "none";
  }

});


//--------------------------------------------- Search Field
document.querySelector("#searchInput").placeholder = "Suche…";
document.querySelector("#searchInput").focus();


//--------------------------------------------- Add Scroll to top button
sc_t = document.createElement("div");
sc_t.id = "scroll-top-button";
document.querySelector("body").append(sc_t);
sc_t.addEventListener("click", topFunction);

function topFunction() {
  document.body.scrollTop = 0; // For Safari
  document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}


//--------------------------------------------- Link Styling (Inactive via CSS)
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

incrementInlist();

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++){
    console.log(l[i].tagName);
}
l = inlist_div.querySelectorAll("ol");
for(var i=0;i<l.length;i++){
    console.log(l[i].tagName);
}
}

function handleInlist(inlist_div, p_listindex){
    var children = [];
    var ol = inlist_div.getElementsByTagName("ol");
    if(ol.length>0){
        for (var i = 0; i < ol[0].children.length; i ++){
            children.push(ol[0].children[i]);
        }
    }
    var ul = inlist.getElementsByTagName("ul");
    if(ul.length>0){
        for (var i = 0; i < ul[0].children.length; i ++){
            children.push(ul[0].children[i]);
        }
    }
console.log(children);

    //var children = ol[0].children;
console.log(children);
    for (var i = 0; i < children.length; i ++){
        var listindex = p_listindex + i + 1;
        var li = children[i];
        if(li.getElementsByTagName("ol").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
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)
}