-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
76 lines (67 loc) · 2.28 KB
/
main.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
---
---
/*!
* Basically Basic Jekyll Theme 1.4.4
* Copyright 2017-2018 Michael Rose - mademistakes | @mmistakes
* Free for personal and commercial use under the MIT license
* https://github.com/mmistakes/jekyll-theme-basically-basic/blob/master/LICENSE
*/
var menuItems = document.querySelectorAll('#sidebar li');
// Get vendor transition property
var docElemStyle = document.documentElement.style;
var transitionProp = typeof docElemStyle.transition == 'string' ?
'transition' : 'WebkitTransition';
// Animate sidebar menu items
function animateMenuItems() {
for (var i = 0; i < menuItems.length; i++) {
var item = menuItems[i];
// Stagger transition with transitionDelay
item.style[transitionProp + 'Delay'] = (i * 75) + 'ms';
item.classList.toggle('is--moved');
}
};
var myWrapper = document.querySelector('.wrapper');
var myMenu = document.querySelector('.sidebar');
var myToggle = document.querySelector('.toggle');
var myInitialContent = document.querySelector('.initial-content');
var mySearchContent = document.querySelector('.search-content');
var mySearchToggle = document.querySelector('.search-toggle');
// Toggle sidebar visibility
function toggleClassMenu() {
myMenu.classList.add('is--animatable');
if (!myMenu.classList.contains('is--visible')) {
myMenu.classList.add('is--visible');
myToggle.classList.add('open');
myWrapper.classList.add('is--pushed');
} else {
myMenu.classList.remove('is--visible');
myToggle.classList.remove('open');
myWrapper.classList.remove('is--pushed');
}
}
// Animation smoother
function OnTransitionEnd() {
myMenu.classList.remove('is--animatable');
}
myMenu.addEventListener('transitionend', OnTransitionEnd, false);
myToggle.addEventListener('click', function () {
toggleClassMenu();
animateMenuItems();
}, false);
myMenu.addEventListener('click', function () {
toggleClassMenu();
animateMenuItems();
}, false);
if (mySearchToggle) {
mySearchToggle.addEventListener('click', function () {
toggleClassSearch();
}, false);
}
// Toggle search input and content visibility
function toggleClassSearch() {
mySearchContent.classList.toggle('is--visible');
myInitialContent.classList.toggle('is--hidden');
setTimeout(function () {
document.querySelector('.search-content input').focus();
}, 400);
}