@bookbox/view-html
Version:
Bookbox view for html
23 lines (22 loc) • 799 B
JavaScript
import { pushHistory, replaceHistory } from "./navigation";
const actions = {
push: pushHistory,
replace: replaceHistory,
};
const className = "book-box_highlight";
function goto(selector, options) {
const node = document.querySelector(selector);
if (!node)
return;
const { useHistory = false, url } = options !== null && options !== void 0 ? options : {};
node.scrollIntoView();
if (useHistory && url) {
const method = typeof useHistory === "string" ? useHistory : "replace";
actions[method](url);
}
node.classList.add(className);
setTimeout(() => (node ? node.classList.remove(className) : undefined), 1000);
}
export function gotoKey(key, options) {
goto(`.book-box_content *[data-layout='top'][data-key='${key}']`, options);
}