Update pinnableHeader class when moving pinnableElement.

Adds functionality to update the pinnable header class
(pinned or unpinned) after is has been moved via
movePinnableElement().

Bug: T348039
Change-Id: I23552bdbb3390222c2c8efbd5f9122a4d5021a00
This commit is contained in:
Jan Drewniak 2023-10-25 12:54:06 -04:00 committed by Jdrewniak
parent 1eb75ab7b1
commit f59ceb4390

View file

@ -193,6 +193,29 @@ function isPinned( header ) {
return features.isEnabled( featureName );
}
/**
* Ensures the header classes are in sync with the pinnable headers state
* in the case that it's moved via movePinnableElement().
* @param {HTMLElement} pinnableElement
*/
function updatePinnableHeaderClass( pinnableElement ) {
const header = pinnableElement.querySelector( '.vector-pinnable-header' );
// Because Typescript
if ( !header || !( header instanceof HTMLElement ) ) {
return;
}
// Toggle header classes
if ( isPinned( header ) ) {
header.classList.add( PINNED_HEADER_CLASS );
header.classList.remove( UNPINNED_HEADER_CLASS );
} else {
header.classList.remove( PINNED_HEADER_CLASS );
header.classList.add( UNPINNED_HEADER_CLASS );
}
}
/**
* @param {string} pinnableElementId
* @param {string} newContainerId
@ -209,6 +232,7 @@ function movePinnableElement( pinnableElementId, newContainerId ) {
// Avoid moving element if unnecessary
if ( currContainer.id !== newContainerId ) {
newContainer.insertAdjacentElement( 'beforeend', pinnableElem );
updatePinnableHeaderClass( pinnableElem );
}
popupNotification.hideAll();