API Docs for: 3.8.0
Show:

File: uploader-deprecated/js/uploader-deprecated.js

  1. /**
  2.  * Attention: this is the 3.4.1 `uploader` module has been deprecated in favor of a new
  3.  * uploader with an HTML5 layer. Please refer to the new Uploader User Guide for migration
  4.  * information.
  5.  *
  6.  * This module uses Flash player transport to upload files to the server, with support for
  7.  * file filtering, multiple file uploads and progress monitoring.
  8.  * @module uploader-deprecated
  9.  * @deprecated
  10.  */
  11.        
  12. var Event = Y.Event,
  13.     Node = Y.Node;

  14. var SWFURL = Y.Env.cdn + "uploader-deprecated/assets/uploader.swf";

  15. /*
  16.  * <p><strong><span style="color:#ff0000;">Attention: this is the 3.4.1 uploader module, which has
  17.  * been deprecated in favor of a new uploader with an HTML5 layer. Please refer to the new
  18.  * Uploader User Guide for migration information.</span></strong></p>
  19.  * <p>The Uploader widget is a tool for uploading files to the server.</p>
  20.  * @module uploader-deprecated
  21.  * @title Uploader
  22.  * @requires base, node, event, swf
  23.  */

  24. /*
  25.  * <p><strong><span style="color:#ff0000;">Attention: this is the 3.4.1 uploader module, which has
  26.  * been deprecated in favor of a new uploader with an HTML5 layer. Please refer to the new
  27.  * Uploader User Guide for migration information.</span></strong></p>
  28.  * <p>Creates the Uploader instance and keeps the initialization data.</p>
  29.  *
  30.  * @class Uploader
  31.  * @extends Y.Base
  32.  * @constructor
  33.  * @param {Object} config (optional) Configuration parameters for the Uploader. The following parameters are available:
  34.  *        <dl>
  35.  *          <dt>boundingBox : String|Node (required)</dt>
  36.  *          <dd></dd>
  37.  *          <dt>buttonSkin : String (optional)</dt>
  38.  *          <dd></dd>
  39.  *          <dt>transparent : String (optional)</dt>
  40.  *          <dd></dd>
  41.  *          <dt>swfURL : String (optional)</dt>
  42.  *          <dd></dd>
  43.  *        </dl>
  44.  * @deprecated
  45.  */
  46.                                
  47. function Uploader (config /*Object*/) {
  48.        
  49.         Uploader.superclass.constructor.apply(this, arguments);

  50.         if (config.hasOwnProperty("boundingBox")) {
  51.                 this.set("boundingBox", config.boundingBox);
  52.         };

  53.         if (config.hasOwnProperty("buttonSkin")) {
  54.                 this.set("buttonSkin", config.buttonSkin);
  55.         };
  56.         if (config.hasOwnProperty("transparent")) {
  57.                 this.set("transparent", config.transparent);
  58.         };
  59.         if (config.hasOwnProperty("swfURL")) {
  60.                 this.set("swfURL", config.swfURL);
  61.         };
  62. };


  63. Y.extend(Uploader, Y.Base, {
  64.        
  65.    /*
  66.     * The reference to the instance of Y.SWF that encapsulates the instance of the Flash player with uploader logic.
  67.     *
  68.     * @private
  69.     * @property uploaderswf
  70.     * @type {SWF}
  71.     * @default null
  72.     * @deprecated
  73.     */
  74.         uploaderswf:null,

  75.    /*
  76.     * The id of this instance of uploader.
  77.     *
  78.     * @private
  79.     * @property _id
  80.     * @type {String}
  81.     * @deprecated
  82.     */
  83.         _id:"",

  84.    /*
  85.     * Construction logic executed during Uploader instantiation.
  86.     *
  87.     * @method initializer
  88.     * @protected
  89.     * @deprecated
  90.     */
  91.         initializer : function () {
  92.                
  93.         this._id = Y.guid("uploader");
  94.     var oElement = Node.one(this.get("boundingBox"));

  95.         var params = {version: "10.0.45",
  96.                           fixedAttributes: {allowScriptAccess:"always", allowNetworking:"all", scale: "noscale"},
  97.                       flashVars: {}};

  98.         if (this.get("buttonSkin") != "") {
  99.                 params.flashVars["buttonSkin"] = this.get("buttonSkin");
  100.         }
  101.         if (this.get("transparent")) {
  102.                 params.fixedAttributes["wmode"] = "transparent";
  103.         }

  104.     this.uploaderswf = new Y.SWF(oElement, this.get("swfURL"), params);

  105.         var upswf = this.uploaderswf;
  106.         var relEvent = Y.bind(this._relayEvent, this);

  107.         /*
  108.         * Announces that the uploader is ready and available for calling methods
  109.         * and setting properties
  110.         *
  111.         * @event uploaderReady
  112.         * @param event {Event} The event object for the uploaderReady.
  113.     * @deprecated
  114.     */
  115.         upswf.on ("swfReady", Y.bind(this._initializeUploader, this));
  116.        
  117.         /*
  118.         * Fired when the mouse button is clicked on the Uploader's 'Browse' button.
  119.         *
  120.         * @event click
  121.         * @param event {Event} The event object for the click.
  122.     * @deprecated
  123.     */
  124.         upswf.on ("click", relEvent);

  125.         /*
  126.         * Fires when the user has finished selecting a set of files to be uploaded.
  127.         *
  128.         * @event fileselect
  129.         * @param event {Event} The event object for the fileSelect.
  130.         *  <dl>
  131.         *      <dt>fileList</dt>
  132.         *          <dd>The file list Object with entries in the following format:
  133.                        fileList[fileID] = {id: fileID, name: fileName, cDate: fileCDate, mDate: fileMDate, size: fileSize}</dd>
  134.         *  </dl>
  135.     * @deprecated
  136.     */
  137.         upswf.on ("fileselect", relEvent);

  138.         /*
  139.         * Fired when the mouse button is pressed on the Uploader's 'Browse' button.
  140.         *
  141.         * @event mousedown
  142.         * @param event {Event} The event object for the mousedown.
  143.     * @deprecated
  144.     */
  145.         upswf.on ("mousedown", relEvent);

  146.         /*
  147.         * Fired when the mouse button is raised on the Uploader's 'Browse' button.
  148.         *
  149.         * @event mouseup
  150.         * @param event {Event} The event object for the mouseup.
  151.     * @deprecated
  152.     */
  153.         upswf.on ("mouseup", relEvent);

  154.         /*
  155.         * Fired when the mouse leaves the Uploader's 'Browse' button.
  156.         *
  157.         * @event mouseleave
  158.         * @param event {Event} The event object for the mouseleave.
  159.     * @deprecated
  160.     */
  161.         upswf.on ("mouseleave", relEvent);

  162.         /*
  163.         * Fired when the mouse enters the Uploader's 'Browse' button.
  164.         *
  165.         * @event mouseenter
  166.         * @param event {Event} The event object for the mouseenter.
  167.     * @deprecated
  168.     */
  169.         upswf.on ("mouseenter", relEvent);

  170.         /*
  171.         * Announces that the uploader is ready and available for calling methods
  172.         * and setting properties
  173.         *
  174.         * @event uploadcancel
  175.         * @param event {Event} The event object for the uploaderReady.
  176.         *  <dl>
  177.         *      <dt>ddEvent</dt>
  178.         *          <dd><code>drag:start</code> event from the thumb</dd>
  179.         *  </dl>
  180.     * @deprecated
  181.     */
  182.         upswf.on ("uploadcancel", relEvent);

  183.         /*
  184.         * Fires when a specific file's upload is cancelled.
  185.         *
  186.         * @event uploadcomplete
  187.         * @param event {Event} The event object for the uploadcancel.
  188.         *  <dl>
  189.         *      <dt>id</dt>
  190.         *          <dd>The id of the file whose upload has been cancelled.</dd>
  191.         *  </dl>
  192.     * @deprecated
  193.     */
  194.         upswf.on ("uploadcomplete", relEvent);

  195.         /*
  196.         * If the server has sent a response to the file upload, this event is
  197.         * fired and the response is added to its payload.
  198.         *
  199.         * @event uploadcompletedata
  200.         * @param event {Event} The event object for the uploadcompletedata.
  201.         *  <dl>
  202.         *      <dt>id</dt>
  203.         *          <dd>The id of the file for which the response is being provided.</dd>
  204.         *      <dt>data</dt>
  205.         *          <dd>The content of the server response.</dd>
  206.         *  </dl>
  207.     * @deprecated
  208.     */
  209.         upswf.on ("uploadcompletedata", relEvent);

  210.         /*
  211.         * Provides error information if an error has occurred during the upload.
  212.         *
  213.         * @event uploaderror
  214.         * @param event {Event} The event object for the uploadeerror.
  215.         *  <dl>
  216.         *      <dt>id</dt>
  217.         *          <dd>The id of the file for which the upload error has occurred.</dd>
  218.         *      <dt>status</dt>
  219.         *          <dd>Relevant error information.</dd>
  220.         *  </dl>
  221.     * @deprecated
  222.     */
  223.         upswf.on ("uploaderror", relEvent);

  224.         /*
  225.         * Provides progress information on a specific file upload.
  226.         *
  227.         * @event uploadprogress
  228.         * @param event {Event} The event object for the uploadprogress.
  229.         *  <dl>
  230.         *      <dt>id</dt>
  231.         *          <dd>The id of the file for which the progress information is being provided.</dd>
  232.         *      <dt>bytesLoaded</dt>
  233.         *          <dd>The number of bytes of the file that has been uploaded.</dd>
  234.         *      <dt>bytesTotal</dt>
  235.         *          <dd>The total number of bytes in the file that is being uploaded.</dd>
  236.         *  </dl>
  237.     * @deprecated
  238.     */
  239.         upswf.on ("uploadprogress", relEvent);

  240.         /*
  241.         * Announces that the upload has been started for a specific file.
  242.         *
  243.         * @event uploadstart
  244.         * @param event {Event} The event object for the uploadstart.
  245.         *  <dl>
  246.         *      <dt>id</dt>
  247.         *          <dd>The id of the file whose upload has been started.</dd>
  248.         *  </dl>
  249.     * @deprecated
  250.     */
  251.         upswf.on ("uploadstart", relEvent);
  252.         },

  253.    /*
  254.     * Removes a specific file from the upload queue.
  255.     *
  256.     * @method removeFile
  257.     * @param fileID {String} The ID of the file to be removed
  258.     * @return {Object} The updated file list, which is an object of the format:
  259.     * fileList[fileID] = {id: fileID, name: fileName, cDate: fileCDate, mDate: fileMDate, size: fileSize}
  260.     * @deprecated
  261.     */
  262.         removeFile : function (fileID /*String*/) {
  263.                 return this.uploaderswf.callSWF("removeFile", [fileID]);
  264.         },
  265.        
  266.    /*
  267.     * Clears the upload queue.
  268.     *
  269.     * @method clearFileList
  270.     * @return {Boolean} This method always returns true.
  271.     * @deprecated
  272.     */
  273.         clearFileList : function () {
  274.                 return this.uploaderswf.callSWF("clearFileList", []);
  275.         },

  276.    /*
  277.     * Starts the upload of a specific file.
  278.     *
  279.     * @method upload
  280.     * @param fileID {String} The ID of the file to be uploaded.
  281.     * @param url {String} The URL to upload the file to.
  282.     * @param method {String} (optional) The HTTP method to use for sending additional variables, either 'GET' or 'POST' ('GET' by default)
  283.         * @param postVars {Object} (optional) A set of key-value pairs to send as variables along with the file upload HTTP request.
  284.         * @param postFileVarName {String} (optional) The name of the POST variable that should contain the uploaded file ('Filedata' by default)
  285.     * @return {Boolean} This method always returns true.
  286.     * @deprecated
  287.     */
  288.         upload : function (fileID /*String*/, url /*String*/, method /*String*/, postVars /*Object*/, postFileVarName /*String*/) {
  289.             if (Y.Lang.isArray(fileID)) {
  290.                         return this.uploaderswf.callSWF("uploadThese", [fileID, url, method, postVars, postFileVarName]);
  291.                 }
  292.                 else if (Y.Lang.isString(fileID)) {
  293.                         return this.uploaderswf.callSWF("upload", [fileID, url, method, postVars, postFileVarName]);
  294.                        
  295.                 }
  296.         },

  297.    /*
  298.     * Starts the upload of a set of files, as specified in the first argument.
  299.     * The upload queue is managed automatically.
  300.     *
  301.     * @method uploadThese
  302.     * @param fileIDs {Array} The array of IDs of the files to be uploaded.
  303.     * @param url {String} The URL to upload the files to.
  304.     * @param method {String} (optional) The HTTP method to use for sending additional variables, either 'GET' or 'POST' ('GET' by default)
  305.         * @param postVars {Object} (optional) A set of key-value pairs to send as variables along with the file upload HTTP request.
  306.         * @param postFileVarName {String} (optional) The name of the POST variable that should contain the uploaded file ('Filedata' by default)
  307.     * @deprecated
  308.     */
  309.         uploadThese : function (fileIDs /*Array*/, url /*String*/, method /*String*/, postVars /*Object*/, postFileVarName /*String*/) {
  310.                 return this.uploaderswf.callSWF("uploadThese", [fileIDs, url, method, postVars, postFileVarName]);
  311.         },

  312.    /*
  313.     * Starts the upload of the files in the upload queue.
  314.     * The upload queue is managed automatically.
  315.     *
  316.     * @method uploadAll
  317.     * @param url {String} The URL to upload the files to.
  318.     * @param method {String} (optional) The HTTP method to use for sending additional variables, either 'GET' or 'POST' ('GET' by default)
  319.         * @param postVars {Object} (optional) A set of key-value pairs to send as variables along with the file upload HTTP request.
  320.         * @param postFileVarName {String} (optional) The name of the POST variable that should contain the uploaded file ('Filedata' by default).
  321.     * @deprecated
  322.     */  
  323.         uploadAll : function (url /*String*/, method /*String*/, postVars /*Object*/, postFileVarName /*String*/) {
  324.                 return this.uploaderswf.callSWF("uploadAll", [url, method, postVars,postFileVarName]);
  325.         },

  326.    /*
  327.     * Cancels the upload of a specific file, if currently in progress.
  328.     *
  329.     * @method cancel
  330.     * @param fileID {String} (optional) The ID of the file whose upload should be cancelled. If no ID is specified, all uploads are cancelled.
  331.     * @deprecated
  332.     */  
  333.         cancel : function (fileID /*String*/) {
  334.                 return this.uploaderswf.callSWF("cancel", [fileID]);
  335.         },

  336.         /*
  337.          * @private
  338.          * Setter for the 'log' property.
  339.          * @method setAllowLogging
  340.          * @param value {Boolean} The value for the 'log' property.
  341.      * @deprecated
  342.          */
  343.         setAllowLogging : function (value /*Boolean*/) {
  344.                 this.uploaderswf.callSWF("setAllowLogging", [value]);
  345.         },

  346.         /*
  347.          * @private
  348.          * Setter for the 'multiFiles' property.
  349.          * @method setAllowMultipleFiles
  350.          * @param value {Boolean} The value for the 'multiFiles' property.
  351.      * @deprecated
  352.          */
  353.         setAllowMultipleFiles : function (value /*Boolean*/) {
  354.                 this.uploaderswf.callSWF("setAllowMultipleFiles", [value]);
  355.         },

  356.         /*
  357.          * @private
  358.          * Setter for the 'simLimit' property.
  359.          * @method setSimUploadLimit
  360.          * @param value {Boolean} The value for the 'simLimit' property.
  361.      * @deprecated
  362.          */
  363.         setSimUploadLimit : function (value /*int*/) {
  364.                 this.uploaderswf.callSWF("setSimUploadLimit", [value]);
  365.         },

  366.         /*
  367.          * @private
  368.          * Setter for the 'fileFilters' property.
  369.          * @method setFileFilters
  370.          * @param value {Boolean} The value for the 'fileFilters' property.
  371.      * @deprecated
  372.          */    
  373.         setFileFilters : function (fileFilters /*Array*/) {
  374.                 this.uploaderswf.callSWF("setFileFilters", [fileFilters]);
  375.         },

  376.    /*
  377.     * Enables the uploader user input (mouse clicks on the 'Browse' button). If the button skin
  378.     * is applied, the sprite is reset from the "disabled" state.
  379.     *
  380.     * @method enable
  381.     * @deprecated
  382.     */  
  383.         enable : function () {
  384.                 this.uploaderswf.callSWF("enable");
  385.         },

  386.    /*
  387.     * Disables the uploader user input (mouse clicks on the 'Browse' button). If the button skin
  388.     * is applied, the sprite is set to the 'disabled' state.
  389.     *
  390.     * @method enable
  391.     * @deprecated
  392.     */  
  393.         disable : function () {
  394.                 this.uploaderswf.callSWF("disable");
  395.         },

  396.         /*
  397.          * @private
  398.          * Called when the uploader SWF is initialized
  399.          * @method _initializeUploader
  400.          * @param event {Object} The event to be propagated from Flash.
  401.      * @deprecated
  402.          */
  403.         _initializeUploader: function (event) {
  404.                         this.publish("uploaderReady", {fireOnce:true});
  405.                 this.fire("uploaderReady", {});
  406.         },

  407.         /*
  408.          * @private
  409.          * Called when an event is dispatched from Uploader
  410.          * @method _relayEvent
  411.          * @param event {Object} The event to be propagated from Flash.
  412.      * @deprecated
  413.          */    
  414.         _relayEvent: function (event) {
  415.                     Y.log("Firing event...");
  416.                     Y.log(event.type);
  417.                     this.fire(event.type, event);
  418.         },
  419.        
  420.         toString: function()
  421.         {
  422.                 return "Uploader " + this._id;
  423.         }

  424. },
  425. {
  426.         ATTRS: {
  427.         /*
  428.          * The flag that allows Flash player to
  429.          * output debug messages to its trace stack
  430.          * (if the Flash debug player is used).
  431.          *
  432.          * @attribute log
  433.          * @type {Boolean}
  434.          * @default false
  435.          * @deprecated
  436.          */
  437.                 log: {
  438.                         value: false,
  439.                         setter : "setAllowLogging"
  440.                 },

  441.         /*
  442.          * The flag that allows the user to select
  443.          * more than one files during the 'Browse'
  444.          * dialog (using 'Shift' or 'Ctrl' keys).
  445.          *
  446.          * @attribute multiFiles
  447.          * @type {Boolean}
  448.          * @default false
  449.          * @deprecated
  450.          */
  451.                 multiFiles : {
  452.                         value: false,
  453.                         setter : "setAllowMultipleFiles"
  454.                 },
  455.        
  456.         /*
  457.          * The number of files that can be uploaded
  458.          * simultaneously if the automatic queue management
  459.          * is used. This value can be in the range between 2
  460.          * and 5.
  461.          *
  462.          * @attribute simLimit
  463.          * @type {Number}
  464.          * @default 2
  465.          * @deprecated
  466.          */
  467.                 simLimit : {
  468.                         value: 2,
  469.                         setter : "setSimUploadLimit"
  470.                 },

  471.         /*
  472.          * The array of filters on file extensions for
  473.          * the 'Browse' dialog. These filters only provide
  474.          * convenience for the user and do not strictly
  475.          * limit the selection to certain file extensions.
  476.          * Each item in the array must contain a 'description'
  477.          * property, and an 'extensions' property that must be
  478.          * in the form "*.ext;*.ext;*.ext;..."
  479.          *
  480.          * @attribute fileFilters
  481.          * @type {Array}
  482.          * @default []
  483.          * @deprecated
  484.          */
  485.                 fileFilters : {
  486.                         value: [],
  487.                         setter : "setFileFilters"
  488.                 },
  489.                
  490.         /*
  491.          * The Node containing the uploader's 'Browse' button.
  492.          *
  493.          * @attribute boundingBox
  494.          * @type {Node}
  495.          * @default null
  496.          * @writeOnce
  497.          * @deprecated
  498.          */
  499.                 boundingBox : {
  500.                         value: null,
  501.                         writeOnce: 'initOnly'
  502.                 },
  503.                
  504.         /*
  505.          * The URL of the image sprite for skinning the uploader's 'Browse' button.
  506.          *
  507.          * @attribute buttonSkin
  508.          * @type {String}
  509.          * @default null
  510.          * @writeOnce
  511.          * @deprecated
  512.          */
  513.                 buttonSkin : {
  514.                         value: null,
  515.                         writeOnce: 'initOnly'
  516.                 },
  517.                
  518.         /*
  519.          * The flag indicating whether the uploader is rendered
  520.          * with a transparent background.
  521.          *
  522.          * @attribute transparent
  523.          * @type {Boolean}
  524.          * @default true
  525.          * @writeOnce
  526.          * @deprecated
  527.          */
  528.                 transparent : {
  529.                         value: true,
  530.                         writeOnce: 'initOnly'
  531.                 },
  532.                
  533.         /*
  534.          * The URL of the uploader's SWF.
  535.          *
  536.          * @attribute swfURL
  537.          * @type {String}
  538.          * @default "assets/uploader.swf"
  539.          * @writeOnce
  540.          * @deprecated
  541.          */
  542.                 swfURL : {
  543.                         value : SWFURL,
  544.                         writeOnce: 'initOnly'
  545.                 }
  546.                
  547.         }
  548. }
  549. );
  550. Y.Uploader = Uploader;
  551.