[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 /* 2 * Javascript for module editWarning 3 */ 4 ( function ( mw, $ ) { 5 'use strict'; 6 7 $( function () { 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 ) { 13 return true; 14 } 15 // Get the original values of some form elements 16 $wpTextbox1.add( $wpSummary ).each( function () { 17 $( this ).data( 'origtext', $( this ).val() ); 18 } ); 19 $( window ) 20 .on( 'beforeunload.editwarning', function () { 21 var retval; 22 23 // Check if the current values of some form elements are the same as 24 // the original values 25 if ( 26 mw.config.get( 'wgAction' ) === 'submit' || 27 $wpTextbox1.data( 'origtext' ) !== $wpTextbox1.textSelection( 'getContents' ) || 28 $wpSummary.data( 'origtext' ) !== $wpSummary.textSelection( 'getContents' ) 29 ) { 30 // Return our message 31 retval = mw.msg( 'editwarning-warning' ); 32 } 33 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; 41 }, 1 ); 42 return retval; 43 } 44 } ) 45 .on( 'pageshow.editwarning', function () { 46 // Re-add onbeforeunload handler 47 if ( !window.onbeforeunload ) { 48 window.onbeforeunload = savedWindowOnBeforeUnload; 49 } 50 } ); 51 52 // Add form submission handler 53 $( '#editform' ).submit( function () { 54 // Unbind our handlers 55 $( window ).off( '.editwarning' ); 56 } ); 57 } ); 58 59 }( mediaWiki, jQuery ) );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |