X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.special%2Fmediawiki.special.preferences.js;h=1f6429b2e6d27724d659d9cb7b82f06b38d38182;hb=bb2d13313743d27f974a387693b5e739f341d6f7;hp=e553f449d61e688bdb6d5e6a37baad5d54a400c4;hpb=19ffc9adbd87863236933bca532054f4438679b7;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.special/mediawiki.special.preferences.js b/resources/src/mediawiki.special/mediawiki.special.preferences.js index e553f449d6..1f6429b2e6 100644 --- a/resources/src/mediawiki.special/mediawiki.special.preferences.js +++ b/resources/src/mediawiki.special/mediawiki.special.preferences.js @@ -5,7 +5,7 @@ jQuery( function ( $ ) { var $preftoc, $preferences, $fieldsets, $legends, hash, labelFunc, $tzSelect, $tzTextbox, $localtimeHolder, servertime, - $checkBoxes; + $checkBoxes, savedWindowOnBeforeUnload; labelFunc = function () { return this.id.replace( /^mw-prefsection/g, 'preftab' ); @@ -263,4 +263,43 @@ jQuery( function ( $ ) { $( '#mw-input-wpsearcheverything' ).change( function () { $checkBoxes.prop( 'disabled', $( this ).prop( 'checked' ) ); } ); + + // Set up a message to notify users if they try to leave the page without + // saving. + $( '#mw-prefs-form' ).data( 'origdata', $( '#mw-prefs-form' ).serialize() ); + $( window ) + .on( 'beforeunload.prefswarning', function () { + var retval; + + // Check if anything changed + if ( $( '#mw-prefs-form' ).serialize() !== $( '#mw-prefs-form' ).data( 'origdata' ) ) { + // Return our message + retval = mediaWiki.msg( 'prefswarning-warning', mediaWiki.msg( 'saveprefs' ) ); + } + + // Unset the onbeforeunload handler so we don't break page caching in Firefox + savedWindowOnBeforeUnload = window.onbeforeunload; + window.onbeforeunload = null; + if ( retval !== undefined ) { + // ...but if the user chooses not to leave the page, we need to rebind it + setTimeout( function () { + window.onbeforeunload = savedWindowOnBeforeUnload; + }, 1 ); + return retval; + } + } ) + .on( 'pageshow.prefswarning', function () { + // Re-add onbeforeunload handler + if ( !window.onbeforeunload ) { + window.onbeforeunload = savedWindowOnBeforeUnload; + } + } ); + $( '#mw-prefs-form' ).submit( function () { + // Unbind our beforeunload handler + $( window ).off( '.prefswarning' ); + } ); + $( '#mw-prefs-restoreprefs' ).click( function () { + // Unbind our beforeunload handler + $( window ).off( '.prefswarning' ); + } ); } );