mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-24 07:44:46 +08:00
15 lines
436 B
JavaScript
15 lines
436 B
JavaScript
function mountWithTurbolinks(app, target, callback = null) {
|
|
const originalHtml = document.querySelector(target).innerHTML;
|
|
|
|
document.addEventListener('turbolinks:before-cache', () => {
|
|
app.unmount();
|
|
if (document.querySelector(target)) {
|
|
document.querySelector(target).innerHTML = originalHtml;
|
|
}
|
|
if (callback) callback();
|
|
}, { once: true });
|
|
|
|
return app.mount(target);
|
|
}
|
|
|
|
export { mountWithTurbolinks };
|