mirror of https://github.com/twbs/ratchet.git
Build mobile apps with simple HTML, CSS, and JS components.
http://goratchet.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1006 B
40 lines
1006 B
/* ---------------------------------- |
|
* 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 modal; |
|
var modalToggle = findModals(event.target); |
|
|
|
if (!modalToggle || !modalToggle.hash) return; |
|
|
|
modal = document.querySelector(modalToggle.hash); |
|
|
|
if (!modal) return; |
|
return modal; |
|
}; |
|
|
|
window.addEventListener('touchend', function (event) { |
|
var modal = getModal(event); |
|
|
|
if (!modal) return; |
|
modal.offsetHeight; |
|
modal.classList.toggle('active'); |
|
}); |
|
|
|
window.addEventListener('click', function (event) { |
|
if (getModal(event)) event.preventDefault(); |
|
}); |
|
}(); |