-
Notifications
You must be signed in to change notification settings - Fork 361
/
Copy pathindex.js
67 lines (57 loc) · 1.74 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const typewriter = require('analytics')
export default function() {
let scrolledToBottom = false
window.onscroll = function(ev) {
if (!scrolledToBottom && (window.innerHeight + window.pageYOffset) >= document.querySelectorAll('[data-tracking-scroll]')[0].offsetHeight) {//document.body.offsetHeight) {
scrolledToBottom = true
console.log("you're at the bottom of the page");
typewriter.scrolledToBottom({
url: document.URL
})
}
}
document.getElementById('home-btn').addEventListener('click', function () {
typewriter.homeButtonClicked({
url: document.URL
})
})
function debounce(func, wait, immediate) {
var timeout;
return function executedFunction() {
var context = this;
var args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
Array.from(document.querySelectorAll('.aa-Input')).forEach(searchInput => {
searchInput.addEventListener('input', debounce(function(e) {
const query = e.target.value
if (query.length) {
typewriter.docsSearched({
query
})
}
}, 300))
// searchInput.onclick = (e) => {
// console.log(e)
// typewriter.searchClicked()
// }
})
Array.from(document.querySelectorAll('.menu-side__link')).forEach(menuLink => {
menuLink.onclick = () => {
const url = location.origin + location.pathname
typewriter.tocClicked({
url,
link: menuLink.href,
name: menuLink.innerHTML
})
}
})
}