Browse Source

Fixes #445 popup using click can sometimes open/close, caused by document clickaway event being preserved

pull/471/head
jlukic 11 years ago
parent
commit
5d4c45cf43
1 changed files with 16 additions and 7 deletions
  1. 23
      src/modules/popup.js

23
src/modules/popup.js

@ -187,10 +187,13 @@ $.fn.popup = function(parameters) {
toggle: function() { toggle: function() {
module.debug('Toggling pop-up'); module.debug('Toggling pop-up');
if( module.is.hidden() ) { if( module.is.hidden() ) {
module.debug('Popup is hidden, showing pop-up');
module.unbind.close();
module.hideAll(); module.hideAll();
module.show(); module.show();
} }
else { else {
module.debug('Popup is visible, hiding pop-up');
module.hide(); module.hide();
} }
}, },
@ -231,9 +234,13 @@ $.fn.popup = function(parameters) {
hideGracefully: function(event) { hideGracefully: function(event) {
// don't close on clicks inside popup // don't close on clicks inside popup
if( $(event.target).closest(selector.popup).size() === 0) {
if(event && $(event.target).closest(selector.popup).size() === 0) {
module.debug('Click occurred outside popup hiding popup');
module.hide(); module.hide();
} }
else {
module.debug('Click was inside popup, keeping popup open');
}
}, },
exists: function() { exists: function() {
@ -265,11 +272,7 @@ $.fn.popup = function(parameters) {
}, },
restore: { restore: {
conditions: function() { conditions: function() {
if(module.cache === undefined) {
module.error(error.cache);
return false;
}
if(module.cache.title) {
if(module.cache && module.cache.title) {
$module.attr('title', module.cache.title); $module.attr('title', module.cache.title);
} }
module.verbose('Restoring original attributes', module.cache.title); module.verbose('Restoring original attributes', module.cache.title);
@ -555,7 +558,10 @@ $.fn.popup = function(parameters) {
if(settings.on == 'click' && settings.closable) { if(settings.on == 'click' && settings.closable) {
module.verbose('Binding popup close event to document'); module.verbose('Binding popup close event to document');
$document $document
.on('click' + eventNamespace, module.hideGracefully)
.on('click' + eventNamespace, function(event) {
module.verbose('Pop-up clickaway intent detected');
$.proxy(module.hideGracefully, this)(event);
})
; ;
} }
} }
@ -573,6 +579,9 @@ $.fn.popup = function(parameters) {
}, },
is: { is: {
animating: function() {
return ( $popup.is(':animated') || $popup.hasClass(className.transition) );
},
visible: function() { visible: function() {
return $popup.is(':visible'); return $popup.is(':visible');
}, },

Loading…
Cancel
Save