| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
( function () { |
| 6 |
$( () => { |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
function isPrefsChanged() { |
| 11 |
|
| 12 |
const $inputs = $( '#mw-prefs-form :input[name]' ); |
| 13 |
|
| 14 |
for ( let index = 0; index < $inputs.length; index++ ) { |
| 15 |
const input = $inputs[ index ]; |
| 16 |
const $input = $( input ); |
| 17 |
|
| 18 |
|
| 19 |
if ( $input.is( 'select' ) ) { |
| 20 |
|
| 21 |
for ( let optIndex = 0; optIndex < input.options.length; optIndex++ ) { |
| 22 |
const opt = input.options[ optIndex ]; |
| 23 |
if ( opt.selected !== opt.defaultSelected ) { |
| 24 |
return true; |
| 25 |
} |
| 26 |
} |
| 27 |
} else if ( $input.is( 'input' ) || $input.is( 'textarea' ) ) { |
| 28 |
|
| 29 |
const inputType = input.type; |
| 30 |
if ( inputType === 'radio' || inputType === 'checkbox' ) { |
| 31 |
if ( input.checked !== input.defaultChecked ) { |
| 32 |
return true; |
| 33 |
} |
| 34 |
} else if ( input.value !== input.defaultValue ) { |
| 35 |
return true; |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
return false; |
| 41 |
} |
| 42 |
|
| 43 |
const saveButton = OO.ui.infuse( $( '#prefcontrol' ) ); |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
saveButton.setDisabled( !isPrefsChanged() ); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
[ 'change', 'keyup', 'mouseup' ].forEach( ( eventType ) => { |
| 54 |
document.addEventListener( eventType, () => { |
| 55 |
|
| 56 |
setTimeout( () => { |
| 57 |
saveButton.setDisabled( !isPrefsChanged() ); |
| 58 |
} ); |
| 59 |
}, true ); |
| 60 |
} ); |
| 61 |
|
| 62 |
|
| 63 |
const allowCloseWindow = mw.confirmCloseWindow( { |
| 64 |
test: isPrefsChanged |
| 65 |
} ); |
| 66 |
$( '#mw-prefs-form' ).on( 'submit', allowCloseWindow.release ); |
| 67 |
} ); |
| 68 |
}() ); |