Difference between revisions of "MediaWiki:Common.js"

From Future Of Mankind
 
(276 intermediate revisions by 3 users not shown)
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. */
  
$( document ).ready(function() {
+
//collapsible table column test, based on: https://codepen.io/feger/pen/eDybC
        console.log( "document loaded" );
+
$(".btnHideEnglish").click(function() {
 +
  console.log ('Hiding first column of table with an id of report');
 +
  $( "table#collapsible_report > tbody:last-child > tr > th:first-child" ).toggle();
 +
  $( "table#collapsible_report > tbody:last-child > tr > td:first-child" ).toggle();
 +
  if ($(this).text() == "Hide English") {
 +
    $(this).text("Show English");
 +
    $("table#collapsible_report").css({"width": "80%", "margin": "0 auto"});
 +
  } else {
 +
    $(this).text("Hide English");
 +
    $("table#collapsible_report").css({"width": "", "border-spacing": "1.5em 0", "margin": "0 -1.5em"});
 +
  }
 +
});
  
var monthNames = [ "January (Januar)", "February (Februar)", "March (März)", "April", "May (Mai)", "June (Juni)", "July (Juli)", "August", "September", "October (Oktober)", "November", "December (Dezember)" ];
+
$(".btnHideHigh-German").click(function() {
 +
  console.log ('Hiding second column of table with an id of report');
 +
  $("table#collapsible_report > tbody:last-child > tr > th:last-child").toggle();
 +
  $("table#collapsible_report > tbody:last-child > tr > td:last-child").toggle();
 +
  if ($(this).text() == "Hide High German") {
 +
    $(this).text("Show High German");
 +
    $("table#collapsible_report").css({"width": "80%", "margin": "0 auto"});
 +
  } else {
 +
    $(this).text("Hide High German");
 +
    $("table#collapsible_report").css({"width": "", "border-spacing": "1.5em 0", "margin": "0 -1.5em"});
 +
  }
 +
});
  
var dayNames= ["Sunday (Sonntag)","Monday (Montag)","Tuesday (Dienstag)","Wednesday (Mittwoch)","Thursday (Donnerstag)","Friday (Freitag)","Saturday (Samstag)"]
+
$(".btnHideGerman").click(function() {
 
+
  console.log ('Hiding second column of table with an id of report');
function nth(n){return["st","nd","rd"][((n+90)%100-10)%10-1]||"th"}
+
  $("table#collapsible_report > tbody:last-child > tr > th:last-child").toggle();
 
+
  $("table#collapsible_report > tbody:last-child > tr > td:last-child").toggle();
var newDate = new Date();
+
  if ($(this).text() == "Hide German") {
 
+
    $(this).text("Show German");
newDate.setDate(newDate.getDate());
+
    $("table#collapsible_report").css({"width": "80%", "margin": "0 auto"});
 
+
  } else {
$('#FOMdate').html(dayNames[newDate.getDay()] + " the " + newDate.getUTCDate()+nth() + " of " + monthNames[newDate.getUTCMonth()] + ' ' + newDate.getUTCFullYear());
+
    $(this).text("Hide German");
 
+
    $("table#collapsible_report").css({"width": "", "border-spacing": "1.5em 0", "margin": "0 -1.5em"});
setInterval( function() {
+
  }
 
 
var seconds = new Date().getSeconds();
 
 
 
$("#sec").html(( seconds < 10 ? "0" : "" ) + seconds);
 
},1000);
 
 
 
setInterval( function() {
 
 
 
var minutes = new Date().getMinutes();
 
 
 
$("#min").html(( minutes < 10 ? "0" : "" ) + minutes);
 
},1000);
 
 
 
setInterval( function() {
 
 
 
var hours = new Date().getHours();
 
 
 
$("#hours").html(( hours < 10 ? "0" : "" ) + hours);
 
}, 1000)
 
 
});
 
});
  
$(function() {
+
// hide the german by default, on page load, but only if the btnHideGerman element exists on the page
  $(".DateDiv").each(function(index) {
+
if (document.getElementById("btnHideGerman")) {
    var sRange = $(this).find(".DateRange").html();
+
  console.log('btnHideGerman exists');
    var arrTemp = sRange.split(" to ");
+
   //$("#btnHideGerman").click();
    var dtFrom = new Date(arrTemp[0]);
+
} else {
    var dtTo = new Date(arrTemp[1]);
+
  // do stuff
    var dtNow = new Date();
+
  console.log('btnHideGerman does not exist');
    if (dtNow >= dtFrom && dtNow <= dtTo)
 
      $(this).show();
 
   });
 
 
 
var dob = $('#agedate').val();
 
if(dob != ''){
 
    var str=dob.split('-');   
 
    var firstdate=new Date(str[0],str[1],str[2]);
 
    var today = new Date();       
 
    var dayDiff = Math.ceil(today.getTime() - firstdate.getTime()) / (1000 * 60 * 60 * 24 * 365);
 
    var age = parseInt(dayDiff);
 
    $('#age').html(age+' years old');
 
 
}
 
}
});
 

Latest revision as of 15:21, 21 November 2023

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

//collapsible table column test, based on: https://codepen.io/feger/pen/eDybC
$(".btnHideEnglish").click(function() {
  console.log ('Hiding first column of table with an id of report');
  $( "table#collapsible_report > tbody:last-child > tr > th:first-child" ).toggle();
  $( "table#collapsible_report > tbody:last-child > tr > td:first-child" ).toggle();
  if ($(this).text() == "Hide English") {
    $(this).text("Show English");
    $("table#collapsible_report").css({"width": "80%", "margin": "0 auto"});
  } else {
    $(this).text("Hide English");
    $("table#collapsible_report").css({"width": "", "border-spacing": "1.5em 0", "margin": "0 -1.5em"});
  }
});

$(".btnHideHigh-German").click(function() {
  console.log ('Hiding second column of table with an id of report');
  $("table#collapsible_report > tbody:last-child > tr > th:last-child").toggle();
  $("table#collapsible_report > tbody:last-child > tr > td:last-child").toggle();
  if ($(this).text() == "Hide High German") {
    $(this).text("Show High German");
    $("table#collapsible_report").css({"width": "80%", "margin": "0 auto"});
  } else {
    $(this).text("Hide High German");
    $("table#collapsible_report").css({"width": "", "border-spacing": "1.5em 0", "margin": "0 -1.5em"});
  }
});

$(".btnHideGerman").click(function() {
  console.log ('Hiding second column of table with an id of report');
  $("table#collapsible_report > tbody:last-child > tr > th:last-child").toggle();
  $("table#collapsible_report > tbody:last-child > tr > td:last-child").toggle();
  if ($(this).text() == "Hide German") {
    $(this).text("Show German");
    $("table#collapsible_report").css({"width": "80%", "margin": "0 auto"});
  } else {
    $(this).text("Hide German");
    $("table#collapsible_report").css({"width": "", "border-spacing": "1.5em 0", "margin": "0 -1.5em"});
  }
});

// hide the german by default, on page load, but only if the btnHideGerman element exists on the page
if (document.getElementById("btnHideGerman")) {
  console.log('btnHideGerman exists');
  //$("#btnHideGerman").click();
} else {
  // do stuff
  console.log('btnHideGerman does not exist');
}