reference http://stackoverflow.com/a/6016404 http://www.codechewing.com/library/how-to-add-callback-functions-to-jquery-plugin/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(function( $ ) {
$.fn.upload = function(options ) {
var opts = $.extend({}, $.fn.upload.defaults, options);
function uploadFile(file, array_pos, ftp_filename, overwrite) {
// prepare XMLHttpRequest
var xhr = new XMLHttpRequest();
xhr.open('POST', "upload.php");
xhr.onload = function() {
if (this.status == 200) {
// Fire the setup callback
$.isFunction( opts.completed) && opts.completed.call( this, d.filename );
}
else {
$.isFunction( opts.error) && opts.error.call( this);
}
}
}
$.fn.upload.defaults = {
single : 1,
overwrite: 0,
ftp_filename: 0,
completed : null,
error : null
};
}
})( jQuery );
//use of
$("#product_drop_fl").upload({
single: 1,
overwrite : 1,
completed : function(e) {
$("#product_drop_fl_image").attr("src",e);
},
error : function() {
$("#product_drop_fl_image").attr("src","404.jpg");
}
});
origin - http://www.pipiscrew.com/?p=3339 jq-jquery-plugin-implement-callback