Skip to content

Instantly share code, notes, and snippets.

@rnmp
Created August 5, 2011 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnmp/1127669 to your computer and use it in GitHub Desktop.
Save rnmp/1127669 to your computer and use it in GitHub Desktop.
$.fn.popup_handler = function(selector_to_show) {
var self = this;
var target = $(selector_to_show);
target.hide();
var target_shown = false;
var self_class = 'target-shown';
var target_show = function() {
target.show();
target_shown = true;
$(self).addClass(self_class);
};
var target_hide = function() {
target.hide();
target_shown = false;
$(self).removeClass(self_class);
};
target_if = function() {
if (target_shown == false) {
target_show();
} else {
target_hide();
}
};
$(this).toggle(function() {
target_if();
}, function() {
target_if();
});
$(window).click(function() {
target_hide();
});
target.click(function(e){
e.stopPropagation();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment