You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
}
The text was updated successfully, but these errors were encountered:
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.
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.
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!
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);
}
The text was updated successfully, but these errors were encountered: