Santhosh has uploaded a new change for review.

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

Change subject: Misc code formatting cleanup
......................................................................

Misc code formatting cleanup

* Consistant whitespace after keywords
* Misc whitespace cleanup as per JS coding guidelines
  https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript
* pass mw to IIFE and use the function arguments close to function body
  ( function ( $, mw ) {
  ...
  }( jQuery, mediaWiki ) )
* Moved prefined moment to .jshintrc. Move browser:true too

Change-Id: If488974e8e5987916bc4043e4e70bb6c60472b30
---
M .jshintrc
M resources/ext.popups.core.js
2 files changed, 62 insertions(+), 56 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups 
refs/changes/90/123190/1

diff --git a/.jshintrc b/.jshintrc
index b6d8dda..caa6075 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -17,10 +17,11 @@
        "unused": true,
        // Legacy
        "onevar": true,
-
+       "browser": true,
        /* Local */
        "predef": [
                "mediaWiki",
-               "jQuery"
+               "jQuery",
+               "moment"
        ]
 }
\ No newline at end of file
diff --git a/resources/ext.popups.core.js b/resources/ext.popups.core.js
index ffa3e44..bf644f9 100644
--- a/resources/ext.popups.core.js
+++ b/resources/ext.popups.core.js
@@ -2,11 +2,8 @@
  * https://en.wikipedia.org/wiki/User:Yair_rand/NavPopupsRestyled.js
  */
 
