Henning Snater has uploaded a new change for review.

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


Change subject: Always update position of all claim group labels
......................................................................

Always update position of all claim group labels

(bug 53672)
Since there may be more than one claim group label whose vertical position 
needs to
be updated because more than one claim group label is visible in the viewport, 
all
those claim group labels' positions are update now, instead of just the first 
one's
visible in the viewport.

Change-Id: Ie81163471090f217aaed8422b624ffc52eec8b33
---
M lib/resources/jquery.wikibase/jquery.wikibase.claimgrouplabelscroll.js
1 file changed, 33 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/08/85208/1

diff --git 
a/lib/resources/jquery.wikibase/jquery.wikibase.claimgrouplabelscroll.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.claimgrouplabelscroll.js
index a48953f..843755a 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.claimgrouplabelscroll.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.claimgrouplabelscroll.js
@@ -116,30 +116,34 @@
 
                        expensiveChecks = 0;
 
-                       var $firstVisibleMainSnak =
-                                       
findFirstVisibleMainSnakElementWithinClaimList( this.element );
+                       var $visibleMainSnaks =
+                                       
findFirstVisibleMainSnakElementsWithinClaimList( this.element );
 
-                       if( !$firstVisibleMainSnak ) {
-                               return;
+                       for( var i = 0; i < $visibleMainSnaks.length; i++ ) {
+                               var $visibleMainSnak = $visibleMainSnaks.eq( i 
),
+                                       $claimGroup = $visibleMainSnak.closest( 
'.wb-claim-section' ),
+                                       $claimNameSection = 
$claimGroup.children( '.wb-claim-section-name' ),
+                                       $claimGroupLabel = 
$claimNameSection.children( '.wb-claim-name' );
+
+                               this._log(
+                                       'positioning',
+                                       $claimGroupLabel.get( 0 ),
+                                       'on',
+                                       $visibleMainSnak.get( 0 )
+                               );
+
+                               var newLabelPosition =
+                                       positionElementInOneLineWithAnother( 
$claimGroupLabel, $visibleMainSnak );
+
+                               this._log( newLabelPosition
+                                       ? ( 'moving label to ' + 
newLabelPosition )
+                                       : 'no position update required'
+                               );
+
+                               var endTime = new Date().getTime();
+                               this._log( expensiveChecks + ' expensive 
checks, execution time '
+                                       + ( endTime - startTime ) + 'ms' );
                        }
-
-                       var $claimGroup = $firstVisibleMainSnak.closest( 
'.wb-claim-section' ),
-                               $claimGroupLabel =
-                                       $claimGroup.children( 
'.wb-claim-section-name' ).children( '.wb-claim-name' );
-
-                       this._log( 'positioning', $claimGroupLabel.get( 0 ), 
'on', $firstVisibleMainSnak.get( 0 ) );
-
-                       var newLabelPosition =
-                               positionElementInOneLineWithAnother( 
$claimGroupLabel, $firstVisibleMainSnak );
-
-                       this._log( newLabelPosition
-                               ? ( 'moving label to ' + newLabelPosition )
-                               : 'no position update required'
-                       );
-
-                       var endTime = new Date().getTime();
-                       this._log( expensiveChecks + ' expensive checks, 
execution time '
-                               + ( endTime - startTime ) + 'ms' );
                },
 
                /**
@@ -165,17 +169,17 @@
        };
 
        /**
-        * Checks an Claim Group's element for Main Snak elements and returns 
the first one visible in
+        * Checks an Claim Group's element for Main Snak elements and returns 
all that are visible in
         * the browser's viewport.
         * This is an optimized version of "findFirstVisibleMainSnakElement" in 
case Claim groups
         * are expected within the DOM that should be searched for Main Snaks.
         *
         * @param {jQuery} $searchRange
-        * @return {null|jQuery}
+        * @return {jQuery}
         */
-       function findFirstVisibleMainSnakElementWithinClaimList( $searchRange ) 
{
+       function findFirstVisibleMainSnakElementsWithinClaimList( $searchRange 
) {
                var $claimGroups = $searchRange.find( '.wb-claim-section' ),
-                       result = null;
+                       $visibleClaimGroups = $();
 
                // TODO: Optimize! E.g.:
                //  (1) don't walk them top to bottom, instead, take the one in 
the middle, check whether
@@ -185,14 +189,12 @@
                //      (up/down) on its neighbouring nodes.
                $claimGroups.each( function( i, claimGroupNode ) {
                        if( elementPartlyVerticallyInViewport( claimGroupNode ) 
) {
-                               result = findFirstVisibleMainSnakElement( $( 
claimGroupNode ) );
-                               if( result ) {
-                                       return false;
-                               }
+                               var $mainSnakElement = 
findFirstVisibleMainSnakElement( $( claimGroupNode ) );
+                               $visibleClaimGroups = $visibleClaimGroups.add( 
$mainSnakElement );
                        }
                } );
 
-               return result;
+               return $visibleClaimGroups;
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie81163471090f217aaed8422b624ffc52eec8b33
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <henning.sna...@wikimedia.de>

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

Reply via email to