mediawiki.action.edit.editWarning: Reuse jQuery collections
authorDerk-Jan Hartman <hartman.wiki@gmail.com>
Tue, 6 May 2014 11:25:57 +0000 (13:25 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Wed, 7 May 2014 12:23:00 +0000 (12:23 +0000)
Change-Id: I3084efe5962bb6a13700f95745c415fb074bc7bd

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

index f8448e6..dcd2b0b 100644 (file)
@@ -2,16 +2,20 @@
  * Javascript for module editWarning
  */
 ( function ( mw, $ ) {
+       'use strict';
+
        $( function () {
+               var savedWindowOnBeforeUnload,
+                       $wpTextbox1 = $( '#wpTextbox1' ),
+                       $wpSummary = $( '#wpSummary' );
                // Check if EditWarning is enabled and if we need it
-               if ( $( '#wpTextbox1' ).length === 0 ) {
+               if ( $wpTextbox1.length === 0 ) {
                        return true;
                }
                // Get the original values of some form elements
-               $( '#wpTextbox1, #wpSummary' ).each( function () {
+               $wpTextbox1.add( $wpSummary ).each( function () {
                        $( this ).data( 'origtext', $( this ).val() );
                } );
-               var savedWindowOnBeforeUnload;
                $( window )
                        .on( 'beforeunload.editwarning', function () {
                                var retval;
@@ -20,8 +24,8 @@
                                // the original values
                                if (
                                        mw.config.get( 'wgAction' ) === 'submit' ||
-                                               $( '#wpTextbox1' ).data( 'origtext' ) !== $( '#wpTextbox1' ).val() ||
-                                               $( '#wpSummary' ).data( 'origtext' ) !== $( '#wpSummary' ).val()
+                                               $wpTextbox1.data( 'origtext' ) !== $wpTextbox1.val() ||
+                                               $wpSummary.data( 'origtext' ) !== $wpSummary.val()
                                ) {
                                        // Return our message
                                        retval = mw.msg( 'editwarning-warning' );