MediaWiki:Common.js

From John's wiki
Revision as of 00:30, 27 January 2022 by Sixsigma (talk | contribs)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

//console.log( 'Hi from Common.js' );

for ( var i in document.jj5_totals ) {

  var spec = document.jj5_totals[ i ];

  sum_column( spec.id, spec.col );

}

function sum_column( id, col ) {
  //console.log( [ id, col ] );
  var total = 0;
  var mytable = document.getElementById( id );
  for ( var v=1; v < mytable.rows.length - 1; v++ ) {
    var val = mytable.rows[v].cells[col].innerHTML;
    //console.log( val );
    val = val.replace( '$', '' );
    val = val.replace( ',', '' );
    val = parseFloat( val );
    if ( ! isNaN( val ) ) {
      //console.log( val );
      total += val;
    }
  }
  //console.log( total );
  total = total.toLocaleString('en-AU',{currency:'AUD',minimumFractionDigits:2});
  document.getElementById( id + '_sum' ).innerHTML = total;
}