2022-06-09 05:02:40 +00:00
|
|
|
// Wait until the initial element position is ready
|
|
|
|
export const waitUntilElementTopNotChange = (
|
|
|
|
elSelector: string,
|
|
|
|
cb: () => void,
|
|
|
|
pollMs: number
|
|
|
|
) => {
|
|
|
|
const initialElement = document.querySelector( elSelector );
|
|
|
|
let lastInitialElementTop = initialElement?.getBoundingClientRect().top;
|
|
|
|
|
|
|
|
const intervalId = setInterval( () => {
|
|
|
|
const top = initialElement?.getBoundingClientRect().top;
|
|
|
|
if ( lastInitialElementTop === top ) {
|
|
|
|
cb();
|
|
|
|
clearInterval( intervalId );
|
|
|
|
}
|
|
|
|
lastInitialElementTop = top;
|
|
|
|
}, pollMs );
|
|
|
|
|
|
|
|
return intervalId;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Overwrite the default behavior of click event for the "Enable guided mode" button
|
|
|
|
export const bindEnableGuideModeClickEvent = (
|
|
|
|
onClick: EventListenerOrEventListenerObject
|
|
|
|
) => {
|
2022-09-27 08:12:01 +00:00
|
|
|
window.document
|
|
|
|
.querySelector( '.wp-heading-inline + .page-title-action' )
|
|
|
|
?.addEventListener( 'click', onClick );
|
2022-06-09 05:02:40 +00:00
|
|
|
};
|
2022-06-14 08:19:32 +00:00
|
|
|
|
|
|
|
// Add listener to product "Publish" button.
|
|
|
|
export const bindPublishClickEvent = (
|
|
|
|
onClick: EventListenerOrEventListenerObject
|
|
|
|
) => {
|
|
|
|
const publishButton = window.document.querySelector( '#publish' );
|
|
|
|
|
|
|
|
if ( publishButton ) {
|
|
|
|
publishButton.addEventListener( 'click', onClick );
|
|
|
|
}
|
|
|
|
|
|
|
|
return function unbind() {
|
|
|
|
publishButton?.removeEventListener( 'click', onClick );
|
|
|
|
};
|
|
|
|
};
|