Bmansurov has uploaded a new change for review.

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

Change subject: Move the isElementInViewport function to "mobile.startup/utils"
......................................................................

Move the isElementInViewport function to "mobile.startup/utils"

Make the function sharable so that other modules can use it.

Change-Id: Ice6d797e8e45f89b68bd5a9908a0b8881f5b3625
---
M resources/mobile.startup/util.js
M resources/mobile.toggle/toggle.js
2 files changed, 27 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/68/265168/1

diff --git a/resources/mobile.startup/util.js b/resources/mobile.startup/util.js
index a77e870..a34ebc1 100644
--- a/resources/mobile.startup/util.js
+++ b/resources/mobile.startup/util.js
@@ -1,5 +1,6 @@
 ( function ( M ) {
-       var util;
+       var util,
+               $window = $( window );
 
        /**
         * Utility library for looking up details on the current user
@@ -36,6 +37,29 @@
                                }
                        }
                        return id;
+               },
+
+               /**
+                * Check if at least half of the element's height and half of 
its width are in viewport
+                *
+                * @method
+                * @param {jQuery.Object} $el - element that's being tested
+                * @return {Boolean}
+                */
+               isElementInViewport: function ( $el ) {
+                       var windowHeight = $window.height(),
+                               windowWidth = $window.width(),
+                               windowScrollLeft = $window.scrollLeft(),
+                               windowScrollTop = $window.scrollTop(),
+                               elHeight = $el.height(),
+                               elWidth = $el.width(),
+                               elOffset = $el.offset();
+
+                       return (
+                               ( windowScrollTop + windowHeight >= 
elOffset.top + elHeight / 2 ) &&
+                               ( windowScrollLeft + windowWidth >= 
elOffset.left + elWidth / 2 ) &&
+                               ( windowScrollTop <= elOffset.top + elHeight / 
2 )
+                       );
                }
        };
 
diff --git a/resources/mobile.toggle/toggle.js 
b/resources/mobile.toggle/toggle.js
index bbdeb55..7ec2591 100644
--- a/resources/mobile.toggle/toggle.js
+++ b/resources/mobile.toggle/toggle.js
@@ -2,6 +2,7 @@
        var context = M.require( 'mobile.context/context' ),
                settings = M.require( 'mobile.settings/settings' ),
                browser = M.require( 'mobile.browser/browser' ),
+               util = M.require( 'mobile.startup/util' ),
                escapeHash = M.require( 'mobile.startup/util' ).escapeHash,
                arrowOptions = {
                        name: 'arrow',
@@ -339,29 +340,6 @@
                }
 
                /**
-                * Check if at least half of the element's height and half of 
its width are in viewport
-                *
-                * @method
-                * @param {jQuery.Object} $el - element that's being tested
-                * @return {Boolean}
-                */
-               function isElementInViewport( $el ) {
-                       var windowHeight = $window.height(),
-                               windowWidth = $window.width(),
-                               windowScrollLeft = $window.scrollLeft(),
-                               windowScrollTop = $window.scrollTop(),
-                               elHeight = $el.height(),
-                               elWidth = $el.width(),
-                               elOffset = $el.offset();
-
-                       return (
-                               ( windowScrollTop + windowHeight >= 
elOffset.top + elHeight / 2 ) &&
-                               ( windowScrollLeft + windowWidth >= 
elOffset.left + elWidth / 2 ) &&
-                               ( windowScrollTop <= elOffset.top + elHeight / 
2 )
-                       );
-               }
-
-               /**
                 * Log when the heading is scrolled into the viewport
                 *
                 * @param {jQuery.Object} $heading
@@ -373,7 +351,7 @@
                         * @ignore
                         */
                        function log() {
-                               if ( isElementInViewport( $heading ) ) {
+                               if ( util.isElementInViewport( $heading ) ) {
                                        $window.off( 'scroll.' + $heading.attr( 
'id' ), log );
                                        self.schema.log( {
                                                eventName: 'scrolled-into-view',

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ice6d797e8e45f89b68bd5a9908a0b8881f5b3625
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Bmansurov <bmansu...@wikimedia.org>

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

Reply via email to