jtsage / jtsage-datebox

A multi-mode date and time picker for Bootstrap (3&4), jQueryMobile, Foundation, Bulma, FomanticUI, and UIKit (or others)
http://datebox.jtsage.dev/
Other
474 stars 166 forks source link

options.openCallback / closeCallback breaking changes #333

Closed slavap closed 10 years ago

slavap commented 10 years ago

In previous version 1.4.2 the code was:

if ( ! $.isFunction(o.openCallback) ) {
    if ( typeof window[o.openCallback] !== 'undefined' ) {
        o.openCallback = window[o.openCallback];
    } else {
        o.openCallback = new Function(o.openCallback);
    }
} 

Now in version 1.4.4 it's:

if ( ! $.isFunction( o.openCallback ) ) {
    if ( typeof window[ o.openCallback ] === "function" ) {
        o.openCallback = window[ o.openCallback ];
    }
} 

Because o.openCallback = new Function(o.openCallback) is removed, my code is not working anymore, and now there is no way how I can define openCallback through data-options attribute. Please return back 'new Function(o.openCallback)' functionality. The same applies to closeCallback as well.

jtsage commented 10 years ago

Yeah, i actually did this to get rid of the ugly eval. I'll give this some more thought - fwiw, I found that to send in a function in data-options, it's much easier to name the function rather than create an anonymous function...

http://dev.jtsage.com/jQM-DateBox/doc/6-1-callback/ shows how I usually do it. of course, if you are building the function on the fly (i.e. serverside, this becomes a bit more difficult)

slavap commented 10 years ago

I don't like evals, but in some cases it's convenient to define function right in data-options. It's up to you, I'm OK with adding special function to window and then use its name.