mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-16 14:17:00 +08:00
17 lines
572 B
JavaScript
17 lines
572 B
JavaScript
function mountWithTurbolinks(app, target, callback = null) {
|
|
const originalHtml = document.querySelector(target).innerHTML;
|
|
const cacheDisabled = document.querySelector('#cache-directive');
|
|
const event = cacheDisabled ? 'turbolinks:before-render' : 'turbolinks:before-cache';
|
|
|
|
document.addEventListener(event, () => {
|
|
app.unmount();
|
|
if (document.querySelector(target)) {
|
|
document.querySelector(target).innerHTML = originalHtml;
|
|
}
|
|
if (callback) callback();
|
|
}, { once: true });
|
|
|
|
return app.mount(target);
|
|
}
|
|
|
|
export { mountWithTurbolinks };
|