~vcs-imports/clansuite/trunk

« back to all changes in this revision

Viewing changes to themes/core/javascript/swfupload/handlers.js

  • Committer: paulbr
  • Date: 2011-01-13 19:44:03 UTC
  • Revision ID: paulbr-20110113194403-gwsy005jgfrqyzca
Ajax Test Modul

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function preLoad() {
 
2
        if (!this.support.loading) {
 
3
                alert("You need the Flash Player 9.028 or above to use SWFUpload.");
 
4
                return false;
 
5
        }
 
6
}
 
7
function loadFailed() {
 
8
        alert("Something went wrong while loading SWFUpload. If this were a real application we'd clean up and then give you an alternative");
 
9
}
 
10
 
 
11
function fileQueueError(file, errorCode, message) {
 
12
        try {
 
13
                var imageName = "error.gif";
 
14
                var errorName = "";
 
15
                if (errorCode === SWFUpload.errorCode_QUEUE_LIMIT_EXCEEDED) {
 
16
                        errorName = "You have attempted to queue too many files.";
 
17
                }
 
18
 
 
19
                if (errorName !== "") {
 
20
                        alert(errorName);
 
21
                        return;
 
22
                }
 
23
 
 
24
                switch (errorCode) {
 
25
                case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
 
26
                        imageName = "zerobyte.gif";
 
27
                        break;
 
28
                case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
 
29
                        imageName = "toobig.gif";
 
30
                        break;
 
31
                case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
 
32
                case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
 
33
                default:
 
34
                        alert(message);
 
35
                        break;
 
36
                }
 
37
 
 
38
                addImage("themes/core/javascript/swfupload/" + imageName);
 
39
 
 
40
        } catch (ex) {
 
41
                this.debug(ex);
 
42
        }
 
43
 
 
44
}
 
45
 
 
46
function fileDialogComplete(numFilesSelected, numFilesQueued) {
 
47
        try {
 
48
                if (numFilesQueued > 0) {
 
49
                        this.startResizedUpload(this.getFile(0).ID, this.customSettings.picture_width, this.customSettings.picture_height, SWFUpload.RESIZE_ENCODING.JPEG, this.customSettings.picture_quality, false);
 
50
                        //this.startUpload();
 
51
                }
 
52
        } catch (ex) {
 
53
                this.debug(ex);
 
54
        }
 
55
}
 
56
 
 
57
function uploadProgress(file, bytesLoaded) {
 
58
 
 
59
        try {
 
60
                var percent = Math.ceil((bytesLoaded / file.size) * 100);
 
61
 
 
62
                var progress = new FileProgress(file,  this.customSettings.upload_target);
 
63
                progress.setProgress(percent);
 
64
                progress.setStatus("Uploading...");
 
65
                progress.toggleCancel(true, this);
 
66
        } catch (ex) {
 
67
                this.debug(ex);
 
68
        }
 
69
}
 
70
 
 
71
function uploadSuccess(file, serverData) {
 
72
        try {
 
73
 
 
74
                document.getElementById("image_small").value = file.name;
 
75
                var progress = new FileProgress(file,  this.customSettings.upload_target);
 
76
 
 
77
                if( file.name != '' ) {
 
78
                        addImg( this.customSettings.uploadpath + "/temps/" + file.name );
 
79
                } else {
 
80
                        addImg(this.customSettings.uploadpath + "/logo_none.jpg");
 
81
                }
 
82
 
 
83
                if (serverData.substring(0, 7) === "FILEID:") {
 
84
                        //addImage("uploads/thumbnail.php?id=" + serverData.substring(7));
 
85
                        progress.setStatus("Upload Complete.");
 
86
                        progress.toggleCancel(false);
 
87
 
 
88
                } else {
 
89
                        //addImage("themes/core/javascript/swfupload/error.gif");
 
90
                        progress.setStatus("Error.");
 
91
                        progress.toggleCancel(false);
 
92
                        alert(serverData);
 
93
                }
 
94
 
 
95
        } catch (ex) {
 
96
                this.debug(ex);
 
97
        }
 
98
}
 
