MediaWiki: Common.js

From Infinity
Jump to: navigation, search
(Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: $(document).ready(function(){ $(".n4").hide(); $("#dropdown").change(function...")
 
Line 1: Line 1:
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
/* Any JavaScript here will be loaded for all users on every page load. */
 +
 +
 +
 +
 +
/* The main toggle function moved here. */
 +
 +
function toggleN4(showN4) {
 +
/*  alert("clicked! " +showN4); */
 +
    if (showN4=="true") {
 +
        $(".n4").show(300);
 +
        $(".n4list").show(300);
 +
        $(".n4inline").show(300);
 +
        $(".c1hide").hide(300);
 +
        setCookie("showN4", "true", 30);
 +
        var user=getCookie("showN4");
 +
/*      alert("Saved cookie: " + user); */
 +
        var ele = document.getElementsByClassName("c1strike");
 +
        for(var i=0;i<ele.length;i++){
 +
            ele[i].style.setProperty("text-decoration", "line-through");
 +
        }
 +
    } else {
 +
        $(".n4").hide(300);
 +
        $(".n4list").hide(300);
 +
        $(".n4inline").hide(300);
 +
        $(".c1hide").show(300);
 +
        setCookie("showN4", "false", 30);
 +
        var user=getCookie("showN4");
 +
/*      alert("Saved cookie: " + user); */
 +
        var ele = document.getElementsByClassName("c1strike");
 +
        for(var i=0;i<ele.length;i++){
 +
            ele[i].style.setProperty("text-decoration", "");
 +
        }
 +
    }
 +
}
 +
 +
 +
function forceN4() {
 +
/*  alert("clicked! " +showN4); */
 +
        setCookie("showN4", "true", 30);
 +
        $(".n4").show(0);
 +
        $(".n4list").show(0);
 +
        $(".n4inline").show(0);
 +
        $(".c1hide").hide(0);
 +
        $('#gametoggle').attr('checked', true);
 +
        var ele = document.getElementsByClassName("c1strike");
 +
        for(var i=0;i<ele.length;i++){
 +
            ele[i].style.setProperty("text-decoration", "line-through");
 +
        }
 +
 +
}
 +
 +
 +
function forceC1() {
 +
/*  alert("clicked! " +showN4); */
 +
        setCookie("showN4", "false", 30);
 +
        $('#gametoggle').attr('checked', false);
 +
      $(".n4").hide(0);
 +
      $(".n4list").hide(0);
 +
        $(".n4inline").hide(0);
 +
        $(".c1hide").show(0);
 +
        var ele = document.getElementsByClassName("c1strike");
 +
        for(var i=0;i<ele.length;i++){
 +
            ele[i].style.setProperty("text-decoration", "");
 +
        }
 +
}
 +
 +
 +
 +
/* This code creates the N4 reveal slider, and what happens when you click on it. */
  
 
$(document).ready(function(){
 
$(document).ready(function(){
          $(".n4").hide();
+
    var doShow=getCookie("showN4");
            $("#dropdown").change(function(){
+
    if (doShow =="true") {
                if ($("#dropdown").val() == "n4") {
+
        forceN4()
                    $(".n4").show(300);
+
    }
                } else {
+
    var showFromURL=getParameterByName('version');
                    $(".n4").hide(300);
+
    if (showFromURL =="n4") {
                }
+
        forceN4()
            });
+
        setCookie("showN4", "true", 30);
        });
+
    }
 +
    if (showFromURL =="c1") {
 +
        forceC1()
 +
        setCookie("showN4", "false", 30);
 +
    }
  
$(document).ready(function(){
+
           $(".n4toggle").hide();
           $(".n5toggle").hide();
 
 
             $("#gametoggle").click(function(){
 
             $("#gametoggle").click(function(){
 
                 if ($("#gametoggle").is(":checked")) {
 
                 if ($("#gametoggle").is(":checked")) {
                     $(".n4").show(300);
+
                     toggleN4("true")
                } else {
+
              } else {
                     $(".n4").hide(300);
+
                     toggleN4("false")
 
                 }
 
                 }
 
             });
 
             });
Line 25: Line 97:
  
 
$(function () {
 
$(function () {
$('#mw-mywiki-gameswap').html("<div class='form-row'><label><span>Game Version: </span><select name='register_as' id='dropdown'><option value='none'>Select One</option><option value='n4'>Show full N4 Rules</option><option value='c1'>Show CodeOne Rules</option></select></label> </div>");
+
$('#n4gametoggle').html("<span class='gamesliderlabel'>Show full N4 rules: </span><label class='switch' > <input type='checkbox' id='gametoggle' ><span class='slider round' ></span></label>");
 
}());
 
}());
  
  
$(function () {
+
 
$('#n5gametoggle').html("<span class='gamesliderlabel'>Show full N4 rules: </span><label class='switch' > <input type='checkbox' id='gametoggle' ><span class='slider round' ></span></label>");
+
 
}());
+
/* URL parameter stuff. */
 +
 
 +
function getParameterByName(name, url) {
 +
    if (!url) url = window.location.href;
 +
    name = name.replace(/[\[\]]/g, '\\$&');
 +
    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
 +
        results = regex.exec(url);
 +
    if (!results) return null;
 +
    if (!results[2]) return '';
 +
    return decodeURIComponent(results[2].replace(/\+/g, ' '));
 +
}
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
/* Cookie stuff. */
 +
 
 +
function setCookie(cname, cvalue, exdays) {
 +
  var d = new Date();
 +
  d.setTime(d.getTime() + (exdays*24*60*60*1000));
 +
  var expires = "expires="+ d.toUTCString();
 +
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
 +
}
 +
 
 +
function getCookie(cname) {
 +
  var name = cname + "=";
 +
  var decodedCookie = decodeURIComponent(document.cookie);
 +
  var ca = decodedCookie.split(';');
 +
  for(var i = 0; i <ca.length; i++) {
 +
    var c = ca[i];
 +
    while (c.charAt(0) == ' ') {
 +
      c = c.substring(1);
 +
    }
 +
    if (c.indexOf(name) == 0) {
 +
      return c.substring(name.length, c.length);
 +
    }
 +
  }
 +
  return "";
 +
}

Revision as of 09:14, 9 September 2020

/* Any JavaScript here will be loaded for all users on every page load. */




/* The main toggle function moved here. */

function toggleN4(showN4) {
/*   alert("clicked! " +showN4); */
    if (showN4=="true") {
        $(".n4").show(300);
        $(".n4list").show(300);
        $(".n4inline").show(300);
        $(".c1hide").hide(300);
        setCookie("showN4", "true", 30);
        var user=getCookie("showN4");
 /*       alert("Saved cookie: " + user); */
        var ele = document.getElementsByClassName("c1strike");
        for(var i=0;i<ele.length;i++){
            ele[i].style.setProperty("text-decoration", "line-through");
        }
    } else {
        $(".n4").hide(300);
        $(".n4list").hide(300);
        $(".n4inline").hide(300);
        $(".c1hide").show(300);
        setCookie("showN4", "false", 30);
        var user=getCookie("showN4");
 /*       alert("Saved cookie: " + user); */
        var ele = document.getElementsByClassName("c1strike");
        for(var i=0;i<ele.length;i++){
            ele[i].style.setProperty("text-decoration", "");
        }
    }
}


function forceN4() {
/*   alert("clicked! " +showN4); */
        setCookie("showN4", "true", 30);
        $(".n4").show(0);
        $(".n4list").show(0);
        $(".n4inline").show(0);
        $(".c1hide").hide(0);
        $('#gametoggle').attr('checked', true);
        var ele = document.getElementsByClassName("c1strike");
        for(var i=0;i<ele.length;i++){
            ele[i].style.setProperty("text-decoration", "line-through");
        }
 
}


function forceC1() {
/*   alert("clicked! " +showN4); */
        setCookie("showN4", "false", 30);
        $('#gametoggle').attr('checked', false);
       $(".n4").hide(0);
       $(".n4list").hide(0);
        $(".n4inline").hide(0);
        $(".c1hide").show(0);
        var ele = document.getElementsByClassName("c1strike");
        for(var i=0;i<ele.length;i++){
            ele[i].style.setProperty("text-decoration", "");
        }
}



/* This code creates the N4 reveal slider, and what happens when you click on it. */

$(document).ready(function(){
    var doShow=getCookie("showN4");
    if (doShow =="true") {
        forceN4()
    }
    var showFromURL=getParameterByName('version');
    if (showFromURL =="n4") {
        forceN4()
        setCookie("showN4", "true", 30);
    }
    if (showFromURL =="c1") {
        forceC1()
        setCookie("showN4", "false", 30);
    }

          $(".n4toggle").hide();
            $("#gametoggle").click(function(){
                if ($("#gametoggle").is(":checked")) {
                    toggleN4("true")
               } else {
                    toggleN4("false")
                }
            });
        });


$(function () {
	$('#n4gametoggle').html("<span class='gamesliderlabel'>Show full N4 rules: </span><label class='switch' > <input type='checkbox' id='gametoggle' ><span class='slider round' ></span></label>");
}());




/* URL parameter stuff. */

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, '\\$&');
    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, ' '));
}






/* Cookie stuff. */

function setCookie(cname, cvalue, exdays) {
  var d = new Date();
  d.setTime(d.getTime() + (exdays*24*60*60*1000));
  var expires = "expires="+ d.toUTCString();
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function getCookie(cname) {
  var name = cname + "=";
  var decodedCookie = decodeURIComponent(document.cookie);
  var ca = decodedCookie.split(';');
  for(var i = 0; i <ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}