Skip to content

Commit

Permalink
feat: 添加 hasToolbar 配置,可以隐藏按钮工具栏;添加 Anchors 模块的独立调用实例;
Browse files Browse the repository at this point in the history
  • Loading branch information
yaohaixiao committed Sep 23, 2023
1 parent f807da0 commit b5ec0d4
Show file tree
Hide file tree
Showing 34 changed files with 344 additions and 65 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ outline.js 的支持的滚动元素可以是 Window 窗口,也可以是某个
* sticky 定位:[https://yaohaixiao.github.io/outline.js/sticky.html](https://yaohaixiao.github.io/outline.js/sticky.html)

![fixed 定位](https://yaohaixiao.github.io/outline.js/img/fixed.png)
* fixed 定位:[https://yaohaixiao.github.io/outline.js/fixed.html](https://yaohaixiao.github.io/outline.js/fixed.html)
* fixed 定位(不显示按钮工具栏)[https://yaohaixiao.github.io/outline.js/fixed.html](https://yaohaixiao.github.io/outline.js/fixed.html)

### DOM 元素滚动

![flex 布局](https://yaohaixiao.github.io/outline.js/img/flex.png)
* flex 布局:[https://yaohaixiao.github.io/outline.js/flex.html](https://yaohaixiao.github.io/outline.js/flex.html)
* flex 布局(超长文章)[https://yaohaixiao.github.io/outline.js/flex.html](https://yaohaixiao.github.io/outline.js/flex.html)

### Anchors 模块独立调用

* Anchors 模块(仅给文章的标题添加):[https://yaohaixiao.github.io/outline.js/anchors.html](https://yaohaixiao.github.io/outline.js/anchors.html)

## 浏览器支持

Expand Down Expand Up @@ -224,6 +226,8 @@ const outline = new Outline({
// 当值为 false 时,则采用高亮当前章节标题的链接文字并加粗文字
// 如果喜欢更简洁的高亮效果,可以选择设置为 false
animationCurrent: true,
// 是否显示侧边的按钮工具栏
hasToolbar: true,
// 标题图标链接的 URL 地址
// (默认)没有设置定制,点击链接页面滚动到标题位置
// 设置了链接地址,则不会滚动定位
Expand Down Expand Up @@ -478,6 +482,7 @@ Outline.DEFAULTS = {
placement: 'rtl',
showCode: true,
animationCurrent: true,
hasToolbar: true,
anchorURL: '',
stickyHeight: 0,
homepage: '',
Expand Down
21 changes: 21 additions & 0 deletions api/pug/anchors.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
doctype html
html(lang='en')
head
include ./meta
title outline.js - 自动生成文章导读(Table of Contents)导航的 JavaScript 工具
link(href="css/example.min.css" rel="stylesheet")
body
.paper
header#header.header
h1.title Outline.js
article#article.article
main#main.article__main
include ./example
h2 License
p JavaScript Code Licensed under MIT License.
p API Documentation Licensed under CC BY 3.0
footer.footer
include ./footer
script(src="js/anchors.min.js")
script.
new Anchors(Anchors.DEFAULTS)
1 change: 1 addition & 0 deletions api/pug/fixed.pug
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ html(lang='en')
defaults.parentElement = '#aside'
defaults.stickyHeight = 86
defaults.homepage = './index.html'
defaults.hasToolbar = false
defaults.afterSticky = function(closed, isStickying) {
const $nav = this.$el
const BORDER_RIGHT = 'utils-border-right'
Expand Down
2 changes: 1 addition & 1 deletion api/pug/options/animationCurrent.pug
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
section.section
header.section__header
h.section__h3 animationCurrent
h3.section__h3 animationCurrent
div.section__content
h4.section__h4 Description
dl.section__dl
Expand Down
15 changes: 15 additions & 0 deletions api/pug/options/hasToolbar.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
section.section
header.section__header
h3.section__h3 hasToolbar
div.section__content
h4.section__h4 Description
dl.section__dl
dt.section__dt Type:
dd.section__dd Boolean
dl.section__dl
dt.section__dt Default:
dd.section__dd true
p 可选,是否显示侧边的按钮工具栏:
ul
li true - 显示按钮工具栏(默认值);
li false - 不显示按钮工具栏;
44 changes: 23 additions & 21 deletions api/pug/options/section.pug
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@ section.section
h2.section__title Options
div.section__content
p outline.js 有者丰富的配置选项,以便适应不同的展示方式。
include articleElement
include title
include scrollElement
include position
include parentElement
include placement
include stickyHeight
include showCode
include animationCurrent
include anchorURL
include homepage
include git
include tags
include issues
include tools
include print
include customClass
include afterScroll
include afterSticky
include afterToggle
include chpaterTextFilter
include ./articleElement
include ./selector
include ./title
include ./scrollElement
include ./position
include ./parentElement
include ./placement
include ./stickyHeight
include ./showCode
include ./animationCurrent
include ./hasToolbar
include ./anchorURL
include ./homepage
include ./git
include ./tags
include ./issues
include ./tools
include ./print
include ./customClass
include ./afterScroll
include ./afterSticky
include ./afterToggle
include ./chpaterTextFilter
2 changes: 1 addition & 1 deletion api/pug/options/showCode.pug
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
section.section
header.section__header
h.section__h3 showCode
h3.section__h3 showCode
div.section__content
h4.section__h4 Description
dl.section__dl
Expand Down
2 changes: 2 additions & 0 deletions api/pug/properties/defaults.pug
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ section.section
stickyHeight: 0,
// 是否显示标题编号
showCode: true,
// 是否显示侧边的按钮工具栏
hasToolbar: true,
// 指定是否采用动画定位高亮当前的章节标题,默认值:true
// 当值为 false 时,则采用高亮当前章节标题的链接文字并加粗文字
// 如果喜欢更简洁的高亮效果,可以选择设置为 false
Expand Down
50 changes: 50 additions & 0 deletions build/rollup.config.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,55 @@ export default [
sourcemap: true
},
plugins: PLUGIN_CONFIG
},
{
input: './anchors.js',
output: {
name: 'Anchors',
file: './docs/js/anchors.min.js',
format: 'umd',
sourcemap: true
},
plugins: PLUGIN_CONFIG
},
{
input: './chapters.js',
output: {
name: 'Chapters',
file: './docs/js/chapters.min.js',
format: 'umd',
sourcemap: true
},
plugins: PLUGIN_CONFIG
},
{
input: './drawer.js',
output: {
name: 'Drawer',
file: './docs/js/drawer.min.js',
format: 'umd',
sourcemap: true
},
plugins: PLUGIN_CONFIG
},
{
input: './toolbar.js',
output: {
name: 'Toolbar',
file: './docs/js/toolbar.min.js',
format: 'umd',
sourcemap: true
},
plugins: PLUGIN_CONFIG
},
{
input: './message.js',
output: {
name: 'Message',
file: './docs/js/message.min.js',
format: 'umd',
sourcemap: true
},
plugins: PLUGIN_CONFIG
}
]
11 changes: 0 additions & 11 deletions build/rollup.config.lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,5 @@ export default [
sourcemap: true
},
plugins: PLUGIN_CONFIG
},
// build for documentation
{
input: './outline.js',
output: {
name: 'Outline',
file: './docs/js/outline.min.js',
format: 'umd',
sourcemap: true
},
plugins: PLUGIN_CONFIG
}
]
2 changes: 1 addition & 1 deletion chapters.min.js.map

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions docs/anchors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="keywords" content="outline.js,Automatic Create,Article,Outline,JavaScript,Toolkit"><meta name="description" content="outline.js - 自动生成文章导读(Table of Contents)导航的 JavaScript 工具。会自动分析文章中的标题( h1~h6 )标签,并生成文章段落层次结构的导读导航菜单。"><link rel="shortcut icon" href="./favicon.ico"><title>outline.js - 自动生成文章导读(Table of Contents)导航的 JavaScript 工具</title><link href="css/example.min.css" rel="stylesheet"></head><body><div class="paper"><header class="header" id="header"><h1 class="title">Outline.js</h1></header><article class="article" id="article"><main class="article__main" id="main"><p>outline.js - 自动生成文章导读(Table of Contents)导航的 JavaScript 工具。会自动分析文章中的标题( h1~h6 )标签,并生成文章段落层次结构的导读导航菜单。</p><h2>创作灵感</h2><p>AnchorJS 是 outline.js 的创作灵感来源。既然 AnchorJS 可创建标题的链接,为什么不直接给文章生成一个文章导读(Table of Contents)导航呢? 于是就有了outline.js。</p><h2>特点</h2><ul><li>原生 JavaScript 编写,无需任何依赖;</li><li>支持 UMD 规范;</li><li>支持 E6 模块,提供功能独立的 ES6 模块;<ul><li>Anchors 模块:类似 AnchorJS 基础功能模块,自动分析段落层级;</li><li>Drawer 模块:独立的侧滑窗口模块;</li><li>Chapters 模块:独立的导航菜单模块;</li><li>Toolbar 模块:独立的固定定位的工具栏模块;</li></ul></li><li>拥有 AnchorJS 基础功能;</li><li>支持中文和英文标题文字生成ID;</li><li>支持生成独立的侧边栏导航菜单;</li><li>支持直接在文章中生成文章导读导航;</li><li>自动分析标题关系,生成段落层级索引值;</li><li>可以作为 jQuery 插件使用;</li><li>界面简洁大方;</li><li>配置灵活,丰富,让你随心所欲掌控 outline.js;</li></ul><h2>安装说明</h2><p>outline.js 提供多种安装方式的支持: npm 安装、加载 CDN 资源、以及本地资源调用。</p><h4>npm install</h4><pre><code>$ npm install -S @yaohaixiao/outline.js</code></pre><h3>CDN 调用</h3><pre><code>&lt;script&nbsp;src=&quot;https://cdn.jsdelivr.net/gh/yaohaixiao/outline.js/outline.min.js&quot;&gt;&lt;/script&gt;</code></pre><h3>调用本地JS文件</h3><pre><code>&lt;script&nbsp;src=&quot;path/to/outline.min.js&quot;&gt;&lt;/script&gt;</code></pre><h2>使用说明</h2><p>outline.js 既支持在 node.js 环境中以 CommonJS 模块调用,也支持 ES6 模块方式加载。</p><pre><code>// Node.js 环境中使用
const Outline = require('@yaohaixiao/outline.js')

// 作为 ES6 模块使用
import Outline from '@yaohaixiao/outline.js/src/outline'
// 调用其他独立模块
import Anchors from '@yaohaixiao/outline.js/src/anchors'
import Chapters from '@yaohaixiao/outline.js/src/chapters'
import Drawer from '@yaohaixiao/outline.js/src/drawer'
import Toolbar from '@yaohaixiao/outline.js/src/toolbar'

// 创建 Outline 实例
// 2.0.0 调整了配置参数,配置更加简单
const outline = new Outline({
// 文章显示区域的 DOM 元素或者选择器字符串
articleElement: '#article',
// 要收集的标题选择器
selector: 'h2,h3,h4,h5,h6',
// 负责文章区域滚动的元素
// String 类型 - 选择器字符串,默认值:html,body(window窗口)
// HTMLElement 类型 - DOM 元素
scrollElement: 'html,body',
// 文章导读菜单的位置
// relative - (默认值)创建独立的侧滑菜单
// sticky - 导航菜单将以 sticky 模式布局(需要确保菜单插入位置支持 sticky 模式布局)
// fixed - 导航菜单将以 fixed 模式布局,会自动监听滚动位置,模拟 sticky 布局
// sticky 和 fixed 布局时,需要设置 parentElement
// 2.0.0 暂时不支持在文章开始位置插入 chapters 导航菜单
position: 'sticky',
// 设置 position: relative 时,placment 定义侧滑菜单和 toolbar 导航位置:
// rtl - 菜单位置在窗口右侧,滑动动画为:right to left
// ltr - 菜单位置在窗口左侧,滑动动画为:left to right
// ttb - 菜单位置在窗口上方,滑动动画为:top to bottom
// btt - 菜单位置在窗口下方,滑动动画为:bottom to top
placement: '',
// 导航菜单将要插入的位置(DOM 元素)
// String 类型 - 选择器字符串
// HTMLElement 类型 - 插入的 DOM 元素
// 仅在 position 设置为 sticky 和 fixed 布局时有效
parentElement: '#aside',
// 是否显示段落章节编号
showCode: true,
// 标题图标链接的 URL 地址
// (默认)没有设置定制,点击链接页面滚动到标题位置
// 设置了链接地址,则不会滚动定位
anchorURL: '',
// DIYer的福利
// 独立侧滑菜单时,customClass 会追加到 drawer 侧滑窗口组件
// 在文章中显示导航菜单时,customClass 会追加到 chapters 导航菜单
customClass
});

// 可以在创建导航后,重置配置信息,重新生成新的导航
Outline.reload({
// 调整位直接在文章内生成导航
position: 'sticky',
articleElement: '#article'
})</code></pre><h2>License</h2><p>JavaScript Code Licensed under MIT License.</p><p>API Documentation Licensed under CC BY 3.0</p></main></article><footer class="footer"><footer class="main__footer" id="footer"><p>Copyright &copy; 2023 <a href="https://github.com/yaohaixiao">Robert Yao</a>, all right reserved.</p><p>Code licensed under&nbsp;<a href="http://opensource.org/licenses/mit-license.html">MIT License</a></p><p>Documentation licensed under&nbsp;
<a href="http://creativecommons.org/licenses/by/3.0/">CC BY 3.0</a></p><p><a href="https://github.com/yaohaixiao/outline.js">View on GitHub</a> ·
<a href="https://github.com/yaohaixiao/outline.js/issues">Issues</a></p></footer></footer></div><script src="js/anchors.min.js"></script><script>new Anchors(Anchors.DEFAULTS)</script></body></html>
11 changes: 10 additions & 1 deletion docs/fixed.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
// Customize Selector
const outline = new Outline({
articleElement: $('#main')
})</code></pre></div></section><section class="section"><header class="section__header"><h3 class="section__h3">selector</h3></header><div class="section__content"><h4 class="section__h4">Description</h4><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="section__dd">String</dd></dl><dl class="section__dl"><dt class="section__dt">Default:</dt><dd class="section__dd">'h1,h2,h3,h4,h5,h6'</dd></dl><p>可选,用来指定 article 节点下,要生成导航的标题标签的选择器。</p><pre class="section__pre"><code class="section__code">// Default selector
new Outline(Outline.DEFAULTS)

// Customize selector
new Outline({
selector: 'h2'
})</code></pre></div></section><section class="section"><header class="section__header"><h3 class="section__h3">title</h3></header><div class="section__content"><h4 class="section__h4">Description</h4><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="section__dd">String|Boolean</dd></dl><dl class="section__dl"><dt class="section__dt">Default:</dt><dd class="section__dd">'目录'</dd></dl><p>可选,用来指定文章导读导航菜单的标题文字。设置空字符串或者 false,则不显示标题。在插入导航菜单的 DOM 元素已有标题时,可以设置 title: '' 或者 false。</p><p>说明:本 API 文档的导航菜单便是使用 outline.js 生成,并且没有设置 title。</p><pre class="section__pre"><code class="section__code">(function(){
const defaults = Outline.DEFAULTS
let outline
Expand Down Expand Up @@ -113,7 +119,7 @@
// 设置 stickyHeight(outline.js 的示例页面的主标题元素的高度)
defaults.stickyHeight = 86
// 默认生成独立的侧滑弹窗导航菜单
new Outline(defaults)</code></pre></div></section><section class="section"><header class="section__header"><h class="section__h3">showCode</h></header><div class="section__content"><h4 class="section__h4">Description</h4><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="section__dd">Boolean</dd></dl><dl class="section__dl"><dt class="section__dt">Default:</dt><dd class="section__dd">true</dd></dl><p>可选,是否显示段落章节编号:</p><ul><li>true - 显示编号(默认值);</li><li>false - 不显示编号;</li></ul></div></section><section class="section"><header class="section__header"><h class="section__h3">animationCurrent</h></header><div class="section__content"><h4 class="section__h4">Description</h4><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="section__dd">Boolean</dd></dl><dl class="section__dl"><dt class="section__dt">Default:</dt><dd class="section__dd">true</dd></dl><p>可选,是否采用动画定位高亮当前的章节标题:</p><ul><li>true - 采用动画定位高亮(默认值);</li><li>false - 采用高亮当前章节标题的链接文字并加粗文字;</li></ul></div></section><section class="section"><header class="section__header"><h3 class="section__h3">anchorURL</h3></header><div class="section__content"><h4 class="section__h4">Description</h4><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="section__dd">String</dd></dl><dl class="section__dl"><dt class="section__dt">Default:</dt><dd class="section__dd">''</dd></dl><p>可选,用来指定文章标题锚点链接图标的链接地址:</p><pre class="section__pre"><code class="section__code">// Default URL - 默认链接,点击图标,页面会滚动到当前标题位置
new Outline(defaults)</code></pre></div></section><section class="section"><header class="section__header"><h3 class="section__h3">showCode</h3></header><div class="section__content"><h4 class="section__h4">Description</h4><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="section__dd">Boolean</dd></dl><dl class="section__dl"><dt class="section__dt">Default:</dt><dd class="section__dd">true</dd></dl><p>可选,是否显示段落章节编号:</p><ul><li>true - 显示编号(默认值);</li><li>false - 不显示编号;</li></ul></div></section><section class="section"><header class="section__header"><h3 class="section__h3">animationCurrent</h3></header><div class="section__content"><h4 class="section__h4">Description</h4><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="section__dd">Boolean</dd></dl><dl class="section__dl"><dt class="section__dt">Default:</dt><dd class="section__dd">true</dd></dl><p>可选,是否采用动画定位高亮当前的章节标题:</p><ul><li>true - 采用动画定位高亮(默认值);</li><li>false - 采用高亮当前章节标题的链接文字并加粗文字;</li></ul></div></section><section class="section"><header class="section__header"><h3 class="section__h3">hasToolbar</h3></header><div class="section__content"><h4 class="section__h4">Description</h4><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="section__dd">Boolean</dd></dl><dl class="section__dl"><dt class="section__dt">Default:</dt><dd class="section__dd">true</dd></dl><p>可选,是否显示侧边的按钮工具栏:</p><ul><li>true - 显示按钮工具栏(默认值);</li><li>false - 不显示按钮工具栏;</li></ul></div></section><section class="section"><header class="section__header"><h3 class="section__h3">anchorURL</h3></header><div class="section__content"><h4 class="section__h4">Description</h4><dl class="section__dl"><dt class="section__dt">Type:</dt><dd class="section__dd">String</dd></dl><dl class="section__dl"><dt class="section__dt">Default:</dt><dd class="section__dd">''</dd></dl><p>可选,用来指定文章标题锚点链接图标的链接地址:</p><pre class="section__pre"><code class="section__code">// Default URL - 默认链接,点击图标,页面会滚动到当前标题位置
new Outline()

// Customize URL - 直接打开链接了
Expand Down Expand Up @@ -774,6 +780,8 @@
stickyHeight: 0,
// 是否显示标题编号
showCode: true,
// 是否显示侧边的按钮工具栏
hasToolbar: true,
// 指定是否采用动画定位高亮当前的章节标题,默认值:true
// 当值为 false 时,则采用高亮当前章节标题的链接文字并加粗文字
// 如果喜欢更简洁的高亮效果,可以选择设置为 false
Expand Down Expand Up @@ -1165,6 +1173,7 @@
defaults.parentElement = '#aside'
defaults.stickyHeight = 86
defaults.homepage = './index.html'
defaults.hasToolbar = false
defaults.afterSticky = function(closed, isStickying) {
const $nav = this.$el
const BORDER_RIGHT = 'utils-border-right'
Expand Down

0 comments on commit b5ec0d4

Please sign in to comment.