Creates simple js file to show how to add js to a theme

This commit is contained in:
David Darnes 2016-06-16 00:24:19 +01:00
parent fd169b2c01
commit 2c3cc33b1e
2 changed files with 15 additions and 0 deletions

14
_includes/scripts.js Normal file
View File

@ -0,0 +1,14 @@
// Data attribute switch
var toggleState = function (elem, one, two) {
var elem = document.querySelector(elem);
elem.setAttribute('data-state', elem.getAttribute('data-state') === one ? two : one);
};
// Mobile navigation toggle selector
var buttonMenu = document.querySelector('.button--nav');
if (typeof(buttonMenu) != 'undefined' && buttonMenu != null) {
buttonMenu.onclick = function (e) {
toggleState('.nav', 'open', 'closed');
e.preventDefault();
};
};

View File

@ -17,5 +17,6 @@
{{ content }}
<script src="/js/scripts.js" type="text/javascript"></script>
</body>
</html>