Prtksxna has uploaded a new change for review.

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

Change subject: Move thumbnail creation to its own method
......................................................................

Move thumbnail creation to its own method

Change-Id: I1d1b2aff4d8b919bd65e0da8ff07b594f061ccd7
---
M resources/ext.popups.core.js
1 file changed, 23 insertions(+), 10 deletions(-)


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

diff --git a/resources/ext.popups.core.js b/resources/ext.popups.core.js
index 5e02a4e..66475cf 100644
--- a/resources/ext.popups.core.js
+++ b/resources/ext.popups.core.js
@@ -43,11 +43,12 @@
                        curRequest.done( function ( re ) {
                                curRequest = undefined;
 
-                               var $thumbnail, $a,
+                               var $a,
                                        page = 
re.query.pages[re.query.pageids[0]],
                                        $contentbox = $( '<div>' ).html( 
page.extract ),
                                        thumbnail = page.thumbnail,
                                        tall = thumbnail && thumbnail.height > 
thumbnail.width,
+                                       $thumbnail = createThumbnail( 
thumbnail, tall ),
                                        timestamp = new Date( page.revisions[ 0 
].timestamp ),
                                        timediff = new Date() - timestamp,
                                        oneDay = 1000 * 60 * 60 * 24,
@@ -60,15 +61,6 @@
                                                        $( '<span>' ).text( 
timeAgo( timediff ).text() )
                                                );
 
-                               if ( thumbnail ){
-                                       $thumbnail = $( '<img>' )
-                                               .attr( 'src', thumbnail.source )
-                                               .removeClass( 
'mwe-popups-is-tall mwe-popups-is-not-tall' )
-                                               .addClass( tall ? 
'mwe-popups-is-tall' : 'mwe-popups-is-not-tall' );
-                               } else {
-                                       $thumbnail = $( '<span>' );
-                               }
-
                                $a = $( '<a>' ).append( $thumbnail, 
$contentbox, $timestamp).attr( 'href', href );
                                cache[ href ] = { box: $a, thumbnail: 
thumbnail, tall: tall     };
                                createBox( href, $el );
@@ -78,6 +70,27 @@
                }
 
                /**
+                * @method createThumbnail
+                * Returns a thumbnail object based on the ratio of the image
+                * @param {Object} thumbnail
+                * @param {boolean} tall
+                * @return {Object} jQuery DOM element of the thumbnail
+                */
+               function createThumbnail ( thumbnail, tall ) {
+                       if ( !thumbnail ) {
+                               return $( '<span>' );
+                       }
+
+                       var $thumbnail = $( '<img>' )
+                               .attr( 'src', thumbnail.source )
+                               .removeClass( 'mwe-popups-is-tall 
mwe-popups-is-not-tall' )
+                               .addClass( tall ? 'mwe-popups-is-tall' : 
'mwe-popups-is-not-tall' );
+
+
+                       return $thumbnail;
+               }
+
+               /**
                 * @method createBox
                 * Looks into the `cache` and uses the href to render the popup
                 * and offsets it to the link. Rebinds the `mouseleave` event

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1d1b2aff4d8b919bd65e0da8ff07b594f061ccd7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Prtksxna <psax...@wikimedia.org>

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

Reply via email to