Make WordPress Core

Ticket #6979: swfupload.2.diff

File swfupload.2.diff, 4.0 KB (added by filosofo, 16 years ago)
  • wp-includes/js/swfupload/plugins/swfupload.queue.js

     
    22        Queue Plug-in
    33       
    44        Features:
    5                 cancelQueue method for cancelling the entire queue.
    6                 All queued files are uploaded when startUpload() is called.
    7                 If false is returned from uploadComplete then the queue upload is stopped.  If false is not returned (strict comparison) then the queue upload is continued.
     5                *Adds a cancelQueue() method for cancelling the entire queue.
     6                *All queued files are uploaded when startUpload() is called.
     7                *If false is returned from uploadComplete then the queue upload is stopped.
     8                 If false is not returned (strict comparison) then the queue upload is continued.
     9                *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
     10                 Set the event handler with the queue_complete_handler setting.
    811               
    912        */
    1013
     
    1215if (typeof(SWFUpload) === "function") {
    1316        SWFUpload.queue = {};
    1417       
    15         SWFUpload.prototype.initSettings = function (old_initSettings) {
    16                 return function (init_settings) {
    17                         if (typeof(old_initSettings) === "function") {
    18                                 old_initSettings.call(this, init_settings);
     18        SWFUpload.prototype.initSettings = (function (oldInitSettings) {
     19                return function () {
     20                        if (typeof(oldInitSettings) === "function") {
     21                                oldInitSettings.call(this);
    1922                        }
    2023                       
    2124                        this.customSettings.queue_cancelled_flag = false;
     25                        this.customSettings.queue_upload_count = 0;
    2226                       
    23                         this.addSetting("user_upload_complete_handler", init_settings.upload_complete_handler, SWFUpload.uploadComplete);
    24                         this.uploadComplete_handler = SWFUpload.queue.uploadComplete;
     27                        this.settings.user_upload_complete_handler = this.settings.upload_complete_handler;
     28                        this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
     29                       
     30                        this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
    2531                };
    26         }(SWFUpload.prototype.initSettings);
     32        })(SWFUpload.prototype.initSettings);
    2733
    28         SWFUpload.prototype.cancelQueue = function () {
    29                 var stats = this.getStats();
     34        SWFUpload.prototype.startUpload = function (fileID) {
    3035                this.customSettings.queue_cancelled_flag = false;
     36                this.callFlash("StartUpload", false, [fileID]);
     37        };
    3138
    32                 if (stats.in_progress > 0) {
    33                         this.customSettings.queue_cancelled_flag = true;
    34                 }
     39        SWFUpload.prototype.cancelQueue = function () {
     40                this.customSettings.queue_cancelled_flag = true;
     41                this.stopUpload();
    3542               
    36                 while(stats.files_queued > 0) {
     43                var stats = this.getStats();
     44                while (stats.files_queued > 0) {
    3745                        this.cancelUpload();
    3846                        stats = this.getStats();
    3947                }
    4048        };
    4149       
    42         SWFUpload.queue.uploadComplete = function (file) {
    43                 var user_upload_complete_handler = this.getSetting("user_upload_complete_handler");
    44                 var continue_upload = true;
     50        SWFUpload.queue.uploadCompleteHandler = function (file) {
     51                var user_upload_complete_handler = this.settings.user_upload_complete_handler;
     52                var continueUpload;
     53               
     54                if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
     55                        this.customSettings.queue_upload_count++;
     56                }
     57
    4558                if (typeof(user_upload_complete_handler) === "function") {
    46                         continue_upload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
     59                        continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
     60                } else {
     61                        continueUpload = true;
    4762                }
    4863               
    49                 if (continue_upload) {
     64                if (continueUpload) {
    5065                        var stats = this.getStats();
    5166                        if (stats.files_queued > 0 && this.customSettings.queue_cancelled_flag === false) {
    5267                                this.startUpload();
     68                        } else if (this.customSettings.queue_cancelled_flag === false) {
     69                                this.queueEvent("queue_complete_handler", [this.customSettings.queue_upload_count]);
     70                                this.customSettings.queue_upload_count = 0;
    5371                        } else {
    5472                                this.customSettings.queue_cancelled_flag = false;
     73                                this.customSettings.queue_upload_count = 0;
    5574                        }
    5675                }
    5776        };