diff --git a/dist/angular-file-upload.js b/dist/angular-file-upload.js deleted file mode 100644 index 0d04a69..0000000 --- a/dist/angular-file-upload.js +++ /dev/null @@ -1,1999 +0,0 @@ -/* - angular-file-upload v2.2.0 - https://github.com/nervgh/angular-file-upload -*/ - -(function webpackUniversalModuleDefinition(root, factory) { - if(typeof exports === 'object' && typeof module === 'object') - module.exports = factory(); - else if(typeof define === 'function' && define.amd) - define([], factory); - else if(typeof exports === 'object') - exports["angular-file-upload"] = factory(); - else - root["angular-file-upload"] = factory(); -})(this, function() { -return /******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) -/******/ return installedModules[moduleId].exports; -/******/ -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ exports: {}, -/******/ id: moduleId, -/******/ loaded: false -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.loaded = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; -/******/ -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(0); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ function(module, exports, __webpack_require__) { - - "use strict"; - - var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; }; - - var CONFIG = _interopRequire(__webpack_require__(1)); - - var options = _interopRequire(__webpack_require__(2)); - - var serviceFileUploader = _interopRequire(__webpack_require__(3)); - - var serviceFileLikeObject = _interopRequire(__webpack_require__(4)); - - var serviceFileItem = _interopRequire(__webpack_require__(5)); - - var serviceFileDirective = _interopRequire(__webpack_require__(6)); - - var serviceFileSelect = _interopRequire(__webpack_require__(7)); - - var serviceFileDrop = _interopRequire(__webpack_require__(8)); - - var serviceFileOver = _interopRequire(__webpack_require__(9)); - - var directiveFileSelect = _interopRequire(__webpack_require__(10)); - - var directiveFileDrop = _interopRequire(__webpack_require__(11)); - - var directiveFileOver = _interopRequire(__webpack_require__(12)); - - angular.module(CONFIG.name, []).value("fileUploaderOptions", options).factory("FileUploader", serviceFileUploader).factory("FileLikeObject", serviceFileLikeObject).factory("FileItem", serviceFileItem).factory("FileDirective", serviceFileDirective).factory("FileSelect", serviceFileSelect).factory("FileDrop", serviceFileDrop).factory("FileOver", serviceFileOver).directive("nvFileSelect", directiveFileSelect).directive("nvFileDrop", directiveFileDrop).directive("nvFileOver", directiveFileOver).run(["FileUploader", "FileLikeObject", "FileItem", "FileDirective", "FileSelect", "FileDrop", "FileOver", function (FileUploader, FileLikeObject, FileItem, FileDirective, FileSelect, FileDrop, FileOver) { - // only for compatibility - FileUploader.FileLikeObject = FileLikeObject; - FileUploader.FileItem = FileItem; - FileUploader.FileDirective = FileDirective; - FileUploader.FileSelect = FileSelect; - FileUploader.FileDrop = FileDrop; - FileUploader.FileOver = FileOver; - }]); - -/***/ }, -/* 1 */ -/***/ function(module, exports) { - - module.exports = { - "name": "angularFileUpload" - }; - -/***/ }, -/* 2 */ -/***/ function(module, exports) { - - "use strict"; - - module.exports = { - url: "/", - alias: "file", - headers: {}, - queue: [], - progress: 0, - autoUpload: false, - removeAfterUpload: false, - method: "POST", - filters: [], - formData: [], - queueLimit: Number.MAX_VALUE, - withCredentials: false - }; - -/***/ }, -/* 3 */ -/***/ function(module, exports, __webpack_require__) { - - "use strict"; - - var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; }; - - var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - - var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; - - var CONFIG = _interopRequire(__webpack_require__(1)); - - var copy = angular.copy; - var extend = angular.extend; - var forEach = angular.forEach; - var isObject = angular.isObject; - var isNumber = angular.isNumber; - var isDefined = angular.isDefined; - var isArray = angular.isArray; - var element = angular.element; - - module.exports = function (fileUploaderOptions, $rootScope, $http, $window, FileLikeObject, FileItem) { - var File = $window.File; - var FormData = $window.FormData; - - var FileUploader = (function () { - /********************** - * PUBLIC - **********************/ - /** - * Creates an instance of FileUploader - * @param {Object} [options] - * @constructor - */ - - function FileUploader(options) { - _classCallCheck(this, FileUploader); - - var settings = copy(fileUploaderOptions); - - extend(this, settings, options, { - isUploading: false, - _nextIndex: 0, - _failFilterIndex: -1, - _directives: { select: [], drop: [], over: [] } - }); - - // add default filters - this.filters.unshift({ name: "queueLimit", fn: this._queueLimitFilter }); - this.filters.unshift({ name: "folder", fn: this._folderFilter }); - } - - _createClass(FileUploader, { - addToQueue: { - /** - * Adds items to the queue - * @param {File|HTMLInputElement|Object|FileList|Array} files - * @param {Object} [options] - * @param {Array|String} filters - */ - - value: function addToQueue(files, options, filters) { - var _this = this; - - var list = this.isArrayLikeObject(files) ? files : [files]; - var arrayOfFilters = this._getFilters(filters); - var count = this.queue.length; - var addedFileItems = []; - - forEach(list, function (some /*{File|HTMLInputElement|Object}*/) { - var temp = new FileLikeObject(some); - - if (_this._isValidFile(temp, arrayOfFilters, options)) { - var fileItem = new FileItem(_this, some, options); - addedFileItems.push(fileItem); - _this.queue.push(fileItem); - _this._onAfterAddingFile(fileItem); - } else { - var filter = arrayOfFilters[_this._failFilterIndex]; - _this._onWhenAddingFileFailed(temp, filter, options); - } - }); - - if (this.queue.length !== count) { - this._onAfterAddingAll(addedFileItems); - this.progress = this._getTotalProgress(); - } - - this._render(); - if (this.autoUpload) this.uploadAll(); - } - }, - removeFromQueue: { - /** - * Remove items from the queue. Remove last: index = -1 - * @param {FileItem|Number} value - */ - - value: function removeFromQueue(value) { - var index = this.getIndexOfItem(value); - var item = this.queue[index]; - if (item.isUploading) item.cancel(); - this.queue.splice(index, 1); - item._destroy(); - this.progress = this._getTotalProgress(); - } - }, - clearQueue: { - /** - * Clears the queue - */ - - value: function clearQueue() { - while (this.queue.length) { - this.queue[0].remove(); - } - this.progress = 0; - } - }, - uploadItem: { - /** - * Uploads a item from the queue - * @param {FileItem|Number} value - */ - - value: function uploadItem(value) { - var index = this.getIndexOfItem(value); - var item = this.queue[index]; - var transport = this.isHTML5 ? "_xhrTransport" : "_iframeTransport"; - - item._prepareToUploading(); - if (this.isUploading) { - return; - }this.isUploading = true; - this[transport](item); - } - }, - cancelItem: { - /** - * Cancels uploading of item from the queue - * @param {FileItem|Number} value - */ - - value: function cancelItem(value) { - var index = this.getIndexOfItem(value); - var item = this.queue[index]; - var prop = this.isHTML5 ? "_xhr" : "_form"; - if (item && item.isUploading) item[prop].abort(); - } - }, - uploadAll: { - /** - * Uploads all not uploaded items of queue - */ - - value: function uploadAll() { - var items = this.getNotUploadedItems().filter(function (item) { - return !item.isUploading; - }); - if (!items.length) { - return; - }forEach(items, function (item) { - return item._prepareToUploading(); - }); - items[0].upload(); - } - }, - cancelAll: { - /** - * Cancels all uploads - */ - - value: function cancelAll() { - var items = this.getNotUploadedItems(); - forEach(items, function (item) { - return item.cancel(); - }); - } - }, - isFile: { - /** - * Returns "true" if value an instance of File - * @param {*} value - * @returns {Boolean} - * @private - */ - - value: function isFile(value) { - return this.constructor.isFile(value); - } - }, - isFileLikeObject: { - /** - * Returns "true" if value an instance of FileLikeObject - * @param {*} value - * @returns {Boolean} - * @private - */ - - value: function isFileLikeObject(value) { - return this.constructor.isFileLikeObject(value); - } - }, - isArrayLikeObject: { - /** - * Returns "true" if value is array like object - * @param {*} value - * @returns {Boolean} - */ - - value: function isArrayLikeObject(value) { - return this.constructor.isArrayLikeObject(value); - } - }, - getIndexOfItem: { - /** - * Returns a index of item from the queue - * @param {Item|Number} value - * @returns {Number} - */ - - value: function getIndexOfItem(value) { - return isNumber(value) ? value : this.queue.indexOf(value); - } - }, - getNotUploadedItems: { - /** - * Returns not uploaded items - * @returns {Array} - */ - - value: function getNotUploadedItems() { - return this.queue.filter(function (item) { - return !item.isUploaded; - }); - } - }, - getReadyItems: { - /** - * Returns items ready for upload - * @returns {Array} - */ - - value: function getReadyItems() { - return this.queue.filter(function (item) { - return item.isReady && !item.isUploading; - }).sort(function (item1, item2) { - return item1.index - item2.index; - }); - } - }, - destroy: { - /** - * Destroys instance of FileUploader - */ - - value: function destroy() { - var _this = this; - - forEach(this._directives, function (key) { - forEach(_this._directives[key], function (object) { - object.destroy(); - }); - }); - } - }, - onAfterAddingAll: { - /** - * Callback - * @param {Array} fileItems - */ - - value: function onAfterAddingAll(fileItems) {} - }, - onAfterAddingFile: { - /** - * Callback - * @param {FileItem} fileItem - */ - - value: function onAfterAddingFile(fileItem) {} - }, - onWhenAddingFileFailed: { - /** - * Callback - * @param {File|Object} item - * @param {Object} filter - * @param {Object} options - */ - - value: function onWhenAddingFileFailed(item, filter, options) {} - }, - onBeforeUploadItem: { - /** - * Callback - * @param {FileItem} fileItem - */ - - value: function onBeforeUploadItem(fileItem) {} - }, - onProgressItem: { - /** - * Callback - * @param {FileItem} fileItem - * @param {Number} progress - */ - - value: function onProgressItem(fileItem, progress) {} - }, - onProgressAll: { - /** - * Callback - * @param {Number} progress - */ - - value: function onProgressAll(progress) {} - }, - onSuccessItem: { - /** - * Callback - * @param {FileItem} item - * @param {*} response - * @param {Number} status - * @param {Object} headers - */ - - value: function onSuccessItem(item, response, status, headers) {} - }, - onErrorItem: { - /** - * Callback - * @param {FileItem} item - * @param {*} response - * @param {Number} status - * @param {Object} headers - */ - - value: function onErrorItem(item, response, status, headers) {} - }, - onCancelItem: { - /** - * Callback - * @param {FileItem} item - * @param {*} response - * @param {Number} status - * @param {Object} headers - */ - - value: function onCancelItem(item, response, status, headers) {} - }, - onCompleteItem: { - /** - * Callback - * @param {FileItem} item - * @param {*} response - * @param {Number} status - * @param {Object} headers - */ - - value: function onCompleteItem(item, response, status, headers) {} - }, - onCompleteAll: { - /** - * Callback - */ - - value: function onCompleteAll() {} - }, - _getTotalProgress: { - /********************** - * PRIVATE - **********************/ - /** - * Returns the total progress - * @param {Number} [value] - * @returns {Number} - * @private - */ - - value: function _getTotalProgress(value) { - if (this.removeAfterUpload) { - return value || 0; - }var notUploaded = this.getNotUploadedItems().length; - var uploaded = notUploaded ? this.queue.length - notUploaded : this.queue.length; - var ratio = 100 / this.queue.length; - var current = (value || 0) * ratio / 100; - - return Math.round(uploaded * ratio + current); - } - }, - _getFilters: { - /** - * Returns array of filters - * @param {Array|String} filters - * @returns {Array} - * @private - */ - - value: function _getFilters(filters) { - if (!filters) { - return this.filters; - }if (isArray(filters)) { - return filters; - }var names = filters.match(/[^\s,]+/g); - return this.filters.filter(function (filter) { - return names.indexOf(filter.name) !== -1; - }); - } - }, - _render: { - /** - * Updates html - * @private - */ - - value: function _render() { - if (!$rootScope.$$phase) $rootScope.$apply(); - } - }, - _folderFilter: { - /** - * Returns "true" if item is a file (not folder) - * @param {File|FileLikeObject} item - * @returns {Boolean} - * @private - */ - - value: function _folderFilter(item) { - return !!(item.size || item.type); - } - }, - _queueLimitFilter: { - /** - * Returns "true" if the limit has not been reached - * @returns {Boolean} - * @private - */ - - value: function _queueLimitFilter() { - return this.queue.length < this.queueLimit; - } - }, - _isValidFile: { - /** - * Returns "true" if file pass all filters - * @param {File|Object} file - * @param {Array} filters - * @param {Object} options - * @returns {Boolean} - * @private - */ - - value: function _isValidFile(file, filters, options) { - var _this = this; - - this._failFilterIndex = -1; - return !filters.length ? true : filters.every(function (filter) { - _this._failFilterIndex++; - return filter.fn.call(_this, file, options); - }); - } - }, - _isSuccessCode: { - /** - * Checks whether upload successful - * @param {Number} status - * @returns {Boolean} - * @private - */ - - value: function _isSuccessCode(status) { - return status >= 200 && status < 300 || status === 304; - } - }, - _transformResponse: { - /** - * Transforms the server response - * @param {*} response - * @param {Object} headers - * @returns {*} - * @private - */ - - value: function _transformResponse(response, headers) { - var headersGetter = this._headersGetter(headers); - forEach($http.defaults.transformResponse, function (transformFn) { - response = transformFn(response, headersGetter); - }); - return response; - } - }, - _parseHeaders: { - /** - * Parsed response headers - * @param headers - * @returns {Object} - * @see https://github.com/angular/angular.js/blob/master/src/ng/http.js - * @private - */ - - value: function _parseHeaders(headers) { - var parsed = {}, - key, - val, - i; - - if (!headers) { - return parsed; - }forEach(headers.split("\n"), function (line) { - i = line.indexOf(":"); - key = line.slice(0, i).trim().toLowerCase(); - val = line.slice(i + 1).trim(); - - if (key) { - parsed[key] = parsed[key] ? parsed[key] + ", " + val : val; - } - }); - - return parsed; - } - }, - _headersGetter: { - /** - * Returns function that returns headers - * @param {Object} parsedHeaders - * @returns {Function} - * @private - */ - - value: function _headersGetter(parsedHeaders) { - return function (name) { - if (name) { - return parsedHeaders[name.toLowerCase()] || null; - } - return parsedHeaders; - }; - } - }, - _xhrTransport: { - /** - * The XMLHttpRequest transport - * @param {FileItem} item - * @private - */ - - value: function _xhrTransport(item) { - var _this = this; - - var xhr = item._xhr = new XMLHttpRequest(); - var form = new FormData(); - - this._onBeforeUploadItem(item); - - forEach(item.formData, function (obj) { - forEach(obj, function (value, key) { - form.append(key, value); - }); - }); - - if (typeof item._file.size != "number") { - throw new TypeError("The file specified is no longer valid"); - } - - form.append(item.alias, item._file, item.file.name); - - xhr.upload.onprogress = function (event) { - var progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0); - _this._onProgressItem(item, progress); - }; - - xhr.onload = function () { - var headers = _this._parseHeaders(xhr.getAllResponseHeaders()); - var response = _this._transformResponse(xhr.response, headers); - var gist = _this._isSuccessCode(xhr.status) ? "Success" : "Error"; - var method = "_on" + gist + "Item"; - _this[method](item, response, xhr.status, headers); - _this._onCompleteItem(item, response, xhr.status, headers); - }; - - xhr.onerror = function () { - var headers = _this._parseHeaders(xhr.getAllResponseHeaders()); - var response = _this._transformResponse(xhr.response, headers); - _this._onErrorItem(item, response, xhr.status, headers); - _this._onCompleteItem(item, response, xhr.status, headers); - }; - - xhr.onabort = function () { - var headers = _this._parseHeaders(xhr.getAllResponseHeaders()); - var response = _this._transformResponse(xhr.response, headers); - _this._onCancelItem(item, response, xhr.status, headers); - _this._onCompleteItem(item, response, xhr.status, headers); - }; - - xhr.open(item.method, item.url, true); - - xhr.withCredentials = item.withCredentials; - - forEach(item.headers, function (value, name) { - xhr.setRequestHeader(name, value); - }); - - xhr.send(form); - this._render(); - } - }, - _iframeTransport: { - /** - * The IFrame transport - * @param {FileItem} item - * @private - */ - - value: function _iframeTransport(item) { - var _this = this; - - var form = element("
"); - var iframe = element("