1 function fileQueueError(file,errorCode,message) {
2 try {
3 var imageName = "error.gif" 4 var errorName = "" 5 if (errorCode == SWFUpload.errorCode_QUEUE_LIMIT_EXCEEDED) {
6 errorName = "上传文件过多!" 7 8
if (errorName != "") {
10 alert(errorName);
11 12 13
14 switch (errorCode) {
15 case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
16 imageName = "zerobyte.gif" 17 break 18 SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
19 imageName = "toobig.gif" 20 21 22 SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
23 default:
alert(message);
25 27 添加图片,注意路径
28 addImage("/swfupload/images/" + imageName);
29
30 } (ex) {
31 .debug(ex);
32 33
34 }
35
36 fileDialogComplete(numFilesSelected,numFilesQueued) {
37 38 if (numFilesQueued > 0 39 .startUpload();
40 41 } 42 43 44 45
46 uploadProgress(file,bytesLoaded) {
47
48 49 var percent = Math.ceil((bytesLoaded / file.size) * 100 50
51 var progress = new FileProgress(file,1)">.customSettings.upload_target);
52 progress.setProgress(percent);
53 if (percent === 100 54 progress.setStatus("正在创建缩略图..." 55 progress.toggleCancel(false,1)"> 56 } else 57 progress.setStatus("正在上传..." 58 progress.toggleCancel(true,1)"> 59 60 } 61 62 63 64
65 uploadSuccess(file,serverData) {
66 67 添加缩略图~~~
68 修改这里来设置生成缩略图的页面
69 addImage("/Handlers/GetThumbHandler.ashx?id=" + serverData);
70 71 progress.setStatus("缩略图创建成功!" 72 progress.toggleCancel( 73 } 74 75 76 77
78 uploadComplete(file) {
79 80 I want the next upload to continue automatically so I'll call startUpload here 81 if (this.getStats().files_queued > 0 82 83 } 84 progress.setComplete();
86 progress.setStatus("图片上传成功" 87 progress.toggleCancel( 88 89 } 90 91 92 94 uploadError(file,1)"> 95 var imageName = "error.gif" 96 var progress;
97 98 99 SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
100 101 progress = progress.setCancelled();
103 progress.setStatus("上传操作被取消"104 progress.toggleCancel(105 106 (ex1) {
.debug(ex1);
109 110 SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
111 112 progress = 113 114 progress.setStatus("上传停止!"115 progress.toggleCancel(true116 117 (ex2) {
118 .debug(ex2);
120 SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
121 imageName = "uploadlimit.gif"122 123 124 125 126 127
128 addImage("/swfupload/images/" +129
130 } (ex3) {
131 .debug(ex3);
132 133
134 135
136 addImage(src) {
137 var newImg = document.createElement("img"138 newImg.style.margin = "5px"139 document.getElementById("thumbnails").appendChild(newImg);
140 (newImg.filters) {
141 142 newImg.filters.item("DXImageTransform.Microsoft.Alpha").opacity = 0143 } (e) {
144 If it is not set initially,the browser will throw an error. This will set it if it is not set yet.
145 newImg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + 0 + ')'146 147 } 148 newImg.style.opacity = 0149 150
151 newImg.onload = () {
152 fadeIn(newImg,0153 };
154 newImg.src = src;
155 156
157 fadeIn(element,opacity) {
158 var reduceOpacityBy = 5159 var rate = 30; 15 fps
160
161
162 if (opacity < 100163 opacity += reduceOpacityBy;
164 if (opacity > 100165 opacity = 100166 167
168 (element.filters) {
169 170 element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
171 } 172 173 element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')'174 175 } 176 element.style.opacity = opacity / 100177 178 179
180 181 setTimeout(182 fadeIn(element,opacity);
183 },rate);
184 185 186
187 ******************************************
188 * FileProgress Object
189 * Control object for displaying file info
190 * ****************************************** 191
192 FileProgress(file,targetID) {
193 this.fileProgressID = "divFileProgress"194
195 this.fileProgressWrapper = document.getElementById(.fileProgressID);
196 if (!.fileProgressWrapper) {
197 this.fileProgressWrapper = document.createElement("div"198 this.fileProgressWrapper.className = "progressWrapper"199 this.fileProgressWrapper.id = .fileProgressID;
200
201 this.fileProgressElement = document.createElement("div"202 this.fileProgressElement.className = "progressContainer"203
204 var progressCancel = document.createElement("a"205 progressCancel.className = "progressCancel"206 progressCancel.href = "#"207 progressCancel.style.visibility = "hidden"208 progressCancel.appendChild(document.createTextNode(" "));
209
210 var progressText = document.createElement("div"211 progressText.className = "progressName"212 progressText.appendChild(document.createTextNode(file.name));
213
214 var progressBar = document.createElement("div"215 progressBar.className = "progressBarInProgress"216
217 var progressStatus = document.createElement("div"218 progressStatus.className = "progressBarStatus"219 progressStatus.innerHTML = " "220
221 .fileProgressElement.appendChild(progressCancel);
222 .fileProgressElement.appendChild(progressText);
223 .fileProgressElement.appendChild(progressStatus);
224 .fileProgressElement.appendChild(progressBar);
225
226 this.fileProgressWrapper.appendChild(.fileProgressElement);
227
228 document.getElementById(targetID).appendChild(.fileProgressWrapper);
229 fadeIn(this.fileProgressWrapper,1)">230
231 } 232 this.fileProgressElement = .fileProgressWrapper.firstChild;
233 this.fileProgressElement.childNodes[1].firstChild.nodeValue = file.name;
234 235
236 this.height = .fileProgressWrapper.offsetHeight;
237
238 239 FileProgress.prototype.setProgress = (percentage) {
240 this.fileProgressElement.className = "progressContainer green"241 this.fileProgressElement.childNodes[3].className = "progressBarInProgress"242 this.fileProgressElement.childNodes[3].style.width = percentage + "%"243 };
244 FileProgress.prototype.setComplete = 245 this.fileProgressElement.className = "progressContainer blue"246 this.fileProgressElement.childNodes[3].className = "progressBarComplete"247 this.fileProgressElement.childNodes[3].style.width = ""248
249 250 FileProgress.prototype.setError = 251 this.fileProgressElement.className = "progressContainer red"252 this.fileProgressElement.childNodes[3].className = "progressBarError"253 254
255 256 FileProgress.prototype.setCancelled = 257 258 259 260
261 262 FileProgress.prototype.setStatus = (status) {
263 this.fileProgressElement.childNodes[2].innerHTML = status;
264 265 FileProgress.prototype.toggleCancel = (show,swfuploadInstance) {
266 this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden"267 (swfuploadInstance) {
268 var fileID = 269 this.fileProgressElement.childNodes[0].onclick = 270 swfuploadInstance.cancelUpload(fileID);
271 272 };
273 274 };