2 * Javascript for module editWarning
8 var savedWindowOnBeforeUnload
,
9 $wpTextbox1
= $( '#wpTextbox1' ),
10 $wpSummary
= $( '#wpSummary' );
11 // Check if EditWarning is enabled and if we need it
12 if ( $wpTextbox1
.length
=== 0 ) {
15 // Get the original values of some form elements
16 $wpTextbox1
.add( $wpSummary
).each( function () {
17 $( this ).data( 'origtext', $( this ).val() );
20 .on( 'beforeunload.editwarning', function () {
23 // Check if the current values of some form elements are the same as
24 // the original values
26 mw
.config
.get( 'wgAction' ) === 'submit' ||
27 $wpTextbox1
.data( 'origtext' ) !== $wpTextbox1
.val() ||
28 $wpSummary
.data( 'origtext' ) !== $wpSummary
.val()
31 retval
= mw
.msg( 'editwarning-warning' );
34 // Unset the onbeforeunload handler so we don't break page caching in Firefox
35 savedWindowOnBeforeUnload
= window
.onbeforeunload
;
36 window
.onbeforeunload
= null;
37 if ( retval
!== undefined ) {
38 // ...but if the user chooses not to leave the page, we need to rebind it
39 setTimeout( function () {
40 window
.onbeforeunload
= savedWindowOnBeforeUnload
;
45 .on( 'pageshow.editwarning', function () {
46 // Re-add onbeforeunload handler
47 if ( !window
.onbeforeunload
) {
48 window
.onbeforeunload
= savedWindowOnBeforeUnload
;
52 // Add form submission handler
53 $( '#editform' ).submit( function () {
54 // Unbind our handlers
55 $( window
).off( '.editwarning' );
59 }( mediaWiki
, jQuery
) );