MediaWiki:Gadget-resign-calculator.js: Difference between revisions

New re-sign post format
The league is NBA RealGM
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
/**
/**
  * 1TC RealGM — re-sign salary calculator.
  * NBA RealGM — re-sign salary calculator.
  * Implements the formula on [[NBA:Re-Signing]]. If the two ever disagree,
  * Implements the formula on [[NBA:Re-Signing]]. If the two ever disagree,
  * the wiki page is the rule and this script is the bug.
  * the wiki page is the rule and this script is the bug.
Line 105: Line 105:
var form = document.createElement( 'div' );
var form = document.createElement( 'div' );
form.className = 'tc-calc';
form.className = 'tc-calc';
/**
* One labelled row. Controls live in their own flex wrapper so that on a
* narrow screen the label can stack above them while they stay in a row.
*/
function row( labelText, controls, extraClass ) {
var r = document.createElement( 'div' );
r.className = 'tc-calc-row' + ( extraClass ? ' ' + extraClass : '' );
var l = document.createElement( 'label' );
l.textContent = labelText;
var c = document.createElement( 'div' );
c.className = 'tc-calc-controls';
controls.forEach( function ( el ) { c.appendChild( el ); } );
r.appendChild( l );
r.appendChild( c );
form.appendChild( r );
return c;
}


// --- Fantrax scores ---
// --- Fantrax scores ---
var scoreRow = document.createElement( 'div' );
scoreRow.className = 'tc-calc-row tc-scores';
var scoreLabel = document.createElement( 'label' );
scoreLabel.textContent = 'Fantrax scores';
scoreRow.appendChild( scoreLabel );
for ( var i = 0; i < 3; i++ ) {
for ( var i = 0; i < 3; i++ ) {
var input = document.createElement( 'input' );
var input = document.createElement( 'input' );
Line 118: Line 131:
input.min = '0';
input.min = '0';
input.placeholder = [ 'season 1', 'season 2', 'season 3' ][ i ];
input.placeholder = [ 'season 1', 'season 2', 'season 3' ][ i ];
scoreRow.appendChild( input );
scoreInputs.push( input );
scoreInputs.push( input );
}
}
form.appendChild( scoreRow );
row( 'Fantrax scores', scoreInputs, 'tc-scores' );
 


// --- term ---
// --- term ---
var termRow = document.createElement( 'div' );
termRow.className = 'tc-calc-row';
var termLabel = document.createElement( 'label' );
termLabel.textContent = 'Contract length';
var term = document.createElement( 'select' );
var term = document.createElement( 'select' );
[ 3, 4, 5 ].forEach( function ( y ) {
[ 3, 4, 5 ].forEach( function ( y ) {
Line 136: Line 143:
term.appendChild( o );
term.appendChild( o );
} );
} );
termRow.appendChild( termLabel );
row( 'Contract length', [ term ] );
termRow.appendChild( term );
form.appendChild( termRow );


// --- optional first season, to generate the contract line ---
// --- first season, to generate the contract line ---
var seasonRow = document.createElement( 'div' );
seasonRow.className = 'tc-calc-row';
var seasonLabel = document.createElement( 'label' );
seasonLabel.textContent = 'First season';
var season = document.createElement( 'input' );
var season = document.createElement( 'input' );
season.type = 'number';
season.type = 'number';
Line 150: Line 151:
season.placeholder = String( UPCOMING_SEASON );
season.placeholder = String( UPCOMING_SEASON );
season.value = String( UPCOMING_SEASON );
season.value = String( UPCOMING_SEASON );
seasonRow.appendChild( seasonLabel );
row( 'First season', [ season ] );
seasonRow.appendChild( season );
form.appendChild( seasonRow );


// --- team and player, for the post block ---
// --- team and player, for the post block ---
var teamRow = document.createElement( 'div' );
teamRow.className = 'tc-calc-row';
var teamLabel = document.createElement( 'label' );
teamLabel.textContent = 'Your team (optional)';
var team = document.createElement( 'input' );
var team = document.createElement( 'input' );
team.type = 'text';
team.type = 'text';
team.placeholder = 'Celtics';
team.placeholder = 'Sonics';
team.style.width = '14em';
team.className = 'tc-calc-wide';
teamRow.appendChild( teamLabel );
row( 'Your team (optional)', [ team ] );
teamRow.appendChild( team );
form.appendChild( teamRow );


var nameRow = document.createElement( 'div' );
nameRow.className = 'tc-calc-row';
var nameLabel = document.createElement( 'label' );
nameLabel.textContent = 'Player (optional)';
var name = document.createElement( 'input' );
var name = document.createElement( 'input' );
name.type = 'text';
name.type = 'text';
name.placeholder = 'Larry Bird';
name.placeholder = 'Larry Bird';
name.style.width = '14em';
name.className = 'tc-calc-wide';
nameRow.appendChild( nameLabel );
row( 'Player (optional)', [ name ] );
nameRow.appendChild( name );
form.appendChild( nameRow );


var out = document.createElement( 'div' );
var out = document.createElement( 'div' );
Line 247: Line 234:
var endYear = first + years - 1;
var endYear = first + years - 1;


// "The Celtics offer Larry Bird 5 years" — team and player drop out if blank.
// "Sonics offer Larry Bird 5 years" — team and player drop out if blank.
var tm = team.value.trim(),
var tm = team.value.trim(),
term_ = years + ( years === 1 ? ' year' : ' years' ),
term_ = years + ( years === 1 ? ' year' : ' years' ),
prefix = tm && who ? 'The ' + tm + ' offer ' + who :
prefix = tm && who ? tm + ' offer ' + who :
( who || ( tm ? 'The ' + tm + ' offer' : '' ) );
( who || ( tm ? tm + ' offer' : '' ) );


var lines = [ prefix ? prefix + ' ' + term_ : term_ ];
var lines = [ prefix ? prefix + ' ' + term_ : term_ ];