JakubAndrysek / mkdocs-open-in-new-tab

🔮 This plugin adds JS to open outgoing links and PDFs in a new tab.
https://newtab.kubaandrysek.cz/
MIT License
24 stars 3 forks source link

Does not work with material navigation.instant #2

Closed ptyork closed 11 months ago

ptyork commented 1 year ago

The "navigation.instant" feature of the material theme breaks this plugin. It works on full page load (initial load, refresh, etc.) but not after navigating an internal link.

I assume using this feature just prevents the DOMContentLoaded event from firing during internal navigation. Perhaps there is another event that can be used to trigger your *_new_window() functions? I don't know enough about what is core MkDocs vs. Material for MkDocs to even know where to start looking for this. But maybe you do. ;)

JakubAndrysek commented 1 year ago

Hi, I have tried to fix it, but nothing works. I run the JS script on page load, but it doesn't handle the page change. If you have any ideas, please let me know.

My test code is here:

window.addEventListener('popstate', function(event) {
    // Handle the page change here
    console.log("popstate: " + document.location + ", state: " + JSON.stringify(event.state));
});

window.addEventListener('hashchange', function(event) {
    // Handle the page change here
    console.log("hashchange: " + document.location + ", state: " + JSON.stringify(event.state));
});

window.addEventListener('change', function(event) {
    // Handle the page change here
    console.log("change: " + document.location + ", state: " + JSON.stringify(event.state));
});

window.addEventListener("DOMContentSwitch", function() {
    console.log("DOMContentSwitch" + document.location);
});

window.addEventListener("DOMContentLoaded", function() {
    console.log("DOMContentLoaded" + document.location);
});

window.addEventListener("change", function() {
    console.log("change" + document.location);
});
JakubAndrysek commented 1 year ago

I have added this info to README.md

JakubAndrysek commented 11 months ago

Look at mkdocs-charts-plugin

JakubAndrysek commented 11 months ago

Add support for instant loading - MkDocs Material.

Thanks to mkdocs_charts_plugin plugin that supports that feature.

Other mentions Mkdocs material LaTeX not rendering in instant mode of solution.