summaryrefslogtreecommitdiff
path: root/www/wiki/resources/src/mediawiki.action/mediawiki.action.edit.editWarning.js
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/resources/src/mediawiki.action/mediawiki.action.edit.editWarning.js')
-rw-r--r--www/wiki/resources/src/mediawiki.action/mediawiki.action.edit.editWarning.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/www/wiki/resources/src/mediawiki.action/mediawiki.action.edit.editWarning.js b/www/wiki/resources/src/mediawiki.action/mediawiki.action.edit.editWarning.js
new file mode 100644
index 00000000..56dba703
--- /dev/null
+++ b/www/wiki/resources/src/mediawiki.action/mediawiki.action.edit.editWarning.js
@@ -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 ) );