Closed sgiraldo closed 10 years ago
function init_fileupload()
{
uploadButton = $('')
.addClass('btn btn-primary')
.prop('disabled', true)
.text('Отправка...')
.on('click', function() {
var $this = $(this),
data = $this.data();
$this.off('click')
.text('Отменить')
.on('click', function() {
$this.remove();
data.abort();
});
data.submit().always(function() {
$this.remove();
});
});
$('.asfileupload').each(function(i, e)
{
$action = $(e).data('action');
$(e).fileupload({
url: $action,
dataType: 'json',
autoUpload: true, //false,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
maxFileSize: 5000000, // 5 MB
disableImageResize: /Android(?!.*Chrome)|Opera/
.test(window.navigator.userAgent),
previewMaxWidth: 100,
previewMaxHeight: 100,
previewCrop: true
}).on('fileuploadadd', function(e, data) {
$($(this).data('fileslist-selector')).html('');
$parent = $(this).parentsUntil(null, '.picture')[0];
$progress = $(this).data('progress-selector');
$($parent).find($progress).parent().slideDown();
data.context = $('').appendTo($(this).data('fileslist-selector'));
$.each(data.files, function(index, file) {
var node = $('')
.append($('').text(file.name));
if (!index) {
node
.append('
')
.append(uploadButton.clone(true).data(data));
}
node.appendTo(data.context);
});
}).on('fileuploadchunksend', function(e, data) {
}).on('fileuploadprogressall', function(e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$parent = $(this).parentsUntil(null, '.picture')[0];
$progress = $(this).data('progress-selector');
$($parent).find($progress).css(
'width',
progress + '%'
);
}).on('fileuploaddone', function(e, data) {
$parent = $(this).parentsUntil(null, '.picture')[0];
$progress = $(this).data('progress-selector');
$($parent).find($progress).parent().slideUp();
//DONE!!!!!
myAlertMessage(data.jqXHR.responseJSON.message, data.jqXHR.responseJSON);
}).on('fileuploadfail', function(e, data) {
$parent = $(this).parentsUntil(null, '.picture')[0];
$progress = $(this).data('progress-selector');
$($parent).find($progress).parent().slideUp();
//ERROR!!!!!!
myAlertError('Error on sent file!', data);
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
});
}
input type="file" class="form-control asfileupload " data-action="http://upload.url" data-progress-selector="#progress-image .progress-bar" data-fileslist-selector="#fileslist-image" id="image" name="image" placeholder=""
If you override functionality, you'll need to reimplement that functionality.
To listen to the stop event without overriding the UI version stop callback, please use the fileuploadstop
event:
https://github.com/blueimp/jQuery-File-Upload/wiki/Options#wiki-callback-options
Hi,
In order to launch an own application after a file is uploaded, I have updated the 'stop' callback on jquery.fileupload-ui.js. Here you have the content
stop: function (e) { if (e.isDefaultPrevented()) { return false; } var that = $(this).data('blueimp-fileupload') || $(this).data('fileupload'), deferred = that._addFinishedDeferreds(); $.when.apply($, that._getFinishedDeferreds()) .done(function () { that._trigger('stopped', e); }); that._transition($(this).find('.fileupload-progress')).done( function () { $(this).find('.progress') .attr('aria-valuenow', '0') .children().first().css('width', '0%'); $(this).find('.progress-extended').html(' '); deferred.resolve(); } ); showPhotos(); }
The function is called perfectly, but the progress bar doesn't fadeOut, even having reached 100%. I've tried putting the call to "loadPhotos" in 'processstop' or 'done' callback, but the result is the same.
I don't know if I'm completely wrong editing this piece of script. Are there another easy way to call my own function without modifying the usual flow of the script? Can I force the fadeOut of the progressbar before calling my own function??
Thanks.