fileprogress_wev8.js
3.8 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
A simple class for displaying file information and progress
Note: This is a demonstration only and not part of SWFUpload.
Note: Some have had problems adapting this class in IE7. It may not be suitable for your application.
*/
// Constructor
// file is a SWFUpload file object
// targetID is the HTML element id attribute that the FileProgress HTML structure will be added to.
// Instantiating a new FileProgress object with an existing file will reuse/update the existing DOM elements
function FileProgress(file, targetID) {
var fileIconName = "";
this.fileProgressID = file.id;
this.opacity = 100;
this.height = 0;
this.fileProgressWrapper = document.getElementById(this.fileProgressID);
if (!this.fileProgressWrapper) {
} else {
this.fileProgressElement = this.fileProgressWrapper.firstChild;
}
this.height = this.fileProgressWrapper.offsetHeight;
}
FileProgress.prototype.setProgress = function (percentage) {
if($("#"+this.fileProgressID+"hiddens").length > 0)
{
this.disappear();
}
else
{
this.fileProgressElement.className = "rprogressContainer rgreen";
this.fileProgressElement.childNodes[8].className = "rprogressBarInProgress";
this.fileProgressElement.childNodes[8].style.width = percentage + "%";
}
};
FileProgress.prototype.setComplete = function () {
this.fileProgressElement.className = "rprogressContainer blue";
this.fileProgressElement.childNodes[6].className = "progressBarComplete";
this.fileProgressElement.childNodes[6].style.width = "";
var oSelf = this;
setTimeout(function () {
oSelf.disappear();
}, 5000);
};
FileProgress.prototype.setError = function () {
// this.fileProgressElement.className = "rprogressContainer red";
// this.fileProgressElement.childNodes[5].className = "progressBarError";
// this.fileProgressElement.childNodes[5].style.width = "";
var oSelf = this;
setTimeout(function () {
// oSelf.disappear();
}, 250000);
};
FileProgress.prototype.setCancelled = function () {
this.fileProgressElement.className = "rprogressContainer";
this.fileProgressElement.childNodes[6].className = "progressBarError";
this.fileProgressElement.childNodes[6].style.width = "";
var oSelf = this;
setTimeout(function () {
oSelf.disappear();
}, 500);
};
FileProgress.prototype.setStatus = function (status) {
this.fileProgressElement.childNodes[4].innerHTML = status;
};
// Show/Hide the cancel button
FileProgress.prototype.toggleCancel = function (show, swfUploadInstance) {
this.fileProgressElement.childNodes[5].style.visibility = show ? "visible" : "hidden";
if (swfUploadInstance) {
var fileID = this.fileProgressID;
this.fileProgressElement.childNodes[5].onclick = function () {
swfUploadInstance.cancelUpload(fileID);
return false;
};
}
};
// Fades out and clips away the FileProgress box.
FileProgress.prototype.disappear = function () {
var reduceOpacityBy = 15;
var reduceHeightBy = 4;
var rate = 30; // 15 fps
if (this.opacity > 0) {
this.opacity -= reduceOpacityBy;
if (this.opacity < 0) {
this.opacity = 0;
}
if (this.fileProgressWrapper.filters) {
try {
this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = this.opacity;
} catch (e) {
// If it is not set initially, the browser will throw an error. This will set it if it is not set yet.
this.fileProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + this.opacity + ")";
}
} else {
this.fileProgressWrapper.style.opacity = this.opacity / 100;
}
}
if (this.height > 0) {
this.height -= reduceHeightBy;
if (this.height < 0) {
this.height = 0;
}
this.fileProgressWrapper.style.height = this.height + "px";
}
if (this.height > 0 || this.opacity > 0) {
var oSelf = this;
setTimeout(function () {
oSelf.disappear();
}, rate);
} else {
this.fileProgressWrapper.style.display = "none";
}
};