Opened and closed events #246

Closed
Blackskyliner opened this Issue Oct 17, 2014 · 4 comments

Projects

None yet

2 participants

@Blackskyliner
Contributor

It would be nice to have some events we could just grab with jQuery somehow.

  • modal-opened(sender) // sender is the element which opened the modal
  • modal-closed(sender) // sender is the original one which opened the modal

and maybe "advanced" ones like:

  • modal-redirect(target) // target uri, but I got no real use-case for this atm so its just more like an idea ;)

I know you got those callbacks for that, but they are kind of a hassle in moular js programming... where I got some late bind/execution of JS code etc.

@nyroDev
Owner
nyroDev commented Oct 17, 2014

you mean trigger some events on the opener tag to indicates wher we are in the popin?

@nyroDev nyroDev added the Todo label Oct 17, 2014
@Blackskyliner
Contributor

More like a global event like "hey there was an modal opened, if you are interested in doing whatever you want to do (like initializing some advanced java stuff inside the modal)".
The this argument for the callback would be the nm object like in callbacks.
The first agument would be the sender, or an event which has some source in it where the event originated from.

@nyroDev
Owner
nyroDev commented Oct 17, 2014

As the events aer bubling from bottom to top, it should work as you excpect.
I'll try something and a basic demo

@nyroDev nyroDev closed this in b7ae3ac Oct 17, 2014
@nyroDev
Owner
nyroDev commented Oct 17, 2014

You can see an example using it here: http://nyromodal.nyrodev.com/testBind.php

The code used show that you'll be able to bind directly on the opener, or in a more globaly place, in the body:

var csl = $('#console');

$('body').on({
    'init.nyroModal': function(e, nm) {
        csl.append('BODY: init<br />');
    },
    'load.nyroModal': function(e, nm) {
        csl.append('BODY: load<br />');
    },
    'afterShowCont.nyroModal': function(e, nm) {
        csl.append('BODY: afterShowCont<br />');
    },
    'close.nyroModal': function(e, nm) {
        csl.append('BODY: close<br />');
    }
});

$('.nyroModal').on({
    'init.nyroModal': function(e, nm) {
        csl.append('Element: init<br />');
    },
    'load.nyroModal': function(e, nm) {
        csl.append('Element: load<br />');
    },
    'afterShowCont.nyroModal': function(e, nm) {
        csl.append('Element: afterShowCont<br />');
    },
    'close.nyroModal': function(e, nm) {
        csl.append('Element: close<br />');
    }
}).nyroModal();

Every single call to the callFilter will be triggered, meaning that you can listen for every nyroModal event.

@nyroDev nyroDev added tips and removed Todo labels Oct 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment