sumba 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +13 -0
- package/.github/workflows/repo-lockdown.yml +24 -0
- package/.jsdoc.conf.json +45 -0
- package/LICENSE +1 -1
- package/README.md +40 -7
- package/docs/Sumba.html +3 -0
- package/docs/data/search.json +1 -0
- package/docs/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/global.html +3 -0
- package/docs/index.html +3 -0
- package/docs/index.js.html +538 -0
- package/docs/scripts/core.js +726 -0
- package/docs/scripts/core.min.js +23 -0
- package/docs/scripts/resize.js +90 -0
- package/docs/scripts/search.js +265 -0
- package/docs/scripts/search.min.js +6 -0
- package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/scripts/third-party/fuse.js +9 -0
- package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/scripts/third-party/hljs-original.js +5171 -0
- package/docs/scripts/third-party/hljs.js +1 -0
- package/docs/scripts/third-party/popper.js +5 -0
- package/docs/scripts/third-party/tippy.js +1 -0
- package/docs/scripts/third-party/tocbot.js +672 -0
- package/docs/scripts/third-party/tocbot.min.js +1 -0
- package/docs/static/bitcoin.jpeg +0 -0
- package/docs/static/home.md +25 -0
- package/docs/static/logo-ecosystem.png +0 -0
- package/docs/static/logo.png +0 -0
- package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
- package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
- package/docs/styles/clean-jsdoc-theme-light.css +482 -0
- package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
- package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
- package/docs/styles/clean-jsdoc-theme.min.css +1 -0
- package/extend/bajo/hook/{dobo.sumba-contact-form@after-record-create.js → dobo.sumba-contact-form@after-create-record.js} +3 -3
- package/extend/bajo/hook/{dobo.sumba-contact-form@before-record-create.js → dobo.sumba-contact-form@before-create-record.js} +3 -3
- package/extend/bajo/hook/{dobo.sumba-user@after-record-create.js → dobo.sumba-user@after-create-record.js} +3 -3
- package/extend/bajo/hook/dobo.sumba-user@after-record-validation.js +3 -3
- package/extend/bajo/hook/{dobo.sumba-user@after-record-update.js → dobo.sumba-user@after-update-record.js} +5 -5
- package/extend/bajo/hook/{dobo.sumba-user@before-record-create.js → dobo.sumba-user@before-create-record.js} +2 -2
- package/extend/bajo/hook/dobo.sumba-user@before-record-validation.js +3 -3
- package/extend/bajo/hook/{dobo.sumba-user@before-record-update.js → dobo.sumba-user@before-update-record.js} +2 -2
- package/extend/bajo/hook/dobo@before-count-record.js +8 -0
- package/extend/bajo/hook/{dobo@before-record-create.js → dobo@before-create-record.js} +6 -6
- package/extend/bajo/hook/dobo@before-find-one-record.js +8 -0
- package/extend/bajo/hook/{dobo@before-record-find.js → dobo@before-find-record.js} +10 -10
- package/extend/bajo/hook/dobo@before-get-record.js +23 -0
- package/extend/bajo/hook/dobo@before-remove-record.js +10 -0
- package/extend/bajo/hook/dobo@before-update-record.js +10 -0
- package/extend/bajo/hook/waibu-mpa.sumba@after-build-locals.js +0 -0
- package/extend/bajo/hook/waibu-mpa@pre-parsing.js +0 -0
- package/extend/bajo/hook/waibu-rest-api@pre-parsing.js +0 -0
- package/extend/bajo/hook/waibu-static@pre-parsing.js +0 -0
- package/extend/bajo/hook/waibu@after-app-boot.js +2 -2
- package/extend/bajo/hook/waibu@after-create-context.js +0 -0
- package/extend/bajo/hook/waibu@on-request.js +0 -0
- package/extend/bajo/intl/en-US.json +1 -0
- package/extend/bajo/intl/id.json +0 -0
- package/extend/bajoTemplate/layout/centered.html +0 -0
- package/extend/bajoTemplate/layout/default.html +0 -0
- package/extend/bajoTemplate/layout/error.html +0 -0
- package/extend/bajoTemplate/layout/info.html +0 -0
- package/extend/bajoTemplate/partial/403.html +0 -0
- package/extend/bajoTemplate/partial/_admin/reset-user-password.html +0 -0
- package/extend/bajoTemplate/partial/_mail/help-contact-form.html +0 -0
- package/extend/bajoTemplate/partial/_mail/help-contact-form.id.html +0 -0
- package/extend/bajoTemplate/partial/_mail/mystuff-change-password.html +0 -0
- package/extend/bajoTemplate/partial/_mail/mystuff-change-password.id.html +0 -0
- package/extend/bajoTemplate/partial/_mail/mystuff-reset-api-key.html +0 -0
- package/extend/bajoTemplate/partial/_mail/mystuff-reset-api-key.id.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-activation-success.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-activation-success.id.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-forgot-password-changed.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-forgot-password-changed.id.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-forgot-password-link.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-forgot-password-link.id.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-signup-success-active.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-signup-success-active.id.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-signup-success.html +0 -0
- package/extend/bajoTemplate/partial/_mail/user-signup-success.id.html +0 -0
- package/extend/bajoTemplate/partial/api-key-modal.html +0 -0
- package/extend/bajoTemplate/partial/app-launcher.html +0 -0
- package/extend/bajoTemplate/partial/help/contact-form/form.html +0 -0
- package/extend/bajoTemplate/partial/help/contact-form/success.html +0 -0
- package/extend/bajoTemplate/partial/help/trouble-tickets/add.html +0 -0
- package/extend/bajoTemplate/partial/help/trouble-tickets/details.html +0 -0
- package/extend/bajoTemplate/partial/help/trouble-tickets/list.html +0 -0
- package/extend/bajoTemplate/partial/layout/address.html +0 -0
- package/extend/bajoTemplate/partial/layout/breadcrumb.html +0 -0
- package/extend/bajoTemplate/partial/layout/footer.html +0 -0
- package/extend/bajoTemplate/partial/layout/more-info.html +0 -0
- package/extend/bajoTemplate/partial/layout/more-info.id.html +0 -0
- package/extend/bajoTemplate/partial/layout/navbar.html +0 -0
- package/extend/bajoTemplate/partial/layout/sidebar.html +0 -0
- package/extend/bajoTemplate/partial/layout/socmed.html +0 -0
- package/extend/bajoTemplate/partial/list-item/change-password.html +0 -0
- package/extend/bajoTemplate/partial/list-item/forgot-password.html +0 -0
- package/extend/bajoTemplate/partial/list-item/goto-home.html +0 -0
- package/extend/bajoTemplate/partial/list-item/member-links.html +0 -0
- package/extend/bajoTemplate/partial/list-item/oauth-signin.html +0 -0
- package/extend/bajoTemplate/partial/list-item/signin.html +0 -0
- package/extend/bajoTemplate/partial/list-item/signout.html +0 -0
- package/extend/bajoTemplate/partial/list-item/user-signup.html +0 -0
- package/extend/bajoTemplate/partial/list-item/your-profile.html +0 -0
- package/extend/bajoTemplate/partial/signin.html +0 -0
- package/extend/bajoTemplate/partial/signout.html +0 -0
- package/extend/bajoTemplate/partial/user/activation.html +0 -0
- package/extend/bajoTemplate/partial/user/forgot-password-nomail.id.md +0 -0
- package/extend/bajoTemplate/partial/user/forgot-password-nomail.md +0 -0
- package/extend/bajoTemplate/partial/user/forgot-password.html +0 -0
- package/extend/bajoTemplate/partial/user/fpl-invalid.html +0 -0
- package/extend/bajoTemplate/partial/user/fpl-invalid.id.md +0 -0
- package/extend/bajoTemplate/partial/user/fpl-invalid.md +0 -0
- package/extend/bajoTemplate/partial/user/fpl.html +0 -0
- package/extend/bajoTemplate/partial/user/signup/form.html +0 -0
- package/extend/bajoTemplate/partial/user/signup/success-mail.id.md +0 -0
- package/extend/bajoTemplate/partial/user/signup/success-mail.md +0 -0
- package/extend/bajoTemplate/partial/user/signup/success-nomail.id.md +0 -0
- package/extend/bajoTemplate/partial/user/signup/success-nomail.md +0 -0
- package/extend/bajoTemplate/partial/user/signup/success.html +0 -0
- package/extend/bajoTemplate/partial/your-stuff/change-password.html +0 -0
- package/extend/bajoTemplate/partial/your-stuff/profile/edit.html +0 -0
- package/extend/bajoTemplate/partial/your-stuff/profile/view.html +0 -0
- package/extend/bajoTemplate/partial/your-stuff/reset-api-key.html +0 -0
- package/extend/bajoTemplate/template/403.html +0 -0
- package/extend/bajoTemplate/template/_admin/reset-user-password.html +0 -0
- package/extend/bajoTemplate/template/_mail/help-contact-form.html +0 -0
- package/extend/bajoTemplate/template/_mail/mystuff-change-password.html +0 -0
- package/extend/bajoTemplate/template/_mail/mystuff-reset-api-key.html +0 -0
- package/extend/bajoTemplate/template/_mail/user-activation-success.html +0 -0
- package/extend/bajoTemplate/template/_mail/user-forgot-password-changed.html +0 -0
- package/extend/bajoTemplate/template/_mail/user-forgot-password-link.html +0 -0
- package/extend/bajoTemplate/template/_mail/user-signup-success-active.html +0 -0
- package/extend/bajoTemplate/template/_mail/user-signup-success.html +0 -0
- package/extend/bajoTemplate/template/help/contact-form/form.html +0 -0
- package/extend/bajoTemplate/template/help/contact-form/success.html +0 -0
- package/extend/bajoTemplate/template/help/trouble-tickets/add.html +0 -0
- package/extend/bajoTemplate/template/help/trouble-tickets/details.html +0 -0
- package/extend/bajoTemplate/template/help/trouble-tickets/list.html +0 -0
- package/extend/bajoTemplate/template/info/about-us.md +0 -0
- package/extend/bajoTemplate/template/info/cookie-policy.md +0 -0
- package/extend/bajoTemplate/template/info/privacy.md +0 -0
- package/extend/bajoTemplate/template/info/terms-conditions.md +0 -0
- package/extend/bajoTemplate/template/signin.html +0 -0
- package/extend/bajoTemplate/template/signout.html +0 -0
- package/extend/bajoTemplate/template/user/activation.html +0 -0
- package/extend/bajoTemplate/template/user/forgot-password.html +0 -0
- package/extend/bajoTemplate/template/user/fpl-invalid.html +0 -0
- package/extend/bajoTemplate/template/user/fpl.html +0 -0
- package/extend/bajoTemplate/template/user/signup/form.html +0 -0
- package/extend/bajoTemplate/template/user/signup/success.html +0 -0
- package/extend/bajoTemplate/template/your-stuff/change-password.html +0 -0
- package/extend/bajoTemplate/template/your-stuff/profile/edit.html +0 -0
- package/extend/bajoTemplate/template/your-stuff/profile/view.html +0 -0
- package/extend/bajoTemplate/template/your-stuff/reset-api-key.html +0 -0
- package/extend/dobo/feature/address.js +1 -1
- package/extend/dobo/feature/category.js +0 -0
- package/extend/dobo/feature/country.js +1 -1
- package/extend/dobo/feature/email.js +0 -0
- package/extend/dobo/feature/lat-lng.js +3 -3
- package/extend/dobo/feature/lat.js +2 -2
- package/extend/dobo/feature/lng.js +2 -2
- package/extend/dobo/feature/person-in-charge.js +0 -0
- package/extend/dobo/feature/phone.js +0 -0
- package/extend/dobo/feature/site-id.js +3 -3
- package/extend/dobo/feature/slug.js +7 -8
- package/extend/dobo/feature/social.js +0 -0
- package/extend/dobo/feature/status.js +2 -2
- package/extend/dobo/feature/team-id.js +3 -3
- package/extend/dobo/feature/ts.js +0 -0
- package/extend/dobo/feature/url.js +6 -6
- package/extend/dobo/feature/user-id.js +5 -5
- package/extend/dobo/fixture/contact-form-cat.json +0 -0
- package/extend/dobo/fixture/site.json +0 -4
- package/extend/dobo/fixture/team-user.json +0 -0
- package/extend/dobo/fixture/team.json +2 -1
- package/extend/dobo/fixture/ticket-cat.json +0 -0
- package/extend/dobo/fixture/user.json +0 -0
- package/extend/dobo/model/contact-form-cat.json +3 -0
- package/extend/dobo/model/contact-form.json +16 -0
- package/extend/dobo/model/download.json +19 -0
- package/extend/dobo/model/site-setting.json +8 -0
- package/extend/dobo/{schema → model}/site.json +4 -8
- package/extend/dobo/{schema → model}/team-user.json +5 -10
- package/extend/dobo/model/team.json +15 -0
- package/extend/dobo/model/ticket-cat.json +3 -0
- package/extend/dobo/model/ticket-detail.json +7 -0
- package/extend/dobo/model/ticket.json +18 -0
- package/extend/dobo/{schema → model}/user.json +14 -11
- package/extend/masohiSocketIo/middleware/server/auth.js +1 -1
- package/extend/sumba/route/anonymous.json +0 -0
- package/extend/sumba/route/secure.json +0 -0
- package/extend/waibuBootstrap/theme/component/factory/nav-dropdown-user.js +5 -5
- package/extend/waibuDb/schema/contact-form-cat.json +0 -0
- package/extend/waibuDb/schema/contact-form.json +0 -0
- package/extend/waibuDb/schema/download.js +1 -1
- package/extend/waibuDb/schema/site.json +2 -2
- package/extend/waibuDb/schema/team-user.js +2 -2
- package/extend/waibuDb/schema/team.json +0 -0
- package/extend/waibuDb/schema/ticket-cat.json +0 -0
- package/extend/waibuDb/schema/user.json +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/contact-form/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/contact-form-cat/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/download/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/reset-user-password.js +5 -6
- package/extend/waibuMpa/extend/waibuAdmin/route/session/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/site.js +25 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/team/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/team-user/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/ticket/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/ticket-cat/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/user/@action.js +0 -0
- package/extend/waibuMpa/route/access-token.js +1 -2
- package/extend/waibuMpa/route/help/contact-form.js +5 -5
- package/extend/waibuMpa/route/help/trouble-tickets/add.js +4 -4
- package/extend/waibuMpa/route/help/trouble-tickets/details/@id.js +5 -5
- package/extend/waibuMpa/route/help/trouble-tickets/list.js +2 -2
- package/extend/waibuMpa/route/info/@item.js +0 -0
- package/extend/waibuMpa/route/signin.js +0 -0
- package/extend/waibuMpa/route/signout.js +1 -14
- package/extend/waibuMpa/route/user/activation.js +4 -6
- package/extend/waibuMpa/route/user/forgot-password/@fpl.js +9 -10
- package/extend/waibuMpa/route/user/forgot-password.js +5 -7
- package/extend/waibuMpa/route/user/signup.js +4 -4
- package/extend/waibuMpa/route/your-stuff/change-password.js +5 -6
- package/extend/waibuMpa/route/your-stuff/download/@action.js +0 -0
- package/extend/waibuMpa/route/your-stuff/download/get.js +0 -0
- package/extend/waibuMpa/route/your-stuff/profile/edit.js +5 -5
- package/extend/waibuMpa/route/your-stuff/profile.js +2 -2
- package/extend/waibuMpa/route/your-stuff/reset-api-key.js +8 -9
- package/extend/waibuRestApi/route/info/get.js +2 -2
- package/extend/waibuRestApi/route/manage/team/model-builder.json +0 -0
- package/extend/waibuRestApi/route/manage/user/model-builder.json +0 -0
- package/extend/waibuRestApi/route/user/access-token/@type/create.js +0 -0
- package/extend/waibuRestApi/route/user/api-key/get.js +1 -2
- package/extend/waibuRestApi/route/your-stuff/api-key/get.js +1 -2
- package/extend/waibuRestApi/route/your-stuff/api-key/update.js +5 -6
- package/extend/waibuRestApi/route/your-stuff/change-password/update.js +2 -3
- package/extend/waibuRestApi/route/your-stuff/profile/get.js +2 -2
- package/extend/waibuRestApi/route/your-stuff/profile/update.js +3 -3
- package/extend/waibuSocketIo/middleware/server/auth.js +2 -3
- package/extend/waibuStatic/asset/user-profile.png +0 -0
- package/index.js +78 -54
- package/lib/check-iconset.js +4 -6
- package/lib/check-team.js +1 -1
- package/lib/check-theme.js +4 -7
- package/lib/check-user-id.js +4 -3
- package/lib/collect-redirects.js +0 -0
- package/lib/collect-routes.js +4 -4
- package/lib/collect-team.js +3 -3
- package/lib/lat-lng-hook.js +2 -2
- package/lib/password-rule.js +0 -0
- package/lib/reset-token.js +1 -1
- package/lib/token-schema.js +0 -0
- package/logo.png +0 -0
- package/package.json +41 -34
- package/wiki/CHANGES.md +6 -0
- package/wiki/CONFIG.md +2 -0
- package/wiki/CONTRIBUTING.md +5 -0
- package/wiki/DEV-GUIDE.md +1 -0
- package/wiki/ECOSYSTEM.md +28 -0
- package/wiki/GETTING-STARTED.md +1 -0
- package/wiki/USER-GUIDE.md +1 -0
- package/extend/bajo/hook/dobo@before-record-count.js +0 -8
- package/extend/bajo/hook/dobo@before-record-find-one.js +0 -8
- package/extend/bajo/hook/dobo@before-record-get.js +0 -23
- package/extend/bajo/hook/dobo@before-record-remove.js +0 -10
- package/extend/bajo/hook/dobo@before-record-update.js +0 -10
- package/extend/dobo/schema/contact-form-cat.json +0 -3
- package/extend/dobo/schema/contact-form.json +0 -20
- package/extend/dobo/schema/download.json +0 -24
- package/extend/dobo/schema/site-setting.json +0 -8
- package/extend/dobo/schema/team.json +0 -19
- package/extend/dobo/schema/ticket-cat.json +0 -3
- package/extend/dobo/schema/ticket-detail.json +0 -7
- package/extend/dobo/schema/ticket.json +0 -17
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
/* eslint no-var: off */
|
|
2
|
+
var defaultOptions = {
|
|
3
|
+
ignoreSelector: '.js-toc-ignore',
|
|
4
|
+
linkClass: 'toc-link',
|
|
5
|
+
extraLinkClasses: '',
|
|
6
|
+
activeLinkClass: 'is-active-link',
|
|
7
|
+
listClass: 'toc-list',
|
|
8
|
+
extraListClasses: '',
|
|
9
|
+
isCollapsedClass: 'is-collapsed',
|
|
10
|
+
collapsibleClass: 'is-collapsible',
|
|
11
|
+
listItemClass: 'toc-list-item',
|
|
12
|
+
activeListItemClass: 'is-active-li',
|
|
13
|
+
collapseDepth: 0,
|
|
14
|
+
scrollSmooth: true,
|
|
15
|
+
scrollSmoothDuration: 420,
|
|
16
|
+
scrollSmoothOffset: 0,
|
|
17
|
+
scrollEndCallback: function (e) { },
|
|
18
|
+
throttleTimeout: 50,
|
|
19
|
+
positionFixedSelector: null,
|
|
20
|
+
positionFixedClass: 'is-position-fixed',
|
|
21
|
+
fixedSidebarOffset: 'auto',
|
|
22
|
+
includeHtml: false,
|
|
23
|
+
includeTitleTags: false,
|
|
24
|
+
orderedList: true,
|
|
25
|
+
scrollContainer: null,
|
|
26
|
+
skipRendering: false,
|
|
27
|
+
headingLabelCallback: false,
|
|
28
|
+
ignoreHiddenElements: false,
|
|
29
|
+
headingObjectCallback: null,
|
|
30
|
+
basePath: '',
|
|
31
|
+
disableTocScrollSync: false
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function ParseContent(options) {
|
|
35
|
+
var reduce = [].reduce
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Get the last item in an array and return a reference to it.
|
|
39
|
+
* @param {Array} array
|
|
40
|
+
* @return {Object}
|
|
41
|
+
*/
|
|
42
|
+
function getLastItem(array) {
|
|
43
|
+
return array[array.length - 1]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get heading level for a heading dom node.
|
|
48
|
+
* @param {HTMLElement} heading
|
|
49
|
+
* @return {Number}
|
|
50
|
+
*/
|
|
51
|
+
function getHeadingLevel(heading) {
|
|
52
|
+
return +heading.nodeName.toUpperCase().replace('H', '')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get important properties from a heading element and store in a plain object.
|
|
57
|
+
* @param {HTMLElement} heading
|
|
58
|
+
* @return {Object}
|
|
59
|
+
*/
|
|
60
|
+
function getHeadingObject(heading) {
|
|
61
|
+
// each node is processed twice by this method because nestHeadingsArray() and addNode() calls it
|
|
62
|
+
// first time heading is real DOM node element, second time it is obj
|
|
63
|
+
// that is causing problem so I am processing only original DOM node
|
|
64
|
+
if (!(heading instanceof window.HTMLElement)) return heading
|
|
65
|
+
|
|
66
|
+
if (options.ignoreHiddenElements && (!heading.offsetHeight || !heading.offsetParent)) {
|
|
67
|
+
return null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const headingLabel = heading.getAttribute('data-heading-label') ||
|
|
71
|
+
(options.headingLabelCallback ? String(options.headingLabelCallback(heading.textContent)) : heading.textContent.trim())
|
|
72
|
+
var obj = {
|
|
73
|
+
id: heading.id,
|
|
74
|
+
children: [],
|
|
75
|
+
nodeName: heading.nodeName,
|
|
76
|
+
headingLevel: getHeadingLevel(heading),
|
|
77
|
+
textContent: headingLabel
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (options.includeHtml) {
|
|
81
|
+
obj.childNodes = heading.childNodes
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (options.headingObjectCallback) {
|
|
85
|
+
return options.headingObjectCallback(obj, heading)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return obj
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Add a node to the nested array.
|
|
93
|
+
* @param {Object} node
|
|
94
|
+
* @param {Array} nest
|
|
95
|
+
* @return {Array}
|
|
96
|
+
*/
|
|
97
|
+
function addNode(node, nest) {
|
|
98
|
+
var obj = getHeadingObject(node)
|
|
99
|
+
var level = obj.headingLevel
|
|
100
|
+
var array = nest
|
|
101
|
+
var lastItem = getLastItem(array)
|
|
102
|
+
var lastItemLevel = lastItem
|
|
103
|
+
? lastItem.headingLevel
|
|
104
|
+
: 0
|
|
105
|
+
var counter = level - lastItemLevel
|
|
106
|
+
|
|
107
|
+
while (counter > 0) {
|
|
108
|
+
lastItem = getLastItem(array)
|
|
109
|
+
// Handle case where there are multiple h5+ in a row.
|
|
110
|
+
if (lastItem && level === lastItem.headingLevel) {
|
|
111
|
+
break
|
|
112
|
+
} else if (lastItem && lastItem.children !== undefined) {
|
|
113
|
+
array = lastItem.children
|
|
114
|
+
}
|
|
115
|
+
counter--
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (level >= options.collapseDepth) {
|
|
119
|
+
obj.isCollapsed = true
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
array.push(obj)
|
|
123
|
+
return array
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Select headings in content area, exclude any selector in options.ignoreSelector
|
|
128
|
+
* @param {HTMLElement} contentElement
|
|
129
|
+
* @param {Array} headingSelector
|
|
130
|
+
* @return {Array}
|
|
131
|
+
*/
|
|
132
|
+
function selectHeadings(contentElement, headingSelector) {
|
|
133
|
+
var selectors = headingSelector
|
|
134
|
+
if (options.ignoreSelector) {
|
|
135
|
+
selectors = headingSelector.split(',')
|
|
136
|
+
.map(function mapSelectors(selector) {
|
|
137
|
+
return selector.trim() + ':not(' + options.ignoreSelector + ')'
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
return contentElement.querySelectorAll(selectors)
|
|
142
|
+
} catch (e) {
|
|
143
|
+
console.warn('Headers not found with selector: ' + selectors); // eslint-disable-line
|
|
144
|
+
return null
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Nest headings array into nested arrays with 'children' property.
|
|
150
|
+
* @param {Array} headingsArray
|
|
151
|
+
* @return {Object}
|
|
152
|
+
*/
|
|
153
|
+
function nestHeadingsArray(headingsArray) {
|
|
154
|
+
return reduce.call(headingsArray, function reducer(prev, curr) {
|
|
155
|
+
var currentHeading = getHeadingObject(curr)
|
|
156
|
+
if (currentHeading) {
|
|
157
|
+
addNode(currentHeading, prev.nest)
|
|
158
|
+
}
|
|
159
|
+
return prev
|
|
160
|
+
}, {
|
|
161
|
+
nest: []
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
nestHeadingsArray: nestHeadingsArray,
|
|
167
|
+
selectHeadings: selectHeadings
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function BuildHtml(options) {
|
|
172
|
+
var forEach = [].forEach
|
|
173
|
+
var some = [].some
|
|
174
|
+
var body = document.body
|
|
175
|
+
var tocElement
|
|
176
|
+
var mainContainer = document.querySelector(options.contentSelector)
|
|
177
|
+
var currentlyHighlighting = true
|
|
178
|
+
var SPACE_CHAR = ' '
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Create link and list elements.
|
|
182
|
+
* @param {Object} d
|
|
183
|
+
* @param {HTMLElement} container
|
|
184
|
+
* @return {HTMLElement}
|
|
185
|
+
*/
|
|
186
|
+
function createEl(d, container) {
|
|
187
|
+
var link = container.appendChild(createLink(d))
|
|
188
|
+
if (d.children.length) {
|
|
189
|
+
var list = createList(d.isCollapsed)
|
|
190
|
+
d.children.forEach(function (child) {
|
|
191
|
+
createEl(child, list)
|
|
192
|
+
})
|
|
193
|
+
link.appendChild(list)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Render nested heading array data into a given element.
|
|
199
|
+
* @param {HTMLElement} parent Optional. If provided updates the {@see tocElement} to match.
|
|
200
|
+
* @param {Array} data
|
|
201
|
+
* @return {HTMLElement}
|
|
202
|
+
*/
|
|
203
|
+
function render(parent, data) {
|
|
204
|
+
var collapsed = false
|
|
205
|
+
var container = createList(collapsed)
|
|
206
|
+
|
|
207
|
+
data.forEach(function (d) {
|
|
208
|
+
createEl(d, container)
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
// Return if no TOC element is provided or known.
|
|
212
|
+
tocElement = parent || tocElement
|
|
213
|
+
if (tocElement === null) {
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Remove existing child if it exists.
|
|
218
|
+
if (tocElement.firstChild) {
|
|
219
|
+
tocElement.removeChild(tocElement.firstChild)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Just return the parent and don't append the list if no links are found.
|
|
223
|
+
if (data.length === 0) {
|
|
224
|
+
return tocElement
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Append the Elements that have been created
|
|
228
|
+
return tocElement.appendChild(container)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Create link element.
|
|
233
|
+
* @param {Object} data
|
|
234
|
+
* @return {HTMLElement}
|
|
235
|
+
*/
|
|
236
|
+
function createLink(data) {
|
|
237
|
+
var item = document.createElement('li')
|
|
238
|
+
var a = document.createElement('a')
|
|
239
|
+
if (options.listItemClass) {
|
|
240
|
+
item.setAttribute('class', options.listItemClass)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (options.onClick) {
|
|
244
|
+
a.onclick = options.onClick
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (options.includeTitleTags) {
|
|
248
|
+
a.setAttribute('title', data.textContent)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (options.includeHtml && data.childNodes.length) {
|
|
252
|
+
forEach.call(data.childNodes, function (node) {
|
|
253
|
+
a.appendChild(node.cloneNode(true))
|
|
254
|
+
})
|
|
255
|
+
} else {
|
|
256
|
+
// Default behavior.
|
|
257
|
+
a.textContent = data.textContent
|
|
258
|
+
}
|
|
259
|
+
a.setAttribute('href', options.basePath + '#' + data.id)
|
|
260
|
+
a.setAttribute('class', options.linkClass +
|
|
261
|
+
SPACE_CHAR + 'node-name--' + data.nodeName +
|
|
262
|
+
SPACE_CHAR + options.extraLinkClasses)
|
|
263
|
+
item.appendChild(a)
|
|
264
|
+
return item
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Create list element.
|
|
269
|
+
* @param {Boolean} isCollapsed
|
|
270
|
+
* @return {HTMLElement}
|
|
271
|
+
*/
|
|
272
|
+
function createList(isCollapsed) {
|
|
273
|
+
var listElement = (options.orderedList) ? 'ol' : 'ul'
|
|
274
|
+
var list = document.createElement(listElement)
|
|
275
|
+
var classes = options.listClass +
|
|
276
|
+
SPACE_CHAR + options.extraListClasses
|
|
277
|
+
if (isCollapsed) {
|
|
278
|
+
classes += SPACE_CHAR + options.collapsibleClass
|
|
279
|
+
classes += SPACE_CHAR + options.isCollapsedClass
|
|
280
|
+
}
|
|
281
|
+
list.setAttribute('class', classes)
|
|
282
|
+
return list
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Update fixed sidebar class.
|
|
287
|
+
* @return {HTMLElement}
|
|
288
|
+
*/
|
|
289
|
+
function updateFixedSidebarClass() {
|
|
290
|
+
if (options.scrollContainer && document.querySelector(options.scrollContainer)) {
|
|
291
|
+
var top
|
|
292
|
+
top = document.querySelector(options.scrollContainer).scrollTop
|
|
293
|
+
} else {
|
|
294
|
+
top = document.documentElement.scrollTop || body.scrollTop
|
|
295
|
+
}
|
|
296
|
+
var posFixedEl = document.querySelector(options.positionFixedSelector)
|
|
297
|
+
|
|
298
|
+
if (options.fixedSidebarOffset === 'auto') {
|
|
299
|
+
options.fixedSidebarOffset = tocElement.offsetTop
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (top > options.fixedSidebarOffset) {
|
|
303
|
+
if (posFixedEl.className.indexOf(options.positionFixedClass) === -1) {
|
|
304
|
+
posFixedEl.className += SPACE_CHAR + options.positionFixedClass
|
|
305
|
+
}
|
|
306
|
+
} else {
|
|
307
|
+
posFixedEl.className = posFixedEl.className.split(SPACE_CHAR + options.positionFixedClass).join('')
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Get top position of heading
|
|
313
|
+
* @param {HTMLElement} obj
|
|
314
|
+
* @return {int} position
|
|
315
|
+
*/
|
|
316
|
+
function getHeadingTopPos(obj) {
|
|
317
|
+
var position = 0
|
|
318
|
+
if (obj !== null) {
|
|
319
|
+
position = obj.offsetTop
|
|
320
|
+
if (options.hasInnerContainers) { position += getHeadingTopPos(obj.offsetParent) }
|
|
321
|
+
}
|
|
322
|
+
return position
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
function updateListActiveElement(topHeader) {
|
|
327
|
+
var forEach = [].forEach
|
|
328
|
+
|
|
329
|
+
var tocLinks = tocElement
|
|
330
|
+
.querySelectorAll('.' + options.linkClass)
|
|
331
|
+
forEach.call(tocLinks, function (tocLink) {
|
|
332
|
+
tocLink.className = tocLink.className.split(SPACE_CHAR + options.activeLinkClass).join('')
|
|
333
|
+
})
|
|
334
|
+
var tocLis = tocElement
|
|
335
|
+
.querySelectorAll('.' + options.listItemClass)
|
|
336
|
+
forEach.call(tocLis, function (tocLi) {
|
|
337
|
+
tocLi.className = tocLi.className.split(SPACE_CHAR + options.activeListItemClass).join('')
|
|
338
|
+
})
|
|
339
|
+
|
|
340
|
+
// Add the active class to the active tocLink.
|
|
341
|
+
var activeTocLink = tocElement
|
|
342
|
+
.querySelector('.' + options.linkClass +
|
|
343
|
+
'.node-name--' + topHeader.nodeName +
|
|
344
|
+
'[href="' + options.basePath + '#' + topHeader.id.replace(/([ #;&,.+*~':"!^$[\]()=>|/@])/g, '\\$1') + '"]')
|
|
345
|
+
if (activeTocLink && activeTocLink.className.indexOf(options.activeLinkClass) === -1) {
|
|
346
|
+
activeTocLink.className += SPACE_CHAR + options.activeLinkClass
|
|
347
|
+
}
|
|
348
|
+
var li = activeTocLink && activeTocLink.parentNode
|
|
349
|
+
if (li && li.className.indexOf(options.activeListItemClass) === -1) {
|
|
350
|
+
li.className += SPACE_CHAR + options.activeListItemClass
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
var tocLists = tocElement
|
|
354
|
+
.querySelectorAll('.' + options.listClass + '.' + options.collapsibleClass)
|
|
355
|
+
|
|
356
|
+
// Collapse the other collapsible lists.
|
|
357
|
+
forEach.call(tocLists, function (list) {
|
|
358
|
+
if (list.className.indexOf(options.isCollapsedClass) === -1) {
|
|
359
|
+
list.className += SPACE_CHAR + options.isCollapsedClass
|
|
360
|
+
}
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
// Expand the active link's collapsible list and its sibling if applicable.
|
|
364
|
+
if (activeTocLink && activeTocLink.nextSibling && activeTocLink.nextSibling.className.indexOf(options.isCollapsedClass) !== -1) {
|
|
365
|
+
activeTocLink.nextSibling.className = activeTocLink.nextSibling.className.split(SPACE_CHAR + options.isCollapsedClass).join('')
|
|
366
|
+
}
|
|
367
|
+
removeCollapsedFromParents(activeTocLink && activeTocLink.parentNode.parentNode)
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Update TOC highlighting and collpased groupings.
|
|
372
|
+
*/
|
|
373
|
+
function updateToc(headingsArray) {
|
|
374
|
+
// If a fixed content container was set
|
|
375
|
+
if (options.scrollContainer && document.querySelector(options.scrollContainer)) {
|
|
376
|
+
var top
|
|
377
|
+
top = document.querySelector(options.scrollContainer).scrollTop
|
|
378
|
+
} else {
|
|
379
|
+
top = document.documentElement.scrollTop || body.scrollTop
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Add fixed class at offset
|
|
383
|
+
if (options.positionFixedSelector) {
|
|
384
|
+
updateFixedSidebarClass()
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// Get the top most heading currently visible on the page so we know what to highlight.
|
|
388
|
+
var headings = headingsArray
|
|
389
|
+
var topHeader
|
|
390
|
+
// Using some instead of each so that we can escape early.
|
|
391
|
+
if (currentlyHighlighting &&
|
|
392
|
+
tocElement !== null &&
|
|
393
|
+
headings.length > 0) {
|
|
394
|
+
some.call(headings, function (heading, i) {
|
|
395
|
+
var modifiedTopOffset = top + 10
|
|
396
|
+
if (mainContainer) {
|
|
397
|
+
modifiedTopOffset += mainContainer.clientHeight * (mainContainer.scrollTop) / (mainContainer.scrollHeight - mainContainer.clientHeight)
|
|
398
|
+
}
|
|
399
|
+
if (getHeadingTopPos(heading) > modifiedTopOffset) {
|
|
400
|
+
// Don't allow negative index value.
|
|
401
|
+
var index = (i === 0) ? i : i - 1
|
|
402
|
+
topHeader = headings[index]
|
|
403
|
+
return true
|
|
404
|
+
} else if (i === headings.length - 1) {
|
|
405
|
+
// This allows scrolling for the last heading on the page.
|
|
406
|
+
topHeader = headings[headings.length - 1]
|
|
407
|
+
return true
|
|
408
|
+
}
|
|
409
|
+
})
|
|
410
|
+
|
|
411
|
+
// Remove the active class from the other tocLinks.
|
|
412
|
+
updateListActiveElement(topHeader)
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Remove collpased class from parent elements.
|
|
418
|
+
* @param {HTMLElement} element
|
|
419
|
+
* @return {HTMLElement}
|
|
420
|
+
*/
|
|
421
|
+
function removeCollapsedFromParents(element) {
|
|
422
|
+
if (element && element.className.indexOf(options.collapsibleClass) !== -1 && element.className.indexOf(options.isCollapsedClass) !== -1) {
|
|
423
|
+
element.className = element.className.split(SPACE_CHAR + options.isCollapsedClass).join('')
|
|
424
|
+
return removeCollapsedFromParents(element.parentNode.parentNode)
|
|
425
|
+
}
|
|
426
|
+
return element
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Disable TOC Animation when a link is clicked.
|
|
431
|
+
* @param {Event} event
|
|
432
|
+
*/
|
|
433
|
+
function disableTocAnimation(event) {
|
|
434
|
+
var target = event.target || event.srcElement
|
|
435
|
+
if (typeof target.className !== 'string' || target.className.indexOf(options.linkClass) === -1) {
|
|
436
|
+
return
|
|
437
|
+
}
|
|
438
|
+
// Bind to tocLink clicks to temporarily disable highlighting
|
|
439
|
+
// while smoothScroll is animating.
|
|
440
|
+
currentlyHighlighting = false
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Enable TOC Animation.
|
|
445
|
+
*/
|
|
446
|
+
function enableTocAnimation() {
|
|
447
|
+
currentlyHighlighting = true
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
return {
|
|
451
|
+
enableTocAnimation: enableTocAnimation,
|
|
452
|
+
disableTocAnimation: disableTocAnimation,
|
|
453
|
+
render: render,
|
|
454
|
+
updateToc: updateToc,
|
|
455
|
+
updateListActiveElement: updateListActiveElement
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function updateTocScroll(options) {
|
|
460
|
+
var toc = options.tocElement || document.querySelector(options.tocSelector)
|
|
461
|
+
if (toc && toc.scrollHeight > toc.clientHeight) {
|
|
462
|
+
var activeItem = toc.querySelector('.' + options.activeListItemClass)
|
|
463
|
+
if (activeItem) {
|
|
464
|
+
var topOffset = toc.getBoundingClientRect().top
|
|
465
|
+
toc.scrollTop = activeItem.offsetTop - topOffset
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
(function (root, factory) {
|
|
471
|
+
if (typeof define === 'function' && define.amd) {
|
|
472
|
+
define([], factory(root))
|
|
473
|
+
} else if (typeof exports === 'object') {
|
|
474
|
+
module.exports = factory(root)
|
|
475
|
+
} else {
|
|
476
|
+
root.tocbot = factory(root)
|
|
477
|
+
}
|
|
478
|
+
})(typeof global !== 'undefined' ? global : this.window || this.global, function (root) {
|
|
479
|
+
'use strict'
|
|
480
|
+
|
|
481
|
+
var options = {}
|
|
482
|
+
var tocbot = {}
|
|
483
|
+
var buildHtml
|
|
484
|
+
var parseContent
|
|
485
|
+
|
|
486
|
+
// Just return if its not a browser.
|
|
487
|
+
var supports = !!root && !!root.document && !!root.document.querySelector && !!root.addEventListener // Feature test
|
|
488
|
+
if (typeof window === 'undefined' && !supports) {
|
|
489
|
+
return
|
|
490
|
+
}
|
|
491
|
+
var headingsArray
|
|
492
|
+
|
|
493
|
+
// From: https://github.com/Raynos/xtend
|
|
494
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty
|
|
495
|
+
function extend() {
|
|
496
|
+
var target = {}
|
|
497
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
498
|
+
var source = arguments[i]
|
|
499
|
+
for (var key in source) {
|
|
500
|
+
if (hasOwnProperty.call(source, key)) {
|
|
501
|
+
target[key] = source[key]
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return target
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// From: https://remysharp.com/2010/07/21/throttling-function-calls
|
|
509
|
+
function throttle(fn, threshhold, scope) {
|
|
510
|
+
threshhold || (threshhold = 250)
|
|
511
|
+
var last
|
|
512
|
+
var deferTimer
|
|
513
|
+
return function () {
|
|
514
|
+
var context = scope || this
|
|
515
|
+
var now = +new Date()
|
|
516
|
+
var args = arguments
|
|
517
|
+
if (last && now < last + threshhold) {
|
|
518
|
+
// hold on to it
|
|
519
|
+
clearTimeout(deferTimer)
|
|
520
|
+
deferTimer = setTimeout(function () {
|
|
521
|
+
last = now
|
|
522
|
+
fn.apply(context, args)
|
|
523
|
+
}, threshhold)
|
|
524
|
+
} else {
|
|
525
|
+
last = now
|
|
526
|
+
fn.apply(context, args)
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function getContentElement(options) {
|
|
532
|
+
try {
|
|
533
|
+
return options.contentElement || document.querySelector(options.contentSelector)
|
|
534
|
+
} catch (e) {
|
|
535
|
+
console.warn('Contents element not found: ' + options.contentSelector) // eslint-disable-line
|
|
536
|
+
return null
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function getTocElement(options) {
|
|
541
|
+
try {
|
|
542
|
+
return options.tocElement || document.querySelector(options.tocSelector)
|
|
543
|
+
} catch (e) {
|
|
544
|
+
console.warn('TOC element not found: ' + options.tocSelector) // eslint-disable-line
|
|
545
|
+
return null
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Destroy tocbot.
|
|
551
|
+
*/
|
|
552
|
+
tocbot.destroy = function () {
|
|
553
|
+
var tocElement = getTocElement(options)
|
|
554
|
+
if (tocElement === null) {
|
|
555
|
+
return
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
if (!options.skipRendering) {
|
|
559
|
+
// Clear HTML.
|
|
560
|
+
if (tocElement) {
|
|
561
|
+
tocElement.innerHTML = ''
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// Remove event listeners.
|
|
566
|
+
if (options.scrollContainer && document.querySelector(options.scrollContainer)) {
|
|
567
|
+
document.querySelector(options.scrollContainer).removeEventListener('scroll', this._scrollListener, false)
|
|
568
|
+
document.querySelector(options.scrollContainer).removeEventListener('resize', this._scrollListener, false)
|
|
569
|
+
} else {
|
|
570
|
+
document.removeEventListener('scroll', this._scrollListener, false)
|
|
571
|
+
document.removeEventListener('resize', this._scrollListener, false)
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Initialize tocbot.
|
|
577
|
+
* @param {object} customOptions
|
|
578
|
+
*/
|
|
579
|
+
tocbot.init = function (customOptions) {
|
|
580
|
+
// feature test
|
|
581
|
+
if (!supports) {
|
|
582
|
+
return
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Merge defaults with user options.
|
|
586
|
+
// Set to options variable at the top.
|
|
587
|
+
options = extend(defaultOptions, customOptions || {})
|
|
588
|
+
this.options = options
|
|
589
|
+
this.state = {}
|
|
590
|
+
|
|
591
|
+
// Init smooth scroll if enabled (default).
|
|
592
|
+
if (options.scrollSmooth) {
|
|
593
|
+
options.duration = options.scrollSmoothDuration
|
|
594
|
+
options.offset = options.scrollSmoothOffset
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// Pass options to these modules.
|
|
598
|
+
buildHtml = BuildHtml(options)
|
|
599
|
+
parseContent = ParseContent(options)
|
|
600
|
+
|
|
601
|
+
// For testing purposes.
|
|
602
|
+
this._buildHtml = buildHtml
|
|
603
|
+
this._parseContent = parseContent
|
|
604
|
+
this._headingsArray = headingsArray
|
|
605
|
+
this.updateTocListActiveElement = buildHtml.updateListActiveElement
|
|
606
|
+
|
|
607
|
+
// Destroy it if it exists first.
|
|
608
|
+
tocbot.destroy()
|
|
609
|
+
|
|
610
|
+
var contentElement = getContentElement(options)
|
|
611
|
+
if (contentElement === null) {
|
|
612
|
+
return
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
var tocElement = getTocElement(options)
|
|
616
|
+
if (tocElement === null) {
|
|
617
|
+
return
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// Get headings array.
|
|
621
|
+
headingsArray = parseContent.selectHeadings(contentElement, options.headingSelector)
|
|
622
|
+
// Return if no headings are found.
|
|
623
|
+
if (headingsArray === null) {
|
|
624
|
+
return
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// Build nested headings array.
|
|
628
|
+
var nestedHeadingsObj = parseContent.nestHeadingsArray(headingsArray)
|
|
629
|
+
var nestedHeadings = nestedHeadingsObj.nest
|
|
630
|
+
|
|
631
|
+
// Render.
|
|
632
|
+
if (!options.skipRendering) {
|
|
633
|
+
buildHtml.render(tocElement, nestedHeadings)
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// Update Sidebar and bind listeners.
|
|
637
|
+
this._scrollListener = throttle(function (e) {
|
|
638
|
+
buildHtml.updateToc(headingsArray)
|
|
639
|
+
!options.disableTocScrollSync && updateTocScroll(options)
|
|
640
|
+
var isTop = e && e.target && e.target.scrollingElement && e.target.scrollingElement.scrollTop === 0
|
|
641
|
+
if ((e && (e.eventPhase === 0 || e.currentTarget === null)) || isTop) {
|
|
642
|
+
buildHtml.updateToc(headingsArray)
|
|
643
|
+
if (options.scrollEndCallback) {
|
|
644
|
+
options.scrollEndCallback(e)
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}, options.throttleTimeout)
|
|
648
|
+
this._scrollListener()
|
|
649
|
+
if (options.scrollContainer && document.querySelector(options.scrollContainer)) {
|
|
650
|
+
document.querySelector(options.scrollContainer).addEventListener('scroll', this._scrollListener, false)
|
|
651
|
+
document.querySelector(options.scrollContainer).addEventListener('resize', this._scrollListener, false)
|
|
652
|
+
} else {
|
|
653
|
+
document.addEventListener('scroll', this._scrollListener, false)
|
|
654
|
+
document.addEventListener('resize', this._scrollListener, false)
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
return this
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Refresh tocbot.
|
|
662
|
+
*/
|
|
663
|
+
tocbot.refresh = function (customOptions) {
|
|
664
|
+
tocbot.destroy()
|
|
665
|
+
tocbot.init(customOptions || this.options)
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// Make tocbot available globally.
|
|
669
|
+
root.tocbot = tocbot
|
|
670
|
+
|
|
671
|
+
return tocbot
|
|
672
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var defaultOptions={ignoreSelector:".js-toc-ignore",linkClass:"toc-link",extraLinkClasses:"",activeLinkClass:"is-active-link",listClass:"toc-list",extraListClasses:"",isCollapsedClass:"is-collapsed",collapsibleClass:"is-collapsible",listItemClass:"toc-list-item",activeListItemClass:"is-active-li",collapseDepth:0,scrollSmooth:!0,scrollSmoothDuration:420,scrollSmoothOffset:0,scrollEndCallback:function(e){},throttleTimeout:50,positionFixedSelector:null,positionFixedClass:"is-position-fixed",fixedSidebarOffset:"auto",includeHtml:!1,includeTitleTags:!1,orderedList:!0,scrollContainer:null,skipRendering:!1,headingLabelCallback:!1,ignoreHiddenElements:!1,headingObjectCallback:null,basePath:"",disableTocScrollSync:!1};function ParseContent(r){var t=[].reduce;function a(e){return e[e.length-1]}function c(e){if(!(e instanceof window.HTMLElement))return e;if(r.ignoreHiddenElements&&(!e.offsetHeight||!e.offsetParent))return null;var t=e.getAttribute("data-heading-label")||(r.headingLabelCallback?String(r.headingLabelCallback(e.textContent)):e.textContent.trim()),t={id:e.id,children:[],nodeName:e.nodeName,headingLevel:+e.nodeName.toUpperCase().replace("H",""),textContent:t};return r.includeHtml&&(t.childNodes=e.childNodes),r.headingObjectCallback?r.headingObjectCallback(t,e):t}return{nestHeadingsArray:function(e){return t.call(e,function(e,t){t=c(t);if(t){for(var l=e.nest,n=(t=c(t)).headingLevel,o=l,s=a(o),i=n-(s?s.headingLevel:0);0<i&&(!(s=a(o))||n!==s.headingLevel);)s&&void 0!==s.children&&(o=s.children),i--;n>=r.collapseDepth&&(t.isCollapsed=!0),o.push(t)}return e},{nest:[]})},selectHeadings:function(e,t){var l=t;r.ignoreSelector&&(l=t.split(",").map(function(e){return e.trim()+":not("+r.ignoreSelector+")"}));try{return e.querySelectorAll(l)}catch(e){return console.warn("Headers not found with selector: "+l),null}}}}function BuildHtml(i){var r,n=[].forEach,a=[].some,c=document.body,d=document.querySelector(i.contentSelector),u=!0,m=" ";function o(e,t){var l,t=t.appendChild(function(e){var t=document.createElement("li"),l=document.createElement("a");i.listItemClass&&t.setAttribute("class",i.listItemClass);i.onClick&&(l.onclick=i.onClick);i.includeTitleTags&&l.setAttribute("title",e.textContent);i.includeHtml&&e.childNodes.length?n.call(e.childNodes,function(e){l.appendChild(e.cloneNode(!0))}):l.textContent=e.textContent;return l.setAttribute("href",i.basePath+"#"+e.id),l.setAttribute("class",i.linkClass+m+"node-name--"+e.nodeName+m+i.extraLinkClasses),t.appendChild(l),t}(e));e.children.length&&(l=s(e.isCollapsed),e.children.forEach(function(e){o(e,l)}),t.appendChild(l))}function s(e){var t=i.orderedList?"ol":"ul",t=document.createElement(t),l=i.listClass+m+i.extraListClasses;return e&&(l=(l+=m+i.collapsibleClass)+(m+i.isCollapsedClass)),t.setAttribute("class",l),t}function f(e){var t=[].forEach,l=r.querySelectorAll("."+i.linkClass),l=(t.call(l,function(e){e.className=e.className.split(m+i.activeLinkClass).join("")}),r.querySelectorAll("."+i.listItemClass)),l=(t.call(l,function(e){e.className=e.className.split(m+i.activeListItemClass).join("")}),r.querySelector("."+i.linkClass+".node-name--"+e.nodeName+'[href="'+i.basePath+"#"+e.id.replace(/([ #;&,.+*~':"!^$[\]()=>|/@])/g,"\\$1")+'"]')),e=(l&&-1===l.className.indexOf(i.activeLinkClass)&&(l.className+=m+i.activeLinkClass),l&&l.parentNode),e=(e&&-1===e.className.indexOf(i.activeListItemClass)&&(e.className+=m+i.activeListItemClass),r.querySelectorAll("."+i.listClass+"."+i.collapsibleClass));t.call(e,function(e){-1===e.className.indexOf(i.isCollapsedClass)&&(e.className+=m+i.isCollapsedClass)}),l&&l.nextSibling&&-1!==l.nextSibling.className.indexOf(i.isCollapsedClass)&&(l.nextSibling.className=l.nextSibling.className.split(m+i.isCollapsedClass).join("")),function e(t){if(t&&-1!==t.className.indexOf(i.collapsibleClass)&&-1!==t.className.indexOf(i.isCollapsedClass))return t.className=t.className.split(m+i.isCollapsedClass).join(""),e(t.parentNode.parentNode);return t}(l&&l.parentNode.parentNode)}return{enableTocAnimation:function(){u=!0},disableTocAnimation:function(e){"string"==typeof(e=e.target||e.srcElement).className&&-1!==e.className.indexOf(i.linkClass)&&(u=!1)},render:function(e,t){var l=s(!1);if(t.forEach(function(e){o(e,l)}),null!==(r=e||r))return r.firstChild&&r.removeChild(r.firstChild),0===t.length?r:r.appendChild(l)},updateToc:function(e){n=i.scrollContainer&&document.querySelector(i.scrollContainer)?document.querySelector(i.scrollContainer).scrollTop:document.documentElement.scrollTop||c.scrollTop,i.positionFixedSelector&&(t=i.scrollContainer&&document.querySelector(i.scrollContainer)?document.querySelector(i.scrollContainer).scrollTop:document.documentElement.scrollTop||c.scrollTop,l=document.querySelector(i.positionFixedSelector),"auto"===i.fixedSidebarOffset&&(i.fixedSidebarOffset=r.offsetTop),t>i.fixedSidebarOffset?-1===l.className.indexOf(i.positionFixedClass)&&(l.className+=m+i.positionFixedClass):l.className=l.className.split(m+i.positionFixedClass).join(""));var n,t,l,o,s=e;u&&null!==r&&0<s.length&&(a.call(s,function(e,t){var l=n+10;return d&&(l+=d.clientHeight*d.scrollTop/(d.scrollHeight-d.clientHeight)),function e(t){var l=0;return null!==t&&(l=t.offsetTop,i.hasInnerContainers&&(l+=e(t.offsetParent))),l}(e)>l?(o=s[0===t?t:t-1],!0):t===s.length-1?(o=s[s.length-1],!0):void 0}),f(o))},updateListActiveElement:f}}function updateTocScroll(e){var t,l=e.tocElement||document.querySelector(e.tocSelector);l&&l.scrollHeight>l.clientHeight&&((e=l.querySelector("."+e.activeListItemClass))&&(t=l.getBoundingClientRect().top,l.scrollTop=e.offsetTop-t))}!function(e,t){"function"==typeof define&&define.amd?define([],t(e)):"object"==typeof exports?module.exports=t(e):e.tocbot=t(e)}("undefined"!=typeof global?global:this.window||this.global,function(e){"use strict";var l,a,c,d,u={},m={},f=!!(e&&e.document&&e.document.querySelector&&e.addEventListener);if("undefined"!=typeof window||f)return d=Object.prototype.hasOwnProperty,m.destroy=function(){var e=C(u);null!==e&&(u.skipRendering||e&&(e.innerHTML=""),u.scrollContainer&&document.querySelector(u.scrollContainer)?(document.querySelector(u.scrollContainer).removeEventListener("scroll",this._scrollListener,!1),document.querySelector(u.scrollContainer).removeEventListener("resize",this._scrollListener,!1)):(document.removeEventListener("scroll",this._scrollListener,!1),document.removeEventListener("resize",this._scrollListener,!1)))},m.init=function(e){if(f){u=function(){for(var e={},t=0;t<arguments.length;t++){var l,n=arguments[t];for(l in n)d.call(n,l)&&(e[l]=n[l])}return e}(defaultOptions,e||{}),this.options=u,this.state={},u.scrollSmooth&&(u.duration=u.scrollSmoothDuration,u.offset=u.scrollSmoothOffset),l=BuildHtml(u),a=ParseContent(u),this._buildHtml=l,this._parseContent=a,this._headingsArray=c,this.updateTocListActiveElement=l.updateListActiveElement,m.destroy();e=function(t){try{return t.contentElement||document.querySelector(t.contentSelector)}catch(e){return console.warn("Contents element not found: "+t.contentSelector),null}}(u);if(null!==e){var n,o,s,i,r,t=C(u);if(null!==t)if(null!==(c=a.selectHeadings(e,u.headingSelector)))return e=a.nestHeadingsArray(c).nest,u.skipRendering||l.render(t,e),this._scrollListener=(n=function(e){l.updateToc(c),u.disableTocScrollSync||updateTocScroll(u);var t=e&&e.target&&e.target.scrollingElement&&0===e.target.scrollingElement.scrollTop;(e&&(0===e.eventPhase||null===e.currentTarget)||t)&&(l.updateToc(c),u.scrollEndCallback&&u.scrollEndCallback(e))},o=(o=u.throttleTimeout)||250,function(){var e=s||this,t=+new Date,l=arguments;i&&t<i+o?(clearTimeout(r),r=setTimeout(function(){i=t,n.apply(e,l)},o)):(i=t,n.apply(e,l))}),this._scrollListener(),u.scrollContainer&&document.querySelector(u.scrollContainer)?(document.querySelector(u.scrollContainer).addEventListener("scroll",this._scrollListener,!1),document.querySelector(u.scrollContainer).addEventListener("resize",this._scrollListener,!1)):(document.addEventListener("scroll",this._scrollListener,!1),document.addEventListener("resize",this._scrollListener,!1)),this}}},m.refresh=function(e){m.destroy(),m.init(e||this.options)},e.tocbot=m;function C(t){try{return t.tocElement||document.querySelector(t.tocSelector)}catch(e){return console.warn("TOC element not found: "+t.tocSelector),null}}});
|
|
Binary file
|