MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
add basic preSelect() option
improved preSelect(), allows filling out 'Other' box
Line 317: Line 317:


function preSelect() {
function preSelect() {
/* Check for a 'preSelect' url parameter, and select that option */
/* Check for a 'preSelect' url parameter, and select that option.
If there isn't an option, add it to the "Other" box and select that */
if ( mw.util.getParamValue('preSelect') ) {
$preSelectOption = $('input[name="amount"][value="' + mw.util.getParamValue('preSelect') + '"]');
var preSelectAmount = mw.util.getParamValue('preSelect');
if ( preSelectAmount.length ) {
if ($preSelectOption) {
$preSelectOption = $('input[name="amount"][value="' + preSelectAmount + '"]');
if ( $preSelectOption.length ) {
// Select existing input, and add class to label for IE
// Select existing input, and add class to label for IE
$preSelectOption.prop('checked', true);
$preSelectOption.prop('checked', true);
$preSelectOption.siblings('label').addClass('checked');
$preSelectOption.siblings('label').addClass('checked');
}
} else {
$('#input_amount_other_box').val( preSelectAmount );
$('#input_amount_other').prop('checked', true);
$('label[for="input_amount_other"]').addClass('checked');
}
}
}
}
}