Skip to content

Commit

Permalink
support auto expanding to a given level at the navigation tree
Browse files Browse the repository at this point in the history
  • Loading branch information
tamlok committed May 19, 2021
1 parent e8d8d8d commit 97e2d88
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="generator" content="Viki">

<title>Viki - A simple Wiki page in Markdown from notebook of VNote</title>
<link id="favicon" rel="icon" href="https://github.com/tamlok/viki/raw/master/resources/viki.ico">
<link id="favicon" rel="icon" href="https://github.com/vnotex/viki/raw/master/resources/viki.ico">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css">
Expand Down
4 changes: 2 additions & 2 deletions dist/js/viki.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions dist/navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
},
{
"text": "Notebook",
"target": "vx.json",
"navi": true
"target": "abc/vx.json",
"navi": true,
"navi_expand_level": 1
}
],
"actions":
[
{
"text": "Viki",
"icon": "css/viki_white.svg",
"target": "https://tamlok.github.io/viki/"
"target": "https://vnotex.github.io/viki/"
}
]
}
2 changes: 1 addition & 1 deletion dist/viki.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"brand": "viki",
"title": "Viki - A simple Wiki page in Markdown from notebook of VNote",
"favicon": "https://github.com/tamlok/viki/raw/master/resources/viki.ico",
"favicon": "https://github.com/vnotex/viki/raw/master/resources/viki.ico",
"footer": "",
"show_suffix": false,
"load_before_search": true,
Expand Down
2 changes: 1 addition & 1 deletion js/configworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Config {
this.brand = "Viki";
this.brandIcon = "";
this.title = "Viki - A simple Wiki page in Markdown from notebook of VNote";
this.favicon = "https://github.com/tamlok/viki/raw/master/resources/viki.ico";
this.favicon = "https://github.com/vnotex/viki/raw/master/resources/viki.ico";
this.footer = "";
// Whether show suffix in navigation panel.
this.showSuffix = false;
Expand Down
3 changes: 2 additions & 1 deletion js/contentworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class ContentWorker extends Worker {
let navier = new NavigationRenderer(container, this, {
showSuffix: this.viki.config.showSuffix,
loadBeforeSearch: this.viki.config.loadBeforeSearch,
fuzzySearch: this.viki.config.fuzzySearch
fuzzySearch: this.viki.config.fuzzySearch,
expandLevel: info.naviExpandLevel
});

if (info.naviIndex &&
Expand Down
2 changes: 1 addition & 1 deletion js/footerworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FooterWorker extends Worker {
/* ATTENTION: As an additional aggrement to the license, removing or hiding
the following footer is not allowed.
*/
let vikiFooter = `Generated by <em><a href="https://tamlok.github.io/viki/">Viki</a></em>.`;
let vikiFooter = `Generated by <em><a href="https://vnotex.github.io/viki/">Viki</a></em>.`;
let vikiP = $(`<p class="viki-footer-row viki-footer-viki">${vikiFooter}</p>`);
container.append(vikiP);

Expand Down
10 changes: 10 additions & 0 deletions js/navigationrenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class NavigationRenderer {
// showSuffix: whether show suffix.
// loadBeforeSearch: whether load all nodes before a search.
// fuzzySearch: whether do a fuzzy search.
// expandLevel: auto expanded level on start.
this.config = p_config;
}

Expand Down Expand Up @@ -51,6 +52,7 @@ class NavigationRenderer {

let showSuffix = this.config.showSuffix;
let fuzzySearch = this.config.fuzzySearch;
let expandLevel = this.config.expandLevel;

tree.on('activate_node.jstree', (p_e, p_data) => {
let node = p_data.node;
Expand All @@ -66,6 +68,14 @@ class NavigationRenderer {
// Expand to the target node.
this.expandToNodeByPath(this.target);
}
}).on('load_node.jstree', (p_e, p_data) => {
let level = p_data.node.parents.length;
if (level < expandLevel) {
// Open its children.
for (let i = 0; i < p_data.node.children.length; ++i) {
this.fileTree.jstree(true).open_node(p_data.node.children[i]);
}
}
}).jstree({
"core": {
"themes": {
Expand Down
8 changes: 8 additions & 0 deletions js/naviworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class NaviItem {
// If @navi is true, this hold the start page of that navigation item.
this.naviIndex = "";

// The auto expand level of the navi tree on start.
this.naviExpandLevel = 1;

// Only 2 levels.
// If not empty, only the text filed of this item is valid.
this.children = [];
Expand All @@ -41,6 +44,10 @@ class NaviItem {
this.naviIndex = p_jobj.navi_index;
}

if (this.navi && p_jobj.navi_expand_level != null) {
this.naviExpandLevel = p_jobj.navi_expand_level;
}

if (!this.target) {
if (!p_jobj.children || p_jobj.children.length == 0) {
return false;
Expand Down Expand Up @@ -296,6 +303,7 @@ class NaviWorker extends Worker {
if (activeItem.navi) {
info.naviFile = activeItem.target;
info.naviIndex = info.baseUrl + activeItem.naviIndex;
info.naviExpandLevel = activeItem.naviExpandLevel;
}
}

Expand Down
3 changes: 3 additions & 0 deletions js/vikiinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class VikiInfo {
// Base URL prepended.
this.naviIndex = '';

// Auto expand level of the navigation tree on start.
this.naviExpandLevel = 1;

// Data of the target file.
this.data = null;

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "viki",
"version": "2.0.1",
"version": "3.2.0",
"description": "A simple Wiki page in Markdown from notebook of VNote.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tamlok/viki.git"
"url": "git+https://github.com/vnotex/viki.git"
},
"keywords": [
"markdown",
Expand All @@ -17,9 +17,9 @@
"author": "Le Tan",
"license": "MIT",
"bugs": {
"url": "https://github.com/tamlok/viki/issues"
"url": "https://github.com/vnotex/viki/issues"
},
"homepage": "https://github.com/tamlok/viki#readme",
"homepage": "https://github.com/vnotex/viki#readme",
"devDependencies": {
"@babel/core": "^7.1.5",
"@babel/preset-env": "^7.1.5",
Expand Down
2 changes: 1 addition & 1 deletion viki.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="generator" content="Viki">

<title>Viki - A simple Wiki page in Markdown from notebook of VNote</title>
<link id="favicon" rel="icon" href="https://github.com/tamlok/viki/raw/master/resources/viki.ico">
<link id="favicon" rel="icon" href="https://github.com/vnotex/viki/raw/master/resources/viki.ico">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css">
Expand Down

0 comments on commit 97e2d88

Please sign in to comment.