[refactor] reduce usages of typescript type declarations
While needed for cloned elements, others can be avoided by using more general Element class Change-Id: Iaee121a9f746e9729b5ecbdec80915bf05c11655
This commit is contained in:
parent
8f2a5c58f2
commit
21a21f7e93
|
@ -57,7 +57,7 @@ function prepareIcons( header, history, talk ) {
|
|||
* @param {HTMLElement} header
|
||||
* @param {HTMLElement} stickyIntersection
|
||||
* @param {HTMLElement} userMenu
|
||||
* @param {HTMLElement} userMenuStickyContainer
|
||||
* @param {Element} userMenuStickyContainer
|
||||
*/
|
||||
function makeStickyHeaderFunctional(
|
||||
header,
|
||||
|
@ -78,11 +78,10 @@ function makeStickyHeaderFunctional(
|
|||
header.classList.remove( STICKY_HEADER_VISIBLE_CLASS );
|
||||
}
|
||||
} ),
|
||||
userMenuClone = /** @type {HTMLElement} */ ( userMenu.cloneNode( true ) ),
|
||||
// Type declaration needed because of https://github.com/Microsoft/TypeScript/issues/3734#issuecomment-118934518
|
||||
userMenuClone = /** @type {HTMLElement} */( userMenu.cloneNode( true ) ),
|
||||
userMenuStickyElementsWithIds = userMenuClone.querySelectorAll( '[ id ], [ data-event-name ]' ),
|
||||
userMenuStickyContainerInner = /** @type {HTMLElement} */ (
|
||||
userMenuStickyContainer.querySelector( VECTOR_USER_LINKS_SELECTOR )
|
||||
);
|
||||
userMenuStickyContainerInner = userMenuStickyContainer.querySelector( VECTOR_USER_LINKS_SELECTOR );
|
||||
|
||||
// Update all ids of the cloned user menu to make them unique.
|
||||
userMenuClone.id += STICKY_HEADER_APPENDED_ID;
|
||||
|
@ -100,14 +99,12 @@ function makeStickyHeaderFunctional(
|
|||
mw.hook( 'util.addPortletLink' ).add( function ( /** @type {HTMLElement} */ item ) {
|
||||
// Get the nav tag parent of the gadget-injected menu item. We verify that .closest is
|
||||
// available for use because of feature detection in init function.
|
||||
var parentNav = /** @type {HTMLElement} */ ( item.closest( 'nav' ) );
|
||||
var parentNav = item.closest( 'nav' );
|
||||
// Check if a gadget is injecting an item into the user menu.
|
||||
if ( parentNav.id === 'p-personal' ) {
|
||||
if ( parentNav && parentNav.getAttribute( 'id' ) === 'p-personal' ) {
|
||||
var
|
||||
itemClone = /** @type {HTMLElement} */ ( item.cloneNode( true ) ),
|
||||
userMenuCloneUl = /** @type {HTMLElement} */ (
|
||||
userMenuClone.querySelector( VECTOR_MENU_CONTENT_LIST_SELECTOR )
|
||||
);
|
||||
userMenuCloneUl = userMenuClone.querySelector( VECTOR_MENU_CONTENT_LIST_SELECTOR );
|
||||
if ( userMenuCloneUl ) {
|
||||
// Remove data-event-name attribute if it exists on the cloned item.
|
||||
itemClone.removeAttribute( 'data-event-name' );
|
||||
|
@ -119,7 +116,9 @@ function makeStickyHeaderFunctional(
|
|||
} );
|
||||
|
||||
// Clone the updated user menu to the sticky header.
|
||||
userMenuStickyContainerInner.appendChild( userMenuClone );
|
||||
if ( userMenuStickyContainerInner ) {
|
||||
userMenuStickyContainerInner.appendChild( userMenuClone );
|
||||
}
|
||||
|
||||
prepareIcons( header,
|
||||
document.querySelector( '#ca-history a' ),
|
||||
|
@ -129,14 +128,14 @@ function makeStickyHeaderFunctional(
|
|||
}
|
||||
|
||||
module.exports = function initStickyHeader() {
|
||||
var header = /** @type {HTMLElement} */ ( document.getElementById( STICKY_HEADER_ID ) ),
|
||||
stickyIntersection = /** @type {HTMLElement} */ ( document.getElementById(
|
||||
var header = document.getElementById( STICKY_HEADER_ID ),
|
||||
stickyIntersection = document.getElementById(
|
||||
FIRST_HEADING_ID
|
||||
) ),
|
||||
userMenu = /** @type {HTMLElement} */ ( document.getElementById( USER_MENU_ID ) ),
|
||||
userMenuStickyContainer = /** @type {HTMLElement} */ ( document.getElementsByClassName(
|
||||
STICKY_HEADER_USER_MENU_CONTAINER_CLASS )[ 0 ]
|
||||
);
|
||||
),
|
||||
userMenu = document.getElementById( USER_MENU_ID ),
|
||||
userMenuStickyContainer = document.getElementsByClassName(
|
||||
STICKY_HEADER_USER_MENU_CONTAINER_CLASS
|
||||
)[ 0 ];
|
||||
|
||||
if ( !(
|
||||
header &&
|
||||
|
|
Loading…
Reference in New Issue