MediaWiki:Common.js
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 ]; var id = spec.id; var col = spec.col; //console.log( [ id, col ] ); var total = 0; var mytable = document.getElementById( id ); for ( var row = 1; row < mytable.rows.length - 1; row++ ) { var val = read_cell( mytable, row, col ); var ordered = read_cell( mytable, row, col + 2 ); if ( ordered ) { continue; } //console.log( val ); var = read_float( val ); if ( isNaN( val ) ) { continue; } //console.log( val ); total += val; } //console.log( total ); total = total.toLocaleString('en-AU',{currency:'AUD',minimumFractionDigits:2}); document.getElementById( id + '_sum' ).innerHTML = total; } for ( var i in document.jj5_options ) { var spec = document.jj5_options[ i ]; var parts_total = 0; for ( var j in spec.parts ) { var part = spec.parts[ j ]; var sum_id = part + '_sum'; var sum = read_float( document.getElementById( sum_id ).innerHTML ); if ( isNaN( sum ) ) { continue; } parts_total += sum; } var options_total = parts_total; for ( var j in spec.options ) { var option = spec.options[ j ]; var sum_id = option + '_sum'; var sum = read_float( document.getElementById( sum_id ).innerHTML ); if ( isNaN( sum ) ) { continue; } options_total += sum; } var ul = document.getElementById( 'jj5_options' ); var parts_label = parts_total.toLocaleString('en-AU',{currency:'AUD',minimumFractionDigits:2}); var options_label = options_total.toLocaleString('en-AU',{currency:'AUD',minimumFractionDigits:2}); var line = spec.label + ': $' + parts_label; if ( spec.options ) { line += ' (with options: $' + options_label + ')'; } var li = document.createElement('li'); li.appendChild(document.createTextNode(line)); ul.appendChild(li); } function read_cell( table, row, col ) { try { return table.rows[row].cells[col].innerHTML.trim(); } catch ( ex ) { return null; } } function read_float( input ) { return parseFloat( input.replace( '$', '' ).replace( ',', '' ) ); }