From c5fd255856f3808f90d3b458e1f3269fbaaced9b Mon Sep 17 00:00:00 2001 From: Mike MacMillan Date: Thu, 4 Dec 2014 23:45:41 -0800 Subject: [PATCH] Added a global accessor for the popover implementation, POPOVER, allowing programmatic showing/hiding of the popover. --- js/popovers.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/js/popovers.js b/js/popovers.js index 0d71644..852149b 100644 --- a/js/popovers.js +++ b/js/popovers.js @@ -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; @@ -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; @@ -92,5 +91,12 @@ window.addEventListener('touchend', showHidePopover); window.addEventListener('click', showHidePopover); - + window.POPOVER = { + show: function (id) { + showHidePopover(null, id); + }, + hide: function () { + popover && hidePopover(); + } + }; }());