This question is Semi-related to Wordpress, but has applications elsewhere. Basically, I'm trying to make it so when someone exits out of a Thickbox, it triggers an event elsewhere on the page. Editting the Thickbox file isn't an option.
It's a bit complicated since Thickbox isn't written that way. But maybe you can use some tricks to do it.
It's not the recommended solution but you can "rewrite" the close function. Something like:
var old_tb_remove = window.tb_remove;
var tb_remove = function() {
old_tb_remove(); // calls the tb_remove() of the Thickbox plugin
alert('ohai');
};
Works \o/ http://jsfiddle.net/8q2JK/1/
You can try something like this...
var tb_unload_count = 1;
$(window).bind('tb_unload', function () {
if (tb_unload_count > 1) {
tb_unload_count = 1;
} else {
// do something here
tb_unload_count = tb_unload_count + 1;
}
});
tb_unload
is triggered twice so this includes a bit of a hack to make sure your code doesn't run the second time.
Not sure if this is a global solution, but for WordPress, at least for the latest version (4.9.5), you can use:
jQuery( 'body' ).on( 'thickbox:removed', function() {
// Your code here.
});
In Thickbox v3.1, tb_remove() calls:
jQuery( 'body' ).trigger( 'thickbox:removed' );
See: https://github.com/WordPress/WordPress/blob/master/wp-includes/js/thickbox/thickbox.js#L290
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With