MediaWiki:Common.js: Difference between revisions

From Future Of Mankind
No edit summary
No edit summary
 
(463 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. */


/*
//collapsible table column test, based on: https://codepen.io/feger/pen/eDybC
== Actual code ==
$(".btnHideEnglish").click(function() {
<source lang="javascript">
    console.log('Hiding first column of table with an id of report');
*/
    $("table#collapsible_report > tbody:last-child > tr > th:first-child, table#collapsible_report > tbody:last-child > tr > td:first-child").toggle();
function collapseTable( tableIndex ) {
    $(this).text($(this).text() == "Hide English" ? "Show English" : "Hide English");
  var Button = document.getElementById( 'collapseButton' + tableIndex );
    $("table#collapsible_report").css({
  var Table = document.getElementById( 'collapsibleTable' + tableIndex );
        "width": $(this).text() == "Show English" ? "80%" : "100%"
  if ( !Table || !Button ) {
     });
     return false;
});
  }


  var collapseColsOptin  = hasCollapsibleCol( tableIndex ); // new
$(".btnHideHigh-German").click(function() {
  var collapseColsOptout = hasNoncollapsibleCol( tableIndex ); // new
    console.log('Hiding first column of table with an id of report');
  var Cols = Table.rows[0].cells; // new
    $("table#collapsible_report > tbody:last-child > tr > th:last-child, table#collapsible_report > tbody:last-child > tr > td:last-child").toggle();
  var CollapseCols = new Array(Cols.length); // new; has to be larger if there are colspans
    $(this).text($(this).text() == "Hide High German" ? "Show High German" : "Hide High German");
    $("table#collapsible_report").css({
        "width": $(this).text() == "Show High German" ? "80%" : "100%"
    });
});


  if ( collapseColsOptin || collapseColsOptout ) {// new
$(".btnHideGerman").click(function() {
    //  @colspan currently not handled
     console.log('Hiding first column of table with an id of report');
    // the following two if-for-if constructs could be combined
     $("table#collapsible_report > tbody:last-child > tr > th:last-child, table#collapsible_report > tbody:last-child > tr > td:last-child").toggle();
    if ( collapseColsOptin ) {
     $(this).text($(this).text() == "Hide German" ? "Show German" : "Hide German");
      for ( var i = 0; i < Cols.length; i++ ) {
     $("table#collapsible_report").css({
        if ( CollapseCols[i] == null || !hasClass( Cols[i], 'collapsible' ) ) {
         "width": $(this).text() == "Show German" ? "80%" : "100%"
          CollapseCols[i] = !collapseColsOptin;
     });
        } else {
});
          CollapseCols[i] = collapseColsOptin;
        }
      }
    }
    // 'nocollapse' takes precedence over 'collapsible', i.e.
    // default columns are not collapsible when both types exist
     if ( collapseColsOptout ) {
      for ( var i = 0; i < Cols.length; i++ ) {
        if ( CollapseCols[i] == null || !hasClass( Cols[i], 'nocollapse' ) ) {
          CollapseCols[i] = collapseColsOptout;
        } else {
          CollapseCols[i] = !collapseColsOptout;
        }
      }
     }
 
    // column with first |th| should be excluded, because it holds the show/hide button
    var Header = Table.rows[0].getElementsByTagName( 'th' )[0];
    CollapseCols[Header.cellIndex] = false;// cellIndex doesn’t handle @colspan
  }
 
  var Rows = Table.rows;
 
  // insert check for @colspan here, change CollapseCols accordingly
 
  if ( Button.firstChild.data == collapseCaption ) {// hide
 
    if ( collapseColsOptin || collapseColsOptout ) {// new
      for ( var i = 0; i < Rows.length; i++ ) {
        var Cells = Rows[i].cells;
        for ( var j = 0; j < CollapseCols.length; j++) {
          // if we used Cells.length the handling of rows with empty cells at the end should improve
          // this would be a problem if the header row had empty cells at the end
          // we could also do CollapseCols.length-Cells.length times Rows[i].insertCell(-1)  
          if ( CollapseCols[j] ) {
            Cells[j].style.display = 'none';// needs to take @colspan into account
          }
        }
      }
    }
 
     var collapseRowsOptin = hasCollapsibleRow( tableIndex );// new
    // @rowspan currently not handled
    for ( var i = 1; i < Rows.length; i++ ) {
      if ( collapseRowsOptin ) {// new
        if ( hasClass( Rows[i], 'collapsible' ) ) {
          Rows[i].style.display = 'none';
        }
      } else if ( !collapseColsOptin && !collapseColsOptout ) {
        if ( !hasClass( Rows[i], 'nocollapse' ) &&
            !( hasClass( Rows[i], 'sortbottom' ) && !hasClass( Rows[i], 'collapsible' ) )
          ) { // new condition to exclude certain rows from collapsing
          Rows[i].style.display = 'none';
        }
      }
    }
 
    Button.firstChild.data = expandCaption;
 
  } else {// show
 
     for ( var i = 0; i < Rows.length; i++ ) {
 
      if ( collapseColsOptin || collapseColsOptout ) {// new
        var Cells = Rows[i].cells;
        for ( var j = 0; j < CollapseCols.length; j++) {
          if ( CollapseCols[j] ) {
            Cells[j].style.display = Rows[0].style.display;
          }
         }
      }
 
      Rows[i].style.display = Rows[0].style.display;
    }
 
    Button.firstChild.data = collapseCaption;
 
  }
}
 
