Merge pull request #135 from benschwarz/feature/modals
[ratchet] / lib / js / modals.js
diff --git a/lib/js/modals.js b/lib/js/modals.js
new file mode 100644 (file)
index 0000000..4448107
--- /dev/null
@@ -0,0 +1,25 @@
+/* ----------------------------------
+ * MODAL v1.0.0
+ * Licensed under The MIT License
+ * http://opensource.org/licenses/MIT
+ * ---------------------------------- */
+
+!function () {
+  var findModals = function (target) {
+    var i;
+    var modals = document.querySelectorAll('a');
+    for (; target && target !== document; target = target.parentNode) {
+      for (i = modals.length; i--;) { if (modals[i] === target) return target; }
+    }
+  };
+
+  var getModal = function (event) {
+    var modalToggle = findModals(event.target);
+    if (modalToggle && modalToggle.hash) return document.querySelector(modalToggle.hash);
+  };
+
+  window.addEventListener('touchend', function (event) {
+    var modal = getModal(event);
+    if (modal) modal.classList.toggle('active');
+  });
+}();
\ No newline at end of file