Adamw has submitted this change and it was merged.

Change subject: Cleaning up JS to pass JSLint
......................................................................


Cleaning up JS to pass JSLint

Change-Id: I7708773342d60c14ff367fe49b901e63c41fdfa3
---
M includes/BannerRenderer.php
M mixins/BannerDiet/BannerDiet.js
M modules/ext.centralNotice.adminUi.bannerEditor/bannereditor.js
M modules/ext.centralNotice.adminUi.bannerManager/bannermanager.js
M modules/ext.centralNotice.adminUi.campaignManager/campaignManager.js
M modules/ext.centralNotice.adminUi/centralnotice.js
M modules/ext.centralNotice.bannerController/bannerController.js
M modules/jquery.ui.multiselect/ui.multiselect.js
M special/SpecialBannerLoader.php
9 files changed, 36 insertions(+), 41 deletions(-)

Approvals:
  Adamw: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/BannerRenderer.php b/includes/BannerRenderer.php
index ec33781..8eb9a1b 100644
--- a/includes/BannerRenderer.php
+++ b/includes/BannerRenderer.php
@@ -113,19 +113,20 @@
 
        function getPreloadJs() {
                $snippets = $this->mixinController->getPreloadJsSnippets();
+               $bundled = array();
+               $bundled[] = 'var retval = true;';
+
                if ( $snippets ) {
-                       $bundled = array();
                        foreach ( $snippets as $mixin => $code ) {
                                if ( 
!$this->context->getRequest()->getFuzzyBool( 'debug' ) ) {
                                        $code = JavaScriptMinifier::minify( 
$code );
                                }
 
-                               $bundled[] = "/* {$mixin}: */{$code}";
+                               $bundled[] = "/* {$mixin}: */ retval &= 
{$code}";
                        }
-                       $js = implode( " && ", $bundled );
-                       return $this->substituteMagicWords( $js );
                }
-               return "";
+               $bundled[] = 'return retval;';
+               return $this->substituteMagicWords( implode( "\n", $bundled ) );
        }
 
        function getResourceLoaderHtml() {
diff --git a/mixins/BannerDiet/BannerDiet.js b/mixins/BannerDiet/BannerDiet.js
index bfa212e..11d47ad 100644
--- a/mixins/BannerDiet/BannerDiet.js
+++ b/mixins/BannerDiet/BannerDiet.js
@@ -3,13 +3,12 @@
                $.cookie( '{{{hide-cookie-name}}}', 0, { expires: 365, path: 
'/' } );
                return true;
        }
-       var cookieCount = parseInt( $.cookie( '{{{hide-cookie-name}}}' ) ) | 0;
+       var cookieCount = parseInt( $.cookie( '{{{hide-cookie-name}}}' ), 10 ) 
| 0;
 
