2

I'm registering multiple featherlight instances upon page-load

jQuery('.feedback').featherlight(jQuery( "#feedback-box" ), { closeIcon: 'close'});
jQuery('#imprint').featherlight(jQuery( "#imprint-box" ), { closeIcon: 'close'});

When one box is opened I would like to close all other open ones before.

How can I achieve this?

Edit: I tried this but it doesn't work.

$('.feedback').featherlight($( "#feedback-box" ), { 
    closeIcon: 'close', 
    beforeOpen: $.featherlight.close()
});
Hedge
  • 16,142
  • 42
  • 141
  • 246

1 Answers1

4

You want beforeOpen to be a function...

With the code you gave, you will get an error in the console, won't you?

You need to write instead:

// ...
beforeOpen: function() { $.featherlight.close() }
Marc-André Lafortune
  • 78,216
  • 16
  • 166
  • 166
  • It works, can you explain why the anonymous function is needed here? – Hedge Jun 10 '15 at 01:16
  • Just saw this. I guess `beforeOpen: $.featherlight.close` should work. With your code it would execute the close function and assign the return value to beforeOpen. Without the braces it just assigns the close function to beforeOpen – Daniel Z. Nov 02 '16 at 10:51
  • Should work too, as long as `close` doesn't rely on `this` being `$.featherlight`, which you can't really assume. – Marc-André Lafortune Nov 02 '16 at 14:37