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.

87 lines
2.0 KiB

/* ========================================================================
* Ratchet: popovers.js v2.0.2
* http://goratchet.com/components#popovers
* ========================================================================
10 years ago
* Copyright 2015 Connor Sears
* Licensed under MIT (https://github.com/twbs/ratchet/blob/master/LICENSE)
* ======================================================================== */
12 years ago
!(function () {
'use strict';
12 years ago
var popover;
var findPopovers = function (target) {
var i;
var popovers = document.querySelectorAll('a');
12 years ago
for (; target && target !== document; target = target.parentNode) {
for (i = popovers.length; i--;) {
if (popovers[i] === target) {
return target;
}
}
12 years ago
}
};
var onPopoverHidden = function () {
popover.style.display = 'none';
popover.removeEventListener(window.RATCHET.getTransitionEnd, onPopoverHidden);
};
12 years ago
var backdrop = (function () {
12 years ago
var element = document.createElement('div');
element.classList.add('backdrop');
element.addEventListener('touchend', function () {
popover.addEventListener(window.RATCHET.getTransitionEnd, onPopoverHidden);
12 years ago
popover.classList.remove('visible');
11 years ago
popover.parentNode.removeChild(backdrop);
12 years ago
});
return element;
}());
12 years ago
var getPopover = function (e) {
var anchor = findPopovers(e.target);
if (!anchor || !anchor.hash || (anchor.hash.indexOf('/') > 0)) {
return;
}
12 years ago
try {
popover = document.querySelector(anchor.hash);
} catch (error) {
popover = null;
}
if (popover === null) {
return;
}
12 years ago
if (!popover || !popover.classList.contains('popover')) {
return;
}
12 years ago
return popover;
};
12 years ago
var showHidePopover = function (e) {
12 years ago
var popover = getPopover(e);
if (!popover) {
return;
}
12 years ago
popover.style.display = 'block';
popover.offsetHeight;
popover.classList.add('visible');
popover.parentNode.appendChild(backdrop);
};
12 years ago
window.addEventListener('touchend', showHidePopover);
12 years ago
}());