mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RelatedArticles
synced 2024-11-12 09:51:11 +00:00
Merge "RelatedArticles load after half window scroll" into dev
This commit is contained in:
commit
4af4c384dc
5
HISTORY
5
HISTORY
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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 ) );
|
||||
|
|
Loading…
Reference in a new issue