JeremyFagis / dropify

Override your input files with style — Demo here : http://jeremyfagis.github.io/dropify
MIT License
974 stars 399 forks source link

Setting data-dropify attribute with something truthy makes Dropify object not be setted #93

Open yvesmedhard opened 5 years ago

yvesmedhard commented 5 years ago

Hello

When I set an data attribute 'data-dropify' with something truthy on my element and call element.data() the library do not instantiate the object Dropify correctly as the if results in false.

<input data-dropify="true">My input</input>
var input = $('[data-dropify="true"]');
var data = input.data();
input.dropify({});
$.fn[pluginName] = function(options) {
    this.each(function() {
    // as the data-attribute data-dropify is something truthy and not 
    // the Dropify instance it will not create it but will not work too.
        if (!$.data(this, pluginName)) {
            $.data(this, pluginName, new Dropify(this, options));
        }
    });

    return this;
};

So naming data-dropify data attribute is not a good pratice, but it would be better to the library to not depend on this, making a validation that the result of this call is the Dropify object and not something truthy only.