Debian Codegraph @

resources/src/mediawiki.action/mediawiki.action.edit.editWarning.js

raw symbols SCIP
1 /*
2 * Javascript for module editWarning
3 */
4 ( function () {
5 'use strict';
6
7 $( () => {
8 const $textBox = $( '#wpTextbox1' );
9 const $summary = $( '#wpSummary' );
10 const $both = $textBox.add( $summary );
11
12 // Check if EditWarning is enabled and if we need it
13 if ( !mw.user.options.get( 'useeditwarning' ) ) {
14 return true;
15 }
16
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' ) );
21 } );
22
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( {
26 test: function () {
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' );
32 },
33
34 namespace: 'editwarning'
35 } );
36
37 // Add form submission handler
38 $( '#editform' ).on( 'submit', () => {
39 allowCloseWindow.release();
40 } );
41 } );
42
43 }() );