~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to lib/yuilib/3.9.1/build/uploader-deprecated/uploader-deprecated.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* YUI 3.9.1 (build 5852) Copyright 2013 Yahoo! Inc. http://yuilibrary.com/license/ */
2
 
YUI.add('uploader-deprecated', function(Y) {
3
 
 
4
 
/**
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 
7
 
 * information.
8
 
 * 
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
12
 
 * @deprecated
13
 
 */
14
 
        
15
 
var Event = Y.Event,
16
 
    Node = Y.Node;
17
 
 
18
 
var SWFURL = Y.Env.cdn + "uploader-deprecated/assets/uploader.swf";
19
 
 
20
 
/*
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
26
 
 * @title Uploader
27
 
 * @requires base, node, event, swf
28
 
 */
29
 
 
30
 
/*
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>
35
 
 *
36
 
 * @class Uploader
37
 
 * @extends Y.Base
38
 
 * @constructor
39
 
 * @param {Object} config (optional) Configuration parameters for the Uploader. The following parameters are available:
40
 
 *        <dl>
41
 
 *          <dt>boundingBox : String|Node (required)</dt>
42
 
 *          <dd></dd>
43
 
 *          <dt>buttonSkin : String (optional)</dt>
44
 
 *          <dd></dd>
45
 
 *          <dt>transparent : String (optional)</dt>
46
 
 *          <dd></dd>
47
 
 *          <dt>swfURL : String (optional)</dt>
48
 
 *          <dd></dd>
49
 
 *        </dl>
50
 
 * @deprecated
51
 
 */
52
 
                                
53
 
function Uploader (config /*Object*/) {
54
 
        
55
 
        Uploader.superclass.constructor.apply(this, arguments);
56
 
 
57
 
        if (config.hasOwnProperty("boundingBox")) {
58
 
                this.set("boundingBox", config.boundingBox);
59
 
        };
60
 
 
61
 
        if (config.hasOwnProperty("buttonSkin")) {
62
 
                this.set("buttonSkin", config.buttonSkin);
63
 
        };
64
 
        if (config.hasOwnProperty("transparent")) {
65
 
                this.set("transparent", config.transparent);
66
 
        };
67
 
        if (config.hasOwnProperty("swfURL")) {
68
 
                this.set("swfURL", config.swfURL);
69
 
        };
70
 
};
71
 
 
72
 
 
73
 
Y.extend(Uploader, Y.Base, {
74
 
        
75
 
   /*
76
 
    * The reference to the instance of Y.SWF that encapsulates the instance of the Flash player with uploader logic.
77
 
    *
78
 
    * @private
79
 
    * @property uploaderswf
80
 
    * @type {SWF}
81
 
    * @default null
82
 
    * @deprecated
83
 
    */
84
 
        uploaderswf:null,
85
 
 
86
 
   /*
87
 
    * The id of this instance of uploader.
88
 
    *
89
 
    * @private
90
 
    * @property _id
91
 
    * @type {String}
92
 
    * @deprecated
93
 
    */
94
 
        _id:"",
95
 
 
96
 
   /*
97
 
    * Construction logic executed during Uploader instantiation.
98
 
    *
99
 
    * @method initializer
100
 
    * @protected
101
 
    * @deprecated
102
 
    */
103
 
        initializer : function () {
104
 
                
105
 
        this._id = Y.guid("uploader");
106
 
    var oElement = Node.one(this.get("boundingBox"));
107
 
 
108
 
        var params = {version: "10.0.45",
109
 
                          fixedAttributes: {allowScriptAccess:"always", allowNetworking:"all", scale: "noscale"},
110
 
                      flashVars: {}};
111
 
 
112
 
        if (this.get("buttonSkin") != "") {
113
 
                params.flashVars["buttonSkin"] = this.get("buttonSkin");
114
 
        }
115
 
        if (this.get("transparent")) {
116
 
                params.fixedAttributes["wmode"] = "transparent";
117
 
        }
118
 
 
119
 
    this.uploaderswf = new Y.SWF(oElement, this.get("swfURL"), params);
120
 
 
121
 
        var upswf = this.uploaderswf;
122
 
        var relEvent = Y.bind(this._relayEvent, this);
123
 
 
124
 
        /*
125
 
        * Announces that the uploader is ready and available for calling methods
126
 
        * and setting properties
127
 
        *
128
 
        * @event uploaderReady
129
 
        * @param event {Event} The event object for the uploaderReady.
130
 
    * @deprecated
131
 
    */
132
 
        upswf.on ("swfReady", Y.bind(this._initializeUploader, this));
133
 
        
134
 
        /*
135
 
        * Fired when the mouse button is clicked on the Uploader's 'Browse' button.
136
 
        *
137
 
        * @event click
138
 
        * @param event {Event} The event object for the click.
139
 
    * @deprecated
140
 
    */
141
 
        upswf.on ("click", relEvent);
142
 
 
143
 
        /*
144
 
        * Fires when the user has finished selecting a set of files to be uploaded.
145
 
        *
146
 
        * @event fileselect
147
 
        * @param event {Event} The event object for the fileSelect.
148
 
        *  <dl>
149
 
        *      <dt>fileList</dt>
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>
152
 
        *  </dl>
153
 
    * @deprecated
154
 
    */
155
 
        upswf.on ("fileselect", relEvent);
156
 
 
157
 
        /*
158
 
        * Fired when the mouse button is pressed on the Uploader's 'Browse' button.
159
 
        *
160
 
        * @event mousedown
161
 
        * @param event {Event} The event object for the mousedown.
162
 
    * @deprecated
163
 
    */
164
 
        upswf.on ("mousedown", relEvent);
165
 
 
166
 
        /*
167
 
        * Fired when the mouse button is raised on the Uploader's 'Browse' button.
168
 
        *
169
 
        * @event mouseup
170
 
        * @param event {Event} The event object for the mouseup.
171
 
    * @deprecated
172
 
    */
173
 
        upswf.on ("mouseup", relEvent);
174
 
 
175
 
        /*
176
 
        * Fired when the mouse leaves the Uploader's 'Browse' button.
177
 
        *
178
 
        * @event mouseleave
179
 
        * @param event {Event} The event object for the mouseleave.
180
 
    * @deprecated
181
 
    */
182
 
        upswf.on ("mouseleave", relEvent);
183
 
 
184
 
        /*
185
 
        * Fired when the mouse enters the Uploader's 'Browse' button.
186
 
        *
187
 
        * @event mouseenter
188
 
        * @param event {Event} The event object for the mouseenter.
189
 
    * @deprecated
190
 
    */
191
 
        upswf.on ("mouseenter", relEvent);
192
 
 
193
 
        /*
194
 
        * Announces that the uploader is ready and available for calling methods
195
 
        * and setting properties
196
 
        *
197
 
        * @event uploadcancel
198
 
        * @param event {Event} The event object for the uploaderReady.
199
 
        *  <dl>
200
 
        *      <dt>ddEvent</dt>
201
 
        *          <dd><code>drag:start</code> event from the thumb</dd>
202
 
        *  </dl>
203
 
    * @deprecated
204
 
    */
205
 
        upswf.on ("uploadcancel", relEvent);
206
 
 
207
 
        /*
208
 
        * Fires when a specific file's upload is cancelled.
209
 
        *
210
 
        * @event uploadcomplete
211
 
        * @param event {Event} The event object for the uploadcancel.
212
 
        *  <dl>
213
 
        *      <dt>id</dt>
214
 
        *          <dd>The id of the file whose upload has been cancelled.</dd>
215
 
        *  </dl>
216
 
    * @deprecated
217
 
    */
218
 
        upswf.on ("uploadcomplete", relEvent);
219
 
 
220
 
        /*
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.
223
 
        *
224
 
        * @event uploadcompletedata
225
 
        * @param event {Event} The event object for the uploadcompletedata.
226
 
        *  <dl>
227
 
        *      <dt>id</dt>
228
 
        *          <dd>The id of the file for which the response is being provided.</dd>
229
 
        *      <dt>data</dt>
230
 
        *          <dd>The content of the server response.</dd>
231
 
        *  </dl>
232
 
    * @deprecated
233
 
    */
234
 
        upswf.on ("uploadcompletedata", relEvent);
235
 
 
236
 
        /*
237
 
        * Provides error information if an error has occurred during the upload.
238
 
        *
239
 
        * @event uploaderror
240
 
        * @param event {Event} The event object for the uploadeerror.
241
 
        *  <dl>
242
 
        *      <dt>id</dt>
243
 
        *          <dd>The id of the file for which the upload error has occurred.</dd>
244
 
        *      <dt>status</dt>
245
 
        *          <dd>Relevant error information.</dd>
246
 
        *  </dl>
247
 
    * @deprecated
248
 
    */
249
 
        upswf.on ("uploaderror", relEvent);
250
 
 
251
 
        /*
252
 
        * Provides progress information on a specific file upload.
253
 
        *
254
 
        * @event uploadprogress
255
 
        * @param event {Event} The event object for the uploadprogress.
256
 
        *  <dl>
257
 
        *      <dt>id</dt>
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>
263
 
        *  </dl>
264
 
    * @deprecated
265
 
    */
266
 
        upswf.on ("uploadprogress", relEvent);
267
 
 
268
 
        /*
269
 
        * Announces that the upload has been started for a specific file.
270
 
        *
271
 
        * @event uploadstart
272
 
        * @param event {Event} The event object for the uploadstart.
273
 
        *  <dl>
274
 
        *      <dt>id</dt>
275
 
        *          <dd>The id of the file whose upload has been started.</dd>
276
 
        *  </dl>
277
 
    * @deprecated
278
 
    */ 
279
 
        upswf.on ("uploadstart", relEvent);
280
 
        },
281
 
 
282
 
   /*
283
 
    * Removes a specific file from the upload queue.
284
 
    *
285
 
    * @method removeFile
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}
289
 
    * @deprecated
290
 
    */
291
 
        removeFile : function (fileID /*String*/) {
292
 
                return this.uploaderswf.callSWF("removeFile", [fileID]);
293
 
        },
294
 
        
295
 
   /*
296
 
    * Clears the upload queue.
297
 
    *
298
 
    * @method clearFileList
299
 
    * @return {Boolean} This method always returns true.
300
 
    * @deprecated
301
 
    */
302
 
        clearFileList : function () {
303
 
                return this.uploaderswf.callSWF("clearFileList", []);
304
 
        },
305
 
 
306
 
   /*
307
 
    * Starts the upload of a specific file.
308
 
    *
309
 
    * @method upload
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.
316
 
    * @deprecated
317
 
    */
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]);
321
 
                }
322
 
                else if (Y.Lang.isString(fileID)) {
323
 
                        return this.uploaderswf.callSWF("upload", [fileID, url, method, postVars, postFileVarName]);
324
 
                        
325
 
                }
326
 
        },
