Menu

[r561]: / swfupload / trunk / FlashDevelop / swfupload.js  Maximize  Restore  History

Download this file

796 lines (682 with data), 29.2 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
/**
* SWFUpload 0.8.3 Revision 7.0 by Jacob Roberts, Sept 2007, linebyline.blogspot.com
* -------- -------- -------- -------- -------- -------- -------- --------
* SWFUpload is (c) 2006 Lars Huring and Mammon Media and is released under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*
* See Changelog.txt for version history
*
*/
/* *********** */
/* Constructor */
/* *********** */
var SWFUpload = function (init_settings) {
// Remove background flicker in IE (read this: http://misterpixel.blogspot.com/2006/09/forensic-analysis-of-ie6.html)
// This doesn't have anything to do with SWFUpload but can help your UI behave better
try {
document.execCommand('BackgroundImageCache', false, true);
} catch (ex1) {
this.debugMessage(ex1);
}
try {
this.settings = {};
this.movieName = "SWFUpload_" + SWFUpload.movieCount++;
this.movieElement = null;
// Setup global control tracking
SWFUpload.instances[this.movieName] = this;
// Load the settings. Load the Flash movie.
this.initSettings(init_settings);
this.loadFlash();
if (this.debug_enabled) {
this.displayDebugInfo();
}
} catch (ex2) {
this.debugMessage(ex2);
}
};
/* *************** */
/* Static thingies */
/* *************** */
SWFUpload.instances = {};
SWFUpload.movieCount = 0;
SWFUpload.ERROR_CODE_HTTP_ERROR = -10;
SWFUpload.ERROR_CODE_MISSING_UPLOAD_TARGET = -20;
SWFUpload.ERROR_CODE_IO_ERROR = -30;
SWFUpload.ERROR_CODE_SECURITY_ERROR = -40;
SWFUpload.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT = -50;
SWFUpload.ERROR_CODE_ZERO_BYTE_FILE = -60;
SWFUpload.ERROR_CODE_UPLOAD_LIMIT_EXCEEDED = -70;
SWFUpload.ERROR_CODE_UPLOAD_FAILED = -80;
SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED = -90;
SWFUpload.ERROR_CODE_SPECIFIED_FILE_NOT_FOUND = -100;
SWFUpload.ERROR_CODE_INVALID_FILETYPE = -110;
SWFUpload.ERROR_CODE_FILE_VALIDATION_FAILED = -120;
SWFUpload.ERROR_CODE_FILE_CANCELLED = -130;
SWFUpload.FILE_STATUS_QUEUED = 0;
SWFUpload.FILE_STATUS_IN_PROGRESS = 1;
SWFUpload.FILE_STATUS_ERROR = 2;
SWFUpload.FILE_STATUS_COMPLETE = 3;
SWFUpload.FILE_STATUS_CANCELLED = 4;
/* ***************** */
/* Instance Thingies */
/* ***************** */
// init is a private method that ensures that all the object settings are set, getting a default value if one was not assigned.
SWFUpload.prototype.initSettings = function (init_settings) {
// UI setting
this.addSetting("ui_function", init_settings.ui_function, null);
this.addSetting("ui_container_id", init_settings.ui_container_id, "");
this.addSetting("degraded_container_id", init_settings.degraded_container_id, "");
// Upload backend settings
this.addSetting("upload_url", init_settings.upload_url, "");
this.addSetting("file_post_name", init_settings.file_post_name, "Filedata");
this.addSetting("post_params", init_settings.post_params, {});
// File Settings
this.addSetting("file_types", init_settings.file_types, "*.gif;*.jpg;*.png");
this.addSetting("file_types_description", init_settings.file_types_description, "Common Web Image Formats (gif, jpg, png)");
this.addSetting("file_size_limit", init_settings.file_size_limit, "1024");
this.addSetting("file_upload_limit", init_settings.file_upload_limit, "0");
this.addSetting("file_queue_limit", init_settings.file_queue_limit, "0");
// Flash Settings
this.addSetting("flash_url", init_settings.flash_url, "swfupload.swf");
this.addSetting("flash_width", init_settings.flash_width, "1px");
this.addSetting("flash_height", init_settings.flash_height, "1px");
this.addSetting("flash_color", init_settings.flash_color, "#FFFFFF");
// Debug Settings
this.addSetting("debug_enabled", init_settings.debug, false);
this.debug_enabled = this.getSetting("debug_enabled");
// Event Handlers
this.flashReady = this.retrieveSetting(init_settings.flash_ready_handler, this.flashReady);
this.fileDialogStart = this.retrieveSetting(init_settings.file_dialog_start_handler, this.fileDialogStart);
this.fileQueued = this.retrieveSetting(init_settings.file_queued_handler, this.fileQueued);
this.fileQueueError = this.retrieveSetting(init_settings.file_queue_error_handler, this.fileQueueError);
this.fileDialogComplete = this.retrieveSetting(init_settings.file_dialog_complete_handler, this.fileDialogComplete);
this.uploadStart = this.retrieveSetting(init_settings.upload_start_handler, this.uploadStart);
this.uploadProgress = this.retrieveSetting(init_settings.upload_progress_handler, this.uploadProgress);
this.uploadError = this.retrieveSetting(init_settings.upload_error_handler, this.uploadError);
this.uploadComplete = this.retrieveSetting(init_settings.upload_complete_handler, this.uploadComplete);
this.fileComplete = this.retrieveSetting(init_settings.file_complete_handler, this.fileComplete);
this.debug = this.retrieveSetting(init_settings.debug_handler, this.debug);
};
// loadFlash is a private method that generates the HTML tag for the Flash
// It then adds the flash to the "target" or to the body and stores a
// reference to the flash element in "movieElement".
SWFUpload.prototype.loadFlash = function () {
var html, target_element, container;
// Make sure an element with the ID we are going to use doesn't already exist
if (document.getElementById(this.movieName) !== null) {
return false;
}
// Get the body tag where we will be adding the flash movie
try {
target_element = document.getElementsByTagName("body")[0];
if (typeof(target_element) === "undefined" || target_element === null) {
this.debugMessage('Could not find an element to add the Flash too. Failed to find element for "flash_container_id" or the BODY element.');
return false;
}
} catch (ex) {
return false;
}
// Append the container and load the flash
container = document.createElement("div");
container.style.width = this.getSetting("flash_width");
container.style.height = this.getSetting("flash_height");
target_element.appendChild(container);
container.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
};
// Generates the embed/object tags needed to embed the flash in to the document
SWFUpload.prototype.getFlashHTML = function () {
var html = "";
// Create Mozilla Embed HTML
if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
// Build the basic embed html
html = '<embed type="application/x-shockwave-flash" src="' + this.getSetting("flash_url") + '" width="' + this.getSetting("flash_width") + '" height="' + this.getSetting("flash_height") + '"';
html += ' id="' + this.movieName + '" name="' + this.movieName + '" ';
html += 'bgcolor="' + this.getSetting("flash_color") + '" quality="high" menu="false" flashvars="';
html += this.getFlashVars();
html += '" />';
// Create IE Object HTML
} else {
// Build the basic Object tag
html = '<object id="' + this.movieName + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.getSetting("flash_width") + '" height="' + this.getSetting("flash_height") + '">';
html += '<param name="movie" value="' + this.getSetting("flash_url") + '">';
html += '<param name="bgcolor" value="' + this.getSetting("flash_color") + '" />';
html += '<param name="quality" value="high" />';
html += '<param name="menu" value="false" />';
html += '<param name="flashvars" value="' + this.getFlashVars() + '" />';
html += '</object>';
}
return html;
};
// This private method builds the parameter string that will be passed
// to flash.
SWFUpload.prototype.getFlashVars = function () {
// Add the cookies to the backend string
var upload_target_url = this.getSetting("upload_target_url");
var param_string = this.buildParamString();
// Build the parameter string
var html = "";
html += "movieName=" + encodeURIComponent(this.movieName);
html += "&uploadURL=" + encodeURIComponent(this.getSetting("upload_url"));
html += "&params=" + encodeURIComponent(param_string);
html += "&filePostName=" + encodeURIComponent(this.getSetting("file_post_name"));
html += "&fileTypes=" + encodeURIComponent(this.getSetting("file_types"));
html += "&fileTypesDescription=" + encodeURIComponent(this.getSetting("file_types_description"));
html += "&fileSizeLimit=" + encodeURIComponent(this.getSetting("file_size_limit"));
html += "&fileUploadLimit=" + encodeURIComponent(this.getSetting("file_upload_limit"));
html += "&fileQueueLimit=" + encodeURIComponent(this.getSetting("file_queue_limit"));
html += "&debugEnabled=" + encodeURIComponent(this.getSetting("debug_enabled"));
return html;
};
SWFUpload.prototype.getMovieElement = function () {
if (typeof(this.movieElement) === "undefined" || this.movieElement === null) {
this.movieElement = document.getElementById(this.movieName);
// Fix IEs "Flash can't callback when in a form" issue (http://www.extremefx.com.ar/blog/fixing-flash-external-interface-inside-form-on-internet-explorer)
// Removed because Revision 6 always adds the flash to the body (inside a containing div)
// If you insist on adding the Flash file inside a Form then in IE you have to make you wait until the DOM is ready
// and run this code to make the form's ID available from the window object so Flash and JavaScript can communicate.
//if (typeof(window[this.movieName]) === "undefined" || window[this.moveName] !== this.movieElement) {
// window[this.movieName] = this.movieElement;
//}
}
return this.movieElement;
};
SWFUpload.prototype.buildParamString = function () {
var post_params = this.getSetting("post_params");
var param_string_pairs = [];
var i, value, name;
// Retrieve the user defined parameters
if (typeof(post_params) === "object") {
for (name in post_params) {
if (post_params.hasOwnProperty(name)) {
if (typeof(post_params[name]) === "string") {
param_string_pairs.push(encodeURIComponent(name) + "=" + encodeURIComponent(post_params[name]));
}
}
}
}
return param_string_pairs.join("&");
};
// This private method "loads" the UI. If a target was specified then it is assumed that "display: none" was set and
// it does a "display: block" so the UI is shown. Then if a degraded_target is specified it hides it by setting "display: none"
// If you want SWFUpload to do something else then provide a "ui_function" setting and that will be called instead.
SWFUpload.prototype.showUI = function () {
var ui_container_id, ui_target, degraded_container_id, degraded_target;
try {
ui_container_id = this.getSetting("ui_container_id");
if (ui_container_id !== "") {
ui_target = document.getElementById(ui_container_id);
if (ui_target !== null) {
ui_target.style.display = "block";
// Now that the UI has been taken care of hide the degraded UI
degraded_container_id = this.getSetting("degraded_container_id");
if (degraded_container_id !== "") {
degraded_target = document.getElementById(degraded_container_id);
if (degraded_target !== null) {
degraded_target.style.display = "none";
}
}
}
}
} catch (ex) {
this.debugMessage(ex);
}
};
// Saves a setting. If the value given is undefined or null then the default_value is used.
SWFUpload.prototype.addSetting = function (name, value, default_value) {
if (typeof(value) === "undefined" || value === null) {
this.settings[name] = default_value;
} else {
this.settings[name] = value;
}
return this.settings[name];
};
// Gets a setting. Returns null if it wasn't found.
SWFUpload.prototype.getSetting = function (name) {
if (typeof(this.settings[name]) === "undefined") {
return "";
} else {
return this.settings[name];
}
};
// Gets a setting, if the setting is undefined then return the default value
// This does not affect or use the interal setting object.
SWFUpload.prototype.retrieveSetting = function (value, default_value) {
if (typeof(value) === "undefined" || value === null) {
return default_value;
} else {
return value;
}
};
// This method is used when debugging is enabled.
// It loops through all the settings and displays
// them in the debug Console.
SWFUpload.prototype.displayDebugInfo = function () {
var key, debug_message = "";
debug_message += "----- DEBUG OUTPUT ----\nID: " + this.getMovieElement().id + "\n";
debug_message += this.outputObject(this.settings);
debug_message += "----- DEBUG OUTPUT END ----\n";
debug_message += "\n";
this.debugMessage(debug_message);
};
SWFUpload.prototype.outputObject = function (object, prefix) {
var output = "", key;
if (typeof(prefix) !== "string") {
prefix = "";
}
if (typeof(object) !== "object") {
return "";
}
for (key in object) {
if (object.hasOwnProperty(key)) {
if (typeof(object[key]) === "object") {
output += (prefix + key + ": { \n" + this.outputObject(object[key], "\t" + prefix) + prefix + "}" + "\n");
} else {
output += (prefix + key + ": " + object[key] + "\n");
}
}
}
return output;
};
/* *****************************
-- Flash control methods --
Your UI should use these
to operate SWFUpload
***************************** */
SWFUpload.prototype.selectFile = function () {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.SelectFile) === "function") {
try {
movie_element.SelectFile();
}
catch (ex) {
this.debugMessage("Could not call SelectFile: " + ex);
}
} else {
this.debugMessage("Could not find Flash element");
}
};
SWFUpload.prototype.selectFiles = function () {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.SelectFiles) === "function") {
try {
movie_element.SelectFiles();
}
catch (ex) {
this.debugMessage("Could not call SelectFile: " + ex);
}
} else {
this.debugMessage("Could not find Flash element");
}
};
/* Start the upload. If a file_id is specified that file is uploaded. Otherwise the first
* file in the queue is uploaded. If no files are in the queue then nothing happens */
SWFUpload.prototype.startUpload = function (file_id) {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.StartUpload) === "function") {
try {
movie_element.StartUpload(file_id);
}
catch (ex) {
this.debugMessage("Could not call StartUpload: " + ex);
}
} else {
this.debugMessage("Could not find Flash element");
}
};
/* Cancels a the file upload. You must specify a file_id */
SWFUpload.prototype.cancelUpload = function (file_id) {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.CancelUpload) === "function") {
try {
movie_element.CancelUpload(file_id);
}
catch (ex) {
this.debugMessage("Could not call CancelUpload");
}
} else {
this.debugMessage("Could not find Flash element");
}
};
// Stops the current upload. The file is re-queued. If nothing is currently uploading then nothing happens.
SWFUpload.prototype.stopUpload = function () {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.StopUpload) === "function") {
try {
movie_element.StopUpload();
}
catch (ex) {
this.debugMessage("Could not call StopUpload");
}
} else {
this.debugMessage("Could not find Flash element");
}
};
/* Gets the file statistics object. It looks like this (n = number):
{
files_queued: n,
complete_uploads: n,
upload_errors: n,
uploads_cancelled: n,
queue_errors: n
}
*/
SWFUpload.prototype.getStats = function () {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.GetStats) === "function") {
try {
movie_element.GetStats();
}
catch (ex) {
this.debugMessage("Could not call GetStats");
}
} else {
this.debugMessage("Could not find Flash element");
}
};
SWFUpload.prototype.addFileParam = function (file_id, name, value) {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.AddFileParam) === "function") {
try {
return movie_element.AddFileParam(file_id, name, value);
}
catch (ex) {
this.debugMessage("Could not call AddFileParam");
}
} else {
this.debugMessage("Could not find Flash element");
}
};
SWFUpload.prototype.removeFileParam = function (file_id, name) {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.RemoveFileParam) === "function") {
try {
return movie_element.RemoveFileParam(file_id, name);
}
catch (ex) {
this.debugMessage("Could not call AddFileParam");
}
} else {
this.debugMessage("Could not find Flash element");
}
};
SWFUpload.prototype.setUploadURL = function (url) {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.SetUploadURL) === "function") {
try {
this.addSetting("upload_url", url);
movie_element.SetUploadURL(this.getSetting("upload_url"));
}
catch (ex) {
this.debugMessage("Could not call SetUploadURL");
}
} else {
this.debugMessage("Could not find Flash element in setUploadURL");
}
};
SWFUpload.prototype.setPostParams = function (param_object) {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.SetPostParams) === "function") {
try {
this.addSetting("post_params", param_object);
movie_element.SetPostParams(this.getSetting("post_params"));
}
catch (ex) {
this.debugMessage("Could not call SetPostParams");
}
} else {
this.debugMessage("Could not find Flash element in SetPostParams");
}
};
SWFUpload.prototype.setFileTypes = function (types, description) {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.SetFileTypes) === "function") {
try {
this.addSetting("file_types", types);
this.addSetting("file_types_description", description);
movie_element.SetFileTypes(this.getSetting("file_types"), this.getSetting("file_types_description"));
}
catch (ex) {
this.debugMessage("Could not call SetFileTypes");
}
} else {
this.debugMessage("Could not find Flash element in SetFileTypes");
}
};
SWFUpload.prototype.setFileSizeLimit = function (file_size_limit) {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.SetFileSizeLimit) === "function") {
try {
this.addSetting("file_size_limit", file_size_limit);
movie_element.SetFileSizeLimit(this.getSetting("file_size_limit"));
}
catch (ex) {
this.debugMessage("Could not call SetFileSizeLimit");
}
} else {
this.debugMessage("Could not find Flash element in SetFileSizeLimit");
}
};
SWFUpload.prototype.setFileUploadLimit = function (file_upload_limit) {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.SetFileUploadLimit) === "function") {
try {
this.addSetting("file_upload_limit", file_upload_limit);
movie_element.SetFileUploadLimit(this.getSetting("file_upload_limit"));
}
catch (ex) {
this.debugMessage("Could not call SetFileUploadLimit");
}
} else {
this.debugMessage("Could not find Flash element in SetFileUploadLimit");
}
};
SWFUpload.prototype.setFileQueueLimit = function (file_queue_limit) {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.SetFileQueueLimit) === "function") {
try {
this.addSetting("file_queue_limit", file_queue_limit);
movie_element.SetFileQueueLimit(this.getSetting("file_queue_limit"));
}
catch (ex) {
this.debugMessage("Could not call SetFileQueueLimit");
}
} else {
this.debugMessage("Could not find Flash element in SetFileQueueLimit");
}
};
SWFUpload.prototype.setFilePostName = function (file_post_name) {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.SetFilePostName) === "function") {
try {
this.addSetting("file_post_name", file_post_name);
movie_element.SetFilePostName(this.getSetting("file_post_name"));
}
catch (ex) {
this.debugMessage("Could not call SetFilePostName");
}
} else {
this.debugMessage("Could not find Flash element in SetFilePostName");
}
};
SWFUpload.prototype.setDebugEnabled = function (debug_enabled) {
var movie_element = this.getMovieElement();
if (movie_element !== null && typeof(movie_element.SetDebugEnabled) === "function") {
try {
this.addSetting("debug_enabled", debug_enabled);
this.debug_enabled = this.getSetting("debug_enabled");
movie_element.SetDebugEnabled(this.getSetting("debug_enabled"));
}
catch (ex) {
this.debugMessage("Could not call SetDebugEnabled");
}
} else {
this.debugMessage("Could not find Flash element in SetDebugEnabled");
}
};
/* *******************************
Default Event Handlers
******************************* */
// This is the callback method that the Flash movie will call when it has been loaded and is ready to go.
// Calling this or showUI "manually" bypass the Flash Detection built in to SWFUpload.
// FlashReady should not generally be overwritten. Use a ui_function setting if you want to control the UI loading after the flash has loaded.
SWFUpload.prototype.flashReady = function () {
var ui_function;
try {
this.debugMessage("Flash called back and is ready.");
ui_function = this.getSetting("ui_function");
if (typeof(ui_function) === "function") {
ui_function.apply(this);
} else {
this.showUI();
}
} catch (ex) {
this.debugMessage(ex);
}
};
SWFUpload.prototype.fileDialogStart = function () {
/* This is a chance to do something before the browse window opens */
};
SWFUpload.prototype.fileQueued = function (file) {
/* Called when a file is successfully added to the queue. */
};
SWFUpload.prototype.fileQueueError = function (error_code, file, message) {
/* Handle errors that occur when an attempt to queue a file fails. */
try {
switch (error_code) {
case SWFUpload.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT:
this.debugMessage("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
case SWFUpload.ERROR_CODE_ZERO_BYTE_FILE:
this.debugMessage("Error Code: Zero Byte File, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
case SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED:
this.debugMessage("Error Code: Upload limit reached, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
case SWFUpload.ERROR_CODE_INVALID_FILETYPE:
this.debugMessage("Error Code: File extension is not allowed, Message: " + message);
break;
default:
this.debugMessage("Error Code: Unhandled error occured. Errorcode: " + error_code);
}
} catch (ex) {
this.debugMessage(ex);
}
};
SWFUpload.prototype.fileDialogComplete = function (num_files_selected) {
/* Called after the file dialog has closed and the selected files have been queued.
You could call startUpload here if you want the queued files to begin uploading immediately.
*/
};
SWFUpload.prototype.uploadStart = function (file) {
/* Gets called when a file upload is about to be started. Return true to continue the upload. Return false to stop the upload.
If you return false then the uploadError callback is called and then fileComplete (like normal).
This is a good place to do any file validation you need.
*/
return true;
};
// Called during upload as the file progresses
SWFUpload.prototype.uploadProgress = function (file, bytes_complete, bytes_total) {
this.debugMessage("File Progress: " + file.id + ", Bytes: " + bytes_complete + ". Total: " + bytes_total);
};
SWFUpload.prototype.uploadComplete = function (file, server_data) {
/* This gets called when a file finishes uploading and the upload script has completed and returned a 200 status code. Any text returned by the
server is available in server_data. The upload script must return some text or uploadComplete will not fire (neither will fileComplete). */
};
// Called when a file upload has completed
SWFUpload.prototype.fileComplete = function (file) {
/* This is called last. The file is uploaded or an error occurred and SWFUpload is ready to make the next upload.
If you want to automatically start the next file just call startUpload from here.
*/
};
// Called by SWFUpload JavaScript and Flash flash functions when debug is enabled
SWFUpload.prototype.debug = function (message) {
this.debugMessage(message);
};
// Called when an error occurs. Use errcode to determine which error occurred.
SWFUpload.prototype.uploadError = function (errcode, file, msg) {
try {
switch (errcode) {
case SWFUpload.ERROR_CODE_SPECIFIED_FILE_NOT_FOUND:
this.debugMessage("Error Code: File ID specified for upload was not found, Message: " + msg);
break;
case SWFUpload.ERROR_CODE_HTTP_ERROR:
this.debugMessage("Error Code: HTTP Error, File name: " + file.name + ", Message: " + msg);
break;
case SWFUpload.ERROR_CODE_MISSING_UPLOAD_TARGET:
this.debugMessage("Error Code: No backend file, File name: " + file.name + ", Message: " + msg);
break;
case SWFUpload.ERROR_CODE_IO_ERROR:
this.debugMessage("Error Code: IO Error, File name: " + file.name + ", Message: " + msg);
break;
case SWFUpload.ERROR_CODE_SECURITY_ERROR:
this.debugMessage("Error Code: Security Error, File name: " + file.name + ", Message: " + msg);
break;
case SWFUpload.ERROR_CODE_UPLOAD_LIMIT_EXCEEDED:
this.debugMessage("Error Code: Upload limit reached, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
break;
case SWFUpload.ERROR_CODE_UPLOAD_FAILED:
this.debugMessage("Error Code: Upload Initialization exception, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
break;
case SWFUpload.ERROR_CODE_FILE_VALIDATION_FAILED:
this.debugMessage("Error Code: uploadStart callback returned false, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
break;
case SWFUpload.ERROR_CODE_FILE_CANCELLED:
this.debugMessage("Error Code: The file upload was cancelled, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
break;
default:
this.debugMessage("Error Code: Unhandled error occured. Errorcode: " + errcode);
}
} catch (ex) {
this.debugMessage(ex);
}
};
/* **********************************
Debug Console
The debug console is a self contained, in page location
for debug message to be sent. The Debug Console adds
itself to the body if necessary.
The console is automatically scrolled as messages appear.
********************************** */
SWFUpload.prototype.debugMessage = function (message) {
var exception_message, exception_values;
if (this.debug_enabled) {
if (typeof(message) === "object" && typeof(message.name) === "string" && typeof(message.message) === "string") {
exception_message = "";
exception_values = [];
for (var key in message) {
exception_values.push(key + ": " + message[key]);
}
exception_message = exception_values.join("\n");
exception_values = exception_message.split("\n");
exception_message = "EXCEPTION: " + exception_values.join("\nEXCEPTION: ");
SWFUpload.Console.writeLine(exception_message);
} else {
SWFUpload.Console.writeLine(message);
}
}
};
SWFUpload.Console = {};
SWFUpload.Console.writeLine = function (message) {
var console, documentForm;
try {
console = document.getElementById("SWFUpload_Console");
if (!console) {
documentForm = document.createElement("form");
document.getElementsByTagName("body")[0].appendChild(documentForm);
console = document.createElement("textarea");
console.id = "SWFUpload_Console";
console.style.fontFamily = "monospace";
console.setAttribute("wrap", "off");
console.wrap = "off";
console.style.overflow = "auto";
console.style.width = "700px";
console.style.height = "350px";
console.style.margin = "5px";
documentForm.appendChild(console);
}
console.value += message + "\n";
console.scrollTop = console.scrollHeight - console.clientHeight;
} catch (ex) {
alert("Exception: " + ex.name + " Message: " + ex.message);
}
};
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.