99
 
 
100
function uploadComplete(file) {
 
101
        try {
 
102
                /*  I want the next upload to continue automatically so I'll call startUpload here */
 
103
                if (this.getStats().files_queued > 0) {
 
104
                        this.startResizedUpload(this.getFile(0).ID, this.customSettings.picture_width, this.customSettings.picture_height, SWFUpload.RESIZE_ENCODING.JPEG, this.customSettings.picture_quality, false);
 
105
                        //this.startUpload();
 
106
                } else {
 
107
                        var progress = new FileProgress(file,  this.customSettings.upload_target);
 
108
                        progress.setComplete();
 
109
                        progress.setStatus("All images received.");
 
110
                        progress.toggleCancel(false);
 
111
                }
 
112
        } catch (ex) {
 
113
                this.debug(ex);
 
114
        }
 
115
}
 
116
 
 
117
function uploadError(file, errorCode, message) {
 
118
        var imageName =  "error.gif";
 
119
        var progress;
 
120
        try {
 
121
                switch (errorCode) {
 
122
                case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
 
123
                        try {
 
124
                                progress = new FileProgress(file,  this.customSettings.upload_target);
 
125
                                progress.setCancelled();
 
126
                                progress.setStatus("Cancelled");
 
127
                                progress.toggleCancel(false);
 
128
                        }
 
129
                        catch (ex1) {
 
130
                                this.debug(ex1);
 
131
                        }
 
132
                        break;
 
133
                case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
 
134
                        try {
 
135
                                progress = new FileProgress(file,  this.customSettings.upload_target);
 
136
                                progress.setCancelled();
 
137
                                progress.setStatus("Stopped");
 
138
                                progress.toggleCancel(true);
 
139
                        }
 
140
                        catch (ex2) {
 
141
                                this.debug(ex2);
 
142
                        }
 
143
                case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
 
144
                        imageName = "uploadlimit.gif";
 
145
                        break;
 
146
                default:
 
147
                        alert(message);
 
148
                        break;
 
149
                }
 
150
 
 
151
                addImage("themes/core/javascript/swfupload/" + imageName);
 
152
 
 
153
        } catch (ex3) {
 
154
                this.debug(ex3);
 
155
        }
 
156
 
 
157
}
 
158
 
 
159
function addImg(src) {
 
160
        var newImg = document.getElementById("previewlogo");
 
161
        newImg.src = src;
 
162
}
 
163
 
 
164
function addImage(src) {
 
165
        var newImg = document.createElement("img");
 
166
        newImg.style.margin = "0";
 
167
        newImg.style.verticalAlign = "middle";
 
168
 
 
169
        var divThumbs = document.getElementById("thumbnails");
 
170
        divThumbs.insertBefore(newImg, divThumbs.firstChild);
 
171
        //document.getElementById("thumbnails").appendChild(newImg);
 
172
        if (newImg.filters) {
 
173
                try {
 
174
                        newImg.filters.item("DXImageTransform.Microsoft.Alpha").opacity = 0;
 
175
                } catch (e) {
 
176
                        // If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
 
177
                        newImg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + 0 + ')';
 
178
                }
 
179
        } else {
 
180
                newImg.style.opacity = 0;
 
181
        }
 
182
 
 
183
        newImg.onload = function () {
 
184
                fadeIn(newImg, 0);
 
185
        };
 
186
        newImg.src = src;
 
187
}
 
188
 
 
189
function fadeIn(element, opacity) {
 
190
        var reduceOpacityBy = 5;
 
191
        var rate = 30;  // 15 fps
 
192
 
 
193
 
 
194
        if (opacity < 100) {
 
195
                opacity += reduceOpacityBy;
 
196
                if (opacity > 100) {
 
197
                        opacity = 100;
 
198
                }
 
199
 
 
200
                if (element.filters) {
 
201
                        try {
 
202
                                element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
 
203
                        } catch (e) {
 
204
                                // If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
 
205
                                element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
 
206
                        }
 
207
                } else {
 
208
                        element.style.opacity = opacity / 100;
 
209
                }
 
210
        }
 
211
 
 
212
        if (opacity < 100) {
 
213
                setTimeout(function () {
 
214
                        fadeIn(element, opacity);
 
215
                }, rate);
 
216
        }
 
217
}
 
