Skip to content

Commit

Permalink
fix(genji-notebook): jump through url link close: #54 (#59)
Browse files Browse the repository at this point in the history
* fix(genji-notebook): jump through url link close: #54

* chore: update to version 0.1.1
  • Loading branch information
pearmini committed Aug 15, 2022
1 parent 25650a1 commit 8ff0ec5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/genji-notebook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genji-notebook",
"version": "0.1.0",
"version": "0.1.1",
"description": "Interactive JavaScript Notebook.",
"bin": "bin/genji.js",
"repository": {
Expand Down
14 changes: 11 additions & 3 deletions packages/genji-notebook/public/$genji_components/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,19 +380,27 @@ export const Notebook = {
},
enableHashLinks() {
const A = this.$refs.container.getElementsByTagName("a");
for (const a of A) {
const notebookLink = (a) => {
const href = a.getAttribute("href");
if (!href.startsWith("#") && a.__enableHash !== true) {
return (
!href.startsWith("#") &&
!href.startsWith("http") &&
a._notebookLink !== true
);
};
for (const a of A) {
if (notebookLink(a)) {
a.onclick = (e) => {
e.preventDefault();
const href = a.getAttribute("href");
// Avoid NavigationDuplicated.
const relativeHref = href.replace(this.baseURL, "");
if (!this.$route.fullPath.includes(relativeHref)) {
this.$router.push(relativeHref);
}
this.jumpToAnchor();
};
a.__enableHash = true;
a._notebookLink = true;
}
}
},
Expand Down

0 comments on commit 8ff0ec5

Please sign in to comment.