-
Notifications
You must be signed in to change notification settings - Fork 0
/
scribbler.js
165 lines (138 loc) · 4.19 KB
/
scribbler.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// 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 = `npm i @mkt-eg/mkt
const { MKT } = require('@mkt-eg/mkt')
const mkt = new MKT(
'bbbc22c3a13c74456a6d4bb7ba5745476ebfdc81c867fc240258122b78eb6a6f'
)
const data = mkt
.exchange({
fsym: 'BTC', // Single Fysm only
tsyms: 'USD,EGP', // Multiaple Tsyms is allowed
type: 'single'
})
.then(response => {
console.log(JSON.stringify(response.data))
})
.catch(error => {
console.log(error)
})
// JSON OUTPUT
{
"USD":9888.01, 💲
"EGP":182256.26 💲
}
`;
var speed = 30;
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(element, event) {
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', function(event) {
// smoothScrollTo(sections[i], event);
// });
// }
btns[0].addEventListener('click', function (event) {
smoothScrollTo(sections[0], event);
});
btns[1].addEventListener('click', function (event) {
smoothScrollTo(sections[1], event);
});
btns[2].addEventListener('click', function (event) {
smoothScrollTo(sections[2], event);
});
btns[3].addEventListener('click', function (event) {
smoothScrollTo(sections[3], event);
});
}
// 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);
});