-       if ( cookieCount < {{{hide-cookie-max-count}}} ) {
+       if ( cookieCount < parseInt( '{{{hide-cookie-max-count}}}', 10 ) ) {
                $.cookie( '{{{hide-cookie-name}}}', cookieCount + 1, { expires: 
365, path: '/' } );
                return true;
        } else {
                return false;
        }
-})()
-/* don't put a semicolon here! */
+})();
diff --git a/modules/ext.centralNotice.adminUi.bannerEditor/bannereditor.js 
b/modules/ext.centralNotice.adminUi.bannerEditor/bannereditor.js
index 6ca2697..4c34d64 100644
--- a/modules/ext.centralNotice.adminUi.bannerEditor/bannereditor.js
+++ b/modules/ext.centralNotice.adminUi.bannerEditor/bannereditor.js
@@ -64,7 +64,7 @@
                 */
                doSaveBanner: function() {
                        if ( $( '#mw-input-wpbanner-body' ).prop( 'value' 
).indexOf( 'document.write' ) > -1 ) {
-                               alert( mediaWiki.msg( 
'centralnotice-documentwrite-error' ) );
+                               window.alert( mediaWiki.msg( 
'centralnotice-documentwrite-error' ) );
                        } else {
                                return true;
                        }
diff --git a/modules/ext.centralNotice.adminUi.bannerManager/bannermanager.js 
b/modules/ext.centralNotice.adminUi.bannerManager/bannermanager.js
index 03ffb04..431f88d 100644
--- a/modules/ext.centralNotice.adminUi.bannerManager/bannermanager.js
+++ b/modules/ext.centralNotice.adminUi.bannerManager/bannermanager.js
@@ -146,8 +146,6 @@
                 * Updates the 'checkAll' check box if any of the banner check 
boxes are checked
                 */
                selectCheckStateAltered: function() {
-                       var selectAllCheck = $( '#mw-input-wpselectAllBanners' 
);
-
                        if ( $( this ).prop( 'checked' ) === true ) {
                                
mw.centralNotice.adminUi.bannerManagement.selectedItemCount++;
                        } else {
@@ -170,7 +168,7 @@
                                selectAllCheck.prop( 'checked', true );
                                selectAllCheck.prop( 'indeterminate', false );
                                deleteButton.prop( 'disabled', false );
-                       } else if ( 
mw.centralNotice.adminUi.bannerManagement.selectedItemCount == 0 ) {
+                       } else if ( 
mw.centralNotice.adminUi.bannerManagement.selectedItemCount === 0 ) {
                                // Nothing selected
                                selectAllCheck.prop( 'checked', false );
                                selectAllCheck.prop( 'indeterminate', false );
diff --git 
a/modules/ext.centralNotice.adminUi.campaignManager/campaignManager.js 
b/modules/ext.centralNotice.adminUi.campaignManager/campaignManager.js
index e0a01e9..eee7abe 100644
--- a/modules/ext.centralNotice.adminUi.campaignManager/campaignManager.js
+++ b/modules/ext.centralNotice.adminUi.campaignManager/campaignManager.js
@@ -22,7 +22,7 @@
  *
  * @file
  */
-( function ( $, mw ) {
+( function ( $ ) {
        $( '#centralnotice-showarchived' ).click( function() {
                if ( $( this ).prop( 'checked' ) === true ) {
                        $( '.cn-archived-item' ).show();
@@ -30,4 +30,4 @@
                        $( '.cn-archived-item' ).hide();
                }
        });
-} )( jQuery, mediaWiki );
+} )( jQuery );
diff --git a/modules/ext.centralNotice.adminUi/centralnotice.js 
b/modules/ext.centralNotice.adminUi/centralnotice.js
index 3fc7a18..b51d1b6 100644
--- a/modules/ext.centralNotice.adminUi/centralnotice.js
+++ b/modules/ext.centralNotice.adminUi/centralnotice.js
@@ -50,8 +50,6 @@
 }
 
 jQuery(document).ready( function ( $ ) {
-       var bucketCheck, buckets;
-
        // Render jquery.ui.datepicker on appropriate fields
        $( '.centralnotice-datepicker' ).each( function () {
                var altFormat = 'yymmdd000000';
@@ -114,11 +112,9 @@
        } );
 
        // Bucketing! Disable bucket selectors if #buckets is not checked.
-       bucketSelect = $( '#buckets' );
-       buckets = $( 'select[id^="bucketSelector"]' );
-
-    bucketSelect.change( function () {
-        numBuckets = parseInt( this[this.selectedIndex].value );
+       $( '#buckets' ).change( function () {
+        var numBuckets = parseInt( this[this.selectedIndex].value, 10 ),
+                       buckets = $( 'select[id^="bucketSelector"]' );
 
         if ( numBuckets == 1 ) {
             buckets.prop( 'disabled', true );
@@ -127,16 +123,13 @@
             // Go through and modify all the options -- disabling 
inappropriate ones
             // and remapping the rings
             buckets.each( function() {
-                var curBucket = parseInt( this[this.selectedIndex].value );
+                var curBucket = parseInt( this[this.selectedIndex].value, 10 );
                 $(this).val( curBucket % numBuckets );
 
                 for ( var i = 0; i < this.options.length; i++ ) {
-                    $(this.options[i]).prop( 'disabled', !(i < numBuckets) );
+                    $(this.options[i]).prop( 'disabled', (i >= numBuckets) );
                 }
-            })
+            });
         }
-       } );
-
-       // Initial state
-       bucketSelect.trigger( 'change' );
+       } ).trigger( 'change' );
 } );
diff --git a/modules/ext.centralNotice.bannerController/bannerController.js 
b/modules/ext.centralNotice.bannerController/bannerController.js
index bad3acb..3a517fe 100644
--- a/modules/ext.centralNotice.bannerController/bannerController.js
+++ b/modules/ext.centralNotice.bannerController/bannerController.js
@@ -170,7 +170,7 @@
 
                        // === Initialize things that don't come from MW itself 
===
                        mw.centralNotice.data.bucket = 
mw.centralNotice.getBucket();
-                       mw.centralNotice.data.country = 
mw.centralNotice.data.getVars.country || Geo.country || 'XX';
+                       mw.centralNotice.data.country = 
mw.centralNotice.data.getVars.country || window.Geo.country || 'XX';
                        mw.centralNotice.isPreviewFrame = (mw.config.get( 
'wgCanonicalSpecialPageName' ) === 'BannerPreview');
                        mw.centralNotice.data.device = 
