javascript - jQuery plugin: Prevent override options -
i did custom plugin add common functionality , validations jquery file upload plugin. resume can idea.
$.fn.mycustomupload = function(options) { if (!$(this).is('input:file')) { return false; } $(this).fileupload({ maxchunksize: options.maxchunksize, maxfilesize: options.maxfilesize, acceptfiletypes: options.allowedtypes, type: 'post', datatype: 'json', add: function (e, data) { // common validations }, start: function (e) { // foo if (options.onuploadstart) { options.onuploadstart(); } }, fail: function(e, data) { // foo if (options.onuploaderror) { options.onuploaderror(result); } }, done: function(e, data) { // foo if (options.onuploaddone) { options.onuploaddone(media_data); } } }); };
the thing made validations or process data, , return results callbacks. but, notice callbacks override next call plugin.. so, upload file in 1 place, , re result show in another! i'm doing wrong?
should need store options each input element, .data()
?
edit 2: fiddle of html, , js structure (not functional) https://jsfiddle.net/a6axfm3v/
edit: use plugin in 2 ways
$input.mycustomupload({ // ... onuploadstart: this.onnewpostuploadstart.bind(this), onuploadprogress: this.onnewpostuploadprogress.bind(this), //this reference object onuploaderror: this.onnewpostuploaderror.bind(this), // ... }); $uploads_buttons = $container.find('._attach_image'); $uploads_buttons.each(function() { var $upload_button = $(this); var $parent = $upload_button.parents('._post-container'); $upload_button.mycustomupload({ /*options, callbacks, etc*/}); });
$input
has own callbacks, , $uploads_buttons
have same, different $input
ones..
thanks.
Comments
Post a Comment