X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;ds=sidebyside;f=assets%2Fjs%2Fscript.js;fp=assets%2Fjs%2Fscript.js;h=95e8c9f2a7e292a5d9e146cfa871d07b15f977b1;hb=2baccb4d920e3af9098a272253664c00d99b083e;hp=0000000000000000000000000000000000000000;hpb=5f13b27eae95b880296c7a15189624ae934e3bab;p=ghost-theme-willow.git diff --git a/assets/js/script.js b/assets/js/script.js new file mode 100644 index 0000000..95e8c9f --- /dev/null +++ b/assets/js/script.js @@ -0,0 +1,48 @@ +/* + | ----------------------------------------------------------------------------- + | Functionality for off-canvas menu / sidebar visibility + | ----------------------------------------------------------------------------- +*/ + +/*jslint browser:true*/ + +(function (document) { + 'use strict'; + + document.addEventListener('DOMContentLoaded', function () { + var menu = document.getElementById('mobile-menu'), + wrapper = document.getElementById('wrapper'), + content = document.getElementById('content'), + menuVisibilityData = 'data-menu-visible'; + + /* + | --------------------------------------------------------------------- + | Click on content element results in menu getting closed + | --------------------------------------------------------------------- + */ + content.addEventListener('click', function (event) { + if (wrapper.getAttribute(menuVisibilityData)) { + wrapper.removeAttribute(menuVisibilityData); + + event.preventDefault(); + event.stopPropagation(); + } + }); + + /* + | --------------------------------------------------------------------- + | Click on menu element results in menu getting opened + | --------------------------------------------------------------------- + */ + menu.addEventListener('click', function (event) { + if (!wrapper.getAttribute(menuVisibilityData)) { + wrapper.setAttribute(menuVisibilityData, '1'); + } else { + wrapper.removeAttribute(menuVisibilityData); + } + + event.preventDefault(); + event.stopPropagation(); + }); + }); +}(document)); \ No newline at end of file