commit
58598dc6e4
|
@ -1,69 +1,69 @@
|
||||||
(function(document) {
|
(function (document) {
|
||||||
var toggleDocumentationMenu = function() {
|
var toggleDocumentationMenu = function () {
|
||||||
var navBtn = document.querySelector('.main-nav__btn');
|
var navBtn = document.querySelector('.main-nav__btn');
|
||||||
var navList = document.querySelector('.main-nav__list');
|
var navList = document.querySelector('.main-nav__list');
|
||||||
var navIsOpenedClass = 'nav-is-opened';
|
var navIsOpenedClass = 'nav-is-opened';
|
||||||
var navListIsOpened = false;
|
var navListIsOpened = false;
|
||||||
|
|
||||||
navBtn.addEventListener('click', function (event) {
|
navBtn.addEventListener('click', function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
if (!navListIsOpened) {
|
if (!navListIsOpened) {
|
||||||
addClass(navList, navIsOpenedClass);
|
addClass(navList, navIsOpenedClass);
|
||||||
navListIsOpened = true;
|
navListIsOpened = true;
|
||||||
} else {
|
} else {
|
||||||
removeClass(navList, navIsOpenedClass);
|
removeClass(navList, navIsOpenedClass);
|
||||||
navListIsOpened = false;
|
navListIsOpened = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var toggleMainNav = function() {
|
var toggleMainNav = function () {
|
||||||
var documentationItem =
|
var documentationItem =
|
||||||
document.querySelector('.main-nav__item--documentation');
|
document.querySelector('.main-nav__item--documentation');
|
||||||
var documentationLink =
|
var documentationLink =
|
||||||
document.querySelector('.main-nav__item--documentation > .main-nav__link');
|
document.querySelector('.main-nav__item--documentation > .main-nav__link');
|
||||||
var documentationIsOpenedClass = 'subnav-is-opened';
|
var documentationIsOpenedClass = 'subnav-is-opened';
|
||||||
var documentationIsOpened = false;
|
var documentationIsOpened = false;
|
||||||
|
|
||||||
documentationLink.addEventListener('click', function (event) {
|
documentationLink.addEventListener('click', function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
if (!documentationIsOpened) {
|
if (!documentationIsOpened) {
|
||||||
documentationIsOpened = true;
|
documentationIsOpened = true;
|
||||||
addClass(documentationItem, documentationIsOpenedClass);
|
addClass(documentationItem, documentationIsOpenedClass);
|
||||||
} else {
|
} else {
|
||||||
documentationIsOpened = false;
|
documentationIsOpened = false;
|
||||||
removeClass(documentationItem, documentationIsOpenedClass);
|
removeClass(documentationItem, documentationIsOpenedClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var isTouch = function() {
|
var isTouch = function () {
|
||||||
return ('ontouchstart' in window) ||
|
return ('ontouchstart' in window) ||
|
||||||
window.DocumentTouch && document instanceof DocumentTouch;
|
window.DocumentTouch && document instanceof DocumentTouch;
|
||||||
};
|
};
|
||||||
|
|
||||||
var addClass = function (element, className) {
|
var addClass = function (element, className) {
|
||||||
if (!element) { return; }
|
if (!element) { return; }
|
||||||
element.className = element.className.replace(/\s+$/gi, '') + ' ' + className;
|
element.className = element.className.replace(/\s+$/gi, '') + ' ' + className;
|
||||||
}
|
}
|
||||||
|
|
||||||
var removeClass = function(element, className) {
|
var removeClass = function (element, className) {
|
||||||
if (!element) { return; }
|
if (!element) { return; }
|
||||||
element.className = element.className.replace(className, '');
|
element.className = element.className.replace(className, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
var html = document.querySelector('html');
|
var html = document.querySelector('html');
|
||||||
removeClass(html, 'no-js');
|
removeClass(html, 'no-js');
|
||||||
addClass(html, 'js');
|
addClass(html, 'js');
|
||||||
|
|
||||||
if (isTouch()) {
|
if (isTouch()) {
|
||||||
removeClass(html, 'no-touch');
|
removeClass(html, 'no-touch');
|
||||||
addClass(html, 'is-touch');
|
addClass(html, 'is-touch');
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleDocumentationMenu();
|
toggleDocumentationMenu();
|
||||||
toggleMainNav();
|
toggleMainNav();
|
||||||
})(document);
|
}(document));
|
||||||
|
|
Loading…
Reference in New Issue