o: ActiveSupport::Cache::Entry :@compressedF:@created_atf1359329222.936497:@expires_in0: @value"ûT{I" class:EFI"ProcessedAsset;FI"logical_path;FI"anjlab/uploads/uploader.js;TI" pathname;FI"V/Users/yury/Work/uploads/app/assets/javascripts/anjlab/uploads/uploader.js.coffee;TI"content_type;FI"application/javascript;FI" mtime;FI"2013-01-28T03:26:42+04:00;FI" length;FiÕQI" digest;F"%bb30cfbe51e369188393e9553b0aad2cI" source;FI"ÕQ(function() { var utils; utils = this.AnjLab.Uploads.Utils; this.AnjLab.Uploads.Uploader = (function() { function Uploader(element, options) { var _this = this; this.$element = $(element); this.options = $.extend(true, {}, $.fn.uploaderDefaults, this.$element.data(), options); this.filesInProgress = []; this.storedFileIds = []; this.autoRetries = []; this.retryTimeouts = []; this.preventRetries = []; this.paramsStore = this.createParamsStore(); this.endpointStore = this.createEndpointStore(); this.handler = this.createUploadHandler(); this.dnd = this.createDragAndDrop(); if (this.options.button) { this.button = new AnjLab.Uploads.Button(this.options.button, { multiple: this.options.multiple && utils.isXhrUploadSupported(), acceptFiles: this.options.validation.acceptFiles, onChange: function(input) { return _this.onInputChange(input); }, hoverClass: this.options.classes.buttonHover, focusClass: this.options.classes.buttonFocus }); } } Uploader.prototype.log = function(str, level) { if (this.options.debug && (!level || level === 'info')) { utils.log('[FineUploader] ' + str); } else if (level && level !== 'info') { utils.log('[FineUploader] ' + str, level); } return true; }; Uploader.prototype.setParams = function(params, fileId) { if (fileId != null) { return this.paramsStore.setParams(params, fileId); } else { return this.options.request.params = params; } }; Uploader.prototype.setEndpoint = function(endpoint, fileId) { if (fileId != null) { return this.endpointStore.setEndpoint(endpoint, fileId); } else { return this.options.request.endpoint = endpoint; } }; Uploader.prototype.getInProgress = function() { return this.filesInProgress.length; }; Uploader.prototype.createDragAndDrop = function() { var _this = this; return new AnjLab.Uploads.DragAndDrop(this.options.dropzones, { multiple: this.options.multiple, classes: { dropActive: this.options.classes.dropActive, bodyDragover: this.options.classes.bodyDragover }, callbacks: { dropProcessing: function(isProcessing, files) { if (files) { return _this.addFiles(files); } }, error: function(code, filename) { return _this.error(code, filename); }, log: function(message, level) { return _this.log(message, level); } } }); }; Uploader.prototype.uploadStoredFiles = function() { var idToUpload, _results; _results = []; while (this.storedFileIds.length) { idToUpload = this.storedFileIds.shift(); this.filesInProgress.push(idToUpload); _results.push(this.handler.upload(idToUpload)); } return _results; }; Uploader.prototype.clearStoredFiles = function() { return this.storedFileIds = []; }; Uploader.prototype.retry = function(id) { if (this.onBeforeManualRetry(id)) { this.handler.retry(id); return true; } else { return false; } }; Uploader.prototype.cancel = function(fileId) { return this.handler.cancel(fileId); }; Uploader.prototype.reset = function() { this.log("Resetting uploader..."); this.handler.reset(); this.filesInProgress = []; this.storedFileIds = []; this.autoRetries = []; this.retryTimeouts = []; this.preventRetries = []; this.button.reset(); this.paramsStore.reset(); return this.endpointStore.reset(); }; Uploader.prototype.addFiles = function(filesOrInputs) { var fileOrInput, verifiedFilesOrInputs, _i, _len; verifiedFilesOrInputs = []; if (!filesOrInputs) { return; } if (!window.FileList || !(filesOrInputs instanceof FileList)) { filesOrInputs = [].concat(filesOrInputs); } for (_i = 0, _len = filesOrInputs.length; _i < _len; _i++) { fileOrInput = filesOrInputs[_i]; if (utils.isFileOrInput(fileOrInput)) { verifiedFilesOrInputs.push(fileOrInput); } else { this.log("" + fileOrInput + " is not a File or INPUT element! Ignoring!", 'warn'); } } this.log("Processing " + verifiedFilesOrInputs.length + " files or inputs..."); return this.uploadFileList(verifiedFilesOrInputs); }; Uploader.prototype.getUuid = function(fileId) { return this.handler.getUuid(fileId); }; Uploader.prototype.getResumableFilesData = function() { return this.handler.getResumableFilesData(); }; Uploader.prototype.getSize = function(fileId) { return this.handler.getSize(fileId); }; Uploader.prototype.getFile = function(fileId) { return this.handler.getFile(fileId); }; Uploader.prototype.createParamsStore = function() { var paramsStore, self; paramsStore = {}; self = this; return { setParams: function(params, fileId) { return paramsStore[fileId] = $.extend(true, {}, params); }, getParams: function(fileId) { if ((fileId != null) && paramsStore[fileId]) { return $.extend(true, {}, paramsStore[fileId]); } else { return $.extend(true, {}, self.options.request.params); } }, remove: function(fileId) { return delete paramsStore[fileId]; }, reset: function() { return paramsStore = {}; } }; }; Uploader.prototype.createEndpointStore = function() { var endpointStore, self; endpointStore = {}; self = this; return { setEndpoint: function(endpoint, fileId) { return endpointStore[fileId] = endpoint; }, getEndpoint: function(fileId) { if ((fileId != null) && endpointStore[fileId]) { return endpointStore[fileId]; } return self.options.request.endpoint; }, remove: function(fileId) { return delete endpointStore[fileId]; }, reset: function() { return endpointStore = {}; } }; }; Uploader.prototype.preventLeaveInProgress = function() { var _this = this; return $(window).on('beforeunload', function(e) { if (!_this.filesInProgress.length) { return; } return e.returnValue = _this.options.messages.onLeave; }); }; Uploader.prototype.onSubmit = function(id, fileName) { if (this.options.autoUpload) { return this.filesInProgress.push(id); } }; Uploader.prototype.onProgress = function(id, fileName, loaded, total) { return false; }; Uploader.prototype.onComplete = function(id, fileName, result, xhr) { this.removeFromFilesInProgress(id); return this.maybeParseAndSendUploadError(id, fileName, result, xhr); }; Uploader.prototype.onCancel = function(id, fileName) { var storedFileIndex; this.removeFromFilesInProgress(id); clearTimeout(this.retryTimeouts[id]); storedFileIndex = $.inArray(id, this.storedFileIds); if (!this.options.autoUpload && storedFileIndex >= 0) { return this.storedFileIds.splice(storedFileIndex, 1); } }; Uploader.prototype.removeFromFilesInProgress = function(id) { var index; index = $.inArray(id, this.filesInProgress); if (index >= 0) { return this.filesInProgress.splice(index, 1); } }; Uploader.prototype.onUpload = function(id, fileName) { return null; }; Uploader.prototype.onInputChange = function(input) { if (utils.isXhrUploadSupported()) { this.addFiles(input.files); } else { this.addFiles(input); } return this.button.reset(); }; Uploader.prototype.onBeforeAutoRetry = function(id, fileName) { return this.log("Waiting " + this.options.retry.autoAttemptDelay + " seconds before retrying " + fileName + "..."); }; Uploader.prototype.onAutoRetry = function(id, fileName, responseJSON) { this.log("Retrying " + fileName + "..."); this.autoRetries[id]++; return this.handler.retry(id); }; Uploader.prototype.shouldAutoRetry = function(id, fileName, responseJSON) { if (!this.preventRetries[id] && this.options.retry.enableAuto) { if (!(this.autoRetries[id] != null)) { this.autoRetries[id] = 0; } return this.autoRetries[id] < this.options.retry.maxAutoAttempts; } return false; }; Uploader.prototype.uploadFile = function(fileContainer) { var fileName, id; id = this.handler.add(fileContainer); fileName = this.handler.getName(id); if (this.options.callbacks.onSubmit(id, fileName) !== false) { this.onSubmit(id, fileName); if (this.options.autoUpload) { return this.handler.upload(id); } else { return this.storeFileForLater(id); } } }; Uploader.prototype.storeFileForLater = function(id) { return this.storedFileIds.push(id); }; Uploader.prototype.parseFileSize = function(file) { var size, _ref; size = null; if (!file.value) { size = (_ref = file.fileSize) != null ? _ref : file.size; } return size; }; Uploader.prototype.formatSize = function(bytes) { var i; i = -1; while (true) { bytes = bytes / 1024; i++; if (bytes <= 99) { break; } } return Math.max(bytes, 0.1).toFixed(1) + this.options.text.sizeSymbols[i]; }; Uploader.prototype.parseFileName = function(file) { var _ref; if (file.value) { return file.value.replace(/.*(\/|\\)/, ""); } else { return (_ref = file.fileName) != null ? _ref : file.name; } }; Uploader.prototype.getValidationDescriptor = function(file) { var fileDescriptor, size; fileDescriptor = { name: this.parseFileName(file) }; size = this.parseFileSize(file); if (size) { fileDescriptor.size = size; } return fileDescriptor; }; Uploader.prototype.getValidationDescriptors = function(files) { var file, _i, _len, _results; _results = []; for (_i = 0, _len = files.length; _i < _len; _i++) { file = files[_i]; _results.push(this.getValidationDescriptor(file)); } return _results; }; Uploader.prototype.isAllowedExtension = function(fileName) { var allowed, allowedExt, extRegex, _i, _len; allowed = this.options.validation.allowedExtensions; if (!allowed.length) { return true; } for (_i = 0, _len = allowed.length; _i < _len; _i++) { allowedExt = allowed[_i]; extRegex = new RegExp('\\.' + allowedExt + "$", 'i'); if (fileName.match(extRegex) != null) { return true; } } return false; }; Uploader.prototype.validateFile = function(file) { var name, size, validationDescriptor; validationDescriptor = this.getValidationDescriptor(file); name = validationDescriptor.name; size = validationDescriptor.size; if (this.options.callbacks.onValidate(validationDescriptor) === false) { return false; } if (!this.isAllowedExtension(name)) { this.error('typeError', name); return false; } else if (size === 0) { this.error('emptyError', name); return false; } else if (size && this.options.validation.sizeLimit && size > this.options.validation.sizeLimit) { this.error('sizeError', name); return false; } else if (size && size < this.options.validation.minSizeLimit) { this.error('minSizeError', name); return false; } else { return true; } }; Uploader.prototype.error = function(code, fileName) { var extensions, message, r; message = this.options.messages[code]; r = function(name, replacement) { return message = message.replace(name, replacement); }; extensions = this.options.validation.allowedExtensions.join(', ').toLowerCase(); r('{file}', this.options.formatFileName(fileName)); r('{extensions}', extensions); r('{sizeLimit}', this.formatSize(this.options.validation.sizeLimit)); r('{minSizeLimit}', this.formatSize(this.options.validation.minSizeLimit)); this.options.callbacks.onError(null, fileName, message); return message; }; Uploader.prototype.onBeforeManualRetry = function(id) { var fileName; if (this.preventRetries[id]) { this.log("Retries are forbidden for id " + id, 'warn'); return false; } else if (this.handler.isValid(id)) { fileName = this.handler.getName(id); if (this.options.callbacks.onManualRetry(id, fileName) === false) { return false; } this.log("Retrying upload for '" + fileName + "' (id: " + id + ")..."); this.filesInProgress.push(id); return true; } else { this.log("'" + id + "' is not a valid file ID", 'error'); return false; } }; Uploader.prototype.maybeParseAndSendUploadError = function(id, fileName, response, xhr) { var errorReason; if (!response.success) { if (xhr && xhr.status !== 200 && !response.error) { return this.options.callbacks.onError(id, fileName, "XHR returned response code " + xhr.status); } else { errorReason = response.error ? response.error : "Upload failure reason unknown"; return this.options.callbacks.onError(id, fileName, errorReason); } } }; Uploader.prototype.uploadFileList = function(files) { var batchInvalid, file, validationDescriptors, _i, _len; validationDescriptors = this.getValidationDescriptors(files); batchInvalid = this.options.callbacks.onValidateBatch(validationDescriptors) === false; if (!batchInvalid) { if (files.length > 0) { for (_i = 0, _len = files.length; _i < _len; _i++) { file = files[_i]; if (this.validateFile(file)) { this.uploadFile(file); } else { if (this.options.validation.stopOnFirstInvalidFile) { return; } } } } else { return this.error('noFilesError', ""); } } }; Uploader.prototype.createUploadHandler = function() { var _this = this; return AnjLab.Uploads.UploadHandler.create({ debug: this.options.debug, forceMultipart: this.options.request.forceMultipart, maxConnections: this.options.maxConnections, customHeaders: this.options.request.customHeaders, inputName: this.options.request.inputName, uuidParamName: this.options.request.uuidName, totalFileSizeParamName: this.options.request.totalFileSizeName, demoMode: this.options.demoMode, paramsStore: this.paramsStore, endpointStore: this.endpointStore, chunking: this.options.chunking, resume: this.options.resume, log: function(str, level) { return _this.log(str, level); }, onProgress: function(id, fileName, loaded, total) { _this.onProgress(id, fileName, loaded, total); return _this.options.callbacks.onProgress(id, fileName, loaded, total); }, onComplete: function(id, fileName, result, xhr) { _this.onComplete(id, fileName, result, xhr); return _this.options.callbacks.onComplete(id, fileName, result); }, onCancel: function(id, fileName) { _this.onCancel(id, fileName); return _this.options.callbacks.onCancel(id, fileName); }, onUpload: function(id, fileName) { _this.onUpload(id, fileName); return _this.options.callbacks.onUpload(id, fileName); }, onUploadChunk: function(id, fileName, chunkData) { return _this.options.callbacks.onUploadChunk(id, fileName, chunkData); }, onResume: function(id, fileName, chunkData) { return _this.options.callbacks.onResume(id, fileName, chunkData); }, onAutoRetry: function(id, fileName, responseJSON, xhr) { _this.preventRetries[id] = responseJSON[_this.options.retry.preventRetryResponseProperty]; if (_this.shouldAutoRetry(id, fileName, responseJSON)) { _this.maybeParseAndSendUploadError(id, fileName, responseJSON, xhr); _this.options.callbacks.onAutoRetry(id, fileName, self._autoRetries[id] + 1); _this.onBeforeAutoRetry(id, fileName); _this.retryTimeouts[id] = setTimeout(function() { return _this.onAutoRetry(id, fileName, responseJSON); }, _this.options.retry.autoAttemptDelay * 1000); return true; } else { return false; } } }); }; return Uploader; })(); $.fn.uploaderDefaults = { debug: false, button: null, multiple: true, maxConnections: 3, disableCancelForFormUploads: false, autoUpload: true, request: { endpoint: '/uploads', params: {}, customHeaders: {}, forceMultipart: true, inputName: 'qqfile', uuidName: 'qquuid', totalFileSizeName: 'qqtotalfilesize' }, validation: { allowedExtensions: [], sizeLimit: 0, minSizeLimit: 0, stopOnFirstInvalidFile: true }, callbacks: { onSubmit: function(id, fileName) { return null; }, onComplete: function(id, fileName, responseJSON) { return null; }, onCancel: function(id, fileName) { return null; }, onUpload: function(id, fileName) { return null; }, onUploadChunk: function(id, fileName, chunkData) { return null; }, onResume: function(id, fileName, chunkData) { return null; }, onProgress: function(id, fileName, loaded, total) { return null; }, onError: function(id, fileName, reason) { return null; }, onAutoRetry: function(id, fileName, attemptNumber) { return null; }, onManualRetry: function(id, fileName) { return false; }, onValidateBatch: function(fileData) { return null; }, onValidate: function(fileData) { return null; } }, messages: { typeError: "{file} has an invalid extension. Valid extension(s): {extensions}.", sizeError: "{file} is too large, maximum file size is {sizeLimit}.", minSizeError: "{file} is too small, minimum file size is {minSizeLimit}.", emptyError: "{file} is empty, please select files again without it.", noFilesError: "No files to upload.", onLeave: "The files are being uploaded, if you leave now the upload will be cancelled." }, retry: { enableAuto: false, maxAutoAttempts: 3, autoAttemptDelay: 5, preventRetryResponseProperty: 'preventRetry' }, classes: { buttonHover: 'qq-upload-button-hover', buttonFocus: 'qq-upload-button-focus', bodyDragover: 'qq-upload-dragging' }, chunking: { enabled: false, partSize: 2000000, paramNames: { partIndex: 'qqpartindex', partByteOffset: 'qqpartbyteoffset', chunkSize: 'qqchunksize', totalFileSize: 'qqtotalfilesize', totalParts: 'qqtotalparts', filename: 'qqfilename' } }, resume: { enabled: false, id: null, cookiesExpireIn: 7, paramNames: { resuming: "qqresume" } }, text: { sizeSymbols: ['kB', 'MB', 'GB', 'TB', 'PB', 'EB'] }, formatFileName: function(fileName) { if (fileName.length > 33) { fileName = fileName.slice(0, 19) + '...' + fileName.slice(-14); } return fileName; } }; $.fn.uploader = function(option) { return this.each(function() { var $this, data, options; $this = $(this); data = $this.data('uploader'); if (!data) { options = $.extend(true, {}, typeof option === 'object' && option); $this.data('uploader', (data = new AnjLab.Uploads.Uploader(this, options))); } if (typeof option === 'string') { return data[option](); } }); }; }).call(this); ;TI"dependency_digest;F"%9f418bca7b5adae626f14716cad5dddfI"required_paths;F[I"V/Users/yury/Work/uploads/app/assets/javascripts/anjlab/uploads/uploader.js.coffee;TI"dependency_paths;F[{I" path;FI"V/Users/yury/Work/uploads/app/assets/javascripts/anjlab/uploads/uploader.js.coffee;TI" mtime;FI"2013-01-28T03:26:42+04:00;FI" digest;F"%150b280561588168afeea3504185b3c6I" _version;F"%6776f581a4329e299531e1d52aa59832