327
 
 
328
 
   /*
329
 
    * Starts the upload of a set of files, as specified in the first argument. 
330
 
    * The upload queue is managed automatically.
331
 
    *
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)
338
 
    * @deprecated
339
 
    */
340
 
        uploadThese : function (fileIDs /*Array*/, url /*String*/, method /*String*/, postVars /*Object*/, postFileVarName /*String*/) {
341
 
                return this.uploaderswf.callSWF("uploadThese", [fileIDs, url, method, postVars, postFileVarName]);
342
 
        },
343
 
 
344
 
   /*
345
 
    * Starts the upload of the files in the upload queue. 
346
 
    * The upload queue is managed automatically.
347
 
    *
348
 
    * @method uploadAll
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).
353
 
    * @deprecated
354
 
    */  
355
 
        uploadAll : function (url /*String*/, method /*String*/, postVars /*Object*/, postFileVarName /*String*/) {
356
 
                return this.uploaderswf.callSWF("uploadAll", [url, method, postVars,postFileVarName]);
357
 
        },
358
 
 
359
 
   /*
360
 
    * Cancels the upload of a specific file, if currently in progress.
361
 
    *
362
 
    * @method cancel
363
 
    * @param fileID {String} (optional) The ID of the file whose upload should be cancelled. If no ID is specified, all uploads are cancelled.
364
 
    * @deprecated
365
 
    */  
