2018-09-14 05:30:46 +00:00
|
|
|
( function () {
|
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() {
|
2024-03-28 12:23:04 +00:00
|
|
|
const readMore = document.querySelector( '.read-more-container' );
|
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
|
|
|
|
2024-03-28 12:23:04 +00:00
|
|
|
if ( !readMore ) {
|
2021-04-30 22:59:41 +00:00
|
|
|
// The container is not in the HTML for some reason and cannot be queried.
|
|
|
|
// See T281547
|
|
|
|
return;
|
|
|
|
}
|
2021-10-26 20:41:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Element} container
|
|
|
|
*/
|
|
|
|
function initRelatedArticlesModule( container ) {
|
2015-12-05 17:44:15 +00:00
|
|
|
$.when(
|
2023-11-08 22:06:07 +00:00
|
|
|
mw.loader.using( 'ext.relatedArticles.readMore' )
|
2024-06-14 12:07:36 +00:00
|
|
|
).then( (
|
2023-11-08 22:06:07 +00:00
|
|
|
/** @type {Function} */ require
|
2024-06-14 12:07:36 +00:00
|
|
|
) => {
|
2023-11-08 22:06:07 +00:00
|
|
|
require( 'ext.relatedArticles.readMore' ).init(
|
|
|
|
container
|
|
|
|
);
|
2015-12-05 17:44:15 +00:00
|
|
|
} );
|
|
|
|
}
|
2021-10-26 20:41:02 +00:00
|
|
|
|
Limit RelatedArticles feature to ES6 browsers
We currently require support for IntersectionObserver.
which is supported on Edge >= 15 (15 has partial support),
Firefox >55, Chrome >58, Safari 12.1, Opera >=38,
iOS Safari >=12.2, Android 100
Full ES6 is supported in Edge >=15, Firefox >=54, Chrome >=51,
Safari >=10, Opera >=38, iOS Safari >=10, so such a change
would only drop support for Edge 15 and Firefox 54.
CSS.escape is guaranteed in all these browsers according to
caniuse, with the only discrepancy being the Edge browser (versions
16-18) so it is also suggested we remove support for those browsers.
Firefox 54 accounts for 0.0026% of page views
Edge 15-18 accounts for 0.069% of page views
Bug: T306355
Change-Id: Id2987e3456607b610c38da9ee157a026d1d00ada
2022-04-18 22:20:04 +00:00
|
|
|
const doc = document.documentElement;
|
2021-10-26 20:41:02 +00:00
|
|
|
// IntersectionObserver will not work if the component is already visible on the page.
|
|
|
|
// To handle this case, we compare scroll height to viewport height.
|
|
|
|
if ( ( doc.scrollHeight / 2 ) < doc.clientHeight ) {
|
|
|
|
// Load straight away. We are on a stub page.
|
|
|
|
initRelatedArticlesModule( readMore );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line compat/compat
|
2024-06-14 12:07:36 +00:00
|
|
|
const observer = /** @type {IntersectionObserver} */( new IntersectionObserver( ( ( entries ) => {
|
2021-10-26 20:41:02 +00:00
|
|
|
if ( !entries[ 0 ].isIntersecting ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// @ts-ignore
|
|
|
|
observer.unobserve( readMore );
|
|
|
|
observer.disconnect();
|
|
|
|
// @ts-ignore
|
|
|
|
initRelatedArticlesModule( readMore );
|
2024-06-14 12:07:36 +00:00
|
|
|
} ), {
|
2021-10-26 20:41:02 +00:00
|
|
|
rootMargin: '-100% 0% 0% 0%'
|
|
|
|
} ) );
|
|
|
|
observer.observe( readMore );
|
2015-12-05 17:44:15 +00:00
|
|
|
}
|
2015-12-29 02:55:43 +00:00
|
|
|
|
Limit RelatedArticles feature to ES6 browsers
We currently require support for IntersectionObserver.
which is supported on Edge >= 15 (15 has partial support),
Firefox >55, Chrome >58, Safari 12.1, Opera >=38,
iOS Safari >=12.2, Android 100
Full ES6 is supported in Edge >=15, Firefox >=54, Chrome >=51,
Safari >=10, Opera >=38, iOS Safari >=10, so such a change
would only drop support for Edge 15 and Firefox 54.
CSS.escape is guaranteed in all these browsers according to
caniuse, with the only discrepancy being the Edge browser (versions
16-18) so it is also suggested we remove support for those browsers.
Firefox 54 accounts for 0.0026% of page views
Edge 15-18 accounts for 0.069% of page views
Bug: T306355
Change-Id: Id2987e3456607b610c38da9ee157a026d1d00ada
2022-04-18 22:20:04 +00:00
|
|
|
$( loadRelatedArticles );
|
2018-09-14 05:30:46 +00:00
|
|
|
}() );
|