2015-12-07 18:19:16 +00:00
|
|
|
( function ( $, mw ) {
|
Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
|
2016-09-15 22:18:45 +00:00
|
|
|
var relatedPages = new mw.relatedPages.RelatedPagesGateway(
|
2015-11-11 15:30:19 +00:00
|
|
|
new mw.Api(),
|
|
|
|
mw.config.get( 'wgPageName' ),
|
|
|
|
mw.config.get( 'wgRelatedArticles' ),
|
|
|
|
mw.config.get( 'wgRelatedArticlesUseCirrusSearch' ),
|
|
|
|
mw.config.get( 'wgRelatedArticlesOnlyUseCirrusSearch' )
|
|
|
|
),
|
2015-12-05 17:44:15 +00:00
|
|
|
LIMIT = 3,
|
|
|
|
debouncedLoad = $.debounce( 100, function () {
|
|
|
|
loadRelatedArticles();
|
|
|
|
} ),
|
2015-12-14 10:34:17 +00:00
|
|
|
$window = $( window );
|
|
|
|
|
2015-12-29 02:55:43 +00:00
|
|
|
/**
|
|
|
|
* Load related articles when the user scrolls past half of the window height.
|
|
|
|
*
|
|
|
|
* @ignore
|
|
|
|
*/
|
2015-12-14 10:34:17 +00:00
|
|
|
function loadRelatedArticles() {
|
2016-08-30 18:01:48 +00:00
|
|
|
var readMore = $( '.read-more-container' ).get( 0 ),
|
2016-09-15 19:10:24 +00:00
|
|
|
scrollThreshold = $window.height() * 2;
|
Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
|
2016-08-30 18:01:48 +00:00
|
|
|
if ( mw.viewport.isElementCloseToViewport( readMore, scrollThreshold ) ) {
|
2015-12-05 17:44:15 +00:00
|
|
|
$.when(
|
|
|
|
// Note we load dependencies here rather than ResourceLoader
|
|
|
|
// to avoid PHP exceptions when Cards not installed
|
|
|
|
// which should never happen given the if statement.
|
|
|
|
mw.loader.using( [ 'ext.cards', 'ext.relatedArticles.readMore' ] ),
|
|
|
|
relatedPages.getForCurrentPage( LIMIT )
|
|
|
|
).done( function ( _, pages ) {
|
|
|
|
if ( pages.length ) {
|
|
|
|
mw.track( 'ext.relatedArticles.init', pages );
|
2016-12-10 12:03:32 +00:00
|
|
|
} else {
|
|
|
|
readMore.remove();
|
2015-12-05 17:44:15 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
// detach handler to stop subsequent loads on scroll
|
|
|
|
$window.off( 'scroll', debouncedLoad );
|
|
|
|
}
|
|
|
|
}
|
2015-12-29 02:55:43 +00:00
|
|
|
|
2016-09-15 22:18:45 +00:00
|
|
|
// Add container to DOM for checking distance on scroll
|
|
|
|
// If a skin has marked up a footer content area prepend it there
|
|
|
|
if ( $( '.footer-content' ).length ) {
|
|
|
|
$( '<div class="read-more-container" />' ).prependTo( '.footer-content' );
|
|
|
|
} else {
|
|
|
|
$( '<div class="read-more-container post-content" />' )
|
|
|
|
.insertAfter( '#content' );
|
Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
}
|
2016-12-10 12:03:32 +00:00
|
|
|
|
2016-09-15 22:18:45 +00:00
|
|
|
// try related articles load on scroll
|
|
|
|
$window.on( 'scroll', debouncedLoad );
|
|
|
|
// try an initial load, in case of no scroll
|
|
|
|
loadRelatedArticles();
|
Add Related Articles section to Minerva
If the page has related articles, is in mainspace, isn't the main page,
and the output is being rendered with the MinervaBeta skin then a
"Related Articles" section is added to the page just before the footer.
Separate loading the information necessary to render the pages, choosing
the renderer, and rendering the data so that multiple skins - currently
Minerva and Vector per the mocks - not just multiple resolutions can all
be handled the same way:
* The bootstrap script (ext.relatedArticles.readMore.bootstrap/index.js)
for fetches the page image and Wikidata description; loading the
renderer module; and, finally, notifying the renderer module that it
should render the data, which it does by emitting
"ext.relatedArticles.readMore.init" event using mw#track
* The Minerva renderer subscribes to the event and, when it's fired,
renders the data by passing it to the WatchstarPageList view
Bug: T113635
Change-Id: I651342bdf9796938fa7051828dd13bc6fe774783
2015-10-07 13:12:42 +00:00
|
|
|
|
2015-12-07 18:19:16 +00:00
|
|
|
}( jQuery, mediaWiki ) );
|