Jdlrobson has uploaded a new change for review.

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

Change subject: Guidance for test (do not merge)
......................................................................

Guidance for test (do not merge)

See
https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
https://github.com/wikimedia/mediawiki-extensions-Gather/blob/master/includes/Gather.hooks.php#L271

Now that positionBanner can be passed an arbitary value you can write tests 
that check the margin left
and top that get set. Ping me if you need help!

Change-Id: I416083253b4da5421466b3ef02fd154204487d6c
---
M 
resources/ext.WikidataPageBanner.positionBanner/ext.WikidataPageBanner.positionBanner.js
1 file changed, 14 insertions(+), 10 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataPageBanner 
refs/changes/35/231735/1

diff --git 
a/resources/ext.WikidataPageBanner.positionBanner/ext.WikidataPageBanner.positionBanner.js
 
b/resources/ext.WikidataPageBanner.positionBanner/ext.WikidataPageBanner.positionBanner.js
index b3f3c5c..9b8a5ea 100644
--- 
a/resources/ext.WikidataPageBanner.positionBanner/ext.WikidataPageBanner.positionBanner.js
+++ 
b/resources/ext.WikidataPageBanner.positionBanner/ext.WikidataPageBanner.positionBanner.js
@@ -1,6 +1,7 @@
 ( function( mw, $ ) {
+var $wpbBannerImageContainer = $( '.wpb-topbanner' );
 
-function positionBanner() {
+function positionBanner( $container ) {
        /**
         * Javascript to fine tune position of banner according to position 
coordinates.
         */
@@ -8,8 +9,7 @@
        var maxOffsetTop, offsetTop, maxOffsetLeft, offsetLeft,
                minOffsetTop = 0,
                minOffsetLeft = 0,
-               $wpbBannerImageContainer = $( '.wpb-topbanner' ),
-               $wpbBannerImage = $( '.wpb-banner-image' ),
+               $wpbBannerImage = $container.find( '.wpb-banner-image' ),
                centerX = $wpbBannerImage.data( 'pos-x' ),
                centerY = $wpbBannerImage.data( 'pos-y' ),
                totalOffsetX = 0,
@@ -21,13 +21,13 @@
                WebkitTransform: 'translate(0)',
                msTransform: 'translate(0)'
        } );
-       if ( $wpbBannerImage.height() > $wpbBannerImageContainer.height() ) {
+       if ( $wpbBannerImage.height() > $container.height() ) {
                // first reset margin
                $wpbBannerImage.css( 'margin-top', 0 );
                // do not shift below to leave blank space
                // this is the max shift up that can be achieved without 
leaving blank space below
                maxOffsetTop = $wpbBannerImage.height() -
-                       $wpbBannerImageContainer.height();
+                       $container.height();
                // offset beyond center 0
                offsetTop = centerY * $wpbBannerImage.height() / 2;
                // offset for default center is maxOffsetTop/2
@@ -40,11 +40,11 @@
                        totalOffsetY = minOffsetTop;
                }
        }
-       if ( $wpbBannerImage.width() > $wpbBannerImageContainer.width() ||
-               $wpbBannerImage.height() > $wpbBannerImageContainer.height() ) {
+       if ( $wpbBannerImage.width() > $container.width() ||
+               $wpbBannerImage.height() > $container.height() ) {
                // this is the max shift that can be achieved without leaving 
blank space
                maxOffsetLeft = $wpbBannerImage.width() -
-                       $wpbBannerImageContainer.width();
+                       $container.width();
                // offset beyond center 0
                offsetLeft = centerX * $wpbBannerImage.width() / 2;
                // offset for default center is maxOffsetLeft/2
@@ -65,7 +65,11 @@
        } );
 }
 
-$( window ).on( 'resize', $.debounce( 100, $.proxy( positionBanner ) ) );
-$( positionBanner );
+$( window ).on( 'resize', $.debounce( 100, $.proxy( positionBanner, 
$wpbBannerImageContainer ) ) );
+$( $.proxy( positionBanner, $wpbBannerImageContainer ) );
 
+// Expose interface for testing.
+mw.wpb = {
+       positionBanner: positionBanner
+};
 } ( mediaWiki, jQuery ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I416083253b4da5421466b3ef02fd154204487d6c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataPageBanner
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

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

Reply via email to