2 * Javascript for module editWarning
6 // Check if EditWarning is enabled and if we need it
7 if ( $( '#wpTextbox1' ).length === 0 ) {
10 // Get the original values of some form elements
11 $( '#wpTextbox1, #wpSummary' ).each( function () {
12 $( this ).data( 'origtext', $( this ).val() );
14 var savedWindowOnBeforeUnload;
16 .on( 'beforeunload.editwarning', function () {
19 // Check if the current values of some form elements are the same as
20 // the original values
22 mw.config.get( 'wgAction' ) === 'submit' ||
23 $( '#wpTextbox1' ).data( 'origtext' ) !== $( '#wpTextbox1' ).val() ||
24 $( '#wpSummary' ).data( 'origtext' ) !== $( '#wpSummary' ).val()
27 retval = mw.msg( 'editwarning-warning' );
30 // Unset the onbeforeunload handler so we don't break page caching in Firefox
31 savedWindowOnBeforeUnload = window.onbeforeunload;
32 window.onbeforeunload = null;
33 if ( retval !== undefined ) {
34 // ...but if the user chooses not to leave the page, we need to rebind it
35 setTimeout( function () {
36 window.onbeforeunload = savedWindowOnBeforeUnload;
41 .on( 'pageshow.editwarning', function () {
42 // Re-add onbeforeunload handler
43 if ( !window.onbeforeunload ) {
44 window.onbeforeunload = savedWindowOnBeforeUnload;
48 // Add form submission handler
49 $( '#editform' ).submit( function () {
50 // Unbind our handlers
51 $( window ).off( '.editwarning' );
55 }( mediaWiki, jQuery ) );