2020-08-09 10:37:32 +00:00
|
|
|
import { SDK_CSS } from './sdk.js';
|
2021-05-17 16:08:35 +00:00
|
|
|
import { IFrameHelper } from './IFrameHelper';
|
2020-04-03 07:34:58 +00:00
|
|
|
|
|
|
|
export const loadCSS = () => {
|
|
|
|
const css = document.createElement('style');
|
|
|
|
css.innerHTML = `${SDK_CSS}`;
|
|
|
|
document.body.appendChild(css);
|
|
|
|
};
|
|
|
|
|
2022-10-12 21:42:06 +00:00
|
|
|
export const addClasses = (elm, classes) => {
|
|
|
|
elm.classList.add(...classes.split(' '));
|
2020-04-03 07:34:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const toggleClass = (elm, classes) => {
|
2022-10-12 21:42:06 +00:00
|
|
|
elm.classList.toggle(classes);
|
2020-04-03 07:34:58 +00:00
|
|
|
};
|
2020-07-07 18:34:44 +00:00
|
|
|
|
2022-10-12 21:42:06 +00:00
|
|
|
export const removeClasses = (elm, classes) => {
|
|
|
|
elm.classList.remove(...classes.split(' '));
|
2020-07-07 18:34:44 +00:00
|
|
|
};
|
2021-05-17 16:08:35 +00:00
|
|
|
|
|
|
|
export const onLocationChange = ({ referrerURL, referrerHost }) => {
|
|
|
|
IFrameHelper.events.onLocationChange({
|
|
|
|
referrerURL,
|
|
|
|
referrerHost,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const onLocationChangeListener = () => {
|
|
|
|
let oldHref = document.location.href;
|
|
|
|
const referrerHost = document.location.host;
|
|
|
|
const config = {
|
|
|
|
childList: true,
|
|
|
|
subtree: true,
|
|
|
|
};
|
|
|
|
onLocationChange({
|
|
|
|
referrerURL: oldHref,
|
|
|
|
referrerHost,
|
|
|
|
});
|
|
|
|
|
|
|
|
const bodyList = document.querySelector('body');
|
|
|
|
const observer = new MutationObserver(mutations => {
|
|
|
|
mutations.forEach(() => {
|
|
|
|
if (oldHref !== document.location.href) {
|
|
|
|
oldHref = document.location.href;
|
|
|
|
onLocationChange({
|
|
|
|
referrerURL: oldHref,
|
|
|
|
referrerHost,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
observer.observe(bodyList, config);
|
|
|
|
};
|