1
/* YUI 3.9.1 (build 5852) Copyright 2013 Yahoo! Inc. http://yuilibrary.com/license/ */
2
YUI.add('uploader-deprecated', function(Y) {
5
* Attention: this is the 3.4.1 `uploader` module has been deprecated in favor of a new
6
* uploader with an HTML5 layer. Please refer to the new Uploader User Guide for migration
9
* This module uses Flash player transport to upload files to the server, with support for
10
* file filtering, multiple file uploads and progress monitoring.
11
* @module uploader-deprecated
18
var SWFURL = Y.Env.cdn + "uploader-deprecated/assets/uploader.swf";
21
* <p><strong><span style="color:#ff0000;">Attention: this is the 3.4.1 uploader module, which has
22
* been deprecated in favor of a new uploader with an HTML5 layer. Please refer to the new
23
* Uploader User Guide for migration information.</span></strong></p>
24
* <p>The Uploader widget is a tool for uploading files to the server.</p>
25
* @module uploader-deprecated
27
* @requires base, node, event, swf
31
* <p><strong><span style="color:#ff0000;">Attention: this is the 3.4.1 uploader module, which has
32
* been deprecated in favor of a new uploader with an HTML5 layer. Please refer to the new
33
* Uploader User Guide for migration information.</span></strong></p>
34
* <p>Creates the Uploader instance and keeps the initialization data.</p>
39
* @param {Object} config (optional) Configuration parameters for the Uploader. The following parameters are available:
41
* <dt>boundingBox : String|Node (required)</dt>
43
* <dt>buttonSkin : String (optional)</dt>
45
* <dt>transparent : String (optional)</dt>
47
* <dt>swfURL : String (optional)</dt>
53
function Uploader (config /*Object*/) {
55
Uploader.superclass.constructor.apply(this, arguments);
57
if (config.hasOwnProperty("boundingBox")) {
58
this.set("boundingBox", config.boundingBox);
61
if (config.hasOwnProperty("buttonSkin")) {
62
this.set("buttonSkin", config.buttonSkin);
64
if (config.hasOwnProperty("transparent")) {
65
this.set("transparent", config.transparent);
67
if (config.hasOwnProperty("swfURL")) {
68
this.set("swfURL", config.swfURL);
73
Y.extend(Uploader, Y.Base, {
76
* The reference to the instance of Y.SWF that encapsulates the instance of the Flash player with uploader logic.
79
* @property uploaderswf
87
* The id of this instance of uploader.
97
* Construction logic executed during Uploader instantiation.
103
initializer : function () {
105
this._id = Y.guid("uploader");
106
var oElement = Node.one(this.get("boundingBox"));
108
var params = {version: "10.0.45",
109
fixedAttributes: {allowScriptAccess:"always", allowNetworking:"all", scale: "noscale"},
112
if (this.get("buttonSkin") != "") {
113
params.flashVars["buttonSkin"] = this.get("buttonSkin");
115
if (this.get("transparent")) {
116
params.fixedAttributes["wmode"] = "transparent";
119
this.uploaderswf = new Y.SWF(oElement, this.get("swfURL"), params);
121
var upswf = this.uploaderswf;
122
var relEvent = Y.bind(this._relayEvent, this);
125
* Announces that the uploader is ready and available for calling methods
126
* and setting properties
128
* @event uploaderReady
129
* @param event {Event} The event object for the uploaderReady.
132
upswf.on ("swfReady", Y.bind(this._initializeUploader, this));
135
* Fired when the mouse button is clicked on the Uploader's 'Browse' button.
138
* @param event {Event} The event object for the click.
141
upswf.on ("click", relEvent);
144
* Fires when the user has finished selecting a set of files to be uploaded.
147
* @param event {Event} The event object for the fileSelect.
150
* <dd>The file list Object with entries in the following format:
151
fileList[fileID] = {id: fileID, name: fileName, cDate: fileCDate, mDate: fileMDate, size: fileSize}</dd>
155
upswf.on ("fileselect", relEvent);
158
* Fired when the mouse button is pressed on the Uploader's 'Browse' button.
161
* @param event {Event} The event object for the mousedown.
164
upswf.on ("mousedown", relEvent);
167
* Fired when the mouse button is raised on the Uploader's 'Browse' button.
170
* @param event {Event} The event object for the mouseup.
173
upswf.on ("mouseup", relEvent);
176
* Fired when the mouse leaves the Uploader's 'Browse' button.
179
* @param event {Event} The event object for the mouseleave.
182
upswf.on ("mouseleave", relEvent);
185
* Fired when the mouse enters the Uploader's 'Browse' button.
188
* @param event {Event} The event object for the mouseenter.
191
upswf.on ("mouseenter", relEvent);
194
* Announces that the uploader is ready and available for calling methods
195
* and setting properties
197
* @event uploadcancel
198
* @param event {Event} The event object for the uploaderReady.
201
* <dd><code>drag:start</code> event from the thumb</dd>
205
upswf.on ("uploadcancel", relEvent);
208
* Fires when a specific file's upload is cancelled.
210
* @event uploadcomplete
211
* @param event {Event} The event object for the uploadcancel.
214
* <dd>The id of the file whose upload has been cancelled.</dd>
218
upswf.on ("uploadcomplete", relEvent);
221
* If the server has sent a response to the file upload, this event is
222
* fired and the response is added to its payload.
224
* @event uploadcompletedata
225
* @param event {Event} The event object for the uploadcompletedata.
228
* <dd>The id of the file for which the response is being provided.</dd>
230
* <dd>The content of the server response.</dd>
234
upswf.on ("uploadcompletedata", relEvent);
237
* Provides error information if an error has occurred during the upload.
240
* @param event {Event} The event object for the uploadeerror.
243
* <dd>The id of the file for which the upload error has occurred.</dd>
245
* <dd>Relevant error information.</dd>
249
upswf.on ("uploaderror", relEvent);
252
* Provides progress information on a specific file upload.
254
* @event uploadprogress
255
* @param event {Event} The event object for the uploadprogress.
258
* <dd>The id of the file for which the progress information is being provided.</dd>
259
* <dt>bytesLoaded</dt>
260
* <dd>The number of bytes of the file that has been uploaded.</dd>
261
* <dt>bytesTotal</dt>
262
* <dd>The total number of bytes in the file that is being uploaded.</dd>
266
upswf.on ("uploadprogress", relEvent);
269
* Announces that the upload has been started for a specific file.
272
* @param event {Event} The event object for the uploadstart.
275
* <dd>The id of the file whose upload has been started.</dd>
279
upswf.on ("uploadstart", relEvent);
283
* Removes a specific file from the upload queue.
286
* @param fileID {String} The ID of the file to be removed
287
* @return {Object} The updated file list, which is an object of the format:
288
* fileList[fileID] = {id: fileID, name: fileName, cDate: fileCDate, mDate: fileMDate, size: fileSize}
291
removeFile : function (fileID /*String*/) {
292
return this.uploaderswf.callSWF("removeFile", [fileID]);
296
* Clears the upload queue.
298
* @method clearFileList
299
* @return {Boolean} This method always returns true.
302
clearFileList : function () {
303
return this.uploaderswf.callSWF("clearFileList", []);
307
* Starts the upload of a specific file.
310
* @param fileID {String} The ID of the file to be uploaded.
311
* @param url {String} The URL to upload the file to.
312
* @param method {String} (optional) The HTTP method to use for sending additional variables, either 'GET' or 'POST' ('GET' by default)
313
* @param postVars {Object} (optional) A set of key-value pairs to send as variables along with the file upload HTTP request.
314
* @param postFileVarName {String} (optional) The name of the POST variable that should contain the uploaded file ('Filedata' by default)
315
* @return {Boolean} This method always returns true.
318
upload : function (fileID /*String*/, url /*String*/, method /*String*/, postVars /*Object*/, postFileVarName /*String*/) {
319
if (Y.Lang.isArray(fileID)) {
320
return this.uploaderswf.callSWF("uploadThese", [fileID, url, method, postVars, postFileVarName]);
322
else if (Y.Lang.isString(fileID)) {
323
return this.uploaderswf.callSWF("upload", [fileID, url, method, postVars, postFileVarName]);
329
* Starts the upload of a set of files, as specified in the first argument.
330
* The upload queue is managed automatically.
332
* @method uploadThese
333
* @param fileIDs {Array} The array of IDs of the files to be uploaded.
334
* @param url {String} The URL to upload the files to.
335
* @param method {String} (optional) The HTTP method to use for sending additional variables, either 'GET' or 'POST' ('GET' by default)
336
* @param postVars {Object} (optional) A set of key-value pairs to send as variables along with the file upload HTTP request.
337
* @param postFileVarName {String} (optional) The name of the POST variable that should contain the uploaded file ('Filedata' by default)
340
uploadThese : function (fileIDs /*Array*/, url /*String*/, method /*String*/, postVars /*Object*/, postFileVarName /*String*/) {
341
return this.uploaderswf.callSWF("uploadThese", [fileIDs, url, method, postVars, postFileVarName]);
345
* Starts the upload of the files in the upload queue.
346
* The upload queue is managed automatically.
349
* @param url {String} The URL to upload the files to.
350
* @param method {String} (optional) The HTTP method to use for sending additional variables, either 'GET' or 'POST' ('GET' by default)
351
* @param postVars {Object} (optional) A set of key-value pairs to send as variables along with the file upload HTTP request.
352
* @param postFileVarName {String} (optional) The name of the POST variable that should contain the uploaded file ('Filedata' by default).
355
uploadAll : function (url /*String*/, method /*String*/, postVars /*Object*/, postFileVarName /*String*/) {
356
return this.uploaderswf.callSWF("uploadAll", [url, method, postVars,postFileVarName]);
360
* Cancels the upload of a specific file, if currently in progress.
363
* @param fileID {String} (optional) The ID of the file whose upload should be cancelled. If no ID is specified, all uploads are cancelled.
366
cancel : function (fileID /*String*/) {
367
return this.uploaderswf.callSWF("cancel", [fileID]);
372
* Setter for the 'log' property.
373
* @method setAllowLogging
374
* @param value {Boolean} The value for the 'log' property.
377
setAllowLogging : function (value /*Boolean*/) {
378
this.uploaderswf.callSWF("setAllowLogging", [value]);
383
* Setter for the 'multiFiles' property.
384
* @method setAllowMultipleFiles
385
* @param value {Boolean} The value for the 'multiFiles' property.
388
setAllowMultipleFiles : function (value /*Boolean*/) {
389
this.uploaderswf.callSWF("setAllowMultipleFiles", [value]);
394
* Setter for the 'simLimit' property.
395
* @method setSimUploadLimit
396
* @param value {Boolean} The value for the 'simLimit' property.
399
setSimUploadLimit : function (value /*int*/) {
400
this.uploaderswf.callSWF("setSimUploadLimit", [value]);
405
* Setter for the 'fileFilters' property.
406
* @method setFileFilters
407
* @param value {Boolean} The value for the 'fileFilters' property.
410
setFileFilters : function (fileFilters /*Array*/) {
411
this.uploaderswf.callSWF("setFileFilters", [fileFilters]);
415
* Enables the uploader user input (mouse clicks on the 'Browse' button). If the button skin
416
* is applied, the sprite is reset from the "disabled" state.
421
enable : function () {
422
this.uploaderswf.callSWF("enable");
426
* Disables the uploader user input (mouse clicks on the 'Browse' button). If the button skin
427
* is applied, the sprite is set to the 'disabled' state.
432
disable : function () {
433
this.uploaderswf.callSWF("disable");
438
* Called when the uploader SWF is initialized
439
* @method _initializeUploader
440
* @param event {Object} The event to be propagated from Flash.
443
_initializeUploader: function (event) {
444
this.publish("uploaderReady", {fireOnce:true});
445
this.fire("uploaderReady", {});
450
* Called when an event is dispatched from Uploader
451
* @method _relayEvent
452
* @param event {Object} The event to be propagated from Flash.
455
_relayEvent: function (event) {
456
this.fire(event.type, event);
461
return "Uploader " + this._id;
468
* The flag that allows Flash player to
469
* output debug messages to its trace stack
470
* (if the Flash debug player is used).
479
setter : "setAllowLogging"
483
* The flag that allows the user to select
484
* more than one files during the 'Browse'
485
* dialog (using 'Shift' or 'Ctrl' keys).
487
* @attribute multiFiles
494
setter : "setAllowMultipleFiles"
498
* The number of files that can be uploaded
499
* simultaneously if the automatic queue management
500
* is used. This value can be in the range between 2
503
* @attribute simLimit
510
setter : "setSimUploadLimit"
514
* The array of filters on file extensions for
515
* the 'Browse' dialog. These filters only provide
516
* convenience for the user and do not strictly
517
* limit the selection to certain file extensions.
518
* Each item in the array must contain a 'description'
519
* property, and an 'extensions' property that must be
520
* in the form "*.ext;*.ext;*.ext;..."
522
* @attribute fileFilters
529
setter : "setFileFilters"
533
* The Node containing the uploader's 'Browse' button.
535
* @attribute boundingBox
543
writeOnce: 'initOnly'
547
* The URL of the image sprite for skinning the uploader's 'Browse' button.
549
* @attribute buttonSkin
557
writeOnce: 'initOnly'
561
* The flag indicating whether the uploader is rendered
562
* with a transparent background.
564
* @attribute transparent
572
writeOnce: 'initOnly'
576
* The URL of the uploader's SWF.
580
* @default "assets/uploader.swf"
586
writeOnce: 'initOnly'
592
Y.Uploader = Uploader;
595
}, '3.9.1' ,{requires:['swf', 'base', 'node', 'event-custom']});