]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - resources/src/mediawiki.action/mediawiki.action.edit.editWarning.js
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / resources / src / mediawiki.action / mediawiki.action.edit.editWarning.js
diff --git a/resources/src/mediawiki.action/mediawiki.action.edit.editWarning.js b/resources/src/mediawiki.action/mediawiki.action.edit.editWarning.js
new file mode 100644 (file)
index 0000000..56dba70
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Javascript for module editWarning
+ */
+( function ( mw, $ ) {
+       'use strict';
+
+       $( function () {
+               var allowCloseWindow,
+                       $textBox = $( '#wpTextbox1' ),
+                       $summary = $( '#wpSummary' ),
+                       $both = $textBox.add( $summary );
+
+               // Check if EditWarning is enabled and if we need it
+               if ( !mw.user.options.get( 'useeditwarning' ) ) {
+                       return true;
+               }
+
+               // Save the original value of the text fields
+               $both.each( function ( index, element ) {
+                       var $element = $( element );
+                       $element.data( 'origtext', $element.textSelection( 'getContents' ) );
+               } );
+
+               allowCloseWindow = mw.confirmCloseWindow( {
+                       test: function () {
+                               // We use .textSelection, because editors might not have updated the form yet.
+                               return mw.config.get( 'wgAction' ) === 'submit' ||
+                                       $textBox.data( 'origtext' ) !== $textBox.textSelection( 'getContents' ) ||
+                                       $summary.data( 'origtext' ) !== $summary.textSelection( 'getContents' );
+                       },
+
+                       message: mw.msg( 'editwarning-warning' ),
+                       namespace: 'editwarning'
+               } );
+
+               // Add form submission handler
+               $( '#editform' ).submit( function () {
+                       allowCloseWindow.release();
+               } );
+       } );
+
+}( mediaWiki, jQuery ) );