Вход Регистрация
Файл: themes/classic/js/jQuery-File-Upload/js/jquery.fileupload-process.js
Строк: 168
<?php
/*
 * jQuery File Upload Processing Plugin 1.1
 * https://github.com/blueimp/jQuery-File-Upload
 *
 * Copyright 2012, Sebastian Tschan
 * https://blueimp.net
 *
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/MIT
 */

/*jslint nomen: true, unparam: true */
/*global define, window */

(function (factory) {
    
'use strict';
    if (
typeof define === 'function' && define.amd) {
        
// Register as an anonymous AMD module:
        
define([
            
'jquery',
            
'./jquery.fileupload'
        
], factory);
    } else {
        
// Browser globals:
        
factory(
            
window.jQuery
        
);
    }
}(function ($) {
    
'use strict';

    var 
originalAdd = $.blueimp.fileupload.prototype.options.add;

    
// The File Upload Processing plugin extends the fileupload widget
    // with file processing functionality:
    
$.widget('blueimp.fileupload', $.blueimp.fileupload, {

        
options: {
            
// The list of processing actions:
            
processQueue: [
                
/*
                {
                    action: 'log',
                    type: 'debug'
                }
                */
            
],
            
add: function (edata) {
                var 
$this = $(this);
                
data.process(function () {
                    return 
$this.fileupload('process'data);
                });
                
originalAdd.call(thisedata);
            }
        },

        
processActions: {
            
/*
            log: function (data, options) {
                console[options.type](
                    'Processing "' + data.files[data.index].name + '"'
                );
            }
            */
        
},

        
_processFile: function (data) {
            var 
that this,
                
dfd = $.Deferred().resolveWith(that, [data]),
                
chain dfd.promise();
            
this._trigger('process'nulldata);
            $.
each(data.processQueue, function (isettings) {
                var 
func = function (data) {
                    return 
that.processActions[settings.action].call(
                        
that,
                        
data,
                        
settings
                    
);
                };
                
chain chain.pipe(funcsettings.always && func);
            });
            
chain
                
.done(function () {
                    
that._trigger('processdone'nulldata);
                    
that._trigger('processalways'nulldata);
                })
                .
fail(function () {
                    
that._trigger('processfail'nulldata);
                    
that._trigger('processalways'nulldata);
                });
            return 
chain;
        },

        
// Replaces the settings of each processQueue item that
        // are strings starting with an "@", using the remaining
        // substring as key for the option map,
        // e.g. "@autoUpload" is replaced with options.autoUpload:
        
_transformProcessQueue: function (options) {
            var 
processQueue = [];
            $.
each(options.processQueue, function () {
                var 
settings = {};
                $.
each(this, function (keyvalue) {
                    if ($.
type(value) === 'string' &&
                            
value.charAt(0) === '@') {
                        
settings[key] = options[value.slice(1)];
                    } else {
                        
settings[key] = value;
                    }
                });
                
processQueue.push(settings);
            });
            
options.processQueue processQueue;
        },

        
// Returns the number of files currently in the processsing queue:
        
processing: function () {
            return 
this._processing;
        },

        
// Processes the files given as files property of the data parameter,
        // returns a Promise object that allows to bind callbacks:
        
process: function (data) {
            var 
that this,
                
options = $.extend({}, this.optionsdata);
            if (
options.processQueue && options.processQueue.length) {
                
this._transformProcessQueue(options);
                if (
this._processing === 0) {
                    
this._trigger('processstart');
                }
                $.
each(data.files, function (indexfile) {
                    var 
opts index ? $.extend({}, options) : options,
                        
func = function () {
                            return 
that._processFile(opts);
                        };
                    
opts.index index;
                    
that._processing += 1;
                    
that._processingQueue that._processingQueue.pipe(funcfunc)
                        .
always(function () {
                            
that._processing -= 1;
                            if (
that._processing === 0) {
                                
that._trigger('processstop');
                            }
                        });
                });
            }
            return 
this._processingQueue;
        },

        
_create: function () {
            
this._super();
            
this._processing 0;
            
this._processingQueue = $.Deferred().resolveWith(this)
                .
promise();
        }

    });

}));
?>
Онлайн: 1
Реклама