3
Copyright 2012 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('uploader-deprecated', function(Y) {
10
* Attention: this is the 3.4.1 `uploader` module has been deprecated in favor of a new
11
* uploader with an HTML5 layer. Please refer to the new Uploader User Guide for migration
14
* This module uses Flash player transport to upload files to the server, with support for
15
* file filtering, multiple file uploads and progress monitoring.
16
* @module uploader-deprecated
23
var SWFURL = Y.Env.cdn + "uploader-deprecated/assets/uploader.swf";
26
* <p><strong><span style="color:#ff0000;">Attention: this is the 3.4.1 uploader module, which has
27
* been deprecated in favor of a new uploader with an HTML5 layer. Please refer to the new
28
* Uploader User Guide for migration information.</span></strong></p>
29
* <p>The Uploader widget is a tool for uploading files to the server.</p>
30
* @module uploader-deprecated
32
* @requires base, node, event, swf
36
* <p><strong><span style="color:#ff0000;">Attention: this is the 3.4.1 uploader module, which has
37
* been deprecated in favor of a new uploader with an HTML5 layer. Please refer to the new
38
* Uploader User Guide for migration information.</span></strong></p>
39
* <p>Creates the Uploader instance and keeps the initialization data.</p>
44
* @param {Object} config (optional) Configuration parameters for the Uploader. The following parameters are available:
46
* <dt>boundingBox : String|Node (required)</dt>
48
* <dt>buttonSkin : String (optional)</dt>
50
* <dt>transparent : String (optional)</dt>
52
* <dt>swfURL : String (optional)</dt>
58
function Uploader (config /*Object*/) {
60
Uploader.superclass.constructor.apply(this, arguments);
62
if (config.hasOwnProperty("boundingBox")) {
63
this.set("boundingBox", config.boundingBox);
66
if (config.hasOwnProperty("buttonSkin")) {
67
this.set("buttonSkin", config.buttonSkin);
69
if (config.hasOwnProperty("transparent")) {
70
this.set("transparent", config.transparent);
72
if (config.hasOwnProperty("swfURL")) {
73
this.set("swfURL", config.swfURL);
78
Y.extend(Uploader, Y.Base, {
81
* The reference to the instance of Y.SWF that encapsulates the instance of the Flash player with uploader logic.
84
* @property uploaderswf
92
* The id of this instance of uploader.
102
* Construction logic executed during Uploader instantiation.
104
* @method initializer
108
initializer : function () {
110
this._id = Y.guid("uploader");
111
var oElement = Node.one(this.get("boundingBox"));
113
var params = {version: "10.0.45",
114
fixedAttributes: {allowScriptAccess:"always", allowNetworking:"all", scale: "noscale"},
117
if (this.get("buttonSkin") != "") {
118
params.flashVars["buttonSkin"] = this.get("buttonSkin");
120
if (this.get("transparent")) {
121
params.fixedAttributes["wmode"] = "transparent";
124
this.uploaderswf = new Y.SWF(oElement, this.get("swfURL"), params);
126
var upswf = this.uploaderswf;
127
var relEvent = Y.bind(this._relayEvent, this);
130
* Announces that the uploader is ready and available for calling methods
131
* and setting properties
133
* @event uploaderReady
134
* @param event {Event} The event object for the uploaderReady.
137
upswf.on ("swfReady", Y.bind(this._initializeUploader, this));
140
* Fired when the mouse button is clicked on the Uploader's 'Browse' button.
143
* @param event {Event} The event object for the click.
146
upswf.on ("click", relEvent);
149
* Fires when the user has finished selecting a set of files to be uploaded.
152
* @param event {Event} The event object for the fileSelect.
155
* <dd>The file list Object with entries in the following format:
156
fileList[fileID] = {id: fileID, name: fileName, cDate: fileCDate, mDate: fileMDate, size: fileSize}</dd>
160
upswf.on ("fileselect", relEvent);
163
* Fired when the mouse button is pressed on the Uploader's 'Browse' button.
166
* @param event {Event} The event object for the mousedown.
169
upswf.on ("mousedown", relEvent);
172
* Fired when the mouse button is raised on the Uploader's 'Browse' button.
175
* @param event {Event} The event object for the mouseup.
178
upswf.on ("mouseup", relEvent);
181
* Fired when the mouse leaves the Uploader's 'Browse' button.
184
* @param event {Event} The event object for the mouseleave.
187
upswf.on ("mouseleave", relEvent);
190
* Fired when the mouse enters the Uploader's 'Browse' button.
193
* @param event {Event} The event object for the mouseenter.
196
upswf.on ("mouseenter", relEvent);
199
* Announces that the uploader is ready and available for calling methods
200
* and setting properties
202
* @event uploadcancel
203
* @param event {Event} The event object for the uploaderReady.
206
* <dd><code>drag:start</code> event from the thumb</dd>
210
upswf.on ("uploadcancel", relEvent);
213
* Fires when a specific file's upload is cancelled.
215
* @event uploadcomplete
216
* @param event {Event} The event object for the uploadcancel.
219
* <dd>The id of the file whose upload has been cancelled.</dd>
223
upswf.on ("uploadcomplete", relEvent);
226
* If the server has sent a response to the file upload, this event is
227
* fired and the response is added to its payload.
229
* @event uploadcompletedata
230
* @param event {Event} The event object for the uploadcompletedata.
233
* <dd>The id of the file for which the response is being provided.</dd>
235
* <dd>The content of the server response.</dd>
239
upswf.on ("uploadcompletedata", relEvent);
242
* Provides error information if an error has occurred during the upload.
245
* @param event {Event} The event object for the uploadeerror.
248
* <dd>The id of the file for which the upload error has occurred.</dd>
250
* <dd>Relevant error information.</dd>
254
upswf.on ("uploaderror", relEvent);
257
* Provides progress information on a specific file upload.
259
* @event uploadprogress
260
* @param event {Event} The event object for the uploadprogress.
263
* <dd>The id of the file for which the progress information is being provided.</dd>
264
* <dt>bytesLoaded</dt>
265
* <dd>The number of bytes of the file that has been uploaded.</dd>
266
* <dt>bytesTotal</dt>
267
* <dd>The total number of bytes in the file that is being uploaded.</dd>
271
upswf.on ("uploadprogress", relEvent);
274
* Announces that the upload has been started for a specific file.
277
* @param event {Event} The event object for the uploadstart.
280
* <dd>The id of the file whose upload has been started.</dd>
284
upswf.on ("uploadstart", relEvent);
288
* Removes a specific file from the upload queue.
291
* @param fileID {String} The ID of the file to be removed
292
* @return {Object} The updated file list, which is an object of the format:
293
* fileList[fileID] = {id: fileID, name: fileName, cDate: fileCDate, mDate: fileMDate, size: fileSize}
296
removeFile : function (fileID /*String*/) {
297
return this.uploaderswf.callSWF("removeFile", [fileID]);
301
* Clears the upload queue.
303
* @method clearFileList
304
* @return {Boolean} This method always returns true.
307
clearFileList : function () {
308
return this.uploaderswf.callSWF("clearFileList", []);
312
* Starts the upload of a specific file.
315
* @param fileID {String} The ID of the file to be uploaded.
316
* @param url {String} The URL to upload the file to.
317
* @param method {String} (optional) The HTTP method to use for sending additional variables, either 'GET' or 'POST' ('GET' by default)
318
* @param postVars {Object} (optional) A set of key-value pairs to send as variables along with the file upload HTTP request.
319
* @param postFileVarName {String} (optional) The name of the POST variable that should contain the uploaded file ('Filedata' by default)
320
* @return {Boolean} This method always returns true.
323
upload : function (fileID /*String*/, url /*String*/, method /*String*/, postVars /*Object*/, postFileVarName /*String*/) {
324
if (Y.Lang.isArray(fileID)) {
325
return this.uploaderswf.callSWF("uploadThese", [fileID, url, method, postVars, postFileVarName]);
327
else if (Y.Lang.isString(fileID)) {
328
return this.uploaderswf.callSWF("upload", [fileID, url, method, postVars, postFileVarName]);
334
* Starts the upload of a set of files, as specified in the first argument.
335
* The upload queue is managed automatically.
337
* @method uploadThese
338
* @param fileIDs {Array} The array of IDs of the files to be uploaded.
339
* @param url {String} The URL to upload the files to.
340
* @param method {String} (optional) The HTTP method to use for sending additional variables, either 'GET' or 'POST' ('GET' by default)
341
* @param postVars {Object} (optional) A set of key-value pairs to send as variables along with the file upload HTTP request.
342
* @param postFileVarName {String} (optional) The name of the POST variable that should contain the uploaded file ('Filedata' by default)
345
uploadThese : function (fileIDs /*Array*/, url /*String*/, method /*String*/, postVars /*Object*/, postFileVarName /*String*/) {
346
return this.uploaderswf.callSWF("uploadThese", [fileIDs, url, method, postVars, postFileVarName]);
350
* Starts the upload of the files in the upload queue.
351
* The upload queue is managed automatically.
354
* @param url {String} The URL to upload the files to.
355
* @param method {String} (optional) The HTTP method to use for sending additional variables, either 'GET' or 'POST' ('GET' by default)
356
* @param postVars {Object} (optional) A set of key-value pairs to send as variables along with the file upload HTTP request.
357
* @param postFileVarName {String} (optional) The name of the POST variable that should contain the uploaded file ('Filedata' by default).
360
uploadAll : function (url /*String*/, method /*String*/, postVars /*Object*/, postFileVarName /*String*/) {
361
return this.uploaderswf.callSWF("uploadAll", [url, method, postVars,postFileVarName]);
365
* Cancels the upload of a specific file, if currently in progress.
368
* @param fileID {String} (optional) The ID of the file whose upload should be cancelled. If no ID is specified, all uploads are cancelled.
371
cancel : function (fileID /*String*/) {
372
return this.uploaderswf.callSWF("cancel", [fileID]);
377
* Setter for the 'log' property.
378
* @method setAllowLogging
379
* @param value {Boolean} The value for the 'log' property.
382
setAllowLogging : function (value /*Boolean*/) {
383
this.uploaderswf.callSWF("setAllowLogging", [value]);
388
* Setter for the 'multiFiles' property.
389
* @method setAllowMultipleFiles
390
* @param value {Boolean} The value for the 'multiFiles' property.
393
setAllowMultipleFiles : function (value /*Boolean*/) {
394
this.uploaderswf.callSWF("setAllowMultipleFiles", [value]);
399
* Setter for the 'simLimit' property.
400
* @method setSimUploadLimit
401
* @param value {Boolean} The value for the 'simLimit' property.
404
setSimUploadLimit : function (value /*int*/) {
405
this.uploaderswf.callSWF("setSimUploadLimit", [value]);
410
* Setter for the 'fileFilters' property.
411
* @method setFileFilters
412
* @param value {Boolean} The value for the 'fileFilters' property.
415
setFileFilters : function (fileFilters /*Array*/) {
416
this.uploaderswf.callSWF("setFileFilters", [fileFilters]);
420
* Enables the uploader user input (mouse clicks on the 'Browse' button). If the button skin
421
* is applied, the sprite is reset from the "disabled" state.
426
enable : function () {
427
this.uploaderswf.callSWF("enable");
431
* Disables the uploader user input (mouse clicks on the 'Browse' button). If the button skin
432
* is applied, the sprite is set to the 'disabled' state.
437
disable : function () {
438
this.uploaderswf.callSWF("disable");
443
* Called when the uploader SWF is initialized
444
* @method _initializeUploader
445
* @param event {Object} The event to be propagated from Flash.
448
_initializeUploader: function (event) {
449
this.publish("uploaderReady", {fireOnce:true});
450
this.fire("uploaderReady", {});
455
* Called when an event is dispatched from Uploader
456
* @method _relayEvent
457
* @param event {Object} The event to be propagated from Flash.
460
_relayEvent: function (event) {
461
this.fire(event.type, event);
466
return "Uploader " + this._id;
473
* The flag that allows Flash player to
474
* output debug messages to its trace stack
475
* (if the Flash debug player is used).
484
setter : "setAllowLogging"
488
* The flag that allows the user to select
489
* more than one files during the 'Browse'
490
* dialog (using 'Shift' or 'Ctrl' keys).
492
* @attribute multiFiles
499
setter : "setAllowMultipleFiles"
503
* The number of files that can be uploaded
504
* simultaneously if the automatic queue management
505
* is used. This value can be in the range between 2
508
* @attribute simLimit
515
setter : "setSimUploadLimit"
519
* The array of filters on file extensions for
520
* the 'Browse' dialog. These filters only provide
521
* convenience for the user and do not strictly
522
* limit the selection to certain file extensions.
523
* Each item in the array must contain a 'description'
524
* property, and an 'extensions' property that must be
525
* in the form "*.ext;*.ext;*.ext;..."
527
* @attribute fileFilters
534
setter : "setFileFilters"
538
* The Node containing the uploader's 'Browse' button.
540
* @attribute boundingBox
548
writeOnce: 'initOnly'
552
* The URL of the image sprite for skinning the uploader's 'Browse' button.
554
* @attribute buttonSkin
562
writeOnce: 'initOnly'
566
* The flag indicating whether the uploader is rendered
567
* with a transparent background.
569
* @attribute transparent
577
writeOnce: 'initOnly'
581
* The URL of the uploader's SWF.
585
* @default "assets/uploader.swf"
591
writeOnce: 'initOnly'
597
Y.Uploader = Uploader;
600
}, '3.5.1' ,{requires:['swf', 'base', 'node', 'event-custom']});