MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 27: | Line 27: | ||
} | } | ||
var options_total = | var options_total = parts_total; | ||
for ( var j in spec.options ) { | for ( var j in spec.options ) { | ||
Line 41: | Line 41: | ||
var ul = document.getElementById( 'jj5_options' ); | 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 + ': $' + | var line = spec.label + ': $' + parts_label; | ||
if ( | if ( spec.options ) { line += ' (with options: $' + options_label + ')'; } | ||
var li = document.createElement('li'); | var li = document.createElement('li'); |
Revision as of 01:04, 27 January 2022
/* 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 ); } 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 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; } function read_float( input ) { var val = input.replace( '$', '' ); val = val.replace( ',', '' ); return parseFloat( val ); }