From 8e6061ff2c8e7aa0f901168ab6b05b12e95246d6 Mon Sep 17 00:00:00 2001
From: weru <fromweru@gmail.com>
Date: Tue, 06 Apr 2021 23:40:30 +0000
Subject: [PATCH] update helpers

---
 assets/js/index.js     |   22 ++++++++++++----------
 assets/js/variables.js |    1 +
 exampleSite/go.mod     |    2 +-
 exampleSite/go.sum     |    2 ++
 assets/js/code.js      |    7 +++----
 5 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/assets/js/code.js b/assets/js/code.js
index 3088550..021d355 100644
--- a/assets/js/code.js
+++ b/assets/js/code.js
@@ -91,7 +91,7 @@
     if(lastLinePos !== 0) {
       maxCodeBlockHeight = `${lastLinePos}px`;
       const codeBlock = lines[0].parentNode;
-      const outerBlock = codeBlock.closest('.highlight');
+      const outerBlock = codeBlock.closest(`.${highlight}`);
       const isExpanded = containsClass(outerBlock, panelExpanded);
       if(!isExpanded) {
         codeBlock.dataset.height = maxCodeBlockHeight;
@@ -120,7 +120,7 @@
     pushClass(expandDot, panelFrom);
     expandDot.title = "Toggle code block expand";
     expandDot.textContent = "...";
-    const outerBlock = block.closest('.highlight');
+    const outerBlock = block.closest(`.${highlight}`);
     window.setTimeout(function(){
       const expandIcon = outerBlock.nextElementSibling.lastElementChild;
       deleteClass(expandIcon, panelHide);
@@ -220,8 +220,7 @@
     return target.matches(`.${id}`) || target.closest(`.${id}`);
   }
 
-  function showActive(target, targetClass,activeClass = 'active') {
-    const active = activeClass;
+  function showActive(target, targetClass) {
     const targetElement = target.matches(`.${targetClass}`) ? target : target.closest(`.${targetClass}`);
 
     deleteClass(targetElement, active);
diff --git a/assets/js/index.js b/assets/js/index.js
index a85c35c..40edb03 100644
--- a/assets/js/index.js
+++ b/assets/js/index.js
@@ -48,19 +48,21 @@
 
 function featureHeading(){
   // show active heading at top.
+  const linkClass = "section_link";
+  const titleClass = "section_title";
   const parent = elem(".aside");
-  let activeHeading = elem(".section_link.active");
-  activeHeading = activeHeading ? activeHeading : elem(".section_title.active");
-  parent.scroll({
-    top: activeHeading.offsetTop,
-    left: 0,
-    // behavior: 'smooth'
-  });
+  if(parent) {
+    let activeHeading = elem(`.${linkClass}.${active}`);
+    activeHeading = activeHeading ? activeHeading : elem(`.${titleClass}.${active}`);
+    parent.scroll({
+      top: activeHeading.offsetTop,
+      left: 0,
+      // behavior: 'smooth'
+    });
+  }
 }
 
 function activeHeading(position, listLinks) {
-  let active = 'active';
-
   let linksToModify = Object.create(null);
   linksToModify.active = listLinks.filter(function(link) {
     return containsClass(link, active);
@@ -102,7 +104,7 @@
           const tocItems = Array.from(toc.children[0].children);
 
           const previousHeading = toc.previousElementSibling;
-          previousHeading.matches('.active') ? pushClass(toc, tocActive) : false;
+          previousHeading.matches(`.${active}`) ? pushClass(toc, tocActive) : false;
 
           tocItems.forEach(function(item){
             pushClass(item, 'toc_item');
diff --git a/assets/js/variables.js b/assets/js/variables.js
index 933f86f..54d55b1 100644
--- a/assets/js/variables.js
+++ b/assets/js/variables.js
@@ -3,6 +3,7 @@
 const toggleId = 'toggle';
 const showId = 'show';
 const menu = 'menu';
+const active = 'active';
 const rootURL = window.location.protocol + "//" + window.location.host;
 const searchFieldClass = '.search_field';
 const searchClass = '.search';
diff --git a/exampleSite/go.mod b/exampleSite/go.mod
index 7428967..2f6aebd 100644
--- a/exampleSite/go.mod
+++ b/exampleSite/go.mod
@@ -2,4 +2,4 @@
 
 go 1.15
 
-require github.com/onweru/compose v0.0.0-20210330103531-e7e0ba391d6a // indirect
+require github.com/onweru/compose v0.0.0-20210406232155-ff1e43943280 // indirect
diff --git a/exampleSite/go.sum b/exampleSite/go.sum
index b855bb7..baf6dfd 100644
--- a/exampleSite/go.sum
+++ b/exampleSite/go.sum
@@ -154,3 +154,5 @@
 github.com/onweru/compose v0.0.0-20210312153401-7f1c7da6d155/go.mod h1:tf1kQIBUcwJ/3mRFU5eiMrMvsDScVTK2IEFsZE3hZOc=
 github.com/onweru/compose v0.0.0-20210330103531-e7e0ba391d6a h1:rpCp0Sg4jjcM1EwdFq3mYoMXz/X3ejm1YXPR8ONetUw=
 github.com/onweru/compose v0.0.0-20210330103531-e7e0ba391d6a/go.mod h1:tf1kQIBUcwJ/3mRFU5eiMrMvsDScVTK2IEFsZE3hZOc=
+github.com/onweru/compose v0.0.0-20210406232155-ff1e43943280 h1:CFctzrbQxiwVhPZUjAiwIXYg3RfdeF8koX10fJBoH/Y=
+github.com/onweru/compose v0.0.0-20210406232155-ff1e43943280/go.mod h1:tf1kQIBUcwJ/3mRFU5eiMrMvsDScVTK2IEFsZE3hZOc=

--
Gitblit v1.10.0