I'm having an issue with callback functions with this module. In the advanced option on the settings page, you can add callback functions to be called after certain events. However these functions are not being called.
From the best that I can tell, the fancybox javascript code is checking $.isFunction before calling the function. $.isFunction is returning false because the callback function names are being stored in currentOpts variable surrounded by quotes. If you call $.isFunction from the console without the quotes, it returns true. I'm not sure where a change needs to be made to remove these quotes. Thanks for your help.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | function_eval.patch | 639 bytes | muenzer |
Comments
Comment #1
bas.hr commentedI had the same problem with the padding and margin properties that needed to be stored as integers, without the quotes. Will try to find a solution for callbacks since they are strings and I can't cast them before storing them in currentOpts.
Comment #2
muenzer commentedI think I found one possible solution. I ran the function names through eval in fancybox.js before saving the settings. For example:
settings.options.onClosed = eval(settings.options.onClosed);I can create a patch that does this for each of the actions, but there might be a more elegant way to handle this.
Comment #3
bas.hr commentedFlowplayer API had the same problem #370478: JavaScript Callbacks
They are also using solution proposed in comment #2, so I think we should do the same.
@muenzer just do the patch so we can fix this, if someone comes with more elegant solution we'll reopen this issue or create new one.
Comment #4
muenzer commentedHere is the patch for the running the function names through eval. I don't create patches often, so let me know if I did this right.
Comment #5
bas.hr commentedAlmost right :) Thanks for the patch!
I've tested your solution but I had problems with eval reporting syntax error before ‘{’ token in sample function:
function(){alert("event");}Then I found a ">solution:
eval accepts a sequence of Javascript statements. The Javascript parser interprets the ‘{’ token, occuring within a statement as the start of a block and not the start of an object literal.
When you enclose your literal into parentheses like this: ({ data_from_the_wire }) you are switching the Javascript parser into expression parsing mode. The token ‘{’ inside an expression means the start of an object literal declaration and not a block, and thus Javascript accepts it as an object literal.
Therefore I've enclosed function into parentheses and it worked. Committed into 6.x-1.x-dev.