Merge "resourceloader: Simplify StringSet fallback"
[lhc/web/wiklou.git] / resources / src / mediawiki.action / mediawiki.action.edit.editWarning.js
1 /*
2 * Javascript for module editWarning
3 */
4 ( function () {
5 'use strict';
6
7 $( function () {
8 var allowCloseWindow,
9 $textBox = $( '#wpTextbox1' ),
10 $summary = $( '#wpSummary' ),
11 $both = $textBox.add( $summary );
12
13 // Check if EditWarning is enabled and if we need it
14 if ( !mw.user.options.get( 'useeditwarning' ) ) {
15 return true;
16 }
17
18 // Save the original value of the text fields
19 $both.each( function ( index, element ) {
20 var $element = $( element );
21 $element.data( 'origtext', $element.textSelection( 'getContents' ) );
22 } );
23
24 allowCloseWindow = mw.confirmCloseWindow( {
25 test: function () {
26 // We use .textSelection, because editors might not have updated the form yet.
27 return mw.config.get( 'wgAction' ) === 'submit' ||
28 $textBox.data( 'origtext' ) !== $textBox.textSelection( 'getContents' ) ||
29 $summary.data( 'origtext' ) !== $summary.textSelection( 'getContents' );
30 },
31
32 message: mw.msg( 'editwarning-warning' ),
33 namespace: 'editwarning'
34 } );
35
36 // Add form submission handler
37 $( '#editform' ).submit( function () {
38 allowCloseWindow.release();
39 } );
40 } );
41
42 }() );