2 * Javascript for module editWarning
8 const $textBox = $( '#wpTextbox1' );
9 const $summary = $( '#wpSummary' );
10 const $both = $textBox.add( $summary );
12 // Check if EditWarning is enabled and if we need it
13 if ( !mw.user.options.get( 'useeditwarning' ) ) {
17 // Save the original value of the text fields
18 $both.each( ( index, element ) => {
19 const $element = $( element );
20 $element.data( 'origtext', $element.textSelection( 'getContents' ) );
23 // This registers an event with the name "beforeunload.editwarning", which allows others to
24 // turn the confirmation off with `$( window ).off( 'beforeunload.editwarning' );`.
25 const allowCloseWindow = mw.confirmCloseWindow( {
27 // When the action is submit we're solving a conflict. Everything is a pending change there.
28 return mw.config.get( 'wgAction' ) === 'submit' ||
29 // We use .textSelection, because editors might not have updated the form yet.
30 $textBox.data( 'origtext' ) !== $textBox.textSelection( 'getContents' ) ||
31 $summary.data( 'origtext' ) !== $summary.textSelection( 'getContents' );
34 namespace: 'editwarning'
37 // Add form submission handler
38 $( '#editform' ).on( 'submit', () => {
39 allowCloseWindow.release();