Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "0.12"
- "iojs"
- "iojs-v1.0.4"
15 changes: 9 additions & 6 deletions demo/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ $(function() {
plupload.each(files, function(file) {
var progress = new FileProgress(file, 'fsUploadProgress');
progress.setStatus("等待...");
progress.bindUploadCancel(up);
});
},
'BeforeUpload': function(up, file) {
Expand All @@ -43,12 +44,14 @@ $(function() {
if (up.runtime === 'html5' && chunk_size) {
progress.setChunkProgess(chunk_size);
}
progress.bindUploadCancel(up);
},
'UploadProgress': function(up, file) {
var progress = new FileProgress(file, 'fsUploadProgress');
var chunk_size = plupload.parseSize(this.getOption('chunk_size'));

progress.setProgress(file.percent + "%", file.speed, chunk_size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否需要在 3个地方调用 progress.uploadCancel(up); ,还是说只一次绑定就可以了。

progress.bindUploadCancel(up);

},
'UploadComplete': function() {
$('#success').show();
Expand All @@ -58,11 +61,11 @@ $(function() {
progress.setComplete(up, info);
},
'Error': function(up, err, errTip) {
$('table').show();
var progress = new FileProgress(err.file, 'fsUploadProgress');
progress.setError();
progress.setStatus(errTip);
}
$('table').show();
var progress = new FileProgress(err.file, 'fsUploadProgress');
progress.setError();
progress.setStatus(errTip);
}
// ,
// 'Key': function(up, file) {
// var key = "";
Expand Down
1 change: 1 addition & 0 deletions demo/js/qiniu.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ function QiniuJsSDK() {
});

uploader.bind('UploadProgress', function(up, file) {

// 计算速度

speedCalInfo.currentTime = new Date().getTime();
Expand Down
35 changes: 25 additions & 10 deletions demo/js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function FileProgress(file, targetID) {
var progressBarWrapper = $("<div/>");
progressBarWrapper.addClass("progress progress-striped");


var progressBar = $("<div/>");
progressBar.addClass("progress-bar progress-bar-info")
.attr('role', 'progressbar')
Expand All @@ -44,22 +43,18 @@ function FileProgress(file, targetID) {
var progressBarPercent = $('<span class=sr-only />');
progressBarPercent.text(fileSize);


var progressCancel = $('<a href=# />');
progressCancel.hide().addClass('progressCancel').text('');

var progressCancel = $('<a href=javascript:; />');
progressCancel.show().addClass('progressCancel').text('×');

progressBar.append(progressBarPercent);
progressBarWrapper.append(progressBar);
progressBarBox.append(progressBarWrapper);
progressBarBox.append(progressCancel);


var progressBarStatus = $('<div class="status text-center"/>');
progressBarBox.append(progressBarStatus);
progressBarTd.append(progressBarBox);


Wrappeer.append(progressText);
Wrappeer.append(progressSize);
Wrappeer.append(progressBarTd);
Expand Down Expand Up @@ -141,6 +136,7 @@ FileProgress.prototype.setProgress = function(percentage, speed, chunk_size) {
if (file.status !== plupload.DONE && percentage === 100) {
percentage = 99;
}

progressbar.attr('aria-valuenow', percentage).css('width', percentage + '%');

if (chunk_size) {
Expand Down Expand Up @@ -187,7 +183,8 @@ FileProgress.prototype.setProgress = function(percentage, speed, chunk_size) {
};

FileProgress.prototype.setComplete = function(up, info) {
var td = this.fileProgressWrapper.find('td:eq(2) .progress');
var td = this.fileProgressWrapper.find('td:eq(2)'),
tdProgress = td.find('.progress');

var res = $.parseJSON(info);
var url;
Expand All @@ -203,7 +200,8 @@ FileProgress.prototype.setComplete = function(up, info) {
"<div class=hash><strong>Hash:</strong>" + res.hash + "</div>";
}

td.html(str).removeClass().next().next('.status').hide();
tdProgress.html(str).removeClass().next().next('.status').hide();
td.find('.progressCancel').hide();

var progressNameTd = this.fileProgressWrapper.find('.progressName');
var imageView = '?imageView2/1/w/100/h/100';
Expand Down Expand Up @@ -360,7 +358,9 @@ FileProgress.prototype.setCancelled = function(manual) {
progressContainer += ' red';
}
this.fileProgressWrapper.attr('class', progressContainer);
this.fileProgressWrapper.find('td .progress .progress-bar-info').css('width', 0);
this.fileProgressWrapper.find('td .progress').remove();
this.fileProgressWrapper.find('td:eq(2) .btn-default').hide();
this.fileProgressWrapper.find('td:eq(2) .progressCancel').hide();
};

FileProgress.prototype.setStatus = function(status, isUploading) {
Expand All @@ -369,6 +369,21 @@ FileProgress.prototype.setStatus = function(status, isUploading) {
}
};

// 绑定取消上传事件
FileProgress.prototype.bindUploadCancel = function(up) {
var self = this;
if (up) {

self.fileProgressWrapper.find('td:eq(2) .progressCancel').on('click', function(){
self.setCancelled(false);
self.setStatus("取消上传");
self.fileProgressWrapper.find('.status').css('left', '0');
up.removeFile(self.file);
return true;
});
}

};

FileProgress.prototype.appear = function() {
if (this.getTimer() !== null) {
Expand Down
12 changes: 12 additions & 0 deletions demo/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ h1 .view_code {
position: relative;
height: 100%;
}
tr .progress{
width: 96%;
display: inline-block;
}
tr .progress-bar {
min-height: 20px;
float: none;
Expand All @@ -63,6 +67,14 @@ tr .progress .chunk-status {
left: 24px;
top: 0;
}
tr .progressCancel{
display: inline-block;
float: right;
position: relative;
z-index: 100;
color: #333;
text-decoration: none;
}
.status {
position: absolute;
width: 100%;
Expand Down
1 change: 1 addition & 0 deletions src/qiniu.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ function QiniuJsSDK() {
});

uploader.bind('UploadProgress', function(up, file) {

// 计算速度

speedCalInfo.currentTime = new Date().getTime();
Expand Down
2 changes: 1 addition & 1 deletion src/qiniu.min.js

Large diffs are not rendered by default.