Thiemo Mättig (WMDE) has uploaded a new change for review.

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

Change subject: Skip property label scrolling on statement groups with one 
statement
......................................................................

Skip property label scrolling on statement groups with one statement

This is a direct follow up to Ic52065d.

This removes all bogus logging code (note that the number was always 0).

This replaces the possibly expensive ….is( ':empty' ) check with a super
trivial ….length check. This does have the following effect:
findFirstVisibleMainSnakElement() is called with a statementlistview (a
set of statements inside a statementgroupview, guaranteed to have the
same property). If such a list contains a single main snak only, there is
nothing to scroll. We can return null and jQuery.add() will ignore null.

Typically there are many, many statement groups with only one statement.

This includes the new, empty statement that appears when using the "add"
function.

Change-Id: I94b9173d6c12f450a93c3444935c49ae1cf97b15
---
M view/resources/jquery/wikibase/jquery.wikibase.statementgrouplabelscroll.js
1 file changed, 6 insertions(+), 47 deletions(-)


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

diff --git 
a/view/resources/jquery/wikibase/jquery.wikibase.statementgrouplabelscroll.js 
b/view/resources/jquery/wikibase/jquery.wikibase.statementgrouplabelscroll.js
index 347004e..faa03b3 100644
--- 
a/view/resources/jquery/wikibase/jquery.wikibase.statementgrouplabelscroll.js
+++ 
b/view/resources/jquery/wikibase/jquery.wikibase.statementgrouplabelscroll.js
@@ -1,6 +1,7 @@
 /**
  * @license GPL-2.0+
  * @author Daniel Werner < [email protected] >
+ * @author Thiemo Mättig
  */
 ( function( $ ) {
        'use strict';
@@ -16,12 +17,6 @@
         * @type {jQuery.wikibase.statementgrouplabelscroll[]}
         */
        var activeInstances = [];
-
-       /**
-        * Counter for expensive checks done in an update. Used for debugging 
output.
-        * @type {number}
-        */
-       var expensiveChecks = 0;
 
        function updateActiveInstances() {
                for ( var i in activeInstances ) {
@@ -81,6 +76,10 @@
                var $mainSnaks = $searchRange.find(
                        '.wikibase-statementview-mainsnak 
.wikibase-snakview-value-container'
                );
+
+               if ( $mainSnaks.length < 2 ) {
+                       return null;
+               }
 
                $mainSnaks.each( function( i, mainSnakNode ) {
                        // Take first Main Snak value in viewport. If value is 
not fully visible in viewport,
@@ -173,20 +172,6 @@
         */
        $.widget( 'wikibase.' + WIDGET_NAME, {
                /**
-                * @see jQuery.widget.options
-                * @type {Object}
-                */
-               options: {
-                       /**
-                        * If set, this object will be used for logging certain 
debug messages. Requires a
-                        * member called "log" taking any value as parameter 1 
to n.
-                        *
-                        * @type {Object|null}
-                        */
-                       logger: null
-               },
-
-               /**
                 * @see jQuery.Widget._create
                 */
                _create: function() {
@@ -211,10 +196,6 @@
                 * @since 0.4
                 */
                update: function() {
-                       var startTime = new Date().getTime();
-
-                       expensiveChecks = 0;
-
                        var $visibleStatementviews
                                = 
findFirstVisibleMainSnakElementsWithinStatementlistview( this.element )
                                        .closest( '.wikibase-statementview' );
@@ -226,37 +207,15 @@
                                                        
'.wikibase-statementgroupview-property-label'
                                                );
 
-                               if ( !$statementGroupLabel.length || 
$statementGroupLabel.is( ':empty' ) ) {
+                               if ( $statementGroupLabel.length !== 1 ) {
                                        continue;
                                }
-
-                               this._log(
-                                       'positioning',
-                                       $statementGroupLabel.get( 0 ),
-                                       'on',
-                                       $visibleClaim.get( 0 )
-                               );
 
                                positionElementInOneLineWithAnother(
                                        $statementGroupLabel,
                                        $visibleClaim,
                                        $statementGroup
                                );
-
-                               var endTime = new Date().getTime();
-                               this._log( expensiveChecks + ' expensive 
checks, execution time '
-                                       + ( endTime - startTime ) + 'ms' );
-                       }
-               },
-
-               /**
-                * If the "logger" option is set, then this method will forward 
any given arguments
-                * to its "log" function.
-                */
-               _log: function() {
-                       var logger = this.option( 'logger' );
-                       if ( logger ) {
-                               logger.log.apply( logger, arguments );
                        }
                }
        } );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I94b9173d6c12f450a93c3444935c49ae1cf97b15
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>

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

Reply via email to