blob: 92abf9760209939043c6806b77d0bfcd8f7f7f4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/* ========================================================================
* Ratchet: modals.js v2.0.2
* http://goratchet.com/components#modals
* ========================================================================
* Copyright 2015 Connor Sears
* Licensed under MIT (https://github.com/twbs/ratchet/blob/master/LICENSE)
* ======================================================================== */
!(function () {
'use strict';
var eventModalOpen = new CustomEvent('modalOpen', {
bubbles: true,
cancelable: true
});
var eventModalClose = new CustomEvent('modalClose', {
bubbles: true,
cancelable: true
});
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) {
var modalSelector = modalToggle.getAttribute('data-modal');
if (modalSelector) {
return document.querySelector(modalSelector);
}
else if (modalToggle.hash) {
try {
return document.querySelector(modalToggle.hash);
}
catch (error) {
if (error.name !== 'SyntaxError') {
throw error;
}
}
}
}
};
window.addEventListener('touchend', function (event) {
var modal = getModal(event);
if (modal && modal.classList.contains('modal')) {
var eventToDispatch = eventModalOpen;
if (modal.classList.contains('active')) {
eventToDispatch = eventModalClose;
}
modal.dispatchEvent(eventToDispatch);
modal.classList.toggle('active');
}
event.preventDefault(); // prevents rewriting url (apps can still use hash values in url)
});
}());
|