modals.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* ========================================================================
  2. * Ratchet: modals.js v2.0.2
  3. * http://goratchet.com/components#modals
  4. * ========================================================================
  5. * Copyright 2014 Connor Sears
  6. * Licensed under MIT (https://github.com/twbs/ratchet/blob/master/LICENSE)
  7. * ======================================================================== */
  8. !(function () {
  9. 'use strict';
  10. var findModals = function (target) {
  11. var i;
  12. var modals = document.querySelectorAll('a');
  13. for (; target && target !== document; target = target.parentNode) {
  14. for (i = modals.length; i--;) {
  15. if (modals[i] === target) {
  16. return target;
  17. }
  18. }
  19. }
  20. };
  21. var getModal = function (event) {
  22. var modalToggle = findModals(event.target);
  23. if (modalToggle && modalToggle.hash) {
  24. return document.querySelector(modalToggle.hash);
  25. }
  26. };
  27. window.addEventListener('touchend', function (event) {
  28. var modal = getModal(event);
  29. if (modal) {
  30. if (modal && modal.classList.contains('modal')) {
  31. modal.classList.toggle('active');
  32. }
  33. event.preventDefault(); // prevents rewriting url (apps can still use hash values in url)
  34. }
  35. });
  36. }());