Difference between revisions of "MediaWiki:Common.js"

From Future Of Mankind
(19 intermediate revisions by 2 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');
var monthNames = [ "January (Januar)", "February (Februar)", "March (März)", "April", "May (Mai)", "June (Juni)", "July (Juli)", "August", "September", "October (Oktober)", "November", "December (Dezember)" ];
+
  $( "table#collapsible_report tbody tr th:nth-child(1)" ).toggle();
 
+
  $( "table#collapsible_report tbody tr td:nth-child(1)" ).toggle();
var dayNames= ["Sunday (Sonntag)","Monday (Montag)","Tuesday (Dienstag)","Wednesday (Mittwoch)","Thursday (Donnerstag)","Friday (Freitag)","Saturday (Samstag)"]
+
  if ($(this).text() == "Hide English"){
 
+
    $(this).text("Show English");
function nth(n){return["st","nd","rd"][((n+90)%100-10)%10-1]||"th"}
+
  } else {
 
+
     $(this).text("Hide English");
var newDate = new Date();
+
  }
 
 
newDate.setDate(newDate.getDate());
 
 
 
$('#FOMdate').html(dayNames[newDate.getDay()] + " the " + newDate.getUTCDate()+nth() + " of " + monthNames[newDate.getUTCMonth()] + ' ' + newDate.getUTCFullYear());
 
 
 
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() {
 
 
 
  $(".DateDiv").each(function(index) {
 
     var sRange = $(this).find(".DateRange").html();
 
    var arrTemp = sRange.split(" to ");
 
    var dtFrom = new Date(arrTemp[0]);
 
    var dtTo = new Date(arrTemp[1]);
 
    var dtNow = new Date();
 
    if (dtNow >= dtFrom && dtNow <= dtTo)
 
      $(this).show();
 
   
 
 
});
 
});
  
var dob = $('#agedate').val();
+
$("#btnHideGerman").click(function(){
if(dob != ''){
+
  console.log ('Hiding second column of table with an id of report');
    var str=dob.split('-');  
+
  $( "table#collapsible_report tbody tr th:nth-child(2)" ).toggle();
    var firstdate=new Date(str[0],str[1],str[2]);
+
  $( "table#collapsible_report tbody tr td:nth-child(2)" ).toggle();
    var today = new Date();      
+
  if ($(this).text() == "Hide German"){
    var dayDiff = Math.ceil(today.getTime() - firstdate.getTime()) / (1000 * 60 * 60 * 24 * 365);
+
    $(this).text("Show German");
    var age = parseInt(dayDiff);
+
  } else {
     $('#age').html(age+' ');
+
     $(this).text("Hide German");
}
+
  }
 
});
 
});

Revision as of 18:44, 20 June 2019

/* 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 tr th:nth-child(1)" ).toggle();
  $( "table#collapsible_report tbody tr td:nth-child(1)" ).toggle();
  if ($(this).text() == "Hide English"){
    $(this).text("Show English");
  } else {
    $(this).text("Hide English");
  }
});

$("#btnHideGerman").click(function(){
  console.log ('Hiding second column of table with an id of report');
  $( "table#collapsible_report tbody tr th:nth-child(2)" ).toggle();
  $( "table#collapsible_report tbody tr td:nth-child(2)" ).toggle();
  if ($(this).text() == "Hide German"){
    $(this).text("Show German");
  } else {
    $(this).text("Hide German");
  }
});