jenkins-bot has submitted this change and it was merged.

Change subject: Hi-DPI/Retina support for hovercard images
......................................................................


Hi-DPI/Retina support for hovercard images

Requires core changeset Ic9cb1654 for $.bracketedDevicePixelRatio()

Bug: T97935
Change-Id: I452b87a90769463328840c6c7e46b583e6148439
---
M Popups.hooks.php
M resources/ext.popups.renderer.article.js
2 files changed, 31 insertions(+), 21 deletions(-)

Approvals:
  Bartosz Dziewoński: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Popups.hooks.php b/Popups.hooks.php
index 63277c9..6c6d9dc 100644
--- a/Popups.hooks.php
+++ b/Popups.hooks.php
@@ -75,6 +75,7 @@
                        'moment',
                        'jquery.jStorage',
                        'jquery.client',
+                       'jquery.hidpi',
                );
 
                // If EventLogging is present, add the schema as a dependency.
diff --git a/resources/ext.popups.renderer.article.js 
b/resources/ext.popups.renderer.article.js
index 4562c77..e73fcd7 100644
--- a/resources/ext.popups.renderer.article.js
+++ b/resources/ext.popups.renderer.article.js
@@ -40,7 +40,8 @@
        article.init = function ( link ) {
                var href = link.attr( 'href' ),
                        title = mw.popups.getTitle( href ),
-                       deferred = $.Deferred();
+                       deferred = $.Deferred(),
+                       scaledThumbSize = 300 * $.bracketedDevicePixelRatio();
 
                if ( !title ) {
                        return deferred.reject().promise();
@@ -57,7 +58,7 @@
                        // so that text does not overflow from the card
                        explaintext: true,
                        piprop: 'thumbnail',
-                       pithumbsize: 300,
+                       pithumbsize: scaledThumbSize,
                        rvprop: 'timestamp',
                        titles: title,
                        smaxage: 300,
@@ -260,15 +261,23 @@
         * @return {Object} jQuery DOM element of the thumbnail
         */
        article.createThumbnail = function ( thumbnail, tall ) {
-               var svg = mw.popups.supportsSVG;
+               var thumbWidth, thumbHeight,
+                       svg = mw.popups.supportsSVG,
+                       devicePixelRatio = $.bracketedDevicePixelRatio();
+
+               // No thumbnail
+               if ( !thumbnail ) {
+                       return $( '<span>' );
+               }
+
+               thumbWidth = thumbnail.width / devicePixelRatio;
+               thumbHeight = thumbnail.height / devicePixelRatio;
 
                if (
-                       // No thumbnail
-                       !thumbnail ||
                        // Image too small for landscape display
-                       ( !tall && thumbnail.width < 
article.SIZES.landscapeImage.w ) ||
-                       // Image too small for protrait display
-                       ( tall && thumbnail.height < 
article.SIZES.portraitImage.h ) ||
+                       ( !tall && thumbWidth < article.SIZES.landscapeImage.w 
) ||
+                       // Image too small for portrait display
+                       ( tall && thumbHeight < article.SIZES.portraitImage.h ) 
||
                        // These characters in URL that could inject CSS and 
thus JS
                        (
                                thumbnail.source.indexOf( '\\' ) > -1 ||
@@ -283,14 +292,14 @@
                        return article.createSvgImageThumbnail(
                                'mwe-popups-is-not-tall',
                                thumbnail.source,
-                               ( thumbnail.width > 
article.SIZES.portraitImage.w ) ?
-                                               ( ( thumbnail.width - 
article.SIZES.portraitImage.w ) / -2 ) :
-                                               ( article.SIZES.portraitImage.w 
- thumbnail.width ),
-                               ( thumbnail.height > 
article.SIZES.portraitImage.h ) ?
-                                               ( ( thumbnail.height - 
article.SIZES.portraitImage.h ) / -2 ) :
+                               ( thumbWidth > article.SIZES.portraitImage.w ) ?
+                                               ( ( thumbWidth - 
article.SIZES.portraitImage.w ) / -2 ) :
+                                               ( article.SIZES.portraitImage.w 
- thumbWidth ),
+                               ( thumbHeight > article.SIZES.portraitImage.h ) 
?
+                                               ( ( thumbHeight - 
article.SIZES.portraitImage.h ) / -2 ) :
                                                0,
-                               thumbnail.width,
-                               thumbnail.height,
+                               thumbWidth,
+                               thumbHeight,
                                article.SIZES.portraitImage.w,
                                article.SIZES.portraitImage.h
                        );
@@ -305,15 +314,15 @@
                                'mwe-popups-is-not-tall',
                                thumbnail.source,
                                0,
-                               ( thumbnail.height > 
article.SIZES.landscapeImage.h ) ?
-                                               ( ( thumbnail.height - 
article.SIZES.landscapeImage.h ) / -2 ) :
+                               ( thumbHeight > article.SIZES.landscapeImage.h 
) ?
+                                               ( ( thumbHeight - 
article.SIZES.landscapeImage.h ) / -2 ) :
                                                0,
-                               thumbnail.width,
-                               thumbnail.height,
+                               thumbWidth,
+                               thumbHeight,
                                article.SIZES.landscapeImage.w + 3,
-                               ( thumbnail.height > 
article.SIZES.landscapeImage.h ) ?
+                               ( thumbHeight > article.SIZES.landscapeImage.h 
) ?
                                                article.SIZES.landscapeImage.h :
-                                               thumbnail.height,
+                                               thumbHeight,
                                'mwe-popups-mask'
                        );
                }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I452b87a90769463328840c6c7e46b583e6148439
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Prtksxna <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to