Search…

X3 Photo Gallery Support Forums

Search…
 
Ruud de Soet
Experienced
Topic Author
Posts: 28
Joined: 11 Apr 2018, 09:42

Slidemenu collapses

09 Jul 2025, 17:19

I’m using Style Slidemenu, which contains several folders and subfolders. When I navigate from a folder with subfolders to another folder, the first folder collapses. This does not happen when I select a folder that doesn't have subfolders. I would like the previously opened folders to always collapse, regardless of whether I select a folder/subfolder or just a folder without subfolders.
 
I believe a custom JavaScript solution is needed for this. I've tried a number of code snippets, but none have worked.
Image
 
User avatar
mjau-mjau
X3 Wizard
Posts: 14469
Joined: 30 Sep 2006, 03:37

Re: Slidemenu collapses

10 Jul 2025, 00:35

Ruud de Soet wrote: I’m using Style Slidemenu, which contains several folders and subfolders. When I navigate from a folder with subfolders to another folder, the first folder collapses. This does not happen when I select a folder that doesn't have subfolders. I would like the previously opened folders to always collapse, regardless of whether I select a folder/subfolder or just a folder without subfolders.
 
I believe a custom JavaScript solution is needed for this. I've tried a number of code snippets, but none have worked.
Image
It doesn't close the subfolder when clicking a folder that doesn't have subfolders, because technically you are not toggling the menu at all, just navigating to an endpoint. I think it should be up to the user to close this folder if they are not using it any more ... Technically, it's still the last used submenu, that the user has not closed. I don't see a huge point in trying to hack this with Javascript ... It's an internal complex javascript menu, and that's how it works. I can't just hack the menu from the outside without spending several hours. There are internal states that control the menu ... It's not just about overriding it from the outside.
 
Ruud de Soet
Experienced
Topic Author
Posts: 28
Joined: 11 Apr 2018, 09:42

Re: Slidemenu collapses

10 Jul 2025, 06:23

Karl, thanks for your explanation and I can understand you can't do that for just one website. But I think many more websites use the Slidemenu and might also encounter the same issue: collapsing the menus is more aesthetically. But I can live with it!

Do you think the following code wil work when ".folder-toggle must be a class that appears on every clickable folder iten" and ".subfolder must be the clas of the element containing the subfolders"?
<script>
document.addEventListener("DOMContentLoaded", function () {
    var folders = document.querySelectorAll(".folder-toggle");

    folders.forEach(function(folder) {
        folder.addEventListener("click", function () {
            // Sluit alle andere mappen
            folders.forEach(function(f) {
                if (f !== folder) {
                    f.classList.remove("open");
                    var sub = f.nextElementSibling;
                    if (sub && sub.classList.contains("sub-folder")) {
                        sub.style.display = "none";
                    }
                }
            });

            // Open of toggle de geklikte map
            folder.classList.toggle("open");
            var sub = folder.nextElementSibling;
            if (sub && sub.classList.contains("sub-folder")) {
                if (sub.style.display === "none" || sub.style.display === "") {
                    sub.style.display = "block";
                } else {
                    sub.style.display = "none";
                }
            }
        });
    });
});
</script>
 
User avatar
mjau-mjau
X3 Wizard
Posts: 14469
Joined: 30 Sep 2006, 03:37

Re: Slidemenu collapses

10 Jul 2025, 22:31

I'm gonna have to reply from the top of my head here. As long as the hide/display is working correctly, and the classes you can see are toggled correctly, then yes it would work. Why not just try it? I can't guarantee you have covered all aspects, but if it works, then likely you have hit the jackpot, nothing more to worry about ...  :clap: