From 12103fc45baa9838cc89edd1e9e1883780aa21b2 Mon Sep 17 00:00:00 2001 From: Harry Hornreich Date: Sat, 2 Jul 2011 15:36:40 +0300 Subject: [PATCH] added ability close current popover in document --- README.rdoc | 4 ++++ jquery.popover.js | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index ea19e18..03a300b 100644 --- a/README.rdoc +++ b/README.rdoc @@ -103,6 +103,10 @@ You can programmatically open and close a popover by using the following: $('#button').trigger('hidePopover'); +To close the currently open popover, for example from the cancel button of a popup dialog, do the following: + + $(document).trigger('hidePopover'); + == Popover styling The popover style provided in popover.css is a basic style to mimic the iPad popover look & feel but you can style it anyway you like. diff --git a/jquery.popover.js b/jquery.popover.js index 9f48b53..02fcfe2 100644 --- a/jquery.popover.js +++ b/jquery.popover.js @@ -30,7 +30,7 @@ settings.triangle$ = $('.triangle', settings.popover$); - // Document click closes active popover + // document click closes active popover $.fn.popover.openedPopup = null; $(document).bind("click", function(event) { if ($.fn.popover.openedPopup != null @@ -40,6 +40,11 @@ } }); + // document hidePopover causes active popover to close + $(document).bind("hidePopover", function(event) { + $.fn.popover.openedPopup.trigger('hidePopover'); + }); + // keyboard callback function keyDown(event) { if (!event.altKey && !event.ctrlKey && !event.shiftKey) {