/* new function to check whether the collapsible table has
* any column with the class 'collapsible'
*/
function hasCollapsibleCol( tableIndex ) {
  var Table = document.getElementById( 'collapsibleTable' + tableIndex );
  if ( !Table ) {
    return false;
  }
  var Cols = Table.rows[0].cells;
 
  for ( var i = 0; i < Cols.length; i++ ) {
     if ( hasClass( Cols[i], 'collapsible' ) ) {
      return true;
    }
  }
  return false;
}
 
/* new function to check whether the collapsible table has
* any column with the class 'nocollapse'
*/
function hasNoncollapsibleCol( tableIndex ) {
  var Table = document.getElementById( 'collapsibleTable' + tableIndex );
  if ( !Table ) {
    return false;
  }
  var Cols = Table.rows[0].cells;


  for ( var i = 0; i < Cols.length; i++ ) {
// hide the german by default, on page load, but only if the btnHideGerman element exists on the page
    if ( hasClass( Cols[i], 'nocollapse' ) ) {
if (document.getElementById("btnHideGerman")) {
      return true;
  console.log('btnHideGerman exists');
    }
  //$("#btnHideGerman").click();
   }
} else {
   return false;
   // do stuff
   console.log('btnHideGerman does not exist');
}
}


/* new function to check whether the collapsible table has
* any row (except the header) with the class 'collapsible'
*/
function hasCollapsibleRow( tableIndex ) {
  var Table = document.getElementById( 'collapsibleTable' + tableIndex );
  if ( !Table ) {
    return false;
  }
  var Rows = Table.rows;


  for ( var i = 1; i < Rows.length; i++ ) {
    if ( hasClass( Rows[i], 'collapsible' ) ) {
      return true;
    }
  }
  return false;
}
// </source>


$(document).ready(function() {
    // Hover for .WD-Ausartung
    $('tr td:first-child .WD-Ausartung').hover(function() {
        // Set the tooltip content from the data attribute
        $(this).attr('data-tooltip', 'Explanation of the Plejaren language scientists, given to Billy on the 27th of August 2010: Ausartung means to get very badly out of control of the good human nature.');
    }, function() {
        // Clear the tooltip content
        $(this).attr('data-tooltip', '');
    });


/* Below was a test to show news on certain days of the year. */
    // Hover for .WD-Gewalt
    $('tr td:first-child .WD-Gewalt').hover(function() {
        // Set the tooltip content from the data attribute
        $(this).attr('data-tooltip', 'Ptaah explains that \'Gewalt\' is distinct from the terms \'heftig\' (violent) and \'Heftigkeit\' (violence). The old Lyrian term \'Gewalt\' refers to \'Gewila,\' which involves using all available coercive means – physical, psychological, mental, and consciousness-based powers, to execute terrible actions.');
    }, function() {
        // Clear the tooltip content
        $(this).attr('data-tooltip', '');
    });


$( document ).ready(function() {
    // Hover for .WD-Ischrisch
         console.log( "document loaded" );
    $('tr td:first-child .WD-Ischrisch').hover(function() {
        // Set the tooltip content from the data attribute
        $(this).attr('data-tooltip', 'Queen of wisdom.');
    }, function() {
         // Clear the tooltip content
        $(this).attr('data-tooltip', '');
    });


var monthNames = [ "January (Januar)", "February (Februar)", "March (März)", "April", "May (Mai)", "June (Juni)", "July (Juli)", "August", "September", "October (Oktober)", "November", "December (Dezember)" ];
    // Hover for .WD-Ischwisch
 
    $('tr td:first-child .WD-Ischwisch').hover(function() {
var dayNames= ["Sunday (Sonntag)","Monday (Montag)","Tuesday (Dienstag)","Wednesday (Mittwoch)","Thursday (Donnerstag)","Friday (Freitag)","Saturday (Samstag)"]
        // Set the tooltip content from the data attribute
 
        $(this).attr('data-tooltip', 'King of wisdom.');
function nth(n){return["st","nd","rd"][((n+90)%100-10)%10-1]||"th"}
     }, function() {
 
        // Clear the tooltip content
var newDate = new Date();
        $(this).attr('data-tooltip', '');
 
     });
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();
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+' ');
}
});
 
