danielm / uploader

A lightweight and very configurable jQuery plugin for file uploading using ajax(a sync); includes support for queues, progress tracking and drag and drop.
https://danielmg.org/demo/java-script/uploader
MIT License
1.17k stars 384 forks source link

Reset queue.length ? #21

Closed markbratanov closed 6 years ago

markbratanov commented 9 years ago

Looking for a way to reset queue.length, i.e. want only 1 upload but allow user to reset / re-upload an image without reloading the script.

Any ideas how to do this?

Not an issue, sorry for listing this question here. I guess you could call it a feature-request :)

markbratanov commented 9 years ago

Got this to work. For those interested, I did the following :

DmUploader.prototype = {
    /**
     * Reset Queue Length 
     */ 
    resetQueue: function()
    {
      this.queue.length = 0;
    }
  }

and changed the $.fn.dmUploader to include methods:

$.fn.dmUploader = function(options){

        var args = arguments;

        if (options === undefined || typeof options === 'object') {
            return this.each(function () {
              if(!$.data(this, pluginName)){
                $.data(this, pluginName, new DmUploader(this, options));
              }
            });

        // If the first parameter is a string and it doesn't start
        // with an underscore or "contains" the `init`-function,
        // treat this as a call to a public method.
        } else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {

            // Cache the method call
            // to make it possible
            // to return a value
            var returns;

            this.each(function () {
                var instance = $.data(this, pluginName);

                // Tests that there's already a plugin-instance
                // and checks that the requested public method exists
                if (instance instanceof DmUploader && typeof instance[options] === 'function') {

                    // Call the method of our plugin instance,
                    // and pass it the supplied arguments.
                    returns = instance[options].apply( instance, Array.prototype.slice.call( args, 1 ) );
                }

                // Allow instances to be destroyed via the 'destroy' method
                if (options === 'destroy') {
                  $.data(this, pluginName, null);
                }
            });

            // If the earlier cached method
            // gives a value back return the value,
            // otherwise return this to preserve chainability.
            return returns !== undefined ? returns : this;
        }
  }
danielm commented 6 years ago

Closing the issue. For future reference, feature included in newest release.