366
 
        cancel : function (fileID /*String*/) {
367
 
                return this.uploaderswf.callSWF("cancel", [fileID]);
368
 
        },
369
 
 
370
 
        /*
371
 
         * @private
372
 
         * Setter for the 'log' property.
373
 
         * @method setAllowLogging
374
 
         * @param value {Boolean} The value for the 'log' property.
375
 
     * @deprecated
376
 
         */
377
 
        setAllowLogging : function (value /*Boolean*/) {
378
 
                this.uploaderswf.callSWF("setAllowLogging", [value]);
379
 
        },
380
 
 
381
 
        /*
382
 
         * @private
383
 
         * Setter for the 'multiFiles' property.
384
 
         * @method setAllowMultipleFiles
385
 
         * @param value {Boolean} The value for the 'multiFiles' property.
386
 
     * @deprecated
387
 
         */
388
 
        setAllowMultipleFiles : function (value /*Boolean*/) {
389
 
                this.uploaderswf.callSWF("setAllowMultipleFiles", [value]);
390
 
        },
391
 
 
392
 
        /*
393
 
         * @private
394
 
         * Setter for the 'simLimit' property.
395
 
         * @method setSimUploadLimit
396
 
         * @param value {Boolean} The value for the 'simLimit' property.
397
 
     * @deprecated
398
 
         */
