Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event handler can't accept parameters. #184

Closed
awilliams219 opened this issue Mar 19, 2015 · 3 comments
Closed

Event handler can't accept parameters. #184

awilliams219 opened this issue Mar 19, 2015 · 3 comments
Labels

Comments

@awilliams219
Copy link

When an event is fired that has a handler attached with the jQuery .on method, the jQuery spec specifies that the first parameter to the handler function should be the event object, including a data object that is populated by one of the arguments in the .on method.

IAS ignores the spec and supplies a DOM object as the first parameter. In fact, there doesn't seem to be any support at all for passing in the data object, rendering it impossible to pass arguments into the event handler function.

To keep it consistent with jQuery, the current first argument to the handler function should be moved to the second argument and replaced with the jQuery event object.

ex:

function init () {
var pageData = { ... };
var params = { argument1: "stuff", argument2: "more stuff" };
var ias = jQuery.ias(pageData);
ias.on('rendered', params, handler);
}

function handler(event, dom) {
var argument1 = event.data.argument1;
var argument2 = event.data.argument2;

do(stuff).with(dom);
}

@fieg
Copy link
Member

fieg commented Mar 19, 2015

I'm not sure. If we would do that, we would also have to make the first argument "event" in the handler consistent with jQuery, so it should be an Event object. But I'm not sure if that would work with the events that IAS is triggering.

@awilliams219
Copy link
Author

Even if it's not a jQuery event, there needs to be some way to get arguments into the event handler. We had to temporarily abandon some planned site functionality because the callbacks couldn't receive arguments.

It wasn't terribly important functionality, but it was frustrating, and may be a problem later if we end up needing it.

If I get some spare time, I'll fork the project and look at options to pass arguments to the event handler. If my code doesn't suck and works/tests well, I'll put in a pull request so you can use it.

@fieg
Copy link
Member

fieg commented Mar 19, 2015

Ok, I agree it would be nice to be able to add arguments to the event handler. Keeping it 100% consistent with jquery might not be necessary but we can use it as a guidance where needed.

I'm really looking forward to you PR, thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants