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.
64 lines
1.6 KiB
64 lines
1.6 KiB
12 years ago
|
/* ----------------------------------
|
||
11 years ago
|
* POPOVER v1.0.0
|
||
12 years ago
|
* Licensed under The MIT License
|
||
|
* http://opensource.org/licenses/MIT
|
||
|
* ---------------------------------- */
|
||
|
|
||
|
!function () {
|
||
|
|
||
|
var popover;
|
||
|
|
||
|
var findPopovers = function (target) {
|
||
|
var i, popovers = document.querySelectorAll('a');
|
||
|
for (; target && target !== document; target = target.parentNode) {
|
||
|
for (i = popovers.length; i--;) { if (popovers[i] === target) return target; }
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var onPopoverHidden = function () {
|
||
11 years ago
|
document.body.removeChild(backdrop);
|
||
12 years ago
|
popover.style.display = 'none';
|
||
|
popover.removeEventListener('webkitTransitionEnd', onPopoverHidden);
|
||
|
}
|
||
|
|
||
|
var backdrop = function () {
|
||
|
var element = document.createElement('div');
|
||
|
|
||
|
element.classList.add('backdrop');
|
||
|
|
||
|
element.addEventListener('touchend', function () {
|
||
|
popover.addEventListener('webkitTransitionEnd', onPopoverHidden);
|
||
|
popover.classList.remove('visible');
|
||
|
});
|
||
|
|
||
|
return element;
|
||
|
}();
|
||
|
|
||
|
var getPopover = function (e) {
|
||
|
var anchor = findPopovers(e.target);
|
||
|
|
||
11 years ago
|
if (!anchor || !anchor.hash) return;
|
||
12 years ago
|
|
||
11 years ago
|
popover = document.querySelector(anchor.hash);
|
||
12 years ago
|
|
||
|
if (!popover || !popover.classList.contains('popover')) return;
|
||
|
|
||
|
return popover;
|
||
|
}
|
||
|
|
||
11 years ago
|
window.addEventListener('touchend', function (e) {
|
||
12 years ago
|
var popover = getPopover(e);
|
||
|
|
||
|
if (!popover) return;
|
||
|
|
||
|
popover.style.display = 'block';
|
||
|
popover.offsetHeight;
|
||
|
popover.classList.add('visible');
|
||
|
|
||
|
popover.parentNode.appendChild(backdrop);
|
||
11 years ago
|
});
|
||
12 years ago
|
|
||
11 years ago
|
window.addEventListener('click', function (e) { if (getPopover(e)) e.preventDefault(); });
|
||
12 years ago
|
|
||
|
}();
|