218
 
 
219
 
 
220
 
 
221
/* ******************************************
 
222
 *      FileProgress Object
 
223
 *      Control object for displaying file info
 
224
 * ****************************************** */
 
225
 
 
226
function FileProgress(file, targetID) {
 
227
        this.fileProgressID = "divFileProgress";
 
228
 
 
229
        this.fileProgressWrapper = document.getElementById(this.fileProgressID);
 
230
        if (!this.fileProgressWrapper) {
 
231
                this.fileProgressWrapper = document.createElement("div");
 
232
                this.fileProgressWrapper.className = "progressWrapper";
 
233
                this.fileProgressWrapper.id = this.fileProgressID;
 
234
 
 
235
                this.fileProgressElement = document.createElement("div");
 
236
                this.fileProgressElement.className = "progressContainer";
 
237
 
 
238
                var progressCancel = document.createElement("a");
 
239
                progressCancel.className = "progressCancel";
 
240
                progressCancel.href = "#";
 
241
                progressCancel.style.visibility = "hidden";
 
242
                progressCancel.appendChild(document.createTextNode(" "));
 
243
 
 
244
                var progressText = document.createElement("div");
 
245
                progressText.className = "progressName";
 
246
                progressText.appendChild(document.createTextNode(file.name));
 
247
 
 
248
                var progressBar = document.createElement("div");
 
249
                progressBar.className = "progressBarInProgress";
 
250
 
 
251
                var progressStatus = document.createElement("div");
 
252
                progressStatus.className = "progressBarStatus";
 
253
                progressStatus.innerHTML = "&nbsp;";
 
254
 
 
255
                this.fileProgressElement.appendChild(progressCancel);
 
256
                this.fileProgressElement.appendChild(progressText);
 
257
                this.fileProgressElement.appendChild(progressStatus);
 
258
                this.fileProgressElement.appendChild(progressBar);
 
259
 
 
260
                this.fileProgressWrapper.appendChild(this.fileProgressElement);
 
261
 
 
262
                document.getElementById(targetID).appendChild(this.fileProgressWrapper);
 
263
                fadeIn(this.fileProgressWrapper, 0);
 
264
 
 
265
        } else {
 
266
                this.fileProgressElement = this.fileProgressWrapper.firstChild;
 
267
                this.fileProgressElement.childNodes[1].firstChild.nodeValue = file.name;
 
268
        }
 
269
 
 
270
        this.height = this.fileProgressWrapper.offsetHeight;
 
271
 
 
272
}
 
273
FileProgress.prototype.setProgress = function (percentage) {
 
274
        this.fileProgressElement.className = "progressContainer green";
 
275
        this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
 
276
        this.fileProgressElement.childNodes[3].style.width = percentage + "%";
 
277
};
 
278
FileProgress.prototype.setComplete = function () {
 
279
        this.fileProgressElement.className = "progressContainer blue";
 
280
        this.fileProgressElement.childNodes[3].className = "progressBarComplete";
 
281
        this.fileProgressElement.childNodes[3].style.width = "";
 
282
 
 
283
};
 
284
FileProgress.prototype.setError = function () {
 
285
        this.fileProgressElement.className = "progressContainer red";
 
286
        this.fileProgressElement.childNodes[3].className = "progressBarError";
 
287
        this.fileProgressElement.childNodes[3].style.width = "";
 
288
 
 
289
};
 
290
FileProgress.prototype.setCancelled = function () {
 
291
        this.fileProgressElement.className = "progressContainer";
 
292
        this.fileProgressElement.childNodes[3].className = "progressBarError";
 
293
        this.fileProgressElement.childNodes[3].style.width = "";
 
294
 
 
295
};
 
296
FileProgress.prototype.setStatus = function (status) {
 
297
        this.fileProgressElement.childNodes[2].innerHTML = status;
 
298
};
 
299
 
 
300
FileProgress.prototype.toggleCancel = function (show, swfuploadInstance) {
 
301
        this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";
 
302
        if (swfuploadInstance) {
 
303
                var fileID = this.fileProgressID;
 
304
                this.fileProgressElement.childNodes[0].onclick = function () {
 
305
                        swfuploadInstance.cancelUpload(fileID);
 
306
                        return false;
 
307
                };
 
308
        }
 
309
};