//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#report tbody tr th:nth-child(1)" ).toggle();
  $( "table#report tbody tr td:nth-child(1)" ).toggle();
  if ($("#btnHideEnglish").text() == "[Hide English]"){
    $("#btnHideEnglish").text("[Show English]");
  } else {
     $("#btnHideEnglish").text("[Hide English]");
  }
});


$("#btnHideGerman").click(function(){
    // Hover for .WD-Wesen
  console.log ('Hiding second column of table with an id of report');
    $('tr td:first-child .WD-Wesen').hover(function() {
  $( "table#report tbody tr th:nth-child(2)" ).toggle();
        // Set the tooltip content from the data attribute
  $( "table#report tbody tr td:nth-child(2)" ).toggle();
        $(this).attr('data-tooltip', 'A Wesen is an independently existing life-form with its own individuality and personality in an impulse-based, instinct-based or conscious consciousness-form with evolution-possibilities that are specifically directed towards everything, and with its own physical, psychical, conscious, part-conscious, unconscious, impulse- or instinct-based development-forms.');
  if ($("#btnHideGerman").text() == "[Hide German]"){
    }, function() {
    $("#btnHideGerman").text("[Show German]");
        // Clear the tooltip content
  } else {
        $(this).attr('data-tooltip', '');
    $("#btnHideGerman").text("[Hide German]");
    });
  }
});
});

Latest revision as of 18:39, 19 September 2024

/* 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, table#collapsible_report > tbody:last-child > tr > td:first-child").toggle();
    $(this).text($(this).text() == "Hide English" ? "Show English" : "Hide English");
    $("table#collapsible_report").css({
        "width": $(this).text() == "Show English" ? "80%" : "100%"
    });
});

$(".btnHideHigh-German").click(function() {
    console.log('Hiding first column of table with an id of report');
    $("table#collapsible_report > tbody:last-child > tr > th:last-child, table#collapsible_report > tbody:last-child > tr > td:last-child").toggle();
    $(this).text($(this).text() == "Hide High German" ? "Show High German" : "Hide High German");
    $("table#collapsible_report").css({
        "width": $(this).text() == "Show High German" ? "80%" : "100%"
    });
});

$(".btnHideGerman").click(function() {
    console.log('Hiding first column of table with an id of report');
    $("table#collapsible_report > tbody:last-child > tr > th:last-child, table#collapsible_report > tbody:last-child > tr > td:last-child").toggle();
    $(this).text($(this).text() == "Hide German" ? "Show German" : "Hide German");
    $("table#collapsible_report").css({
        "width": $(this).text() == "Show German" ? "80%" : "100%"
    });
});

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



$(document).ready(function() {
    // Hover for .WD-Ausartung
    $('tr td:first-child .WD-Ausartung').hover(function() {
        // Set the tooltip content from the data attribute
        $(this).attr('data-tooltip', 'Explanation of the Plejaren language scientists, given to Billy on the 27th of August 2010: Ausartung means to get very badly out of control of the good human nature.');
    }, function() {
        // Clear the tooltip content
        $(this).attr('data-tooltip', '');
    });

    // Hover for .WD-Gewalt
    $('tr td:first-child .WD-Gewalt').hover(function() {
        // Set the tooltip content from the data attribute
        $(this).attr('data-tooltip', 'Ptaah explains that \'Gewalt\' is distinct from the terms \'heftig\' (violent) and \'Heftigkeit\' (violence). The old Lyrian term \'Gewalt\' refers to \'Gewila,\' which involves using all available coercive means – physical, psychological, mental, and consciousness-based powers, to execute terrible actions.');
    }, function() {
        // Clear the tooltip content
        $(this).attr('data-tooltip', '');
    });

    // Hover for .WD-Ischrisch
    $('tr td:first-child .WD-Ischrisch').hover(function() {
        // Set the tooltip content from the data attribute
        $(this).attr('data-tooltip', 'Queen of wisdom.');
    }, function() {
        // Clear the tooltip content
        $(this).attr('data-tooltip', '');
    });

    // Hover for .WD-Ischwisch
    $('tr td:first-child .WD-Ischwisch').hover(function() {
        // Set the tooltip content from the data attribute
        $(this).attr('data-tooltip', 'King of wisdom.');
    }, function() {
        // Clear the tooltip content
        $(this).attr('data-tooltip', '');
    });

    // Hover for .WD-Wesen
    $('tr td:first-child .WD-Wesen').hover(function() {
        // Set the tooltip content from the data attribute
        $(this).attr('data-tooltip', 'A Wesen is an independently existing life-form with its own individuality and personality in an impulse-based, instinct-based or conscious consciousness-form with evolution-possibilities that are specifically directed towards everything, and with its own physical, psychical, conscious, part-conscious, unconscious, impulse- or instinct-based development-forms.');
    }, function() {
        // Clear the tooltip content
        $(this).attr('data-tooltip', '');
    });
});