2021-10-26 23:37:56 +00:00
|
|
|
/**
|
|
|
|
* Functions and variables to implement sticky header.
|
|
|
|
*/
|
2021-10-20 19:10:42 +00:00
|
|
|
const
|
2021-09-07 19:48:23 +00:00
|
|
|
STICKY_HEADER_ID = 'vector-sticky-header',
|
2021-12-03 19:19:27 +00:00
|
|
|
header = document.getElementById( STICKY_HEADER_ID ),
|
2021-09-16 19:27:10 +00:00
|
|
|
initSearchToggle = require( './searchToggle.js' ),
|
2021-09-09 02:26:33 +00:00
|
|
|
STICKY_HEADER_APPENDED_ID = '-sticky-header',
|
2021-09-07 19:48:23 +00:00
|
|
|
STICKY_HEADER_VISIBLE_CLASS = 'vector-sticky-header-visible',
|
2021-09-09 02:26:33 +00:00
|
|
|
STICKY_HEADER_USER_MENU_CONTAINER_CLASS = 'vector-sticky-header-icon-end',
|
|
|
|
FIRST_HEADING_ID = 'firstHeading',
|
|
|
|
USER_MENU_ID = 'p-personal',
|
|
|
|
VECTOR_USER_LINKS_SELECTOR = '.vector-user-links',
|
2021-10-26 23:37:56 +00:00
|
|
|
SEARCH_TOGGLE_SELECTOR = '.vector-sticky-header-search-toggle',
|
|
|
|
STICKY_HEADER_EXPERIMENT_NAME = 'vector.sticky_header_2021_11';
|
2021-09-07 19:48:23 +00:00
|
|
|
|
2021-09-14 16:53:35 +00:00
|
|
|
/**
|
|
|
|
* Copies attribute from an element to another.
|
|
|
|
*
|
|
|
|
* @param {Element} from
|
|
|
|
* @param {Element} to
|
|
|
|
* @param {string} attribute
|
|
|
|
*/
|
|
|
|
function copyAttribute( from, to, attribute ) {
|
2021-10-20 19:10:42 +00:00
|
|
|
const fromAttr = from.getAttribute( attribute );
|
2021-09-14 16:53:35 +00:00
|
|
|
if ( fromAttr ) {
|
|
|
|
to.setAttribute( attribute, fromAttr );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-03 19:19:27 +00:00
|
|
|
/**
|
|
|
|
* Show the sticky header.
|
|
|
|
*/
|
|
|
|
function show() {
|
|
|
|
if ( header ) {
|
|
|
|
// eslint-disable-next-line mediawiki/class-doc
|
|
|
|
header.classList.add( STICKY_HEADER_VISIBLE_CLASS );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the sticky header.
|
|
|
|
*/
|
|
|
|
function hide() {
|
|
|
|
if ( header ) {
|
|
|
|
// eslint-disable-next-line mediawiki/class-doc
|
|
|
|
header.classList.remove( STICKY_HEADER_VISIBLE_CLASS );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-19 15:27:18 +00:00
|
|
|
/**
|
|
|
|
* Copies attribute from an element to another.
|
|
|
|
*
|
|
|
|
* @param {Element} from
|
|
|
|
* @param {Element} to
|
|
|
|
*/
|
|
|
|
function copyButtonAttributes( from, to ) {
|
|
|
|
copyAttribute( from, to, 'href' );
|
|
|
|
copyAttribute( from, to, 'title' );
|
|
|
|
}
|
|
|
|
|
2021-09-14 19:32:09 +00:00
|
|
|
/**
|
|
|
|
* Suffixes an attribute with a value that indicates it
|
|
|
|
* relates to the sticky header to support click tracking instrumentation.
|
|
|
|
*
|
|
|
|
* @param {Element} node
|
|
|
|
* @param {string} attribute
|
|
|
|
*/
|
|
|
|
function suffixStickyAttribute( node, attribute ) {
|
2021-10-20 19:10:42 +00:00
|
|
|
const value = node.getAttribute( attribute );
|
2021-09-14 19:32:09 +00:00
|
|
|
if ( value ) {
|
|
|
|
node.setAttribute( attribute, value + STICKY_HEADER_APPENDED_ID );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes a node trackable by our click tracking instrumentation.
|
|
|
|
*
|
|
|
|
* @param {Element} node
|
|
|
|
*/
|
|
|
|
function makeNodeTrackable( node ) {
|
|
|
|
suffixStickyAttribute( node, 'id' );
|
|
|
|
suffixStickyAttribute( node, 'data-event-name' );
|
|
|
|
}
|
|
|
|
|
2021-09-24 21:00:32 +00:00
|
|
|
/**
|
|
|
|
*
|
2021-10-19 19:14:30 +00:00
|
|
|
* @param {null|HTMLElement|Node|EventTarget} node
|
2021-09-24 21:00:32 +00:00
|
|
|
* @return {HTMLElement}
|
|
|
|
*/
|
|
|
|
function toHTMLElement( node ) {
|
|
|
|
// @ts-ignore
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {HTMLElement} node
|
|
|
|
*/
|
|
|
|
function removeNode( node ) {
|
|
|
|
toHTMLElement( node.parentNode ).removeChild( node );
|
|
|
|
}
|
|
|
|
|
2021-10-14 15:00:04 +00:00
|
|
|
/**
|
|
|
|
* @param {NodeList} nodes
|
|
|
|
* @param {string} className
|
|
|
|
*/
|
|
|
|
function removeClassFromNodes( nodes, className ) {
|
|
|
|
Array.prototype.forEach.call( nodes, function ( node ) {
|
|
|
|
// eslint-disable-next-line mediawiki/class-doc
|
|
|
|
node.classList.remove( className );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2021-09-14 16:53:35 +00:00
|
|
|
/**
|
|
|
|
* Makes sticky header icons functional for modern Vector.
|
|
|
|
*
|
2021-12-03 19:19:27 +00:00
|
|
|
* @param {HTMLElement} headerElement
|
2021-09-14 16:53:35 +00:00
|
|
|
* @param {HTMLElement|null} history
|
|
|
|
* @param {HTMLElement|null} talk
|
|
|
|
*/
|
2021-12-03 19:19:27 +00:00
|
|
|
function prepareIcons( headerElement, history, talk ) {
|
|
|
|
const historySticky = headerElement.querySelector( '#ca-history-sticky-header' ),
|
|
|
|
talkSticky = headerElement.querySelector( '#ca-talk-sticky-header' );
|
2021-09-14 16:53:35 +00:00
|
|
|
|
|
|
|
if ( !historySticky || !talkSticky ) {
|
|
|
|
throw new Error( 'Sticky header has unexpected HTML' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( history ) {
|
2021-10-19 15:27:18 +00:00
|
|
|
copyButtonAttributes( history, historySticky );
|
2021-09-14 16:53:35 +00:00
|
|
|
} else {
|
|
|
|
// @ts-ignore
|
|
|
|
historySticky.parentNode.removeChild( historySticky );
|
|
|
|
}
|
|
|
|
if ( talk ) {
|
2021-10-19 15:27:18 +00:00
|
|
|
copyButtonAttributes( talk, talkSticky );
|
2021-09-14 16:53:35 +00:00
|
|
|
} else {
|
|
|
|
// @ts-ignore
|
|
|
|
talkSticky.parentNode.removeChild( talkSticky );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-24 21:00:32 +00:00
|
|
|
/**
|
|
|
|
* Render sticky header edit or protected page icons for modern Vector.
|
|
|
|
*
|
2021-12-03 19:19:27 +00:00
|
|
|
* @param {HTMLElement} headerElement
|
2021-09-24 21:00:32 +00:00
|
|
|
* @param {HTMLElement|null} primaryEdit
|
|
|
|
* @param {boolean} isProtected
|
|
|
|
* @param {HTMLElement|null} secondaryEdit
|
2021-10-19 19:14:30 +00:00
|
|
|
* @param {Function} disableStickyHeader function to call to disable the sticky
|
|
|
|
* header.
|
2021-09-24 21:00:32 +00:00
|
|
|
*/
|
|
|
|
function prepareEditIcons(
|
2021-12-03 19:19:27 +00:00
|
|
|
headerElement,
|
2021-09-24 21:00:32 +00:00
|
|
|
primaryEdit,
|
|
|
|
isProtected,
|
2021-10-19 19:14:30 +00:00
|
|
|
secondaryEdit,
|
|
|
|
disableStickyHeader
|
2021-09-24 21:00:32 +00:00
|
|
|
) {
|
2021-10-20 19:10:42 +00:00
|
|
|
const
|
2021-12-03 19:19:27 +00:00
|
|
|
primaryEditStickyElement = headerElement.querySelector(
|
2021-10-26 21:34:05 +00:00
|
|
|
'#ca-ve-edit-sticky-header'
|
|
|
|
),
|
|
|
|
primaryEditSticky = primaryEditStickyElement ? toHTMLElement(
|
2021-12-03 19:19:27 +00:00
|
|
|
headerElement.querySelector(
|
2021-09-24 21:00:32 +00:00
|
|
|
'#ca-ve-edit-sticky-header'
|
|
|
|
)
|
2021-10-26 21:34:05 +00:00
|
|
|
) : null,
|
2021-09-24 21:00:32 +00:00
|
|
|
protectedSticky = toHTMLElement(
|
2021-12-03 19:19:27 +00:00
|
|
|
headerElement.querySelector(
|
2021-09-24 21:00:32 +00:00
|
|
|
'#ca-viewsource-sticky-header'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
wikitextSticky = toHTMLElement(
|
2021-12-03 19:19:27 +00:00
|
|
|
headerElement.querySelector(
|
2021-09-24 21:00:32 +00:00
|
|
|
'#ca-edit-sticky-header'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2021-10-26 21:34:05 +00:00
|
|
|
// If no primary edit icon is present the feature is disabled.
|
|
|
|
if ( !primaryEditSticky ) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-24 21:00:32 +00:00
|
|
|
if ( !primaryEdit ) {
|
|
|
|
removeNode( protectedSticky );
|
|
|
|
removeNode( wikitextSticky );
|
|
|
|
removeNode( primaryEditSticky );
|
|
|
|
return;
|
|
|
|
} else if ( isProtected ) {
|
|
|
|
removeNode( wikitextSticky );
|
|
|
|
removeNode( primaryEditSticky );
|
2021-10-19 15:27:18 +00:00
|
|
|
copyButtonAttributes( primaryEdit, protectedSticky );
|
2021-09-24 21:00:32 +00:00
|
|
|
} else {
|
|
|
|
removeNode( protectedSticky );
|
2021-10-19 15:27:18 +00:00
|
|
|
copyButtonAttributes( primaryEdit, primaryEditSticky );
|
2021-10-19 19:14:30 +00:00
|
|
|
|
|
|
|
primaryEditSticky.addEventListener( 'click', function ( ev ) {
|
|
|
|
const target = toHTMLElement( ev.target );
|
|
|
|
const $ve = $( primaryEdit );
|
|
|
|
|
|
|
|
if ( target && $ve.length ) {
|
|
|
|
const event = $.Event( 'click' );
|
|
|
|
$ve.trigger( event );
|
|
|
|
// The link has been progressively enhanced.
|
|
|
|
if ( event.isDefaultPrevented() ) {
|
|
|
|
disableStickyHeader();
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
2021-09-24 21:00:32 +00:00
|
|
|
if ( secondaryEdit ) {
|
2021-10-19 15:27:18 +00:00
|
|
|
copyButtonAttributes( secondaryEdit, wikitextSticky );
|
2021-10-19 19:14:30 +00:00
|
|
|
wikitextSticky.addEventListener( 'click', function ( ev ) {
|
|
|
|
const target = toHTMLElement( ev.target );
|
|
|
|
if ( target ) {
|
|
|
|
const $edit = $( secondaryEdit );
|
|
|
|
if ( $edit.length ) {
|
|
|
|
const event = $.Event( 'click' );
|
|
|
|
$edit.trigger( event );
|
|
|
|
// The link has been progressively enhanced.
|
|
|
|
if ( event.isDefaultPrevented() ) {
|
|
|
|
disableStickyHeader();
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
2021-09-24 21:00:32 +00:00
|
|
|
} else {
|
|
|
|
removeNode( wikitextSticky );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if element is in viewport.
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} element
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
function isInViewport( element ) {
|
2021-10-20 19:10:42 +00:00
|
|
|
const rect = element.getBoundingClientRect();
|
2021-09-24 21:00:32 +00:00
|
|
|
return (
|
|
|
|
rect.top >= 0 &&
|
|
|
|
rect.left >= 0 &&
|
|
|
|
rect.bottom <= ( window.innerHeight || document.documentElement.clientHeight ) &&
|
|
|
|
rect.right <= ( window.innerWidth || document.documentElement.clientWidth )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-26 23:37:56 +00:00
|
|
|
/**
|
|
|
|
* Add hooks for sticky header when Visual Editor is used.
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} targetIntersection intersection element
|
|
|
|
* @param {IntersectionObserver} observer
|
|
|
|
*/
|
2021-12-03 19:19:27 +00:00
|
|
|
function addVisualEditorHooks( targetIntersection, observer ) {
|
2021-10-26 23:37:56 +00:00
|
|
|
// When Visual Editor is activated, hide the sticky header.
|
|
|
|
mw.hook( 've.activate' ).add( () => {
|
2021-12-03 19:19:27 +00:00
|
|
|
hide();
|
2021-10-26 23:37:56 +00:00
|
|
|
observer.unobserve( targetIntersection );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// When Visual Editor is deactivated (by clicking "Read" tab at top of page), show sticky header
|
|
|
|
// by re-triggering the observer.
|
|
|
|
mw.hook( 've.deactivationComplete' ).add( () => {
|
|
|
|
observer.observe( targetIntersection );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// After saving edits, re-apply the sticky header if the target is not in the viewport.
|
|
|
|
mw.hook( 'postEdit.afterRemoval' ).add( () => {
|
|
|
|
if ( !isInViewport( targetIntersection ) ) {
|
2021-12-03 19:19:27 +00:00
|
|
|
show();
|
2021-10-26 23:37:56 +00:00
|
|
|
observer.observe( targetIntersection );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2021-09-07 19:48:23 +00:00
|
|
|
/**
|
|
|
|
* Makes sticky header functional for modern Vector.
|
|
|
|
*
|
2021-12-03 19:19:27 +00:00
|
|
|
* @param {HTMLElement} headerElement
|
2021-09-09 02:26:33 +00:00
|
|
|
* @param {HTMLElement} userMenu
|
2021-09-14 19:24:26 +00:00
|
|
|
* @param {Element} userMenuStickyContainer
|
2021-10-26 23:37:56 +00:00
|
|
|
* @param {IntersectionObserver} stickyObserver
|
|
|
|
* @param {HTMLElement} stickyIntersection
|
2021-09-07 19:48:23 +00:00
|
|
|
*/
|
2021-09-09 02:26:33 +00:00
|
|
|
function makeStickyHeaderFunctional(
|
2021-12-03 19:19:27 +00:00
|
|
|
headerElement,
|
2021-09-09 02:26:33 +00:00
|
|
|
userMenu,
|
2021-10-26 23:37:56 +00:00
|
|
|
userMenuStickyContainer,
|
|
|
|
stickyObserver,
|
|
|
|
stickyIntersection
|
2021-09-09 02:26:33 +00:00
|
|
|
) {
|
2021-10-20 19:10:42 +00:00
|
|
|
const
|
2021-09-14 19:24:26 +00:00
|
|
|
// Type declaration needed because of https://github.com/Microsoft/TypeScript/issues/3734#issuecomment-118934518
|
|
|
|
userMenuClone = /** @type {HTMLElement} */( userMenu.cloneNode( true ) ),
|
2021-09-09 02:26:33 +00:00
|
|
|
userMenuStickyElementsWithIds = userMenuClone.querySelectorAll( '[ id ], [ data-event-name ]' ),
|
2021-09-16 18:00:05 +00:00
|
|
|
userMenuStickyContainerInner = userMenuStickyContainer
|
|
|
|
.querySelector( VECTOR_USER_LINKS_SELECTOR );
|
2021-09-09 02:26:33 +00:00
|
|
|
|
|
|
|
// Update all ids of the cloned user menu to make them unique.
|
2021-09-14 19:32:09 +00:00
|
|
|
makeNodeTrackable( userMenuClone );
|
|
|
|
userMenuStickyElementsWithIds.forEach( makeNodeTrackable );
|
2021-09-09 02:26:33 +00:00
|
|
|
|
2021-09-21 16:01:33 +00:00
|
|
|
// Remove portlet links added by gadgets using mw.util.addPortletLink, T291426
|
2021-10-20 19:10:42 +00:00
|
|
|
const gadgetLinks = userMenuClone.querySelector( 'mw-list-item-js' );
|
2021-09-22 17:18:44 +00:00
|
|
|
if ( gadgetLinks ) {
|
|
|
|
gadgetLinks.remove();
|
|
|
|
}
|
2021-10-14 15:00:04 +00:00
|
|
|
removeClassFromNodes(
|
|
|
|
userMenuClone.querySelectorAll( '.user-links-collapsible-item' ),
|
|
|
|
'user-links-collapsible-item'
|
|
|
|
);
|
2021-09-07 19:48:23 +00:00
|
|
|
|
2021-09-21 16:01:33 +00:00
|
|
|
// Prevents user menu from being focusable, T290201
|
2021-10-20 19:10:42 +00:00
|
|
|
const userMenuCheckbox = userMenuClone.querySelector( 'input' );
|
2021-09-21 16:01:33 +00:00
|
|
|
if ( userMenuCheckbox ) {
|
|
|
|
userMenuCheckbox.setAttribute( 'tabindex', '-1' );
|
|
|
|
}
|
|
|
|
|
2021-09-09 02:26:33 +00:00
|
|
|
// Clone the updated user menu to the sticky header.
|
2021-09-14 19:24:26 +00:00
|
|
|
if ( userMenuStickyContainerInner ) {
|
|
|
|
userMenuStickyContainerInner.appendChild( userMenuClone );
|
|
|
|
}
|
2021-09-09 02:26:33 +00:00
|
|
|
|
2021-12-03 19:19:27 +00:00
|
|
|
prepareIcons( headerElement,
|
2021-09-14 16:53:35 +00:00
|
|
|
document.querySelector( '#ca-history a' ),
|
|
|
|
document.querySelector( '#ca-talk a' )
|
|
|
|
);
|
2021-09-20 23:37:54 +00:00
|
|
|
|
2021-10-20 19:10:42 +00:00
|
|
|
const veEdit = document.querySelector( '#ca-ve-edit a' );
|
|
|
|
const ceEdit = document.querySelector( '#ca-edit a' );
|
|
|
|
const protectedEdit = document.querySelector( '#ca-viewsource a' );
|
|
|
|
const isProtected = !!protectedEdit;
|
|
|
|
const primaryEdit = protectedEdit || ( veEdit || ceEdit );
|
|
|
|
const secondaryEdit = veEdit ? ceEdit : null;
|
2021-10-19 19:14:30 +00:00
|
|
|
const disableStickyHeader = () => {
|
|
|
|
// eslint-disable-next-line mediawiki/class-doc
|
2021-12-03 19:19:27 +00:00
|
|
|
headerElement.classList.remove( STICKY_HEADER_VISIBLE_CLASS );
|
2021-10-19 19:14:30 +00:00
|
|
|
stickyObserver.unobserve( stickyIntersection );
|
|
|
|
};
|
2021-09-24 21:00:32 +00:00
|
|
|
|
|
|
|
prepareEditIcons(
|
2021-12-03 19:19:27 +00:00
|
|
|
headerElement,
|
2021-09-24 21:00:32 +00:00
|
|
|
toHTMLElement( primaryEdit ),
|
|
|
|
isProtected,
|
2021-10-19 19:14:30 +00:00
|
|
|
toHTMLElement( secondaryEdit ),
|
|
|
|
disableStickyHeader
|
2021-09-24 21:00:32 +00:00
|
|
|
);
|
2021-09-20 23:37:54 +00:00
|
|
|
|
2021-09-07 19:48:23 +00:00
|
|
|
stickyObserver.observe( stickyIntersection );
|
|
|
|
}
|
|
|
|
|
2021-09-09 21:40:06 +00:00
|
|
|
/**
|
2021-12-03 19:19:27 +00:00
|
|
|
* @param {HTMLElement} headerElement
|
2021-09-09 21:40:06 +00:00
|
|
|
*/
|
2021-12-03 19:19:27 +00:00
|
|
|
function setupSearchIfNeeded( headerElement ) {
|
2021-10-20 19:10:42 +00:00
|
|
|
const
|
2021-12-03 19:19:27 +00:00
|
|
|
searchToggle = headerElement.querySelector( SEARCH_TOGGLE_SELECTOR );
|
2021-09-09 21:40:06 +00:00
|
|
|
|
2021-10-20 19:10:42 +00:00
|
|
|
if ( !document.body.classList.contains( 'skin-vector-search-vue' ) ) {
|
2021-09-09 21:40:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-20 19:10:42 +00:00
|
|
|
if ( searchToggle ) {
|
|
|
|
initSearchToggle( searchToggle );
|
|
|
|
}
|
2021-09-09 21:40:06 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 21:21:24 +00:00
|
|
|
/**
|
|
|
|
* Determines if sticky header should be visible for a given namespace.
|
|
|
|
*
|
|
|
|
* @param {number} namespaceNumber
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
function isAllowedNamespace( namespaceNumber ) {
|
|
|
|
// Corresponds to Main, User, Wikipedia, Template, Help, Category, Portal, Module.
|
2021-10-20 19:10:42 +00:00
|
|
|
const allowedNamespaceNumbers = [ 0, 2, 4, 10, 12, 14, 100, 828 ];
|
2021-09-15 21:21:24 +00:00
|
|
|
return allowedNamespaceNumbers.indexOf( namespaceNumber ) > -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if sticky header should be visible for a given action.
|
|
|
|
*
|
|
|
|
* @param {string} action
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
function isAllowedAction( action ) {
|
2021-10-20 19:10:42 +00:00
|
|
|
const disallowedActions = [ 'history', 'edit' ],
|
2021-09-15 21:21:24 +00:00
|
|
|
hasDiffId = mw.config.get( 'wgDiffOldId' );
|
|
|
|
return disallowedActions.indexOf( action ) < 0 && !hasDiffId;
|
|
|
|
}
|
|
|
|
|
2021-10-26 23:37:56 +00:00
|
|
|
const
|
|
|
|
stickyIntersection = document.getElementById(
|
|
|
|
FIRST_HEADING_ID
|
|
|
|
),
|
|
|
|
userMenu = document.getElementById( USER_MENU_ID ),
|
|
|
|
userMenuStickyContainer = document.getElementsByClassName(
|
|
|
|
STICKY_HEADER_USER_MENU_CONTAINER_CLASS
|
|
|
|
)[ 0 ],
|
|
|
|
allowedNamespace = isAllowedNamespace( mw.config.get( 'wgNamespaceNumber' ) ),
|
|
|
|
allowedAction = isAllowedAction( mw.config.get( 'wgAction' ) );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if all conditions are met to enable sticky header
|
|
|
|
*
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
function isStickyHeaderAllowed() {
|
|
|
|
// @ts-ignore
|
|
|
|
return header &&
|
2021-09-09 02:26:33 +00:00
|
|
|
stickyIntersection &&
|
|
|
|
userMenu &&
|
|
|
|
userMenuStickyContainer &&
|
2021-09-15 21:21:24 +00:00
|
|
|
allowedNamespace &&
|
|
|
|
allowedAction &&
|
2021-10-26 23:37:56 +00:00
|
|
|
'IntersectionObserver' in window;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {IntersectionObserver} observer
|
|
|
|
*/
|
|
|
|
function initStickyHeader( observer ) {
|
|
|
|
if ( !isStickyHeaderAllowed() ) {
|
2021-08-30 22:44:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-09-07 19:48:23 +00:00
|
|
|
|
2021-10-26 23:37:56 +00:00
|
|
|
makeStickyHeaderFunctional(
|
|
|
|
// @ts-ignore
|
|
|
|
header,
|
|
|
|
userMenu,
|
|
|
|
userMenuStickyContainer,
|
|
|
|
observer,
|
|
|
|
stickyIntersection
|
|
|
|
);
|
|
|
|
// @ts-ignore
|
2021-09-09 21:40:06 +00:00
|
|
|
setupSearchIfNeeded( header );
|
2021-10-26 23:37:56 +00:00
|
|
|
// @ts-ignore
|
|
|
|
addVisualEditorHooks( header, stickyIntersection, observer );
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2021-12-03 19:19:27 +00:00
|
|
|
show,
|
|
|
|
hide,
|
2021-10-26 23:37:56 +00:00
|
|
|
initStickyHeader,
|
|
|
|
isStickyHeaderAllowed,
|
|
|
|
header,
|
2021-12-01 22:31:48 +00:00
|
|
|
stickyIntersection,
|
2021-10-26 23:37:56 +00:00
|
|
|
STICKY_HEADER_EXPERIMENT_NAME
|
2021-08-30 22:44:00 +00:00
|
|
|
};
|