var button = false;
var active = true;
$(document).ready(function () {
$('div.emailReportIcon').CreateBubblePopup({
manageMouseEvents: false
});
$('div.emailReportIcon').click(function (event) {
resetActiveBubble();
button = $(this);
active = true;
var email = button.attr("data-email");
var message = '<div style="padding:10px;width: 250px;"><p><input type="checkbox"> Email me when new reports are ready.</p>' + '<p>Email Address<br /><input type="text" value="' + email + '"></p>' + '<div >' + '<input type="image" name="submit" value="submit" class="submitButton">' + '</div></div>';
button.ShowBubblePopup({
manageMouseEvents: false,
position: 'bottom',
align: 'left',
tail: {
align: 'left'
},
innerHtml: message,
innerHtmlStyle: {
color: '#000',
'text-align': 'left'
},
themePath: 'http://www.maxvergelli.com/docs/jquery-bubble-popup-examples/images/jquerybubblepopup-themes',
alwaysVisible: false,
closingDelay: 200,
selectable: true,
afterShown: function() {
active = false;
$(".jquerybubblepopup").bind("mouseenter",function() {
active = true;
}).bind("mouseleave", function() {
active = false;
});
}
});
});
$(window).bind('click',function() {
resetActiveBubble();
});
});
function resetActiveBubble() {
if ( button && active == false ) {
button.RemoveBubblePopup();
button.CreateBubblePopup({
manageMouseEvents: false
});
}
}
The above code has a window click listener, and a boolean variable to determine whether the bubble is "active" or not (e.g mouse is sitting over the bubble).
This solution won't resolve for ipads etc (you'll need touch listeners), and when playing with jsfiddle, you can still close the bubble by clicking it during it's loading; the active state doesn't get attached until afterShown is fired.
I'm sure it can be optimised (also note the console.logs in the jsfiddle). I hope this helps.