123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- function FileProgress(file, targetID) {
- //this.fileProgressID = file.id;
- this.fileProgressID = 0;
- this.opacity = 100;
- this.height = 0;
- this.fileProgressWrapper = document.getElementById(this.fileProgressID);
- if (!this.fileProgressWrapper) {
- this.fileProgressWrapper = document.createElement("div");
- this.fileProgressWrapper.className = "progressWrapper";
- this.fileProgressWrapper.id = this.fileProgressID;
- this.fileProgressElement = document.createElement("div");
- this.fileProgressElement.className = "progressContainer";
- var progressCancel = document.createElement("a");
- progressCancel.className = "progressCancel";
- progressCancel.href = "#";
- progressCancel.style.visibility = "hidden";
- progressCancel.appendChild(document.createTextNode(" "));
- var progressText = document.createElement("div");
- progressText.className = "progressName";
- //
-
- //progressText.innerHTML = '<tr><td><a href="#" target="_blank">发票1.jpg</a></td><td>20kb</td><td><a href="">删除</a></td></tr>';
- //progressText.appendChild(document.createTextNode('<tr><td><a href="#" target="_blank">发票1.jpg</a></td><td>20kb</td><td><a href="">删除</a></td></tr>'));
- //progressText.appendChild(document.createTextNode(file.name));
- //td1.appendChild(document.createTextNode());
- // var tr = document.createElement("tr");
- // var td1 = document.createElement("td");
- // td1.innerHTML = '<a href="#" target="_blank">'+file.name+'</a>';
- // var td2 = document.createElement("td");
- // td2.innerHTML = toDecimal2(file.size/1024)+'kb';
- // var td3 = document.createElement("td");
- // td3.innerHTML = '<a href="#" target="_blank">删除</a>';
- // tr.appendChild(td1);
- // tr.appendChild(td2);
- // tr.appendChild(td3);
- //
- // var kt=document.getElementById('KT');
- // kt.appendChild(tr);
-
-
-
- var progressBar = document.createElement("div");
- progressBar.className = "progressBarInProgress";
- var progressStatus = document.createElement("div");
- progressStatus.className = "progressBarStatus";
- progressStatus.innerHTML = "";
- this.fileProgressElement.appendChild(progressCancel);
- this.fileProgressElement.appendChild(progressText);
- this.fileProgressElement.appendChild(progressStatus);
- this.fileProgressElement.appendChild(progressBar);
- this.fileProgressWrapper.appendChild(this.fileProgressElement);
- document.getElementById(targetID).appendChild(this.fileProgressWrapper);
- } else {
- this.fileProgressElement = this.fileProgressWrapper.firstChild;
- }
- this.height = this.fileProgressWrapper.offsetHeight;
- }
- FileProgress.prototype.setProgress = function (percentage) {
- this.fileProgressElement.className = "progressContainer green";
- this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
- this.fileProgressElement.childNodes[3].style.width = percentage + "%";
- };
- FileProgress.prototype.setComplete = function () {
- this.fileProgressElement.className = "progressContainer blue";
- this.fileProgressElement.childNodes[3].className = "progressBarComplete";
- this.fileProgressElement.childNodes[3].style.width = "";
- var oSelf = this;
- // setTimeout(function () {
- // oSelf.disappear();
- // }, 10000);
- };
- FileProgress.prototype.setError = function () {
- this.fileProgressElement.className = "progressContainer red";
- this.fileProgressElement.childNodes[3].className = "progressBarError";
- this.fileProgressElement.childNodes[3].style.width = "";
- var oSelf = this;
- setTimeout(function () {
- oSelf.disappear();
- }, 5000);
- };
- FileProgress.prototype.setCancelled = function () {
- this.fileProgressElement.className = "progressContainer";
- this.fileProgressElement.childNodes[3].className = "progressBarError";
- this.fileProgressElement.childNodes[3].style.width = "";
- var oSelf = this;
- setTimeout(function () {
- oSelf.disappear();
- }, 2000);
- };
- FileProgress.prototype.setStatus = function (status) {
- this.fileProgressElement.childNodes[2].innerHTML = status;
- };
- // Show/Hide the cancel button
- FileProgress.prototype.toggleCancel = function (show, swfUploadInstance) {
- this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";
- if (swfUploadInstance) {
- var fileID = this.fileProgressID;
- this.fileProgressElement.childNodes[0].onclick = function () {
- swfUploadInstance.cancelUpload(fileID);
- return false;
- };
- }
- };
- // Fades out and clips away the FileProgress box.
- FileProgress.prototype.disappear1 = 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";
- }
- };
- function toDecimal2(x) {
- var f = parseFloat(x);
- if (isNaN(f)) {
- return false;
- }
- var f = Math.round(x*100)/100;
- var s = f.toString();
- var rs = s.indexOf('.');
- if (rs < 0) {
- rs = s.length;
- s += '.';
- }
- while (s.length <= rs + 2) {
- s += '0';
- }
- return s;
- }
|