-/*global mw: false, moment: false */
-/*jshint browser: true */
-
-(function ( $ ) {
-       $( document ).ready( function() {
+( function ( $, mw ) {
+       $( document ).ready( function () {
 
                var closeTimer, // The timer use to delay `closeBox`
                        openTimer, // The timer used to delay sending the API 
request/opening the popup form cache
@@ -40,7 +37,7 @@
                 * @param {String} title
                 * @param {Object} $el
                 */
-               function sendRequest ( href, title, $el ) {
+               function sendRequest( href, title, $el ) {
 
                        curRequest = api.get( {
                                action: 'query',
@@ -61,8 +58,10 @@
                                curRequest = undefined;
 
                                var $a,
-                                       page = 
re.query.pages[re.query.pageids[0]],
-                                       $contentbox = $( '<div>' ).addClass( 
'mwe-popups-extract' ).text( page.extract ),
+                                       page = re.query.pages[ 
re.query.pageids[ 0 ] ],
+                                       $contentbox = $( '<div>' )
+                                               .addClass( 'mwe-popups-extract' 
)
+                                               .text( page.extract ),
                                        thumbnail = page.thumbnail,
                                        tall = thumbnail && thumbnail.height > 
thumbnail.width,
                                        $thumbnail = createThumbnail( 
thumbnail, tall ),
@@ -75,17 +74,22 @@
                                        $timestamp = $( '<div>' )
                                                .addClass( timestampclass )
                                                .append(
-                                                       $( '<span>' ).text( 
mw.message( 'popups-last-edited', moment( timestamp ).fromNow() ).text() )
-                                               );
+                                                       $( '<span>' ).text( 
mw.message( 'popups-last-edited',
+                                                               moment( 
timestamp ).fromNow() ).text() )
+                                       );
 
                                $a = $( '<a>' )
-                                       .append( $thumbnail, $contentbox, 
$timestamp)
+                                       .append( $thumbnail, $contentbox, 
$timestamp )
                                        .attr( 'href', href )
                                        .on( 'click', logClick );
 
-                               cache[ href ] = { box: $a, thumbnail: 
thumbnail, tall: tall     };
+                               cache[ href ] = {
+                                       box: $a,
+                                       thumbnail: thumbnail,
+                                       tall: tall
+                               };
                                createBox( href, $el );
-                       });
+                       } );
 
                        return true;
                }
@@ -106,7 +110,7 @@
                 * @param {boolean} tall
                 * @return {Object} jQuery DOM element of the thumbnail
                 */
-               function createThumbnail ( thumbnail, tall ) {
+               function createThumbnail( thumbnail, tall ) {
                        if ( !thumbnail ) {
                                return $( '<span>' );
                        }
@@ -120,9 +124,11 @@
                                                .attr( {
                                                        'xlink:href': 
thumbnail.source,
                                                        x: ( thumbnail.width > 
SIZES.portraitImage.w ) ?
-                                                               ( ( 
thumbnail.width - SIZES.portraitImage.w ) / -2 ) :
-                                                               ( 
SIZES.portraitImage.w - thumbnail.width ),
-                                                       y: ( thumbnail.height > 
SIZES.portraitImage.h) ? ( ( thumbnail.height - SIZES.portraitImage.h ) / -2 ) 
: thumbnail.height,
+                                                               ( ( 
thumbnail.width - SIZES.portraitImage.w ) / -2 )
+                                                               : ( 
SIZES.portraitImage.w - thumbnail.width ),
+                                                       y: ( thumbnail.height > 
SIZES.portraitImage.h ) ?
+                                                               ( ( 
thumbnail.height - SIZES.portraitImage.h ) / -2 )
+                                                               : 
thumbnail.height,
                                                        width: thumbnail.width,
                                                        height: thumbnail.height
                                                } );
@@ -138,7 +144,7 @@
                                } else {
                                        $thumbnail = $( '<div>' )
                                                .addClass( 'mwe-popups-is-tall' 
)
-                                               .css( 'background-image', 
'url(' + thumbnail.source + ')');
+                                               .css( 'background-image', 
'url(' + thumbnail.source + ')' );
                                }
                        } else {
                                if ( supportsSVG() ) {
@@ -148,7 +154,7 @@
                                                        'xlink:href': 
thumbnail.source,
                                                        'clip-path': 
'url(#mwe-popups-mask)',
                                                        x: 0,
-                                                       y: ( thumbnail.height > 
SIZES.landscapeImage.h) ? ( ( thumbnail.height - SIZES.landscapeImage.h ) / -2 
) : thumbnail.height,
+                                                       y: ( thumbnail.height > 
SIZES.landscapeImage.h ) ? ( ( thumbnail.height - SIZES.landscapeImage.h ) / -2 
) : thumbnail.height,
                                                        width: thumbnail.width,
                                                        height: thumbnail.height
                                                } );
@@ -179,7 +185,7 @@
                 * @param {String} href
                 * @param {Object} $el
                 */
-               function createBox ( href, $el ) {
+               function createBox( href, $el ) {
                        var bar = cache[ href ],
                                offsetTop = $el.offset().top + $el.height() + 9,
                                offsetLeft = $el.offset().left,
@@ -214,10 +220,10 @@
                                // If theres an image and the popup is portrait 
do the SVG stuff
                                .toggleClass( 'mwe-popups-image-tri', ( 
bar.thumbnail && !bar.tall ) )
                                .addClass( bar.tall ? 'mwe-popups-is-tall' : 
'mwe-popups-is-not-tall' )
-                               .css({
+                               .css( {
                                        top: offsetTop,
                                        left: offsetLeft
-                               })
+                               } )
                                .append( bar.box )
                                .show()
                                .removeClass( 'mwe-popups-fade-out 
mwe-popups-fade-in' )
@@ -227,13 +233,13 @@
                                // More information and workarounds here - 
http://stackoverflow.com/a/13654655/366138
                                .html( $box.html() );
 
-                       if ( flipped  && bar.thumbnail ) {
+                       if ( flipped && bar.thumbnail ) {
                                if ( !bar.tall ) {
-                                       $box.find( 'image' )[0].setAttribute( 
'clip-path', 'url(#mwe-popups-mask-flip)' );
+                                       $box.find( 'image' )[ 0 ].setAttribute( 
'clip-path', 'url(#mwe-popups-mask-flip)' );
                                } else {
                                        $box
                                                .removeClass( 
'mwe-popups-no-image-tri' )
-                                               .find( 'image' 
)[0].setAttribute( 'clip-path', 'url(#mwe-popups-landscape-mask)' );
+                                               .find( 'image' )[ 0 
].setAttribute( 'clip-path', 'url(#mwe-popups-landscape-mask)' );
                                }
                        }
 
@@ -248,7 +254,7 @@
                 * Delay to give enough time for the use to move the pointer 
from
                 * the link to the popup box. Also avoids closing the popup by 
accident.
                 */
-               function leaveActive () {
+               function leaveActive() {
                        closeTimer = setTimeout( closeBox, 100 );
                }
 
@@ -256,7 +262,7 @@
                 * @method leaveInactive
                 * Unbinds events on the anchor tag and aborts AJAX request.
                 */
-               function leaveInactive () {
+               function leaveInactive() {
                        $( currentLink ).off( 'mouseleave', leaveInactive );
                        clearTimeout( openTimer );
                        if ( curRequest ) {
@@ -271,7 +277,7 @@
                 * Hides the popup, clears timers and sets it and the
                 * `currentLink` to undefined.
                 */
-               function closeBox () {
+               function closeBox() {
                        elDuration = mw.now() - elTime;
 
                        $( currentLink ).removeClass( 'mwe-popups-anchor-hover' 
).off( 'mouseleave', leaveActive );
@@ -282,13 +288,13 @@
                                .on( 'webkitAnimationEnd oanimationend 
msAnimationEnd animationend', function () {
                                        if ( $( this ).hasClass( 
'mwe-popups-fade-out' ) ) {
                                                $( this )
-                                               .off( 'webkitAnimationEnd 
oanimationend msAnimationEnd animationend' )
-                                               .removeClass( 
'mwe-popups-fade-out' )
-                                               .hide();
+                                                       .off( 
'webkitAnimationEnd oanimationend msAnimationEnd animationend' )
+                                                       .removeClass( 
'mwe-popups-fade-out' )
+                                                       .hide();
                                        }
                                } );
 
-                       if ( closeTimer ){
+                       if ( closeTimer ) {
                                clearTimeout( closeTimer );
                        }
 
@@ -302,13 +308,13 @@
                 * Is bound to the `click` event.
                 * @param {Object} e
                 */
-               function logClick ( e ) {
-                       if ( e.which === 2) { // middle click
+               function logClick( e ) {
+                       if ( e.which === 2 ) { // middle click
                                elAction = 'opened in new tab';
-                       } else if ( e.which === 1) {
+                       } else if ( e.which === 1 ) {
                                if ( e.ctrlKey || e.metaKey ) {
                                        elAction = 'opened in new tab';
-                               } else if ( e.shiftKey ){
+                               } else if ( e.shiftKey ) {
                                        elAction = 'opened in new window';
                                } else {
                                        elAction = 'opened in same tab';
@@ -326,15 +332,15 @@
                 * If `href` is passed it redirects to that location after the 
event is logged.
                 * @param {string} href
                 */
-               function logEvent ( href ) {
+               function logEvent( href ) {
                        if ( typeof mw.eventLog !== 'function' ) {
                                return false;
                        }
 
                        var dfd = $.Deferred(),
                                event = {
-                                       'duration': Math.round( elDuration ),
-                                       'action': elAction
+                                       duration: Math.round( elDuration ),
+                                       action: elAction
                                };
 
                        if ( elSessionId !== null ) {
@@ -357,7 +363,7 @@
                 * Generates a unique sessionId or pulls an existing one from 
localStorage
                 * @return {string} sessionId
                 */
-               function getSessionId () {
+               function getSessionId() {
                        var sessionId = null;
                        try {
                                sessionId = localStorage.getItem( 
'popupsSessionId' );
@@ -380,14 +386,13 @@
                        .on( 'mouseenter focus', function () {
                                $( this )
                                        .attr( 'data-original-title', $( this 
).attr( 'title' ) )
-                                       .attr( 'title', '');
+                                       .attr( 'title', '' );
                        } )
                        .on( 'mouseleave blur', function () {
                                $( this )
                                        .attr( 'title', $( this ).attr( 
'data-original-title' ) )
-                                       .attr( 'data-original-title', '');
+                                       .attr( 'data-original-title', '' );
                        } );
-
 
                $( '#mw-content-text a' ).on( 'mouseenter focus', function () {
                        var $this = $( this ),
@@ -421,7 +426,7 @@
                        currentLink = this;
                        $this.on( 'mouseleave blur', leaveInactive );
 
-                       if ( cache[ href ] ){
+                       if ( cache[ href ] ) {
                                openTimer = setTimeout( function () {
                                        createBox( href, $this );
                                }, 150 );
@@ -454,18 +459,18 @@
                                .attr( 'id', 'mwe-popups-svg' )
                                .appendTo( document.body )
                                .html( '<svg width=\"0\" height=\"0\">' +
-                                               '<defs><clippath 
id=\"mwe-popups-mask\">' +
-                                                       '<polygon points=\"0 8, 
10 8, 18 0, 26 8, 1000 8, 1000 1000, 0 1000\"/></clippath>' +
-                                               '</defs>' +
-                                               '<defs><clippath 
id=\"mwe-popups-mask-flip\">' +
-                                                       '<polygon points=\"0 8, 
274 8, 282 0, 290 8, 1000 8, 1000 1000, 0 1000\"/></clippath>' +
-                                               '</defs>' +
-                                               '<defs><clippath 
id=\"mwe-popups-landscape-mask\">' +
-                                                       '<polygon points=\"0 8, 
174 8, 182 0, 190 8, 1000 8, 1000 1000, 0 1000\"/></clippath>' +
-                                               '</defs>' +
+                                       '<defs><clippath 
id=\"mwe-popups-mask\">' +
+                                       '<polygon points=\"0 8, 10 8, 18 0, 26 
8, 1000 8, 1000 1000, 0 1000\"/></clippath>' +
+                                       '</defs>' +
+                                       '<defs><clippath 
id=\"mwe-popups-mask-flip\">' +
+                                       '<polygon points=\"0 8, 274 8, 282 0, 
290 8, 1000 8, 1000 1000, 0 1000\"/></clippath>' +
+                                       '</defs>' +
+                                       '<defs><clippath 
id=\"mwe-popups-landscape-mask\">' +
+                                       '<polygon points=\"0 8, 174 8, 182 0, 
190 8, 1000 8, 1000 1000, 0 1000\"/></clippath>' +
+                                       '</defs>' +
                                        '</svg>' );
                }
 
        } );
 
-} ) ( jQuery );
+}( jQuery, mediaWiki ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If488974e8e5987916bc4043e4e70bb6c60472b30
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to