Merge "RelatedArticles load after half window scroll" into dev

This commit is contained in:
jenkins-bot 2015-12-08 23:27:24 +00:00 committed by Gerrit Code Review
commit 4af4c384dc
3 changed files with 38 additions and 14 deletions

View file

@ -1,3 +1,8 @@
==RelatedArticles 2.0.0==
fbc6961 Fix RelatedPagesGateway unit test failures
18990e6 Correctly show related articles on desktop
9157e30 [Hygiene] Reorganise hooks to reflect placements
040314c [Breaking] Configure footer and sidebar placements
==RelatedArticles 1.2.0==
e86fc3b Fall back to CirrusSearch's morelike: feature
5b5a0b2 Put Read More behind a feature flag

View file

@ -1,6 +1,6 @@
{
"name": "RelatedArticles",
"version": "1.2.0",
"version": "2.0.0",
"author": [
"Roland Unger",
"Hans Musil",
@ -88,7 +88,8 @@
],
"dependencies": [
"mediawiki.api",
"ext.relatedArticles.readMore.gateway"
"ext.relatedArticles.readMore.gateway",
"jquery.throttle-debounce"
],
"targets": [
"mobile",

View file

@ -8,14 +8,18 @@
mw.config.get( 'wgRelatedArticlesUseCirrusSearch' ),
mw.config.get( 'wgRelatedArticlesOnlyUseCirrusSearch' )
),
LIMIT = 3;
LIMIT = 3,
debouncedLoad = $.debounce( 100, function () {
loadRelatedArticles();
} ),
$window = $( window ),
/**
* Threshold value to load related articles - after about half scroll
*/
scrollThreshold = ( $( document ).height() / 2 ) - $window.height();
if (
config.wgNamespaceNumber === 0 &&
!config.wgIsMainPage &&
// any skin except minerva stable
( config.skin !== 'minerva' || config.wgMFMode === 'beta' )
) {
function loadRelatedArticles() {
if ( $window.scrollTop() > scrollThreshold ) {
$.when(
// Note we load dependencies here rather than ResourceLoader
// to avoid PHP exceptions when Cards not installed
@ -27,6 +31,20 @@
mw.track( 'ext.relatedArticles.init', pages );
}
} );
// detach handler to stop subsequent loads on scroll
$window.off( 'scroll', debouncedLoad );
}
}
if (
config.wgNamespaceNumber === 0 &&
!config.wgIsMainPage &&
// any skin except minerva stable
( config.skin !== 'minerva' || config.wgMFMode === 'beta' )
) {
// try related articles load on scroll
$window.on( 'scroll', debouncedLoad );
// try an initial load, in case of no scroll
loadRelatedArticles();
}
}( jQuery, mediaWiki ) );