MarkTraceur has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/86804


Change subject: jquery audit of mw.DestinationChecker.js
......................................................................

jquery audit of mw.DestinationChecker.js

Bug: 53245
Change-Id: Ic053d97be27bfeedc86168e4ad15e24b6876d17e
---
M resources/mw.DestinationChecker.js
1 file changed, 24 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard 
refs/changes/04/86804/1

diff --git a/resources/mw.DestinationChecker.js 
b/resources/mw.DestinationChecker.js
index 53d06a0..f721e68 100644
--- a/resources/mw.DestinationChecker.js
+++ b/resources/mw.DestinationChecker.js
@@ -1,4 +1,10 @@
 ( function ( mw, $ ) {
+var validOptions = [
+       'preprocess',
+       'delay',
+       'events'
+];
+
 /**
  * Object to attach to a file name input, to be run on its change() event
  * Largely derived from wgUploadWarningObj in old upload.js
@@ -19,8 +25,7 @@
  *             events     what events on the input trigger a check.
  */
 mw.DestinationChecker = function( options ) {
-
-       var checker = this,
+       var i, option, event,
                check = this.getDelayedChecker();
 
        this.selector = options.selector;
@@ -28,20 +33,23 @@
        this.processResult = options.processResult;
        this.api = options.api;
 
-       $.each( ['preprocess', 'delay', 'events'], function( i, option ) {
-               if ( options[option] ) {
-                       checker[option] = options[option];
+       for ( i = 0; i < validOptions.length; i++ ) {
+               option = validOptions[i];
+
+               if ( options[option] !== undefined ) {
+                       this[option] = options[option];
                }
-       } );
+       }
 
-       $.each( this.events, function ( i, eventName ) {
-               $( checker.selector )[eventName]( check );
-       } );
+       this.$input = $( this.selector );
 
+       for ( i = 0; i < this.events; i++ ) {
+               event = this.events[i];
+               this.$input.on( event, check );
+       }
 };
 
 mw.DestinationChecker.prototype = {
-
        // events that the input undergoes which fire off a check
        events: [ 'change', 'keyup' ],
 
@@ -113,7 +121,6 @@
                                status.blacklist = result.blacklist;
                        }
 
-                       //$.extend( status, result );
                        if ( status.unique !== null && status.blacklist !== 
null ) {
                                status.title = title;
                                checker.processResult( status );
@@ -131,7 +138,7 @@
         * @return the current input value, with optional processing
         */
        getTitle: function() {
-               return this.preprocess( $( this.selector ).val() );
+               return this.preprocess( this.$input.val() );
        },
 
        /**
@@ -211,7 +218,7 @@
                        if ( data.query.pages[-1] && 
!data.query.pages[-1].imageinfo ) {
                                protection = data.query.pages[-1].protection;
                                if ( protection && protection.length > 0 ) {
-                                       $.each( protection, function( i, val ) {
+                                       $.each( protection, function ( i, val ) 
{
                                                if ( $.inArray( val.level, 
mw.config.get( 'wgUserGroups' ) ) === -1 ) {
                                                        result = {
                                                                isUnique: true,
@@ -299,13 +306,15 @@
 
 };
 
-
 /**
  * jQuery extension to make a field upload-checkable
  */
 $.fn.destinationChecked = function( options ) {
+       var checker;
+
        options.selector = this;
-       var checker = new mw.DestinationChecker( options );
+       checker = new mw.DestinationChecker( options );
+
        // this should really be done with triggers
        this.checkTitle = function() { checker.checkTitle(); };
        return this;

-- 
To view, visit https://gerrit.wikimedia.org/r/86804
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic053d97be27bfeedc86168e4ad15e24b6876d17e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to