Created
November 29, 2012 03:24
-
-
Save adrexia/4166595 to your computer and use it in GitHub Desktop.
Close tabs when something else is clicked
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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