UNPKG

2.06 kBJavaScriptView Raw
1/* eslint-disable no-new */
2var Pjax = require('pjax')
3var Nprogress = require('nprogress')
4var onmount = require('onmount')
5var each = require('dom101/each')
6var toggleClass = require('dom101/toggle-class')
7var ready = require('dom101/ready')
8var Scrolltrack = require('./scrolltrack')
9var Scrollclass = require('./scrollclass')
10
11/*
12 * pjax/nprogress
13 */
14
15void (function () {
16 ready(function () {
17 new Pjax({
18 selectors: ['.body', '.toc-menu', 'title']
19 })
20 })
21
22 document.addEventListener('pjax:send', function () {
23 Nprogress.start()
24 })
25
26 document.addEventListener('pjax:error', function () {
27 Nprogress.done()
28 })
29
30 document.addEventListener('pjax:complete', function () {
31 Nprogress.done()
32 })
33}())
34
35/*
36 * menu toggle
37 */
38
39onmount('.js-menu-toggle', function () {
40 this.addEventListener('click', function () {
41 toggleClass(document.body, '-menu-visible')
42 })
43})
44
45/*
46 * onmount
47 */
48
49void (function () {
50 ready(function () {
51 onmount()
52 })
53
54 document.addEventListener('pjax:complete', function () {
55 onmount()
56 })
57}())
58
59/*
60 * scrolltrack
61 */
62
63void (function () {
64 var st = new Scrolltrack({
65 menu: '.toc-menu',
66 selector: 'h2, h3',
67 onupdate: function (active, last) {
68 var menu = document.querySelector('.toc-menu')
69 var link = menu.querySelector('.link.-active, .link.-notactive')
70
71 toggleClass(link, '-active', !active)
72 toggleClass(link, '-notactive', active)
73 }
74 })
75
76 document.addEventListener('pjax:complete', function () {
77 st.update()
78 })
79
80 ready(function () {
81 st.update()
82 })
83}())
84
85void(function () {
86 onmount('.footer-nav', function (b) {
87 b.sc = Scrollclass(this, {
88 className: '-expanded',
89 onscroll: function (y) {
90 return this.maxScroll - y < 88
91 }
92 })
93 }, function (b) {
94 b.sc.destroy()
95 })
96}())
97
98void(function () {
99 onmount('.header-nav', function (b) {
100 b.sc = Scrollclass(this, {
101 className: '-expanded',
102 onscroll: function (y) { return y < 40 }
103 })
104 }, function (b) {
105 b.sc.destroy()
106 })
107}())