blob: 6b3301285406c00bda30a93a69a131033f0634d2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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();
} );
} );
}( mediaWiki, jQuery ) );
|