399
 
        setSimUploadLimit : function (value /*int*/) {
400
 
                this.uploaderswf.callSWF("setSimUploadLimit", [value]);
401
 
        },
402
 
 
403
 
        /*
404
 
         * @private
405
 
         * Setter for the 'fileFilters' property.
406
 
         * @method setFileFilters
407
 
         * @param value {Boolean} The value for the 'fileFilters' property.
408
 
     * @deprecated
409
 
         */     
410
 
        setFileFilters : function (fileFilters /*Array*/) {
411
 
                this.uploaderswf.callSWF("setFileFilters", [fileFilters]);
412
 
        },
413
 
 
414
 
   /*
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.
417
 
    *
418
 
    * @method enable
419
 
    * @deprecated
420
 
    */  
421
 
        enable : function () {
422
 
                this.uploaderswf.callSWF("enable");
423
 
        },
424
 
 
425
 
   /*
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.
428
 
    *
429
 
    * @method enable
430
 
    * @deprecated
431
 
    */  
432
 
        disable : function () {
433
 
                this.uploaderswf.callSWF("disable");
434
 
        },
435
 
 
436
 
        /*
437
 
         * @private
438
 
         * Called when the uploader SWF is initialized
439
 
         * @method _initializeUploader
440
 
         * @param event {Object} The event to be propagated from Flash.
441
 
     * @deprecated
442
 
         */
443
 
        _initializeUploader: function (event) {
444
 
                        this.publish("uploaderReady", {fireOnce:true});
445
 
                this.fire("uploaderReady", {});
446
 
        },
447
 
 
448
 
        /*
449
 
         * @private
450
 
         * Called when an event is dispatched from Uploader
451
 
         * @method _relayEvent
452
 
         * @param event {Object} The event to be propagated from Flash.
453
 
     * @deprecated
454
 
         */     
