Added all theme files
[ghost-theme-willow.git] / assets / js / script.js
diff --git a/assets/js/script.js b/assets/js/script.js
new file mode 100644 (file)
index 0000000..95e8c9f
--- /dev/null
@@ -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