Difference between revisions of "MediaWiki:Common.js"

From Future Of Mankind
(78 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');
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:last-child > tr > th:first-child" ).toggle();
var dayNames= ["Sunday / Sonntag,","Monday / Montag,","Tuesday / Dienstag,","Wednesday / Mittwoch,","Thursday / Donnerstag,","Friday / Freitag,","Saturday / Samstag,"]
+
  $( "table#collapsible_report > tbody:last-child > tr > td:first-child" ).toggle();
 
+
  if ($(this).text() == "Hide English"){
var newDate = new Date();
+
    $(this).text("Show English");
 
+
  } else {
newDate.setDate(newDate.getDate());
+
    $(this).text("Hide English");
 
+
  }
$('#FOMdate').html(dayNames[newDate.getDay()] + " " + newDate.getUTCDate() + ' ' + 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);
+
$("#btnHideSwiss-German").click(function(){
},1000);
+
  console.log ('Hiding second column of table with an id of report');
 
+
  $( "table#collapsible_report > tbody:last-child > tr > th:last-child" ).toggle();
setInterval( function() {
+
  $( "table#collapsible_report > tbody:last-child > tr > td:last-child" ).toggle();
 
+
  if ($(this).text() == "Hide Swiss-German"){
var hours = new Date().getHours();
+
    $(this).text("Show Swiss-German");
 
+
  } else {
$("#hours").html(( hours < 10 ? "0" : "" ) + hours);
+
    $(this).text("Hide Swiss-German");
}, 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();
 
  });
 
});
 

Revision as of 09:53, 7 June 2022

/* 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");
  } else {
    $(this).text("Hide English");
  }
});

$("#btnHideSwiss-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 Swiss-German"){
    $(this).text("Show Swiss-German");
  } else {
    $(this).text("Hide Swiss-German");
  }
});

// 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');
}