455
 
        _relayEvent: function (event) {
456
 
                    this.fire(event.type, event);
457
 
        },
458
 
        
459
 
        toString: function()
460
 
        {
461
 
                return "Uploader " + this._id;
462
 
        }
463
 
 
464
 
},
465
 
{
466
 
        ATTRS: {
467
 
        /*
468
 
         * The flag that allows Flash player to 
469
 
         * output debug messages to its trace stack 
470
 
         * (if the Flash debug player is used).
471
 
         *
472
 
         * @attribute log
473
 
         * @type {Boolean}
474
 
         * @default false
475
 
         * @deprecated
476
 
         */
477
 
                log: {
478
 
                        value: false,
479
 
                        setter : "setAllowLogging"
480
 
                },
481
 
 
482
 
        /*
483
 
         * The flag that allows the user to select
484
 
         * more than one files during the 'Browse'
485
 
         * dialog (using 'Shift' or 'Ctrl' keys).
486
 
         *
487
 
         * @attribute multiFiles
488
 
         * @type {Boolean}
489
 
         * @default false
490
 
         * @deprecated
491
 
         */
492
 
                multiFiles : {
493
 
                        value: false,
494
 
                        setter : "setAllowMultipleFiles"
495
 
                },
496
 
        
497
 
        /*
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
501
 
         * and 5.
502
 
         *
503
 
         * @attribute simLimit
504
 
         * @type {Number}
505
 
         * @default 2
506
 
         * @deprecated
507
 
         */
508
 
                simLimit : {
509
 
                        value: 2,
510
 
                        setter : "setSimUploadLimit"
511
 
                },
512
 
 
513
 
        /*
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;..."
521
 
         *
522
 
         * @attribute fileFilters
523
 
         * @type {Array}
524
 
         * @default []
525
 
         * @deprecated
526
 
         */
527
 
                fileFilters : {
528
 
                        value: [],
529
 
                        setter : "setFileFilters"
530
 
                },
531
 
                
532
 
        /*
533
 
         * The Node containing the uploader's 'Browse' button.
534
 
         *
535
 
         * @attribute boundingBox
536
 
         * @type {Node}
537
 
         * @default null
538
 
         * @writeOnce
539
 
         * @deprecated
540
 
         */
541
 
                boundingBox : {
542
 
                        value: null,
543
 
                        writeOnce: 'initOnly'
544
 
                },
545
 
                
546
 
        /*
547
 
         * The URL of the image sprite for skinning the uploader's 'Browse' button.
548
 
         *
549
 
         * @attribute buttonSkin
550
 
         * @type {String}
551
 
         * @default null
552
 
         * @writeOnce
553
 
         * @deprecated
554
 
         */
555
 
                buttonSkin : {
556
 
                        value: null,
557
 
                        writeOnce: 'initOnly'
558
 
                },
559
 
                
560
 
        /*
561
 
         * The flag indicating whether the uploader is rendered 
562
 
         * with a transparent background.
563
 
         *
564
 
         * @attribute transparent
565
 
         * @type {Boolean}
566
 
         * @default true
567
 
         * @writeOnce
568
 
         * @deprecated
569
 
         */
570
 
                transparent : {
571
 
                        value: true,
572
 
                        writeOnce: 'initOnly'
573
 
                },
574
 
                
575
 
        /*
576
 
         * The URL of the uploader's SWF.
577
 
         *
578
 
         * @attribute swfURL
579
 
         * @type {String}
580
 
         * @default "assets/uploader.swf"
581
 
         * @writeOnce
582
 
         * @deprecated
583
 
         */
584
 
                swfURL : {
585
 
                        value : SWFURL,
586
 
                        writeOnce: 'initOnly'
587
 
                }
588
 
                
589
 
        }
590
 
}
591
 
);
592
 
Y.Uploader = Uploader;
593
 
 
594
 
 
595
 
}, '3.9.1' ,{requires:['swf', 'base', 'node', 'event-custom']});