« get me outta code hell

client: remember scoped chronology links selection - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-04-23 15:04:44 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-30 20:48:17 -0300
commit38cba5da6e8e8e06e242a48854c8aacd3d32e2a9 (patch)
tree4ee9de5804378f10e40fea2d15b1ecb43853fdfe /src
parentfe8f774aeb51eb9167421a1c5f6356163e04af04 (diff)
client: remember scoped chronology links selection
Diffstat (limited to 'src')
-rw-r--r--src/static/js/client.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/static/js/client.js b/src/static/js/client.js
index 32fffebe..5611a349 100644
--- a/src/static/js/client.js
+++ b/src/static/js/client.js
@@ -2955,6 +2955,11 @@ clientSteps.addPageListeners.push(addAdditionalNamesBoxListeners);
 const scopedChronologyLinksInfo = initInfo('scopedChronologyLinksInfo', {
   containers: null,
   switchers: null,
+  modes: null,
+
+  session: {
+    selectedMode: 'wiki',
+  },
 });
 
 function getScopedChronologyLinksReferences() {
@@ -2966,10 +2971,18 @@ function getScopedChronologyLinksReferences() {
   info.switchers =
     info.containers
       .map(container => container.querySelector('.scoped-chronology-switcher'));
+
+  info.modes =
+    info.containers
+      .map(container =>
+        Array.from(container.classList)
+          .find(className => className.startsWith('scope-'))
+          .slice('scope-'.length));
 }
 
 function addScopedChronologyLinksPageHandlers() {
   const info = scopedChronologyLinksInfo;
+  const {session} = scopedChronologyLinksInfo;
 
   for (const [index, switcher] of info.switchers.entries()) {
     const currentContainer =
@@ -2978,15 +2991,40 @@ function addScopedChronologyLinksPageHandlers() {
     const nextContainer =
       atOffset(info.containers, index, +1, {wrap: true});
 
+    const nextMode =
+      atOffset(info.modes, index, +1, {wrap: true});
+
     switcher.addEventListener('click', domEvent => {
       domEvent.preventDefault();
+
       cssProp(currentContainer, 'display', 'none');
       cssProp(nextContainer, 'display', 'block');
+
+      session.selectedMode = nextMode;
     });
   }
 }
 
+function mutateScopedChronologyLinksContent() {
+  const info = scopedChronologyLinksInfo;
+
+  const {selectedMode} = info.session;
+
+  if (info.modes.includes(selectedMode)) {
+    const selectedIndex = info.modes.indexOf(selectedMode);
+
+    for (const [index, container] of info.containers.entries()) {
+      if (index === selectedIndex) {
+        cssProp(container, 'display', 'block');
+      } else {
+        cssProp(container, 'display', 'none');
+      }
+    }
+  }
+}
+
 clientSteps.getPageReferences.push(getScopedChronologyLinksReferences);
+clientSteps.mutatePageContent.push(mutateScopedChronologyLinksContent);
 clientSteps.addPageListeners.push(addScopedChronologyLinksPageHandlers);
 
 // Group contributions table ------------------------------