mw.centralNotice.data.getVars.device || mw.config.get( 'wgMobileDeviceName', 
'desktop' );
 
@@ -200,8 +200,8 @@
                                        dataType: 'script',
                                        cache: true,
                                        complete: function() {
-                                               if ( Geo.country ) {
-                                                       
mw.centralNotice.data.country = Geo.country;
+                                               if ( window.Geo.country ) {
+                                                       
mw.centralNotice.data.country = window.Geo.country;
                                                } else {
                                                        
mw.centralNotice.data.country = 'XX';
                                                }
@@ -230,7 +230,7 @@
        //
        // TODO: Migrate away from global functions
        window.insertBanner = function ( bannerJson ) {
-               var url, targets, data;
+               var url, targets;
 
                var impressionData = {
                        country: mw.centralNotice.data.country,
@@ -260,7 +260,7 @@
                                impressionResultData = {
                                        result: 'hide',
                                        reason: 'preload'
-                               }
+                               };
                        } else if (
                                bannerJson.priority < 3 && /* A priority of 3 
is Emergency and cannot be hidden */
                                !mw.centralNotice.data.testing && /* And we 
want to see what we're testing! :) */
@@ -270,7 +270,7 @@
                                impressionResultData = {
                                        result: 'hide',
                                        reason: 'cookie'
-                               }
+                               };
                        } else {
                                // All conditions fulfilled, inject the banner
                                mw.centralNotice.bannerData.bannerName = 
bannerJson.bannerName;
diff --git a/modules/jquery.ui.multiselect/ui.multiselect.js 
b/modules/jquery.ui.multiselect/ui.multiselect.js
index 1012d0d..7a22d54 100644
--- a/modules/jquery.ui.multiselect/ui.multiselect.js
+++ b/modules/jquery.ui.multiselect/ui.multiselect.js
@@ -82,7 +82,7 @@
                                this.selectedList.sortable({
                                        placeholder: 'ui-state-highlight',
                                        axis: 'y',
-                                       update: function(event, ui) {
+                                       update: function() {
                                                // apply the new sort order to 
the original selectbox
                                                
that.selectedList.find('li').each(function() {
                                                        if 
($(this).data('optionLink')) {
@@ -148,7 +148,7 @@
                        this.count = 0;
 
                        var that = this;
-                       var items = $(options.map(function(i) {
+                       $(options.map(function(i) {
                                var item = 
that._getOptionNode(this).appendTo(this.selected ? that.selectedList : 
that.availableList).show();
 
                                if (this.selected) that.count += 1;
@@ -198,7 +198,7 @@
                                // TODO: test needed for dynamic list populating
                                if ( direction ) {
                                        while (i>=0 && i<items.length) {
-                                               direction > 0 ? i++ : i--;
+                                               i += (direction > 0) ? 1 : -1;
                                                if ( direction != 
comparator(item, $(items[i])) ) {
                                                        // going up, go back 
one item down, otherwise leave as is
                                                        succ = items[direction 
> 0 ? i : i+1];
@@ -210,7 +210,11 @@
                                }
 
                                var availableItem = this._cloneWithData(item);
-                               succ ? availableItem.insertBefore($(succ)) : 
availableItem.appendTo(this.availableList);
+                               if (succ) {
+                                       availableItem.insertBefore($(succ));
+                               } else {
+                                       
availableItem.appendTo(this.availableList);
+                               }
                                item[this.options.hide](this.options.animated, 
function() { $(this).remove(); });
                                
availableItem.hide()[this.options.show](this.options.animated);
 
@@ -283,7 +287,7 @@
                _registerAddEvents: function(elements) {
                        var that = this;
                        elements.click(function() {
-                               var item = that._setSelected($(this).parent(), 
true);
+                               that._setSelected($(this).parent(), true);
                                that.count += 1;
                                that._updateCount();
                                return false;
diff --git a/special/SpecialBannerLoader.php b/special/SpecialBannerLoader.php
index 63156e1..3b19185 100644
--- a/special/SpecialBannerLoader.php
+++ b/special/SpecialBannerLoader.php
@@ -131,7 +131,7 @@
 
                $preload = $bannerRenderer->getPreloadJs();
                if ( $preload ) {
-                       $preload = "mw.centralNotice.bannerData.preload = 
function() { return {$preload}; };";
+                       $preload = "mw.centralNotice.bannerData.preload = 
function() { {$preload} };";
                }
 
                $bannerJs = $preload . "mw.centralNotice.insertBanner( 
{$bannerJson} );";

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7708773342d60c14ff367fe49b901e63c41fdfa3
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Mwalker <[email protected]>
Gerrit-Reviewer: Adamw <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to