Template:Judd UK/Scripts/wiki

/* JSWiki Javascript Library v0.4.3

*
* Copyright Aleksandur Murfitt
* Released under the MIT license
* (<[URL]>)/license.txt
*
* Date: 2017-10-01T12:38Z
*/

var qs = document.querySelector.bind(document),

   magic = false,
   objectList = null;

var qsa = document.querySelectorAll.bind(document); var page = location.pathname.slice(14, -5).replace(/\//g, "*"); var html = qs(".JC" + ('content' in document.createElement('template')) ? "template" : "#content-template");

var mouseDetected = false;

function animate() {

   if (!safe) return;
   handle.style.webkitAnimationName = 'handle';
   handle.style.animationName = 'handle';
   sprite.style.webkitAnimationName = 'sprite';
   sprite.style.animationName = 'sprite';
   safe = false;

}

function loadStyleSheet(src) {

   if (document.createStyleSheet) document.createStyleSheet(src);
   else {
       var stylesheet = document.createElement('link');
       stylesheet.href = src;
       stylesheet.rel = 'stylesheet';
       stylesheet.type = 'text/css';
       document.getElementsByTagName('head')[0].appendChild(stylesheet);
   }

}

function AJAX(url, callback) {

   var xmlhttp;
   xmlhttp = new XMLHttpRequest();
   xmlhttp.onreadystatechange = function () {
       if (xmlhttp.readyState == 4)
           callback(xmlhttp);
   };
   xmlhttp.open("GET", url, true);
   xmlhttp.send();

}

function createindex() {

   var obj = contentIndexData;
   Object.keys(obj.project).forEach(function (e, i) {
       if (typeof (obj.project[e]) == 'string') {
qs('#O2>ul').innerHTML += '
  • <a href="£' + obj.project[e] + '">' + e + '</a>
  • ';
           } else {
    
    qs('#O2>ul').innerHTML += '
  • <a href="#O2-S' + i + '">' + e + '</a>
  • '; qs('#O2>ul').innerHTML += '
    • ';
                 obj.project[e].forEach(function (n) {
      
      qs('#O2>ul>li:last-child>ul').innerHTML += '
    • <a href="£' + n.replace(/\s+/g, '-').replace(/[^A-Z0-9-_]+/gi, ) + '">' + n + '</a>
    • ';
                 });
             }
         });
         Object.keys(obj.team).forEach(function (e, i) {
             if (typeof (obj.team[e]) == 'string') {
      
      qs('#O4>ul').innerHTML += '
    • <a href="£' + obj.team[e] + '">' + e + '</a>
    • ';
             } else {
      
      qs('#O4>ul').innerHTML += '
    • <a href="#O4-S' + i + '">' + e + '</a>
    • '; qs('#O4>ul').innerHTML += '
      • ';
                   obj.team[e].forEach(function (n) {
        
        qs('#O4>ul>li:last-child>ul').innerHTML += '
      • <a href="£' + n.replace(/\s+/g, '-').replace(/[^A-Z0-9-_]+/gi, ) + '">' + n + '</a>
      • ';
                   });
               }
           });
        

        } window.onpopstate = function (e) {

           if (magic) {
               magic = false;
               return;
           }
           if (location.pathname.replace(/\//g, "*").slice(14, -5) != page) {
               loadPage(location.pathname.replace(/\//g, "*").slice(14, -5));
           } else
               return;
        

        }

        function newPage(e) {

           e = window.e || e;
           var href = e.target.getAttribute("href");
           if (href === null || (href[0] != "£" && href[0] != "#")) return;
           if (href[0] == "#") {
               magic = true;
               try {
                   qs(".JC #content-body " + href).scrollIntoView({
                       behavior: "smooth",
                       block: "start",
                       inline: "nearest"
                   });
               } catch (e) {
                   location.hash = href;
               }
               if (href == "#" + e.target.parentElement.id) {
                   window.scrollTo(0, document.body.scrollTop);
               }
               e.preventDefault();
               return;
           }
           e.preventDefault();
           href = href.substring(1);
           loadPage(href);
           window.history.pushState(null, null, "/Team:Judd_UK/" + href.replace('*', "/") + ".html");
        

        }

        function loadPage(href) {

           qs(".JC #content-container").style.visibility = "hidden";
           AJAX("/Team:Judd_UK/Pages/" + href + "?action=raw&ctype=text/plain", function (xmlhttp) {
               if (xmlhttp.status == 200) {
                   page = href;
                   html.innerHTML = xmlhttp.responseText;
                   var content = (html.content || html);
                   qs('.JC #content-body').innerHTML = "";
                   qs('.JC #content-index ol').innerHTML = "";
                   if (content.querySelector("div").dataset.templated != "false")
                       qsa("[data-selector]").forEach(function (elem) {
                           var i = (content.querySelector(elem.dataset.selector));
                           if (i)
                               elem.innerHTML = (elem.dataset.text) ? i.innerText : i.outerHTML;
                           else
                               elem.innerHTML = "";
                       });
                   if (content.querySelector("div").dataset.wiki != "false") {
                       qs(".JC #content-index").style.display = "block";
                       content.querySelectorAll("h2, h3").forEach(function (elem, index) {
                           if (elem.tagName == "H2")
        
        qs(".JC #content-index ol").innerHTML += '
      • <a href="#' + elem.innerHTML.replace(/\s+/g, "-").replace(/[^A-Z0-9-_]+/gi, "") + "-" + index + '">' + elem.innerHTML + '</a>
      • ';
                           else
                           if (qs(".JC #content-index ol").lastChild.querySelector("ol"))
        
        qs(".JC #content-index ol").lastChild.querySelector("ol").innerHTML += '
      • <a href="#' + elem.innerHTML.replace(/\s+/g, "-").replace(/[^A-Z0-9-_]+/gi, "") + "-" + index + '">' + elem.innerHTML + '</a>
      • ';
                           else {
        
        qs(".JC #content-index ol").lastChild.innerHTML += '
        1. <a href="#' + elem.innerHTML.replace(/\s+/g, "-").replace(/[^A-Z0-9-_]+/gi, "") + "-" + index + '">' + elem.innerHTML + '</a>
        ';
                           }
                       });
                       content.querySelectorAll("div h2, div h3").forEach(function (elem, index) {
                           elem.id = elem.innerHTML.replace(/\s+/g, "-").replace(/[^A-Z0-9-_]+/gi, "") + "-" + index;
                       });
                   } else
                       qs(".JC #content-index").style.display = "none";
                   qs(".JC #content-body").innerHTML = content.querySelector("div") ? content.querySelector("div").innerHTML : "";
                   qs(".JC #content-container").style.visibility = "visible";
                   animate();
               } else {
                   loadPage("404");
               }
           });
        

        }

        var handle = qs(".JC #handle"); var sprite = qs(".JC #sprite"); var safe = true; qs("#HQ_page #bodyContent>.mw-content-ltr").classList.remove("mw-content-ltr"); qs("#HQ_page #bodyContent").id = ""; qs("#HQ_page").id = ""; loadPage(page); createindex(); qs(".JC #sprite").addEventListener((qs(".JC").style.animationName === undefined ? "webkit" : "") + 'animationend', function () {

           handle.style.webkitAnimationName = ;
           handle.style.animationName = ;
           sprite.style.webkitAnimationName = ;
           sprite.style.animationName = ;
           safe = true;
        

        }, false); qs(".JC #main-img").onmouseenter = animate; document.addEventListener("click", newPage, false); document.addEventListener("mousemove", function () {

           if (mouseDetected)
               qs("#topstyles").innerHTML = "";
           mouseDetected = true;
           document.removeEventListener("mousemove", arguments.callee);
        

        }, false); qs("#topstyles").innerHTML = ".JC #O1 a{transform:translateX(-150%)!important;opacity:1!important}.JC #O2 a{transform: translateX(-50%)!important;opacity:1!important}.JC #O3 a{transform:translateX(50%)!important;opacity:1!important}.JC #O4 a{transform:translateX(150%)!important;opacity:1!important}"; setTimeout(function () {

           if (mouseDetected)
               qs("#topstyles").innerHTML = "";
           else mouseDetected = true;
        

        }, 4000); loadStyleSheet("https://fonts.googleapis.com/css?family=Raleway%7COpen+Sans:300"); loadStyleSheet("https://fonts.googleapis.com/css?family=Creepster");