Add new utility function for detecting pinned elements

* Introduces a new utility function, `hasPinnedElements()`, that allows us to check whether there are any pinned elements in the HTML document based on their CSS class names.
* This function will be useful for detecting pinned elements and can be used within WikimediaEvents.


Bug: T346106
Change-Id: I4283cd234ba71acce1e5cbadabf8aeb17cd8d86e
This commit is contained in:
ksarabia 2023-09-22 16:05:20 -05:00 committed by Kimberly Sarabia
parent 507de0f4e2
commit a1c2d5ca35
2 changed files with 22 additions and 0 deletions

View file

@ -224,7 +224,22 @@ function initPinnableElement() {
} );
}
/**
* Checks if at least one of the elements in the HTML document is pinned based on CSS class names.
*
* @function
* @return {boolean} True if at least one pinned element is found, otherwise false.
*/
function hasPinnedElements() {
const suffixesToCheck = [ 'pinned-clientpref-1', 'pinned-enabled' ];
const htmlElement = document.documentElement;
return Array.from( htmlElement.classList ).some( ( className ) => {
return suffixesToCheck.some( ( suffix ) => className.endsWith( suffix ) );
} );
}
module.exports = {
hasPinnedElements,
initPinnableElement,
movePinnableElement,
setFocusAfterToggle,

View file

@ -142,3 +142,10 @@ if ( document.readyState === 'interactive' || document.readyState === 'complete'
main( window );
} );
}
// Provider of skins.vector.js module:
/**
* skins.vector.js
* @stable for use inside WikimediaEvents ONLY.
*/
module.exports = { pinnableElement };