Skip to content

Instantly share code, notes, and snippets.

@adrexia
Created November 29, 2012 03:24
Show Gist options
  • Save adrexia/4166595 to your computer and use it in GitHub Desktop.
Save adrexia/4166595 to your computer and use it in GitHub Desktop.
Close tabs when something else is clicked
var that = this;
var closeHandler = function(event){
if (!$(event.target).closest(that).length) {
that.tabs('option', 'active', false);
var frame = $('.cms').find('iframe');
frame.each(function(index, iframe){
$(iframe).contents().off('click', closeHandler);
});
$(document).off('click', closeHandler);
};
}
this.tabs({
beforeActivate:function(event, ui){
var frame = $('.cms').find('iframe');
$(document).on('click', closeHandler);
//Make sure iframe click also closes tab
if(frame.length > 0){
frame.each(function(index, iframe){
$(iframe).contents().on('click', closeHandler);
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment