Skip to content

Commit

Permalink
Added a global accessor for the popover implementation, POPOVER, allo…
Browse files Browse the repository at this point in the history
…wing programmatic showing/hiding of the popover.
  • Loading branch information
mmacmillan committed Dec 5, 2014
1 parent a7dd7f0 commit c5fd255
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions js/popovers.js
Expand Up @@ -40,22 +40,21 @@
var element = document.createElement('div');

element.classList.add('backdrop');

element.addEventListener('touchend', hidePopover);
element.addEventListener('click', hidePopover);

return element;
}());

var getPopover = function (e) {
var anchor = findPopovers(e.target);
var getPopover = function (e, id) {
var anchor = e && findPopovers(e.target);

if (!anchor || !anchor.hash || (anchor.hash.indexOf('/') > 0)) {
if ((!anchor || !anchor.hash || (anchor.hash.indexOf('/') > 0)) && !id) {
return;
}

try {
popover = document.querySelector(anchor.hash);
popover = document.querySelector(id || anchor.hash);
}
catch (error) {
popover = null;
Expand All @@ -72,8 +71,8 @@
return popover;
};

var showHidePopover = function (e) {
var popover = getPopover(e);
var showHidePopover = function (e, id) {
var popover = getPopover(e, id);

if (!popover || !!listener) {
return;
Expand All @@ -92,5 +91,12 @@

window.addEventListener('touchend', showHidePopover);
window.addEventListener('click', showHidePopover);

window.POPOVER = {
show: function (id) {
showHidePopover(null, id);
},
hide: function () {
popover && hidePopover();
}
};

This comment has been minimized.

Copy link
@mmacmillan

mmacmillan Dec 5, 2014

Author

"POPOVER" name chosen based on the push.js's "PUSH" global being ratchet's only export...may not be an ideal name, could be a good time to choose a global "namespace" for ratchet to house further additional functionality.

}());

0 comments on commit c5fd255

Please sign in to comment.