Jhernandez has uploaded a new change for review.
https://gerrit.wikimedia.org/r/304997
Change subject: Combine scroll handlers into the global one
......................................................................
Combine scroll handlers into the global one
In order to keep the number of handlers attached on scroll to the window, let's
use the events in mw.mobileFrontend so that there is only one handler attached
to the window.
This moves the handlers on back to top and the infinite scrolling component to
use the global event handler (using 'scroll' when debounced or
'scroll:throttled' when needed)
Bug: T124870
Change-Id: Ic21dc04389cab065c6dd52968689f72c045939ab
---
M resources/mobile.backtotop/backtotop.js
M resources/mobile.infiniteScroll/InfiniteScroll.js
2 files changed, 3 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/97/304997/1
diff --git a/resources/mobile.backtotop/backtotop.js
b/resources/mobile.backtotop/backtotop.js
index 43f4294..3c2efff 100644
--- a/resources/mobile.backtotop/backtotop.js
+++ b/resources/mobile.backtotop/backtotop.js
@@ -5,11 +5,11 @@
// initialize the back to top element
backtotop.appendTo( 'body' );
- $( window ).on( 'scroll', $.debounce( 100, function () {
+ M.on( 'scroll', function () {
if ( $( window ).height() - $( window ).scrollTop() <= 0 ) {
backtotop.show();
} else {
backtotop.hide();
}
- } ) );
+ } );
}( mw.mobileFrontend, jQuery ) );
diff --git a/resources/mobile.infiniteScroll/InfiniteScroll.js
b/resources/mobile.infiniteScroll/InfiniteScroll.js
index 5105cb6..6787c9e 100644
--- a/resources/mobile.infiniteScroll/InfiniteScroll.js
+++ b/resources/mobile.infiniteScroll/InfiniteScroll.js
@@ -69,10 +69,7 @@
* @private
*/
_bindScroll: function () {
- // FIXME: Consider using setInterval instead or some
sort of
- // dethrottling/debouncing to avoid performance
degradation
- // e.g.
http://benalman.com/projects/jquery-throttle-debounce-plugin/
- $( window ).on( 'scroll', $.proxy( this, '_onScroll' )
);
+ M.on( 'scroll:throttled', $.proxy( this, '_onScroll' )
);
},
/**
* Scroll handler. Triggers load event when near the end of the
container.
--
To view, visit https://gerrit.wikimedia.org/r/304997
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic21dc04389cab065c6dd52968689f72c045939ab
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits