I want to create a plugin, which will be looking for a img
file on PC, and after load this image file, the user can choose some methods to apply in this. For example, in a call plugin:
$('#test').myPlugin({
legend: true
});
And my code for plugin upload a file is this:
(function( $ ){
var handleFileSelect = function (evt) {
var files = evt.target.files;
for(var i = 0, f; f = files[i]; i++) {
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
// Render thumbnail.
var span = document.createElement('span');
span.innerHTML = ['<img class="responsive-img thumb" src="', e.target.result,
'" title="', escape(theFile.name), '"/>'].join('');
document.getElementById('list').insertBefore(span, null);
};
})(f);
reader.readAsDataURL(f);
}
};
$.fn.upload = function(options) {
var settings = $.extend( {}, options );
return this.each(function() {
document.getElementById('files').addEventListener('change', handleFileSelect, false);
});
};
})( jQuery );
This code works fine on upload img
, but I don´t have idea, how I can add methods in this plugin. Someone help me?
Thanks!