forked from amiechen/codrops-scribbler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscribbler.js
More file actions
executable file
·122 lines (102 loc) · 3.11 KB
/
scribbler.js
File metadata and controls
executable file
·122 lines (102 loc) · 3.11 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// utilities
var get = function (selector, scope) {
scope = scope ? scope : document;
return scope.querySelector(selector);
};
var getAll = function (selector, scope) {
scope = scope ? scope : document;
return scope.querySelectorAll(selector);
};
// setup typewriter effect in the terminal demo
if (document.getElementsByClassName("demo").length > 0) {
var i = 0;
var txt = ` git remote add origin dgit://VC4NJ3nlVJJPgyJ4DScpeXx3-UnXmiasfrxiIFpJwb0/repo-name
dgit~$ git push origin master`;
var speed = 15;
function typeItOut() {
if (i < txt.length) {
document.getElementsByClassName("demo")[0].innerHTML += txt.charAt(i);
i++;
setTimeout(typeItOut, speed);
}
}
setTimeout(typeItOut, 1800);
}
// toggle tabs on codeblock
window.addEventListener("load", function () {
// get all tab_containers in the document
var tabContainers = getAll(".tab__container");
// bind click event to each tab container
for (var i = 0; i < tabContainers.length; i++) {
get(".tab__menu", tabContainers[i]).addEventListener("click", tabClick);
}
// each click event is scoped to the tab_container
function tabClick(event) {
var scope = event.currentTarget.parentNode;
var clickedTab = event.target;
var tabs = getAll(".tab", scope);
var panes = getAll(".tab__pane", scope);
var activePane = get(`.${clickedTab.getAttribute("data-tab")}`, scope);
// remove all active tab classes
for (var i = 0; i < tabs.length; i++) {
tabs[i].classList.remove("active");
}
// remove all active pane classes
for (var i = 0; i < panes.length; i++) {
panes[i].classList.remove("active");
}
// apply active classes on desired tab and pane
clickedTab.classList.add("active");
activePane.classList.add("active");
}
});
//in page scrolling for documentaiton page
var btns = getAll(".js-btn");
var sections = getAll(".js-section");
function setActiveLink(event) {
// remove all active tab classes
for (var i = 0; i < btns.length; i++) {
btns[i].classList.remove("selected");
}
event.target.classList.add("selected");
}
function smoothScrollTo(i, event) {
var element = sections[i];
setActiveLink(event);
window.scrollTo({
behavior: "smooth",
top: element.offsetTop - 20,
left: 0,
});
}
if (btns.length && sections.length > 0) {
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", smoothScrollTo.bind(this, i));
}
}
// fix menu to page-top once user starts scrolling
window.addEventListener("scroll", function () {
var docNav = get(".doc__nav > ul");
if (docNav) {
if (window.pageYOffset > 63) {
docNav.classList.add("fixed");
} else {
docNav.classList.remove("fixed");
}
}
});
// responsive navigation
var topNav = get(".menu");
var icon = get(".toggle");
window.addEventListener("load", function () {
function showNav() {
if (topNav.className === "menu") {
topNav.className += " responsive";
icon.className += " open";
} else {
topNav.className = "menu";
icon.classList.remove("open");
}
}
icon.addEventListener("click", showNav);
});