|
|
1
|
+/**
|
|
|
2
|
+ * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
|
|
|
3
|
+ *
|
|
|
4
|
+ * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
|
|
|
5
|
+ *
|
|
|
6
|
+ * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilz锟絥 and Mammon Media and is released under the MIT License:
|
|
|
7
|
+ * http://www.opensource.org/licenses/mit-license.php
|
|
|
8
|
+ *
|
|
|
9
|
+ * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
|
|
|
10
|
+ * http://www.opensource.org/licenses/mit-license.php
|
|
|
11
|
+ *
|
|
|
12
|
+ */
|
|
|
13
|
+
|
|
|
14
|
+
|
|
|
15
|
+/* ******************* */
|
|
|
16
|
+/* Constructor & Init */
|
|
|
17
|
+/* ******************* */
|
|
|
18
|
+var SWFUpload;
|
|
|
19
|
+
|
|
|
20
|
+if (SWFUpload == undefined) {
|
|
|
21
|
+ SWFUpload = function(settings) {
|
|
|
22
|
+ this.initSWFUpload(settings);
|
|
|
23
|
+ };
|
|
|
24
|
+}
|
|
|
25
|
+
|
|
|
26
|
+SWFUpload.prototype.initSWFUpload = function(settings) {
|
|
|
27
|
+ try {
|
|
|
28
|
+ this.customSettings = {}; // A container where developers can place their own settings associated with this instance.
|
|
|
29
|
+ this.settings = settings;
|
|
|
30
|
+ this.eventQueue = [];
|
|
|
31
|
+ this.movieName = 'SWFUpload_' + SWFUpload.movieCount++;
|
|
|
32
|
+ this.movieElement = null;
|
|
|
33
|
+
|
|
|
34
|
+
|
|
|
35
|
+ // Setup global control tracking
|
|
|
36
|
+ SWFUpload.instances[this.movieName] = this;
|
|
|
37
|
+
|
|
|
38
|
+ // Load the settings. Load the Flash movie.
|
|
|
39
|
+ this.initSettings();
|
|
|
40
|
+ this.loadFlash();
|
|
|
41
|
+ this.displayDebugInfo();
|
|
|
42
|
+ } catch (ex) {
|
|
|
43
|
+ delete SWFUpload.instances[this.movieName];
|
|
|
44
|
+ throw ex;
|
|
|
45
|
+ }
|
|
|
46
|
+};
|
|
|
47
|
+
|
|
|
48
|
+/* *************** */
|
|
|
49
|
+/* Static Members */
|
|
|
50
|
+/* *************** */
|
|
|
51
|
+SWFUpload.instances = {};
|
|
|
52
|
+SWFUpload.movieCount = 0;
|
|
|
53
|
+SWFUpload.version = '2.2.0 2009-03-25';
|
|
|
54
|
+SWFUpload.QUEUE_ERROR = {
|
|
|
55
|
+ QUEUE_LIMIT_EXCEEDED: -100,
|
|
|
56
|
+ FILE_EXCEEDS_SIZE_LIMIT: -110,
|
|
|
57
|
+ ZERO_BYTE_FILE: -120,
|
|
|
58
|
+ INVALID_FILETYPE: -130
|
|
|
59
|
+};
|
|
|
60
|
+SWFUpload.UPLOAD_ERROR = {
|
|
|
61
|
+ HTTP_ERROR: -200,
|
|
|
62
|
+ MISSING_UPLOAD_URL: -210,
|
|
|
63
|
+ IO_ERROR: -220,
|
|
|
64
|
+ SECURITY_ERROR: -230,
|
|
|
65
|
+ UPLOAD_LIMIT_EXCEEDED: -240,
|
|
|
66
|
+ UPLOAD_FAILED: -250,
|
|
|
67
|
+ SPECIFIED_FILE_ID_NOT_FOUND: -260,
|
|
|
68
|
+ FILE_VALIDATION_FAILED: -270,
|
|
|
69
|
+ FILE_CANCELLED: -280,
|
|
|
70
|
+ UPLOAD_STOPPED: -290
|
|
|
71
|
+};
|
|
|
72
|
+SWFUpload.FILE_STATUS = {
|
|
|
73
|
+ QUEUED: -1,
|
|
|
74
|
+ IN_PROGRESS: -2,
|
|
|
75
|
+ ERROR: -3,
|
|
|
76
|
+ COMPLETE: -4,
|
|
|
77
|
+ CANCELLED: -5
|
|
|
78
|
+};
|
|
|
79
|
+SWFUpload.BUTTON_ACTION = {
|
|
|
80
|
+ SELECT_FILE: -100,
|
|
|
81
|
+ SELECT_FILES: -110,
|
|
|
82
|
+ START_UPLOAD: -120
|
|
|
83
|
+};
|
|
|
84
|
+SWFUpload.CURSOR = {
|
|
|
85
|
+ ARROW: -1,
|
|
|
86
|
+ HAND: -2
|
|
|
87
|
+};
|
|
|
88
|
+SWFUpload.WINDOW_MODE = {
|
|
|
89
|
+ WINDOW: 'window',
|
|
|
90
|
+ TRANSPARENT: 'transparent',
|
|
|
91
|
+ OPAQUE: 'opaque'
|
|
|
92
|
+};
|
|
|
93
|
+
|
|
|
94
|
+// Private: takes a URL, determines if it is relative and converts to an absolute URL
|
|
|
95
|
+// using the current site. Only processes the URL if it can, otherwise returns the URL untouched
|
|
|
96
|
+SWFUpload.completeURL = function(url) {
|
|
|
97
|
+ if (typeof(url) !== 'string' || url.match(/^https?:\/\//i) || url.match(/^\//)) {
|
|
|
98
|
+ return url;
|
|
|
99
|
+ }
|
|
|
100
|
+
|
|
|
101
|
+ var currentURL = window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '');
|
|
|
102
|
+
|
|
|
103
|
+ var indexSlash = window.location.pathname.lastIndexOf('/');
|
|
|
104
|
+ if (indexSlash <= 0) {
|
|
|
105
|
+ path = '/';
|
|
|
106
|
+ } else {
|
|
|
107
|
+ path = window.location.pathname.substr(0, indexSlash) + '/';
|
|
|
108
|
+ }
|
|
|
109
|
+
|
|
|
110
|
+ return /* currentURL +*/ path + url;
|
|
|
111
|
+
|
|
|
112
|
+};
|
|
|
113
|
+
|
|
|
114
|
+
|
|
|
115
|
+/* ******************** */
|
|
|
116
|
+/* Instance Members */
|
|
|
117
|
+/* ******************** */
|
|
|
118
|
+
|
|
|
119
|
+// Private: initSettings ensures that all the
|
|
|
120
|
+// settings are set, getting a default value if one was not assigned.
|
|
|
121
|
+SWFUpload.prototype.initSettings = function() {
|
|
|
122
|
+ this.ensureDefault = function(settingName, defaultValue) {
|
|
|
123
|
+ this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
|
|
|
124
|
+ };
|
|
|
125
|
+
|
|
|
126
|
+ // Upload backend settings
|
|
|
127
|
+ this.ensureDefault('upload_url', '');
|
|
|
128
|
+ this.ensureDefault('preserve_relative_urls', false);
|
|
|
129
|
+ this.ensureDefault('file_post_name', 'Filedata');
|
|
|
130
|
+ this.ensureDefault('post_params', {});
|
|
|
131
|
+ this.ensureDefault('use_query_string', false);
|
|
|
132
|
+ this.ensureDefault('requeue_on_error', false);
|
|
|
133
|
+ this.ensureDefault('http_success', []);
|
|
|
134
|
+ this.ensureDefault('assume_success_timeout', 0);
|
|
|
135
|
+
|
|
|
136
|
+ // File Settings
|
|
|
137
|
+ this.ensureDefault('file_types', '*.*');
|
|
|
138
|
+ this.ensureDefault('file_types_description', 'All Files');
|
|
|
139
|
+ this.ensureDefault('file_size_limit', 0); // Default zero means "unlimited"
|
|
|
140
|
+ this.ensureDefault('file_upload_limit', 0);
|
|
|
141
|
+ this.ensureDefault('file_queue_limit', 0);
|
|
|
142
|
+
|
|
|
143
|
+ // Flash Settings
|
|
|
144
|
+ this.ensureDefault('flash_url', 'swfupload.swf');
|
|
|
145
|
+ this.ensureDefault('prevent_swf_caching', true);
|
|
|
146
|
+
|
|
|
147
|
+ // Button Settings
|
|
|
148
|
+ this.ensureDefault('button_image_url', '');
|
|
|
149
|
+ this.ensureDefault('button_width', 1);
|
|
|
150
|
+ this.ensureDefault('button_height', 1);
|
|
|
151
|
+ this.ensureDefault('button_text', '');
|
|
|
152
|
+ this.ensureDefault('button_text_style', 'color: #000000; font-size: 16pt;');
|
|
|
153
|
+ this.ensureDefault('button_text_top_padding', 0);
|
|
|
154
|
+ this.ensureDefault('button_text_left_padding', 0);
|
|
|
155
|
+ this.ensureDefault('button_action', SWFUpload.BUTTON_ACTION.SELECT_FILES);
|
|
|
156
|
+ this.ensureDefault('button_disabled', false);
|
|
|
157
|
+ this.ensureDefault('button_placeholder_id', '');
|
|
|
158
|
+ this.ensureDefault('button_placeholder', null);
|
|
|
159
|
+ this.ensureDefault('button_cursor', SWFUpload.CURSOR.ARROW);
|
|
|
160
|
+ this.ensureDefault('button_window_mode', SWFUpload.WINDOW_MODE.WINDOW);
|
|
|
161
|
+
|
|
|
162
|
+ // Debug Settings
|
|
|
163
|
+ this.ensureDefault('debug', false);
|
|
|
164
|
+ this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API
|
|
|
165
|
+
|
|
|
166
|
+ // Event Handlers
|
|
|
167
|
+ this.settings.return_upload_start_handler = this.returnUploadStart;
|
|
|
168
|
+ this.ensureDefault('swfupload_loaded_handler', null);
|
|
|
169
|
+ this.ensureDefault('file_dialog_start_handler', null);
|
|
|
170
|
+ this.ensureDefault('file_queued_handler', null);
|
|
|
171
|
+ this.ensureDefault('file_queue_error_handler', null);
|
|
|
172
|
+ this.ensureDefault('file_dialog_complete_handler', null);
|
|
|
173
|
+
|
|
|
174
|
+ this.ensureDefault('upload_start_handler', null);
|
|
|
175
|
+ this.ensureDefault('upload_progress_handler', null);
|
|
|
176
|
+ this.ensureDefault('upload_error_handler', null);
|
|
|
177
|
+ this.ensureDefault('upload_success_handler', null);
|
|
|
178
|
+ this.ensureDefault('upload_complete_handler', null);
|
|
|
179
|
+
|
|
|
180
|
+ this.ensureDefault('debug_handler', this.debugMessage);
|
|
|
181
|
+
|
|
|
182
|
+ this.ensureDefault('custom_settings', {});
|
|
|
183
|
+
|
|
|
184
|
+ // Other settings
|
|
|
185
|
+ this.customSettings = this.settings.custom_settings;
|
|
|
186
|
+
|
|
|
187
|
+ // Update the flash url if needed
|
|
|
188
|
+ if (!!this.settings.prevent_swf_caching) {
|
|
|
189
|
+ this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf('?') < 0 ? '?' : '&') + 'preventswfcaching=' + new Date().getTime();
|
|
|
190
|
+ }
|
|
|
191
|
+
|
|
|
192
|
+ if (!this.settings.preserve_relative_urls) {
|
|
|
193
|
+ // this.settings.flash_url = SWFUpload.completeURL(this.settings.flash_url); // Don't need to do this one since flash doesn't look at it
|
|
|
194
|
+ this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
|
|
|
195
|
+ if (this.settings.button_image_url) {
|
|
|
196
|
+ this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
|
|
|
197
|
+ }
|
|
|
198
|
+ }
|
|
|
199
|
+
|
|
|
200
|
+ delete this.ensureDefault;
|
|
|
201
|
+};
|
|
|
202
|
+
|
|
|
203
|
+// Private: loadFlash replaces the button_placeholder element with the flash movie.
|
|
|
204
|
+SWFUpload.prototype.loadFlash = function() {
|
|
|
205
|
+ var targetElement, tempParent;
|
|
|
206
|
+
|
|
|
207
|
+ // Make sure an element with the ID we are going to use doesn't already exist
|
|
|
208
|
+ if (document.getElementById(this.movieName) !== null) {
|
|
|
209
|
+ throw 'ID ' + this.movieName + ' is already in use. The Flash Object could not be added';
|
|
|
210
|
+ }
|
|
|
211
|
+
|
|
|
212
|
+ // Get the element where we will be placing the flash movie
|
|
|
213
|
+ targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
|
|
|
214
|
+
|
|
|
215
|
+ if (targetElement == undefined) {
|
|
|
216
|
+ throw 'Could not find the placeholder element: ' + this.settings.button_placeholder_id;
|
|
|
217
|
+ }
|
|
|
218
|
+
|
|
|
219
|
+ // Append the container and load the flash
|
|
|
220
|
+ tempParent = document.createElement('div');
|
|
|
221
|
+ tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
|
|
|
222
|
+ targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
|
|
|
223
|
+
|
|
|
224
|
+ // Fix IE Flash/Form bug
|
|
|
225
|
+ if (window[this.movieName] == undefined) {
|
|
|
226
|
+ window[this.movieName] = this.getMovieElement();
|
|
|
227
|
+ }
|
|
|
228
|
+
|
|
|
229
|
+};
|
|
|
230
|
+
|
|
|
231
|
+// Private: getFlashHTML generates the object tag needed to embed the flash in to the document
|
|
|
232
|
+SWFUpload.prototype.getFlashHTML = function() {
|
|
|
233
|
+ // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
|
|
|
234
|
+ return ['<object id="', this.movieName, '" type="application/x-shockwave-flash" data="', this.settings.flash_url, '" width="', this.settings.button_width, '" height="', this.settings.button_height, '" class="swfupload">',
|
|
|
235
|
+ '<param name="wmode" value="', this.settings.button_window_mode, '" />',
|
|
|
236
|
+ '<param name="movie" value="', this.settings.flash_url, '" />',
|
|
|
237
|
+ '<param name="quality" value="high" />',
|
|
|
238
|
+ '<param name="menu" value="false" />',
|
|
|
239
|
+ '<param name="allowScriptAccess" value="always" />',
|
|
|
240
|
+ '<param name="flashvars" value="' + this.getFlashVars() + '" />',
|
|
|
241
|
+ '</object>'].join('');
|
|
|
242
|
+};
|
|
|
243
|
+
|
|
|
244
|
+// Private: getFlashVars builds the parameter string that will be passed
|
|
|
245
|
+// to flash in the flashvars param.
|
|
|
246
|
+SWFUpload.prototype.getFlashVars = function() {
|
|
|
247
|
+ // Build a string from the post param object
|
|
|
248
|
+ var paramString = this.buildParamString();
|
|
|
249
|
+ var httpSuccessString = this.settings.http_success.join(',');
|
|
|
250
|
+
|
|
|
251
|
+ // Build the parameter string
|
|
|
252
|
+ return ['movieName=', encodeURIComponent(this.movieName),
|
|
|
253
|
+ '&uploadURL=', encodeURIComponent(this.settings.upload_url),
|
|
|
254
|
+ '&useQueryString=', encodeURIComponent(this.settings.use_query_string),
|
|
|
255
|
+ '&requeueOnError=', encodeURIComponent(this.settings.requeue_on_error),
|
|
|
256
|
+ '&httpSuccess=', encodeURIComponent(httpSuccessString),
|
|
|
257
|
+ '&assumeSuccessTimeout=', encodeURIComponent(this.settings.assume_success_timeout),
|
|
|
258
|
+ '&params=', encodeURIComponent(paramString),
|
|
|
259
|
+ '&filePostName=', encodeURIComponent(this.settings.file_post_name),
|
|
|
260
|
+ '&fileTypes=', encodeURIComponent(this.settings.file_types),
|
|
|
261
|
+ '&fileTypesDescription=', encodeURIComponent(this.settings.file_types_description),
|
|
|
262
|
+ '&fileSizeLimit=', encodeURIComponent(this.settings.file_size_limit),
|
|
|
263
|
+ '&fileUploadLimit=', encodeURIComponent(this.settings.file_upload_limit),
|
|
|
264
|
+ '&fileQueueLimit=', encodeURIComponent(this.settings.file_queue_limit),
|
|
|
265
|
+ '&debugEnabled=', encodeURIComponent(this.settings.debug_enabled),
|
|
|
266
|
+ '&buttonImageURL=', encodeURIComponent(this.settings.button_image_url),
|
|
|
267
|
+ '&buttonWidth=', encodeURIComponent(this.settings.button_width),
|
|
|
268
|
+ '&buttonHeight=', encodeURIComponent(this.settings.button_height),
|
|
|
269
|
+ '&buttonText=', encodeURIComponent(this.settings.button_text),
|
|
|
270
|
+ '&buttonTextTopPadding=', encodeURIComponent(this.settings.button_text_top_padding),
|
|
|
271
|
+ '&buttonTextLeftPadding=', encodeURIComponent(this.settings.button_text_left_padding),
|
|
|
272
|
+ '&buttonTextStyle=', encodeURIComponent(this.settings.button_text_style),
|
|
|
273
|
+ '&buttonAction=', encodeURIComponent(this.settings.button_action),
|
|
|
274
|
+ '&buttonDisabled=', encodeURIComponent(this.settings.button_disabled),
|
|
|
275
|
+ '&buttonCursor=', encodeURIComponent(this.settings.button_cursor)
|
|
|
276
|
+ ].join('');
|
|
|
277
|
+};
|
|
|
278
|
+
|
|
|
279
|
+// Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
|
|
|
280
|
+// The element is cached after the first lookup
|
|
|
281
|
+SWFUpload.prototype.getMovieElement = function() {
|
|
|
282
|
+ if (this.movieElement == undefined) {
|
|
|
283
|
+ this.movieElement = document.getElementById(this.movieName);
|
|
|
284
|
+ }
|
|
|
285
|
+
|
|
|
286
|
+ if (this.movieElement === null) {
|
|
|
287
|
+ throw 'Could not find Flash element';
|
|
|
288
|
+ }
|
|
|
289
|
+
|
|
|
290
|
+ return this.movieElement;
|
|
|
291
|
+};
|
|
|
292
|
+
|
|
|
293
|
+// Private: buildParamString takes the name/value pairs in the post_params setting object
|
|
|
294
|
+// and joins them up in to a string formatted "name=value&name=value"
|
|
|
295
|
+SWFUpload.prototype.buildParamString = function() {
|
|
|
296
|
+ var postParams = this.settings.post_params;
|
|
|
297
|
+ var paramStringPairs = [];
|
|
|
298
|
+
|
|
|
299
|
+ if (typeof(postParams) === 'object') {
|
|
|
300
|
+ for (var name in postParams) {
|
|
|
301
|
+ if (postParams.hasOwnProperty(name)) {
|
|
|
302
|
+ paramStringPairs.push(encodeURIComponent(name.toString()) + '=' + encodeURIComponent(postParams[name].toString()));
|
|
|
303
|
+ }
|
|
|
304
|
+ }
|
|
|
305
|
+ }
|
|
|
306
|
+
|
|
|
307
|
+ return paramStringPairs.join('&');
|
|
|
308
|
+};
|
|
|
309
|
+
|
|
|
310
|
+// Public: Used to remove a SWFUpload instance from the page. This method strives to remove
|
|
|
311
|
+// all references to the SWF, and other objects so memory is properly freed.
|
|
|
312
|
+// Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
|
|
|
313
|
+// Credits: Major improvements provided by steffen
|
|
|
314
|
+SWFUpload.prototype.destroy = function() {
|
|
|
315
|
+ try {
|
|
|
316
|
+ // Make sure Flash is done before we try to remove it
|
|
|
317
|
+ this.cancelUpload(null, false);
|
|
|
318
|
+
|
|
|
319
|
+
|
|
|
320
|
+ // Remove the SWFUpload DOM nodes
|
|
|
321
|
+ var movieElement = null;
|
|
|
322
|
+ movieElement = this.getMovieElement();
|
|
|
323
|
+
|
|
|
324
|
+ if (movieElement && typeof(movieElement.CallFunction) === 'unknown') { // We only want to do this in IE
|
|
|
325
|
+ // Loop through all the movie's properties and remove all function references (DOM/JS IE 6/7 memory leak workaround)
|
|
|
326
|
+ for (var i in movieElement) {
|
|
|
327
|
+ try {
|
|
|
328
|
+ if (typeof(movieElement[i]) === 'function') {
|
|
|
329
|
+ movieElement[i] = null;
|
|
|
330
|
+ }
|
|
|
331
|
+ } catch (ex1) {}
|
|
|
332
|
+ }
|
|
|
333
|
+
|
|
|
334
|
+ // Remove the Movie Element from the page
|
|
|
335
|
+ try {
|
|
|
336
|
+ movieElement.parentNode.removeChild(movieElement);
|
|
|
337
|
+ } catch (ex) {}
|
|
|
338
|
+ }
|
|
|
339
|
+
|
|
|
340
|
+ // Remove IE form fix reference
|
|
|
341
|
+ window[this.movieName] = null;
|
|
|
342
|
+
|
|
|
343
|
+ // Destroy other references
|
|
|
344
|
+ SWFUpload.instances[this.movieName] = null;
|
|
|
345
|
+ delete SWFUpload.instances[this.movieName];
|
|
|
346
|
+
|
|
|
347
|
+ this.movieElement = null;
|
|
|
348
|
+ this.settings = null;
|
|
|
349
|
+ this.customSettings = null;
|
|
|
350
|
+ this.eventQueue = null;
|
|
|
351
|
+ this.movieName = null;
|
|
|
352
|
+
|
|
|
353
|
+
|
|
|
354
|
+ return true;
|
|
|
355
|
+ } catch (ex2) {
|
|
|
356
|
+ return false;
|
|
|
357
|
+ }
|
|
|
358
|
+};
|
|
|
359
|
+
|
|
|
360
|
+
|
|
|
361
|
+// Public: displayDebugInfo prints out settings and configuration
|
|
|
362
|
+// information about this SWFUpload instance.
|
|
|
363
|
+// This function (and any references to it) can be deleted when placing
|
|
|
364
|
+// SWFUpload in production.
|
|
|
365
|
+SWFUpload.prototype.displayDebugInfo = function() {
|
|
|
366
|
+ this.debug(
|
|
|
367
|
+ [
|
|
|
368
|
+ '---SWFUpload Instance Info---\n',
|
|
|
369
|
+ 'Version: ', SWFUpload.version, '\n',
|
|
|
370
|
+ 'Movie Name: ', this.movieName, '\n',
|
|
|
371
|
+ 'Settings:\n',
|
|
|
372
|
+ '\t', 'upload_url: ', this.settings.upload_url, '\n',
|
|
|
373
|
+ '\t', 'flash_url: ', this.settings.flash_url, '\n',
|
|
|
374
|
+ '\t', 'use_query_string: ', this.settings.use_query_string.toString(), '\n',
|
|
|
375
|
+ '\t', 'requeue_on_error: ', this.settings.requeue_on_error.toString(), '\n',
|
|
|
376
|
+ '\t', 'http_success: ', this.settings.http_success.join(', '), '\n',
|
|
|
377
|
+ '\t', 'assume_success_timeout: ', this.settings.assume_success_timeout, '\n',
|
|
|
378
|
+ '\t', 'file_post_name: ', this.settings.file_post_name, '\n',
|
|
|
379
|
+ '\t', 'post_params: ', this.settings.post_params.toString(), '\n',
|
|
|
380
|
+ '\t', 'file_types: ', this.settings.file_types, '\n',
|
|
|
381
|
+ '\t', 'file_types_description: ', this.settings.file_types_description, '\n',
|
|
|
382
|
+ '\t', 'file_size_limit: ', this.settings.file_size_limit, '\n',
|
|
|
383
|
+ '\t', 'file_upload_limit: ', this.settings.file_upload_limit, '\n',
|
|
|
384
|
+ '\t', 'file_queue_limit: ', this.settings.file_queue_limit, '\n',
|
|
|
385
|
+ '\t', 'debug: ', this.settings.debug.toString(), '\n',
|
|
|
386
|
+
|
|
|
387
|
+ '\t', 'prevent_swf_caching: ', this.settings.prevent_swf_caching.toString(), '\n',
|
|
|
388
|
+
|
|
|
389
|
+ '\t', 'button_placeholder_id: ', this.settings.button_placeholder_id.toString(), '\n',
|
|
|
390
|
+ '\t', 'button_placeholder: ', (this.settings.button_placeholder ? 'Set' : 'Not Set'), '\n',
|
|
|
391
|
+ '\t', 'button_image_url: ', this.settings.button_image_url.toString(), '\n',
|
|
|
392
|
+ '\t', 'button_width: ', this.settings.button_width.toString(), '\n',
|
|
|
393
|
+ '\t', 'button_height: ', this.settings.button_height.toString(), '\n',
|
|
|
394
|
+ '\t', 'button_text: ', this.settings.button_text.toString(), '\n',
|
|
|
395
|
+ '\t', 'button_text_style: ', this.settings.button_text_style.toString(), '\n',
|
|
|
396
|
+ '\t', 'button_text_top_padding: ', this.settings.button_text_top_padding.toString(), '\n',
|
|
|
397
|
+ '\t', 'button_text_left_padding: ', this.settings.button_text_left_padding.toString(), '\n',
|
|
|
398
|
+ '\t', 'button_action: ', this.settings.button_action.toString(), '\n',
|
|
|
399
|
+ '\t', 'button_disabled: ', this.settings.button_disabled.toString(), '\n',
|
|
|
400
|
+
|
|
|
401
|
+ '\t', 'custom_settings: ', this.settings.custom_settings.toString(), '\n',
|
|
|
402
|
+ 'Event Handlers:\n',
|
|
|
403
|
+ '\t', 'swfupload_loaded_handler assigned: ', (typeof this.settings.swfupload_loaded_handler === 'function').toString(), '\n',
|
|
|
404
|
+ '\t', 'file_dialog_start_handler assigned: ', (typeof this.settings.file_dialog_start_handler === 'function').toString(), '\n',
|
|
|
405
|
+ '\t', 'file_queued_handler assigned: ', (typeof this.settings.file_queued_handler === 'function').toString(), '\n',
|
|
|
406
|
+ '\t', 'file_queue_error_handler assigned: ', (typeof this.settings.file_queue_error_handler === 'function').toString(), '\n',
|
|
|
407
|
+ '\t', 'upload_start_handler assigned: ', (typeof this.settings.upload_start_handler === 'function').toString(), '\n',
|
|
|
408
|
+ '\t', 'upload_progress_handler assigned: ', (typeof this.settings.upload_progress_handler === 'function').toString(), '\n',
|
|
|
409
|
+ '\t', 'upload_error_handler assigned: ', (typeof this.settings.upload_error_handler === 'function').toString(), '\n',
|
|
|
410
|
+ '\t', 'upload_success_handler assigned: ', (typeof this.settings.upload_success_handler === 'function').toString(), '\n',
|
|
|
411
|
+ '\t', 'upload_complete_handler assigned: ', (typeof this.settings.upload_complete_handler === 'function').toString(), '\n',
|
|
|
412
|
+ '\t', 'debug_handler assigned: ', (typeof this.settings.debug_handler === 'function').toString(), '\n'
|
|
|
413
|
+ ].join('')
|
|
|
414
|
+ );
|
|
|
415
|
+};
|
|
|
416
|
+
|
|
|
417
|
+/* Note: addSetting and getSetting are no longer used by SWFUpload but are included
|
|
|
418
|
+ the maintain v2 API compatibility
|
|
|
419
|
+*/
|
|
|
420
|
+// Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
|
|
|
421
|
+SWFUpload.prototype.addSetting = function(name, value, default_value) {
|
|
|
422
|
+ if (value == undefined) {
|
|
|
423
|
+ return (this.settings[name] = default_value);
|
|
|
424
|
+ } else {
|
|
|
425
|
+ return (this.settings[name] = value);
|
|
|
426
|
+ }
|
|
|
427
|
+};
|
|
|
428
|
+
|
|
|
429
|
+// Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
|
|
|
430
|
+SWFUpload.prototype.getSetting = function(name) {
|
|
|
431
|
+ if (this.settings[name] != undefined) {
|
|
|
432
|
+ return this.settings[name];
|
|
|
433
|
+ }
|
|
|
434
|
+
|
|
|
435
|
+ return '';
|
|
|
436
|
+};
|
|
|
437
|
+
|
|
|
438
|
+
|
|
|
439
|
+
|
|
|
440
|
+// Private: callFlash handles function calls made to the Flash element.
|
|
|
441
|
+// Calls are made with a setTimeout for some functions to work around
|
|
|
442
|
+// bugs in the ExternalInterface library.
|
|
|
443
|
+SWFUpload.prototype.callFlash = function(functionName, argumentArray) {
|
|
|
444
|
+ argumentArray = argumentArray || [];
|
|
|
445
|
+
|
|
|
446
|
+ var movieElement = this.getMovieElement();
|
|
|
447
|
+ var returnValue, returnString;
|
|
|
448
|
+
|
|
|
449
|
+ // Flash's method if calling ExternalInterface methods (code adapted from MooTools).
|
|
|
450
|
+ try {
|
|
|
451
|
+ returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
|
|
|
452
|
+ returnValue = eval(returnString);
|
|
|
453
|
+ } catch (ex) {
|
|
|
454
|
+ throw 'Call to ' + functionName + ' failed';
|
|
|
455
|
+ }
|
|
|
456
|
+
|
|
|
457
|
+ // Unescape file post param values
|
|
|
458
|
+ if (returnValue != undefined && typeof returnValue.post === 'object') {
|
|
|
459
|
+ returnValue = this.unescapeFilePostParams(returnValue);
|
|
|
460
|
+ }
|
|
|
461
|
+
|
|
|
462
|
+ return returnValue;
|
|
|
463
|
+};
|
|
|
464
|
+
|
|
|
465
|
+/* *****************************
|
|
|
466
|
+ -- Flash control methods --
|
|
|
467
|
+ Your UI should use these
|
|
|
468
|
+ to operate SWFUpload
|
|
|
469
|
+ ***************************** */
|
|
|
470
|
+
|
|
|
471
|
+// WARNING: this function does not work in Flash Player 10
|
|
|
472
|
+// Public: selectFile causes a File Selection Dialog window to appear. This
|
|
|
473
|
+// dialog only allows 1 file to be selected.
|
|
|
474
|
+SWFUpload.prototype.selectFile = function() {
|
|
|
475
|
+ this.callFlash('SelectFile');
|
|
|
476
|
+};
|
|
|
477
|
+
|
|
|
478
|
+// WARNING: this function does not work in Flash Player 10
|
|
|
479
|
+// Public: selectFiles causes a File Selection Dialog window to appear/ This
|
|
|
480
|
+// dialog allows the user to select any number of files
|
|
|
481
|
+// Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
|
|
|
482
|
+// If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around
|
|
|
483
|
+// for this bug.
|
|
|
484
|
+SWFUpload.prototype.selectFiles = function() {
|
|
|
485
|
+ this.callFlash('SelectFiles');
|
|
|
486
|
+};
|
|
|
487
|
+
|
|
|
488
|
+
|
|
|
489
|
+// Public: startUpload starts uploading the first file in the queue unless
|
|
|
490
|
+// the optional parameter 'fileID' specifies the ID
|
|
|
491
|
+SWFUpload.prototype.startUpload = function(fileID) {
|
|
|
492
|
+ this.callFlash('StartUpload', [fileID]);
|
|
|
493
|
+};
|
|
|
494
|
+
|
|
|
495
|
+// Public: cancelUpload cancels any queued file. The fileID parameter may be the file ID or index.
|
|
|
496
|
+// If you do not specify a fileID the current uploading file or first file in the queue is cancelled.
|
|
|
497
|
+// If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter.
|
|
|
498
|
+SWFUpload.prototype.cancelUpload = function(fileID, triggerErrorEvent) {
|
|
|
499
|
+ if (triggerErrorEvent !== false) {
|
|
|
500
|
+ triggerErrorEvent = true;
|
|
|
501
|
+ }
|
|
|
502
|
+ this.callFlash('CancelUpload', [fileID, triggerErrorEvent]);
|
|
|
503
|
+};
|
|
|
504
|
+
|
|
|
505
|
+// Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
|
|
|
506
|
+// If nothing is currently uploading then nothing happens.
|
|
|
507
|
+SWFUpload.prototype.stopUpload = function() {
|
|
|
508
|
+ this.callFlash('StopUpload');
|
|
|
509
|
+};
|
|
|
510
|
+
|
|
|
511
|
+/* ************************
|
|
|
512
|
+ * Settings methods
|
|
|
513
|
+ * These methods change the SWFUpload settings.
|
|
|
514
|
+ * SWFUpload settings should not be changed directly on the settings object
|
|
|
515
|
+ * since many of the settings need to be passed to Flash in order to take
|
|
|
516
|
+ * effect.
|
|
|
517
|
+ * *********************** */
|
|
|
518
|
+
|
|
|
519
|
+// Public: getStats gets the file statistics object.
|
|
|
520
|
+SWFUpload.prototype.getStats = function() {
|
|
|
521
|
+ return this.callFlash('GetStats');
|
|
|
522
|
+};
|
|
|
523
|
+
|
|
|
524
|
+// Public: setStats changes the SWFUpload statistics. You shouldn't need to
|
|
|
525
|
+// change the statistics but you can. Changing the statistics does not
|
|
|
526
|
+// affect SWFUpload accept for the successful_uploads count which is used
|
|
|
527
|
+// by the upload_limit setting to determine how many files the user may upload.
|
|
|
528
|
+SWFUpload.prototype.setStats = function(statsObject) {
|
|
|
529
|
+ this.callFlash('SetStats', [statsObject]);
|
|
|
530
|
+};
|
|
|
531
|
+
|
|
|
532
|
+// Public: getFile retrieves a File object by ID or Index. If the file is
|
|
|
533
|
+// not found then 'null' is returned.
|
|
|
534
|
+SWFUpload.prototype.getFile = function(fileID) {
|
|
|
535
|
+ if (typeof(fileID) === 'number') {
|
|
|
536
|
+ return this.callFlash('GetFileByIndex', [fileID]);
|
|
|
537
|
+ } else {
|
|
|
538
|
+ return this.callFlash('GetFile', [fileID]);
|
|
|
539
|
+ }
|
|
|
540
|
+};
|
|
|
541
|
+
|
|
|
542
|
+// Public: addFileParam sets a name/value pair that will be posted with the
|
|
|
543
|
+// file specified by the Files ID. If the name already exists then the
|
|
|
544
|
+// exiting value will be overwritten.
|
|
|
545
|
+SWFUpload.prototype.addFileParam = function(fileID, name, value) {
|
|
|
546
|
+ return this.callFlash('AddFileParam', [fileID, name, value]);
|
|
|
547
|
+};
|
|
|
548
|
+
|
|
|
549
|
+// Public: removeFileParam removes a previously set (by addFileParam) name/value
|
|
|
550
|
+// pair from the specified file.
|
|
|
551
|
+SWFUpload.prototype.removeFileParam = function(fileID, name) {
|
|
|
552
|
+ this.callFlash('RemoveFileParam', [fileID, name]);
|
|
|
553
|
+};
|
|
|
554
|
+
|
|
|
555
|
+// Public: setUploadUrl changes the upload_url setting.
|
|
|
556
|
+SWFUpload.prototype.setUploadURL = function(url) {
|
|
|
557
|
+ this.settings.upload_url = url.toString();
|
|
|
558
|
+ this.callFlash('SetUploadURL', [url]);
|
|
|
559
|
+};
|
|
|
560
|
+
|
|
|
561
|
+// Public: setPostParams changes the post_params setting
|
|
|
562
|
+SWFUpload.prototype.setPostParams = function(paramsObject) {
|
|
|
563
|
+ this.settings.post_params = paramsObject;
|
|
|
564
|
+ this.callFlash('SetPostParams', [paramsObject]);
|
|
|
565
|
+};
|
|
|
566
|
+
|
|
|
567
|
+// Public: addPostParam adds post name/value pair. Each name can have only one value.
|
|
|
568
|
+SWFUpload.prototype.addPostParam = function(name, value) {
|
|
|
569
|
+ this.settings.post_params[name] = value;
|
|
|
570
|
+ this.callFlash('SetPostParams', [this.settings.post_params]);
|
|
|
571
|
+};
|
|
|
572
|
+
|
|
|
573
|
+// Public: removePostParam deletes post name/value pair.
|
|
|
574
|
+SWFUpload.prototype.removePostParam = function(name) {
|
|
|
575
|
+ delete this.settings.post_params[name];
|
|
|
576
|
+ this.callFlash('SetPostParams', [this.settings.post_params]);
|
|
|
577
|
+};
|
|
|
578
|
+
|
|
|
579
|
+// Public: setFileTypes changes the file_types setting and the file_types_description setting
|
|
|
580
|
+SWFUpload.prototype.setFileTypes = function(types, description) {
|
|
|
581
|
+ this.settings.file_types = types;
|
|
|
582
|
+ this.settings.file_types_description = description;
|
|
|
583
|
+ this.callFlash('SetFileTypes', [types, description]);
|
|
|
584
|
+};
|
|
|
585
|
+
|
|
|
586
|
+// Public: setFileSizeLimit changes the file_size_limit setting
|
|
|
587
|
+SWFUpload.prototype.setFileSizeLimit = function(fileSizeLimit) {
|
|
|
588
|
+ this.settings.file_size_limit = fileSizeLimit;
|
|
|
589
|
+ this.callFlash('SetFileSizeLimit', [fileSizeLimit]);
|
|
|
590
|
+};
|
|
|
591
|
+
|
|
|
592
|
+// Public: setFileUploadLimit changes the file_upload_limit setting
|
|
|
593
|
+SWFUpload.prototype.setFileUploadLimit = function(fileUploadLimit) {
|
|
|
594
|
+ this.settings.file_upload_limit = fileUploadLimit;
|
|
|
595
|
+ this.callFlash('SetFileUploadLimit', [fileUploadLimit]);
|
|
|
596
|
+};
|
|
|
597
|
+
|
|
|
598
|
+// Public: setFileQueueLimit changes the file_queue_limit setting
|
|
|
599
|
+SWFUpload.prototype.setFileQueueLimit = function(fileQueueLimit) {
|
|
|
600
|
+ this.settings.file_queue_limit = fileQueueLimit;
|
|
|
601
|
+ this.callFlash('SetFileQueueLimit', [fileQueueLimit]);
|
|
|
602
|
+};
|
|
|
603
|
+
|
|
|
604
|
+// Public: setFilePostName changes the file_post_name setting
|
|
|
605
|
+SWFUpload.prototype.setFilePostName = function(filePostName) {
|
|
|
606
|
+ this.settings.file_post_name = filePostName;
|
|
|
607
|
+ this.callFlash('SetFilePostName', [filePostName]);
|
|
|
608
|
+};
|
|
|
609
|
+
|
|
|
610
|
+// Public: setUseQueryString changes the use_query_string setting
|
|
|
611
|
+SWFUpload.prototype.setUseQueryString = function(useQueryString) {
|
|
|
612
|
+ this.settings.use_query_string = useQueryString;
|
|
|
613
|
+ this.callFlash('SetUseQueryString', [useQueryString]);
|
|
|
614
|
+};
|
|
|
615
|
+
|
|
|
616
|
+// Public: setRequeueOnError changes the requeue_on_error setting
|
|
|
617
|
+SWFUpload.prototype.setRequeueOnError = function(requeueOnError) {
|
|
|
618
|
+ this.settings.requeue_on_error = requeueOnError;
|
|
|
619
|
+ this.callFlash('SetRequeueOnError', [requeueOnError]);
|
|
|
620
|
+};
|
|
|
621
|
+
|
|
|
622
|
+// Public: setHTTPSuccess changes the http_success setting
|
|
|
623
|
+SWFUpload.prototype.setHTTPSuccess = function(http_status_codes) {
|
|
|
624
|
+ if (typeof http_status_codes === 'string') {
|
|
|
625
|
+ http_status_codes = http_status_codes.replace(' ', '').split(',');
|
|
|
626
|
+ }
|
|
|
627
|
+
|
|
|
628
|
+ this.settings.http_success = http_status_codes;
|
|
|
629
|
+ this.callFlash('SetHTTPSuccess', [http_status_codes]);
|
|
|
630
|
+};
|
|
|
631
|
+
|
|
|
632
|
+// Public: setHTTPSuccess changes the http_success setting
|
|
|
633
|
+SWFUpload.prototype.setAssumeSuccessTimeout = function(timeout_seconds) {
|
|
|
634
|
+ this.settings.assume_success_timeout = timeout_seconds;
|
|
|
635
|
+ this.callFlash('SetAssumeSuccessTimeout', [timeout_seconds]);
|
|
|
636
|
+};
|
|
|
637
|
+
|
|
|
638
|
+// Public: setDebugEnabled changes the debug_enabled setting
|
|
|
639
|
+SWFUpload.prototype.setDebugEnabled = function(debugEnabled) {
|
|
|
640
|
+ this.settings.debug_enabled = debugEnabled;
|
|
|
641
|
+ this.callFlash('SetDebugEnabled', [debugEnabled]);
|
|
|
642
|
+};
|
|
|
643
|
+
|
|
|
644
|
+// Public: setButtonImageURL loads a button image sprite
|
|
|
645
|
+SWFUpload.prototype.setButtonImageURL = function(buttonImageURL) {
|
|
|
646
|
+ if (buttonImageURL == undefined) {
|
|
|
647
|
+ buttonImageURL = '';
|
|
|
648
|
+ }
|
|
|
649
|
+
|
|
|
650
|
+ this.settings.button_image_url = buttonImageURL;
|
|
|
651
|
+ this.callFlash('SetButtonImageURL', [buttonImageURL]);
|
|
|
652
|
+};
|
|
|
653
|
+
|
|
|
654
|
+// Public: setButtonDimensions resizes the Flash Movie and button
|
|
|
655
|
+SWFUpload.prototype.setButtonDimensions = function(width, height) {
|
|
|
656
|
+ this.settings.button_width = width;
|
|
|
657
|
+ this.settings.button_height = height;
|
|
|
658
|
+
|
|
|
659
|
+ var movie = this.getMovieElement();
|
|
|
660
|
+ if (movie != undefined) {
|
|
|
661
|
+ movie.style.width = width + 'px';
|
|
|
662
|
+ movie.style.height = height + 'px';
|
|
|
663
|
+ }
|
|
|
664
|
+
|
|
|
665
|
+ this.callFlash('SetButtonDimensions', [width, height]);
|
|
|
666
|
+};
|
|
|
667
|
+
|
|
|
668
|
+// Public: setButtonText Changes the text overlaid on the button
|
|
|
669
|
+SWFUpload.prototype.setButtonText = function(html) {
|
|
|
670
|
+ this.settings.button_text = html;
|
|
|
671
|
+ this.callFlash('SetButtonText', [html]);
|
|
|
672
|
+};
|
|
|
673
|
+
|
|
|
674
|
+// Public: setButtonTextPadding changes the top and left padding of the text overlay
|
|
|
675
|
+SWFUpload.prototype.setButtonTextPadding = function(left, top) {
|
|
|
676
|
+ this.settings.button_text_top_padding = top;
|
|
|
677
|
+ this.settings.button_text_left_padding = left;
|
|
|
678
|
+ this.callFlash('SetButtonTextPadding', [left, top]);
|
|
|
679
|
+};
|
|
|
680
|
+
|
|
|
681
|
+// Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button
|
|
|
682
|
+SWFUpload.prototype.setButtonTextStyle = function(css) {
|
|
|
683
|
+ this.settings.button_text_style = css;
|
|
|
684
|
+ this.callFlash('SetButtonTextStyle', [css]);
|
|
|
685
|
+};
|
|
|
686
|
+
|
|
|
687
|
+// Public: setButtonDisabled disables/enables the button
|
|
|
688
|
+SWFUpload.prototype.setButtonDisabled = function(isDisabled) {
|
|
|
689
|
+ this.settings.button_disabled = isDisabled;
|
|
|
690
|
+ this.callFlash('SetButtonDisabled', [isDisabled]);
|
|
|
691
|
+};
|
|
|
692
|
+
|
|
|
693
|
+// Public: setButtonAction sets the action that occurs when the button is clicked
|
|
|
694
|
+SWFUpload.prototype.setButtonAction = function(buttonAction) {
|
|
|
695
|
+ this.settings.button_action = buttonAction;
|
|
|
696
|
+ this.callFlash('SetButtonAction', [buttonAction]);
|
|
|
697
|
+};
|
|
|
698
|
+
|
|
|
699
|
+// Public: setButtonCursor changes the mouse cursor displayed when hovering over the button
|
|
|
700
|
+SWFUpload.prototype.setButtonCursor = function(cursor) {
|
|
|
701
|
+ this.settings.button_cursor = cursor;
|
|
|
702
|
+ this.callFlash('SetButtonCursor', [cursor]);
|
|
|
703
|
+};
|
|
|
704
|
+
|
|
|
705
|
+/* *******************************
|
|
|
706
|
+ Flash Event Interfaces
|
|
|
707
|
+ These functions are used by Flash to trigger the various
|
|
|
708
|
+ events.
|
|
|
709
|
+
|
|
|
710
|
+ All these functions a Private.
|
|
|
711
|
+
|
|
|
712
|
+ Because the ExternalInterface library is buggy the event calls
|
|
|
713
|
+ are added to a queue and the queue then executed by a setTimeout.
|
|
|
714
|
+ This ensures that events are executed in a determinate order and that
|
|
|
715
|
+ the ExternalInterface bugs are avoided.
|
|
|
716
|
+******************************* */
|
|
|
717
|
+
|
|
|
718
|
+SWFUpload.prototype.queueEvent = function(handlerName, argumentArray) {
|
|
|
719
|
+ // Warning: Don't call this.debug inside here or you'll create an infinite loop
|
|
|
720
|
+
|
|
|
721
|
+ if (argumentArray == undefined) {
|
|
|
722
|
+ argumentArray = [];
|
|
|
723
|
+ } else if (!(argumentArray instanceof Array)) {
|
|
|
724
|
+ argumentArray = [argumentArray];
|
|
|
725
|
+ }
|
|
|
726
|
+
|
|
|
727
|
+ var self = this;
|
|
|
728
|
+ if (typeof this.settings[handlerName] === 'function') {
|
|
|
729
|
+ // Queue the event
|
|
|
730
|
+ this.eventQueue.push(function() {
|
|
|
731
|
+ this.settings[handlerName].apply(this, argumentArray);
|
|
|
732
|
+ });
|
|
|
733
|
+
|
|
|
734
|
+ // Execute the next queued event
|
|
|
735
|
+ setTimeout(function() {
|
|
|
736
|
+ self.executeNextEvent();
|
|
|
737
|
+ }, 0);
|
|
|
738
|
+
|
|
|
739
|
+ } else if (this.settings[handlerName] !== null) {
|
|
|
740
|
+ throw 'Event handler ' + handlerName + ' is unknown or is not a function';
|
|
|
741
|
+ }
|
|
|
742
|
+};
|
|
|
743
|
+
|
|
|
744
|
+// Private: Causes the next event in the queue to be executed. Since events are queued using a setTimeout
|
|
|
745
|
+// we must queue them in order to garentee that they are executed in order.
|
|
|
746
|
+SWFUpload.prototype.executeNextEvent = function() {
|
|
|
747
|
+ // Warning: Don't call this.debug inside here or you'll create an infinite loop
|
|
|
748
|
+
|
|
|
749
|
+ var f = this.eventQueue ? this.eventQueue.shift() : null;
|
|
|
750
|
+ if (typeof(f) === 'function') {
|
|
|
751
|
+ f.apply(this);
|
|
|
752
|
+ }
|
|
|
753
|
+};
|
|
|
754
|
+
|
|
|
755
|
+// Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have
|
|
|
756
|
+// properties that contain characters that are not valid for JavaScript identifiers. To work around this
|
|
|
757
|
+// the Flash Component escapes the parameter names and we must unescape again before passing them along.
|
|
|
758
|
+SWFUpload.prototype.unescapeFilePostParams = function(file) {
|
|
|
759
|
+ var reg = /[$]([0-9a-f]{4})/i;
|
|
|
760
|
+ var unescapedPost = {};
|
|
|
761
|
+ var uk;
|
|
|
762
|
+
|
|
|
763
|
+ if (file != undefined) {
|
|
|
764
|
+ for (var k in file.post) {
|
|
|
765
|
+ if (file.post.hasOwnProperty(k)) {
|
|
|
766
|
+ uk = k;
|
|
|
767
|
+ var match;
|
|
|
768
|
+ while ((match = reg.exec(uk)) !== null) {
|
|
|
769
|
+ uk = uk.replace(match[0], String.fromCharCode(parseInt('0x' + match[1], 16)));
|
|
|
770
|
+ }
|
|
|
771
|
+ unescapedPost[uk] = file.post[k];
|
|
|
772
|
+ }
|
|
|
773
|
+ }
|
|
|
774
|
+
|
|
|
775
|
+ file.post = unescapedPost;
|
|
|
776
|
+ }
|
|
|
777
|
+
|
|
|
778
|
+ return file;
|
|
|
779
|
+};
|
|
|
780
|
+
|
|
|
781
|
+// Private: Called by Flash to see if JS can call in to Flash (test if External Interface is working)
|
|
|
782
|
+SWFUpload.prototype.testExternalInterface = function() {
|
|
|
783
|
+ try {
|
|
|
784
|
+ return this.callFlash('TestExternalInterface');
|
|
|
785
|
+ } catch (ex) {
|
|
|
786
|
+ return false;
|
|
|
787
|
+ }
|
|
|
788
|
+};
|
|
|
789
|
+
|
|
|
790
|
+// Private: This event is called by Flash when it has finished loading. Don't modify this.
|
|
|
791
|
+// Use the swfupload_loaded_handler event setting to execute custom code when SWFUpload has loaded.
|
|
|
792
|
+SWFUpload.prototype.flashReady = function() {
|
|
|
793
|
+ // Check that the movie element is loaded correctly with its ExternalInterface methods defined
|
|
|
794
|
+ var movieElement = this.getMovieElement();
|
|
|
795
|
+
|
|
|
796
|
+ if (!movieElement) {
|
|
|
797
|
+ this.debug('Flash called back ready but the flash movie can\'t be found.');
|
|
|
798
|
+ return;
|
|
|
799
|
+ }
|
|
|
800
|
+
|
|
|
801
|
+ this.cleanUp(movieElement);
|
|
|
802
|
+
|
|
|
803
|
+ this.queueEvent('swfupload_loaded_handler');
|
|
|
804
|
+};
|
|
|
805
|
+
|
|
|
806
|
+// Private: removes Flash added fuctions to the DOM node to prevent memory leaks in IE.
|
|
|
807
|
+// This function is called by Flash each time the ExternalInterface functions are created.
|
|
|
808
|
+SWFUpload.prototype.cleanUp = function(movieElement) {
|
|
|
809
|
+ // Pro-actively unhook all the Flash functions
|
|
|
810
|
+ try {
|
|
|
811
|
+ if (this.movieElement && typeof(movieElement.CallFunction) === 'unknown') { // We only want to do this in IE
|
|
|
812
|
+ this.debug('Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)');
|
|
|
813
|
+ for (var key in movieElement) {
|
|
|
814
|
+ try {
|
|
|
815
|
+ if (typeof(movieElement[key]) === 'function') {
|
|
|
816
|
+ movieElement[key] = null;
|
|
|
817
|
+ }
|
|
|
818
|
+ } catch (ex) {
|
|
|
819
|
+ }
|
|
|
820
|
+ }
|
|
|
821
|
+ }
|
|
|
822
|
+ } catch (ex1) {
|
|
|
823
|
+
|
|
|
824
|
+ }
|
|
|
825
|
+
|
|
|
826
|
+ // Fix Flashes own cleanup code so if the SWFMovie was removed from the page
|
|
|
827
|
+ // it doesn't display errors.
|
|
|
828
|
+ window['__flash__removeCallback'] = function(instance, name) {
|
|
|
829
|
+ try {
|
|
|
830
|
+ if (instance) {
|
|
|
831
|
+ instance[name] = null;
|
|
|
832
|
+ }
|
|
|
833
|
+ } catch (flashEx) {
|
|
|
834
|
+
|
|
|
835
|
+ }
|
|
|
836
|
+ };
|
|
|
837
|
+
|
|
|
838
|
+};
|
|
|
839
|
+
|
|
|
840
|
+
|
|
|
841
|
+/* This is a chance to do something before the browse window opens */
|
|
|
842
|
+SWFUpload.prototype.fileDialogStart = function() {
|
|
|
843
|
+ this.queueEvent('file_dialog_start_handler');
|
|
|
844
|
+};
|
|
|
845
|
+
|
|
|
846
|
+
|
|
|
847
|
+/* Called when a file is successfully added to the queue. */
|
|
|
848
|
+SWFUpload.prototype.fileQueued = function(file) {
|
|
|
849
|
+ file = this.unescapeFilePostParams(file);
|
|
|
850
|
+ this.queueEvent('file_queued_handler', file);
|
|
|
851
|
+};
|
|
|
852
|
+
|
|
|
853
|
+
|
|
|
854
|
+/* Handle errors that occur when an attempt to queue a file fails. */
|
|
|
855
|
+SWFUpload.prototype.fileQueueError = function(file, errorCode, message) {
|
|
|
856
|
+ file = this.unescapeFilePostParams(file);
|
|
|
857
|
+ this.queueEvent('file_queue_error_handler', [file, errorCode, message]);
|
|
|
858
|
+};
|
|
|
859
|
+
|
|
|
860
|
+/* Called after the file dialog has closed and the selected files have been queued.
|
|
|
861
|
+ You could call startUpload here if you want the queued files to begin uploading immediately. */
|
|
|
862
|
+SWFUpload.prototype.fileDialogComplete = function(numFilesSelected, numFilesQueued, numFilesInQueue) {
|
|
|
863
|
+ this.queueEvent('file_dialog_complete_handler', [numFilesSelected, numFilesQueued, numFilesInQueue]);
|
|
|
864
|
+};
|
|
|
865
|
+
|
|
|
866
|
+SWFUpload.prototype.uploadStart = function(file) {
|
|
|
867
|
+ file = this.unescapeFilePostParams(file);
|
|
|
868
|
+ this.queueEvent('return_upload_start_handler', file);
|
|
|
869
|
+};
|
|
|
870
|
+
|
|
|
871
|
+SWFUpload.prototype.returnUploadStart = function(file) {
|
|
|
872
|
+ var returnValue;
|
|
|
873
|
+ if (typeof this.settings.upload_start_handler === 'function') {
|
|
|
874
|
+ file = this.unescapeFilePostParams(file);
|
|
|
875
|
+ returnValue = this.settings.upload_start_handler.call(this, file);
|
|
|
876
|
+ } else if (this.settings.upload_start_handler != undefined) {
|
|
|
877
|
+ throw 'upload_start_handler must be a function';
|
|
|
878
|
+ }
|
|
|
879
|
+
|
|
|
880
|
+ // Convert undefined to true so if nothing is returned from the upload_start_handler it is
|
|
|
881
|
+ // interpretted as 'true'.
|
|
|
882
|
+ if (returnValue === undefined) {
|
|
|
883
|
+ returnValue = true;
|
|
|
884
|
+ }
|
|
|
885
|
+
|
|
|
886
|
+ returnValue = !!returnValue;
|
|
|
887
|
+
|
|
|
888
|
+ this.callFlash('ReturnUploadStart', [returnValue]);
|
|
|
889
|
+};
|
|
|
890
|
+
|
|
|
891
|
+
|
|
|
892
|
+
|
|
|
893
|
+SWFUpload.prototype.uploadProgress = function(file, bytesComplete, bytesTotal) {
|
|
|
894
|
+ file = this.unescapeFilePostParams(file);
|
|
|
895
|
+ this.queueEvent('upload_progress_handler', [file, bytesComplete, bytesTotal]);
|
|
|
896
|
+};
|
|
|
897
|
+
|
|
|
898
|
+SWFUpload.prototype.uploadError = function(file, errorCode, message) {
|
|
|
899
|
+ file = this.unescapeFilePostParams(file);
|
|
|
900
|
+ this.queueEvent('upload_error_handler', [file, errorCode, message]);
|
|
|
901
|
+};
|
|
|
902
|
+
|
|
|
903
|
+SWFUpload.prototype.uploadSuccess = function(file, serverData, responseReceived) {
|
|
|
904
|
+ file = this.unescapeFilePostParams(file);
|
|
|
905
|
+ this.queueEvent('upload_success_handler', [file, serverData, responseReceived]);
|
|
|
906
|
+};
|
|
|
907
|
+
|
|
|
908
|
+SWFUpload.prototype.uploadComplete = function(file) {
|
|
|
909
|
+ file = this.unescapeFilePostParams(file);
|
|
|
910
|
+ this.queueEvent('upload_complete_handler', file);
|
|
|
911
|
+};
|
|
|
912
|
+
|
|
|
913
|
+/* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
|
|
|
914
|
+ internal debug console. You can override this event and have messages written where you want. */
|
|
|
915
|
+SWFUpload.prototype.debug = function(message) {
|
|
|
916
|
+ this.queueEvent('debug_handler', message);
|
|
|
917
|
+};
|
|
|
918
|
+
|
|
|
919
|
+
|
|
|
920
|
+/* **********************************
|
|
|
921
|
+ Debug Console
|
|
|
922
|
+ The debug console is a self contained, in page location
|
|
|
923
|
+ for debug message to be sent. The Debug Console adds
|
|
|
924
|
+ itself to the body if necessary.
|
|
|
925
|
+
|
|
|
926
|
+ The console is automatically scrolled as messages appear.
|
|
|
927
|
+
|
|
|
928
|
+ If you are using your own debug handler or when you deploy to production and
|
|
|
929
|
+ have debug disabled you can remove these functions to reduce the file size
|
|
|
930
|
+ and complexity.
|
|
|
931
|
+********************************** */
|
|
|
932
|
+
|
|
|
933
|
+// Private: debugMessage is the default debug_handler. If you want to print debug messages
|
|
|
934
|
+// call the debug() function. When overriding the function your own function should
|
|
|
935
|
+// check to see if the debug setting is true before outputting debug information.
|
|
|
936
|
+SWFUpload.prototype.debugMessage = function(message) {
|
|
|
937
|
+ if (this.settings.debug) {
|
|
|
938
|
+ var exceptionMessage, exceptionValues = [];
|
|
|
939
|
+
|
|
|
940
|
+ // Check for an exception object and print it nicely
|
|
|
941
|
+ if (typeof message === 'object' && typeof message.name === 'string' && typeof message.message === 'string') {
|
|
|
942
|
+ for (var key in message) {
|
|
|
943
|
+ if (message.hasOwnProperty(key)) {
|
|
|
944
|
+ exceptionValues.push(key + ': ' + message[key]);
|
|
|
945
|
+ }
|
|
|
946
|
+ }
|
|
|
947
|
+ exceptionMessage = exceptionValues.join('\n') || '';
|
|
|
948
|
+ exceptionValues = exceptionMessage.split('\n');
|
|
|
949
|
+ exceptionMessage = 'EXCEPTION: ' + exceptionValues.join('\nEXCEPTION: ');
|
|
|
950
|
+ SWFUpload.Console.writeLine(exceptionMessage);
|
|
|
951
|
+ } else {
|
|
|
952
|
+ SWFUpload.Console.writeLine(message);
|
|
|
953
|
+ }
|
|
|
954
|
+ }
|
|
|
955
|
+};
|
|
|
956
|
+
|
|
|
957
|
+SWFUpload.Console = {};
|
|
|
958
|
+SWFUpload.Console.writeLine = function(message) {
|
|
|
959
|
+ var console, documentForm;
|
|
|
960
|
+
|
|
|
961
|
+ try {
|
|
|
962
|
+ console = document.getElementById('SWFUpload_Console');
|
|
|
963
|
+
|
|
|
964
|
+ if (!console) {
|
|
|
965
|
+ documentForm = document.createElement('form');
|
|
|
966
|
+ document.getElementsByTagName('body')[0].appendChild(documentForm);
|
|
|
967
|
+
|
|
|
968
|
+ console = document.createElement('textarea');
|
|
|
969
|
+ console.id = 'SWFUpload_Console';
|
|
|
970
|
+ console.style.fontFamily = 'monospace';
|
|
|
971
|
+ console.setAttribute('wrap', 'off');
|
|
|
972
|
+ console.wrap = 'off';
|
|
|
973
|
+ console.style.overflow = 'auto';
|
|
|
974
|
+ console.style.width = '700px';
|
|
|
975
|
+ console.style.height = '350px';
|
|
|
976
|
+ console.style.margin = '5px';
|
|
|
977
|
+ documentForm.appendChild(console);
|
|
|
978
|
+ }
|
|
|
979
|
+
|
|
|
980
|
+ console.value += message + '\n';
|
|
|
981
|
+
|
|
|
982
|
+ console.scrollTop = console.scrollHeight - console.clientHeight;
|
|
|
983
|
+ } catch (ex) {
|
|
|
984
|
+ alert('Exception: ' + ex.name + ' Message: ' + ex.message);
|
|
|
985
|
+ }
|
|
|
986
|
+};
|
|
|
987
|
+
|
|
|
988
|
+exports.SWFUpload = SWFUpload; |