Przeglądaj źródła

Add anchor links

simov 8 lat temu
rodzic
commit
fb9c33f51f
2 zmienionych plików z 24 dodań i 5 usunięć
  1. 20 5
      content/content.js
  2. 4 0
      css/content.css

+ 20 - 5
content/content.js

@@ -41,6 +41,8 @@ var oncreate = {
     }
 
     setTimeout(() => Prism.highlightAll(), 20)
+
+    anchors()
   }
 }
 
@@ -146,11 +148,17 @@ function scroll () {
   })
 }
 
-if (document.readyState === 'complete') {
-  mount()
-}
-else {
-  window.addEventListener('DOMContentLoaded', mount)
+function anchors () {
+  Array.from($('#_html').childNodes)
+  .filter((node) => /h[1-6]/i.test(node.tagName))
+  .forEach((node) => {
+    var a = document.createElement('a')
+    a.className = 'anchor'
+    a.name = node.id
+    a.href = '#' + node.id
+    a.innerHTML = '<span class="octicon octicon-link"></span>'
+    node.prepend(a)
+  })
 }
 
 var toc = (
@@ -183,3 +191,10 @@ var toc = (
     }
     return html
   }, '<div id="_toc"><div id="_ul">') + '</div></div>'
+
+if (document.readyState === 'complete') {
+  mount()
+}
+else {
+  window.addEventListener('DOMContentLoaded', mount)
+}

Plik diff jest za duży
+ 4 - 0
css/content.css


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików