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
|
|
|
|
2015-12-29 02:55:43 +00:00
|
|
|
var config = mw.config.get( [ 'skin', 'wgNamespaceNumber', 'wgMFMode',
|
|
|
|
'wgIsMainPage', 'wgAction' ] ),
|
2015-11-14 00:03:39 +00:00
|
|
|
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() {
|
2015-12-05 17:44:15 +00:00
|
|
|
/**
|
|
|
|
* Threshold value to load related articles - after about half scroll
|
|
|
|
*/
|
2015-12-14 10:34:17 +00:00
|
|
|
var scrollThreshold = ( $( document ).height() / 2 ) - $window.height();
|
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-05 17:44:15 +00:00
|
|
|
if ( $window.scrollTop() > scrollThreshold ) {
|
|
|
|
$.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 );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
// detach handler to stop subsequent loads on scroll
|
|
|
|
$window.off( 'scroll', debouncedLoad );
|
|
|
|
}
|
|
|
|
}
|
2015-12-29 02:55:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is the current page a diff page?
|
|
|
|
*
|
|
|
|
* @ignore
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
function isDiffPage() {
|
|
|
|
var queryParams = new mw.Uri( window.location.href ).query;
|
|
|
|
|
|
|
|
return !!(
|
|
|
|
queryParams.type === 'revision' ||
|
|
|
|
queryParams.hasOwnProperty( 'diff' ) ||
|
|
|
|
queryParams.hasOwnProperty( 'oldid' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
if (
|
|
|
|
config.wgNamespaceNumber === 0 &&
|
|
|
|
!config.wgIsMainPage &&
|
2015-12-09 23:11:00 +00:00
|
|
|
// T120735
|
2015-12-29 02:55:43 +00:00
|
|
|
config.wgAction === 'view' &&
|
|
|
|
!isDiffPage() &&
|
2015-11-16 10:40:03 +00:00
|
|
|
// any skin except minerva stable
|
|
|
|
( config.skin !== 'minerva' || config.wgMFMode === 'beta' )
|
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-05 17:44:15 +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 ) );
|