044e426d22
angular-file-upload (angularFileUpload) and angular-messages (ngMessages).
1999 lines
72 KiB
JavaScript
1999 lines
72 KiB
JavaScript
/*
|
|
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<Object>} files
|
|
* @param {Object} [options]
|
|
* @param {Array<Function>|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<Function>|String} filters
|
|
* @returns {Array<Function>}
|
|
* @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<Function>} 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("<form style=\"display: none;\" />");
|
|
var iframe = element("<iframe name=\"iframeTransport" + Date.now() + "\">");
|
|
var input = item._input;
|
|
|
|
if (item._form) item._form.replaceWith(input); // remove old form
|
|
item._form = form; // save link to new form
|
|
|
|
this._onBeforeUploadItem(item);
|
|
|
|
input.prop("name", item.alias);
|
|
|
|
forEach(item.formData, function (obj) {
|
|
forEach(obj, function (value, key) {
|
|
var element_ = element("<input type=\"hidden\" name=\"" + key + "\" />");
|
|
element_.val(value);
|
|
form.append(element_);
|
|
});
|
|
});
|
|
|
|
form.prop({
|
|
action: item.url,
|
|
method: "POST",
|
|
target: iframe.prop("name"),
|
|
enctype: "multipart/form-data",
|
|
encoding: "multipart/form-data" // old IE
|
|
});
|
|
|
|
iframe.bind("load", function () {
|
|
var html = "";
|
|
var status = 200;
|
|
|
|
try {
|
|
// Fix for legacy IE browsers that loads internal error page
|
|
// when failed WS response received. In consequence iframe
|
|
// content access denied error is thrown becouse trying to
|
|
// access cross domain page. When such thing occurs notifying
|
|
// with empty response object. See more info at:
|
|
// http://stackoverflow.com/questions/151362/access-is-denied-error-on-accessing-iframe-document-object
|
|
// Note that if non standard 4xx or 5xx error code returned
|
|
// from WS then response content can be accessed without error
|
|
// but 'XHR' status becomes 200. In order to avoid confusion
|
|
// returning response via same 'success' event handler.
|
|
|
|
// fixed angular.contents() for iframes
|
|
html = iframe[0].contentDocument.body.innerHTML;
|
|
} catch (e) {
|
|
// in case we run into the access-is-denied error or we have another error on the server side
|
|
// (intentional 500,40... errors), we at least say 'something went wrong' -> 500
|
|
status = 500;
|
|
}
|
|
|
|
var xhr = { response: html, status: status, dummy: true };
|
|
var headers = {};
|
|
var response = _this._transformResponse(xhr.response, headers);
|
|
|
|
_this._onSuccessItem(item, response, xhr.status, headers);
|
|
_this._onCompleteItem(item, response, xhr.status, headers);
|
|
});
|
|
|
|
form.abort = function () {
|
|
var xhr = { status: 0, dummy: true };
|
|
var headers = {};
|
|
var response;
|
|
|
|
iframe.unbind("load").prop("src", "javascript:false;");
|
|
form.replaceWith(input);
|
|
|
|
_this._onCancelItem(item, response, xhr.status, headers);
|
|
_this._onCompleteItem(item, response, xhr.status, headers);
|
|
};
|
|
|
|
input.after(form);
|
|
form.append(input).append(iframe);
|
|
|
|
form[0].submit();
|
|
this._render();
|
|
}
|
|
},
|
|
_onWhenAddingFileFailed: {
|
|
/**
|
|
* Inner callback
|
|
* @param {File|Object} item
|
|
* @param {Object} filter
|
|
* @param {Object} options
|
|
* @private
|
|
*/
|
|
|
|
value: function _onWhenAddingFileFailed(item, filter, options) {
|
|
this.onWhenAddingFileFailed(item, filter, options);
|
|
}
|
|
},
|
|
_onAfterAddingFile: {
|
|
/**
|
|
* Inner callback
|
|
* @param {FileItem} item
|
|
*/
|
|
|
|
value: function _onAfterAddingFile(item) {
|
|
this.onAfterAddingFile(item);
|
|
}
|
|
},
|
|
_onAfterAddingAll: {
|
|
/**
|
|
* Inner callback
|
|
* @param {Array<FileItem>} items
|
|
*/
|
|
|
|
value: function _onAfterAddingAll(items) {
|
|
this.onAfterAddingAll(items);
|
|
}
|
|
},
|
|
_onBeforeUploadItem: {
|
|
/**
|
|
* Inner callback
|
|
* @param {FileItem} item
|
|
* @private
|
|
*/
|
|
|
|
value: function _onBeforeUploadItem(item) {
|
|
item._onBeforeUpload();
|
|
this.onBeforeUploadItem(item);
|
|
}
|
|
},
|
|
_onProgressItem: {
|
|
/**
|
|
* Inner callback
|
|
* @param {FileItem} item
|
|
* @param {Number} progress
|
|
* @private
|
|
*/
|
|
|
|
value: function _onProgressItem(item, progress) {
|
|
var total = this._getTotalProgress(progress);
|
|
this.progress = total;
|
|
item._onProgress(progress);
|
|
this.onProgressItem(item, progress);
|
|
this.onProgressAll(total);
|
|
this._render();
|
|
}
|
|
},
|
|
_onSuccessItem: {
|
|
/**
|
|
* Inner callback
|
|
* @param {FileItem} item
|
|
* @param {*} response
|
|
* @param {Number} status
|
|
* @param {Object} headers
|
|
* @private
|
|
*/
|
|
|
|
value: function _onSuccessItem(item, response, status, headers) {
|
|
item._onSuccess(response, status, headers);
|
|
this.onSuccessItem(item, response, status, headers);
|
|
}
|
|
},
|
|
_onErrorItem: {
|
|
/**
|
|
* Inner callback
|
|
* @param {FileItem} item
|
|
* @param {*} response
|
|
* @param {Number} status
|
|
* @param {Object} headers
|
|
* @private
|
|
*/
|
|
|
|
value: function _onErrorItem(item, response, status, headers) {
|
|
item._onError(response, status, headers);
|
|
this.onErrorItem(item, response, status, headers);
|
|
}
|
|
},
|
|
_onCancelItem: {
|
|
/**
|
|
* Inner callback
|
|
* @param {FileItem} item
|
|
* @param {*} response
|
|
* @param {Number} status
|
|
* @param {Object} headers
|
|
* @private
|
|
*/
|
|
|
|
value: function _onCancelItem(item, response, status, headers) {
|
|
item._onCancel(response, status, headers);
|
|
this.onCancelItem(item, response, status, headers);
|
|
}
|
|
},
|
|
_onCompleteItem: {
|
|
/**
|
|
* Inner callback
|
|
* @param {FileItem} item
|
|
* @param {*} response
|
|
* @param {Number} status
|
|
* @param {Object} headers
|
|
* @private
|
|
*/
|
|
|
|
value: function _onCompleteItem(item, response, status, headers) {
|
|
item._onComplete(response, status, headers);
|
|
this.onCompleteItem(item, response, status, headers);
|
|
|
|
var nextItem = this.getReadyItems()[0];
|
|
this.isUploading = false;
|
|
|
|
if (isDefined(nextItem)) {
|
|
nextItem.upload();
|
|
return;
|
|
}
|
|
|
|
this.onCompleteAll();
|
|
this.progress = this._getTotalProgress();
|
|
this._render();
|
|
}
|
|
}
|
|
}, {
|
|
isFile: {
|
|
/**********************
|
|
* STATIC
|
|
**********************/
|
|
/**
|
|
* Returns "true" if value an instance of File
|
|
* @param {*} value
|
|
* @returns {Boolean}
|
|
* @private
|
|
*/
|
|
|
|
value: function isFile(value) {
|
|
return File && value instanceof File;
|
|
}
|
|
},
|
|
isFileLikeObject: {
|
|
/**
|
|
* Returns "true" if value an instance of FileLikeObject
|
|
* @param {*} value
|
|
* @returns {Boolean}
|
|
* @private
|
|
*/
|
|
|
|
value: function isFileLikeObject(value) {
|
|
return value instanceof FileLikeObject;
|
|
}
|
|
},
|
|
isArrayLikeObject: {
|
|
/**
|
|
* Returns "true" if value is array like object
|
|
* @param {*} value
|
|
* @returns {Boolean}
|
|
*/
|
|
|
|
value: function isArrayLikeObject(value) {
|
|
return isObject(value) && "length" in value;
|
|
}
|
|
},
|
|
inherit: {
|
|
/**
|
|
* Inherits a target (Class_1) by a source (Class_2)
|
|
* @param {Function} target
|
|
* @param {Function} source
|
|
*/
|
|
|
|
value: function inherit(target, source) {
|
|
target.prototype = Object.create(source.prototype);
|
|
target.prototype.constructor = target;
|
|
target.super_ = source;
|
|
}
|
|
}
|
|
});
|
|
|
|
return FileUploader;
|
|
})();
|
|
|
|
/**********************
|
|
* PUBLIC
|
|
**********************/
|
|
/**
|
|
* Checks a support the html5 uploader
|
|
* @returns {Boolean}
|
|
* @readonly
|
|
*/
|
|
FileUploader.prototype.isHTML5 = !!(File && FormData);
|
|
/**********************
|
|
* STATIC
|
|
**********************/
|
|
/**
|
|
* @borrows FileUploader.prototype.isHTML5
|
|
*/
|
|
FileUploader.isHTML5 = FileUploader.prototype.isHTML5;
|
|
|
|
return FileUploader;
|
|
};
|
|
|
|
module.exports.$inject = ["fileUploaderOptions", "$rootScope", "$http", "$window", "FileLikeObject", "FileItem"];
|
|
|
|
/***/ },
|
|
/* 4 */
|
|
/***/ 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 isElement = angular.isElement;
|
|
var isString = angular.isString;
|
|
|
|
module.exports = function () {
|
|
var FileLikeObject = (function () {
|
|
/**
|
|
* Creates an instance of FileLikeObject
|
|
* @param {File|HTMLInputElement|Object} fileOrInput
|
|
* @constructor
|
|
*/
|
|
|
|
function FileLikeObject(fileOrInput) {
|
|
_classCallCheck(this, FileLikeObject);
|
|
|
|
var isInput = isElement(fileOrInput);
|
|
var fakePathOrObject = isInput ? fileOrInput.value : fileOrInput;
|
|
var postfix = isString(fakePathOrObject) ? "FakePath" : "Object";
|
|
var method = "_createFrom" + postfix;
|
|
this[method](fakePathOrObject);
|
|
}
|
|
|
|
_createClass(FileLikeObject, {
|
|
_createFromFakePath: {
|
|
/**
|
|
* Creates file like object from fake path string
|
|
* @param {String} path
|
|
* @private
|
|
*/
|
|
|
|
value: function _createFromFakePath(path) {
|
|
this.lastModifiedDate = null;
|
|
this.size = null;
|
|
this.type = "like/" + path.slice(path.lastIndexOf(".") + 1).toLowerCase();
|
|
this.name = path.slice(path.lastIndexOf("/") + path.lastIndexOf("\\") + 2);
|
|
}
|
|
},
|
|
_createFromObject: {
|
|
/**
|
|
* Creates file like object from object
|
|
* @param {File|FileLikeObject} object
|
|
* @private
|
|
*/
|
|
|
|
value: function _createFromObject(object) {
|
|
this.lastModifiedDate = copy(object.lastModifiedDate);
|
|
this.size = object.size;
|
|
this.type = object.type;
|
|
this.name = object.name;
|
|
}
|
|
}
|
|
});
|
|
|
|
return FileLikeObject;
|
|
})();
|
|
|
|
return FileLikeObject;
|
|
};
|
|
|
|
module.exports.$inject = [];
|
|
|
|
/***/ },
|
|
/* 5 */
|
|
/***/ 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 element = angular.element;
|
|
var isElement = angular.isElement;
|
|
|
|
module.exports = function ($compile, FileLikeObject) {
|
|
var FileItem = (function () {
|
|
/**
|
|
* Creates an instance of FileItem
|
|
* @param {FileUploader} uploader
|
|
* @param {File|HTMLInputElement|Object} some
|
|
* @param {Object} options
|
|
* @constructor
|
|
*/
|
|
|
|
function FileItem(uploader, some, options) {
|
|
_classCallCheck(this, FileItem);
|
|
|
|
var isInput = isElement(some);
|
|
var input = isInput ? element(some) : null;
|
|
var file = !isInput ? some : null;
|
|
|
|
extend(this, {
|
|
url: uploader.url,
|
|
alias: uploader.alias,
|
|
headers: copy(uploader.headers),
|
|
formData: copy(uploader.formData),
|
|
removeAfterUpload: uploader.removeAfterUpload,
|
|
withCredentials: uploader.withCredentials,
|
|
method: uploader.method
|
|
}, options, {
|
|
uploader: uploader,
|
|
file: new FileLikeObject(some),
|
|
isReady: false,
|
|
isUploading: false,
|
|
isUploaded: false,
|
|
isSuccess: false,
|
|
isCancel: false,
|
|
isError: false,
|
|
progress: 0,
|
|
index: null,
|
|
_file: file,
|
|
_input: input
|
|
});
|
|
|
|
if (input) this._replaceNode(input);
|
|
}
|
|
|
|
_createClass(FileItem, {
|
|
upload: {
|
|
/**********************
|
|
* PUBLIC
|
|
**********************/
|
|
/**
|
|
* Uploads a FileItem
|
|
*/
|
|
|
|
value: function upload() {
|
|
try {
|
|
this.uploader.uploadItem(this);
|
|
} catch (e) {
|
|
this.uploader._onCompleteItem(this, "", 0, []);
|
|
this.uploader._onErrorItem(this, "", 0, []);
|
|
}
|
|
}
|
|
},
|
|
cancel: {
|
|
/**
|
|
* Cancels uploading of FileItem
|
|
*/
|
|
|
|
value: function cancel() {
|
|
this.uploader.cancelItem(this);
|
|
}
|
|
},
|
|
remove: {
|
|
/**
|
|
* Removes a FileItem
|
|
*/
|
|
|
|
value: function remove() {
|
|
this.uploader.removeFromQueue(this);
|
|
}
|
|
},
|
|
onBeforeUpload: {
|
|
/**
|
|
* Callback
|
|
* @private
|
|
*/
|
|
|
|
value: function onBeforeUpload() {}
|
|
},
|
|
onProgress: {
|
|
/**
|
|
* Callback
|
|
* @param {Number} progress
|
|
* @private
|
|
*/
|
|
|
|
value: function onProgress(progress) {}
|
|
},
|
|
onSuccess: {
|
|
/**
|
|
* Callback
|
|
* @param {*} response
|
|
* @param {Number} status
|
|
* @param {Object} headers
|
|
*/
|
|
|
|
value: function onSuccess(response, status, headers) {}
|
|
},
|
|
onError: {
|
|
/**
|
|
* Callback
|
|
* @param {*} response
|
|
* @param {Number} status
|
|
* @param {Object} headers
|
|
*/
|
|
|
|
value: function onError(response, status, headers) {}
|
|
},
|
|
onCancel: {
|
|
/**
|
|
* Callback
|
|
* @param {*} response
|
|
* @param {Number} status
|
|
* @param {Object} headers
|
|
*/
|
|
|
|
value: function onCancel(response, status, headers) {}
|
|
},
|
|
onComplete: {
|
|
/**
|
|
* Callback
|
|
* @param {*} response
|
|
* @param {Number} status
|
|
* @param {Object} headers
|
|
*/
|
|
|
|
value: function onComplete(response, status, headers) {}
|
|
},
|
|
_onBeforeUpload: {
|
|
/**********************
|
|
* PRIVATE
|
|
**********************/
|
|
/**
|
|
* Inner callback
|
|
*/
|
|
|
|
value: function _onBeforeUpload() {
|
|
this.isReady = true;
|
|
this.isUploading = true;
|
|
this.isUploaded = false;
|
|
this.isSuccess = false;
|
|
this.isCancel = false;
|
|
this.isError = false;
|
|
this.progress = 0;
|
|
this.onBeforeUpload();
|
|
}
|
|
},
|
|
_onProgress: {
|
|
/**
|
|
* Inner callback
|
|
* @param {Number} progress
|
|
* @private
|
|
*/
|
|
|
|
value: function _onProgress(progress) {
|
|
this.progress = progress;
|
|
this.onProgress(progress);
|
|
}
|
|
},
|
|
_onSuccess: {
|
|
/**
|
|
* Inner callback
|
|
* @param {*} response
|
|
* @param {Number} status
|
|
* @param {Object} headers
|
|
* @private
|
|
*/
|
|
|
|
value: function _onSuccess(response, status, headers) {
|
|
this.isReady = false;
|
|
this.isUploading = false;
|
|
this.isUploaded = true;
|
|
this.isSuccess = true;
|
|
this.isCancel = false;
|
|
this.isError = false;
|
|
this.progress = 100;
|
|
this.index = null;
|
|
this.onSuccess(response, status, headers);
|
|
}
|
|
},
|
|
_onError: {
|
|
/**
|
|
* Inner callback
|
|
* @param {*} response
|
|
* @param {Number} status
|
|
* @param {Object} headers
|
|
* @private
|
|
*/
|
|
|
|
value: function _onError(response, status, headers) {
|
|
this.isReady = false;
|
|
this.isUploading = false;
|
|
this.isUploaded = true;
|
|
this.isSuccess = false;
|
|
this.isCancel = false;
|
|
this.isError = true;
|
|
this.progress = 0;
|
|
this.index = null;
|
|
this.onError(response, status, headers);
|
|
}
|
|
},
|
|
_onCancel: {
|
|
/**
|
|
* Inner callback
|
|
* @param {*} response
|
|
* @param {Number} status
|
|
* @param {Object} headers
|
|
* @private
|
|
*/
|
|
|
|
value: function _onCancel(response, status, headers) {
|
|
this.isReady = false;
|
|
this.isUploading = false;
|
|
this.isUploaded = false;
|
|
this.isSuccess = false;
|
|
this.isCancel = true;
|
|
this.isError = false;
|
|
this.progress = 0;
|
|
this.index = null;
|
|
this.onCancel(response, status, headers);
|
|
}
|
|
},
|
|
_onComplete: {
|
|
/**
|
|
* Inner callback
|
|
* @param {*} response
|
|
* @param {Number} status
|
|
* @param {Object} headers
|
|
* @private
|
|
*/
|
|
|
|
value: function _onComplete(response, status, headers) {
|
|
this.onComplete(response, status, headers);
|
|
if (this.removeAfterUpload) this.remove();
|
|
}
|
|
},
|
|
_destroy: {
|
|
/**
|
|
* Destroys a FileItem
|
|
*/
|
|
|
|
value: function _destroy() {
|
|
if (this._input) this._input.remove();
|
|
if (this._form) this._form.remove();
|
|
delete this._form;
|
|
delete this._input;
|
|
}
|
|
},
|
|
_prepareToUploading: {
|
|
/**
|
|
* Prepares to uploading
|
|
* @private
|
|
*/
|
|
|
|
value: function _prepareToUploading() {
|
|
this.index = this.index || ++this.uploader._nextIndex;
|
|
this.isReady = true;
|
|
}
|
|
},
|
|
_replaceNode: {
|
|
/**
|
|
* Replaces input element on his clone
|
|
* @param {JQLite|jQuery} input
|
|
* @private
|
|
*/
|
|
|
|
value: function _replaceNode(input) {
|
|
var clone = $compile(input.clone())(input.scope());
|
|
clone.prop("value", null); // FF fix
|
|
input.css("display", "none");
|
|
input.after(clone); // remove jquery dependency
|
|
}
|
|
}
|
|
});
|
|
|
|
return FileItem;
|
|
})();
|
|
|
|
return FileItem;
|
|
};
|
|
|
|
module.exports.$inject = ["$compile", "FileLikeObject"];
|
|
|
|
/***/ },
|
|
/* 6 */
|
|
/***/ 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 extend = angular.extend;
|
|
|
|
module.exports = function () {
|
|
var FileDirective = (function () {
|
|
/**
|
|
* Creates instance of {FileDirective} object
|
|
* @param {Object} options
|
|
* @param {Object} options.uploader
|
|
* @param {HTMLElement} options.element
|
|
* @param {Object} options.events
|
|
* @param {String} options.prop
|
|
* @constructor
|
|
*/
|
|
|
|
function FileDirective(options) {
|
|
_classCallCheck(this, FileDirective);
|
|
|
|
extend(this, options);
|
|
this.uploader._directives[this.prop].push(this);
|
|
this._saveLinks();
|
|
this.bind();
|
|
}
|
|
|
|
_createClass(FileDirective, {
|
|
bind: {
|
|
/**
|
|
* Binds events handles
|
|
*/
|
|
|
|
value: function bind() {
|
|
for (var key in this.events) {
|
|
var prop = this.events[key];
|
|
this.element.bind(key, this[prop]);
|
|
}
|
|
}
|
|
},
|
|
unbind: {
|
|
/**
|
|
* Unbinds events handles
|
|
*/
|
|
|
|
value: function unbind() {
|
|
for (var key in this.events) {
|
|
this.element.unbind(key, this.events[key]);
|
|
}
|
|
}
|
|
},
|
|
destroy: {
|
|
/**
|
|
* Destroys directive
|
|
*/
|
|
|
|
value: function destroy() {
|
|
var index = this.uploader._directives[this.prop].indexOf(this);
|
|
this.uploader._directives[this.prop].splice(index, 1);
|
|
this.unbind();
|
|
// this.element = null;
|
|
}
|
|
},
|
|
_saveLinks: {
|
|
/**
|
|
* Saves links to functions
|
|
* @private
|
|
*/
|
|
|
|
value: function _saveLinks() {
|
|
for (var key in this.events) {
|
|
var prop = this.events[key];
|
|
this[prop] = this[prop].bind(this);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
return FileDirective;
|
|
})();
|
|
|
|
/**
|
|
* Map of events
|
|
* @type {Object}
|
|
*/
|
|
FileDirective.prototype.events = {};
|
|
|
|
return FileDirective;
|
|
};
|
|
|
|
module.exports.$inject = [];
|
|
|
|
/***/ },
|
|
/* 7 */
|
|
/***/ 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 _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc && desc.writable) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
|
|
|
|
var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };
|
|
|
|
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 extend = angular.extend;
|
|
|
|
module.exports = function (FileDirective) {
|
|
var FileSelect = (function (_FileDirective) {
|
|
/**
|
|
* Creates instance of {FileSelect} object
|
|
* @param {Object} options
|
|
* @constructor
|
|
*/
|
|
|
|
function FileSelect(options) {
|
|
_classCallCheck(this, FileSelect);
|
|
|
|
var extendedOptions = extend(options, {
|
|
// Map of events
|
|
events: {
|
|
$destroy: "destroy",
|
|
change: "onChange"
|
|
},
|
|
// Name of property inside uploader._directive object
|
|
prop: "select"
|
|
});
|
|
|
|
_get(Object.getPrototypeOf(FileSelect.prototype), "constructor", this).call(this, extendedOptions);
|
|
|
|
if (!this.uploader.isHTML5) {
|
|
this.element.removeAttr("multiple");
|
|
}
|
|
this.element.prop("value", null); // FF fix
|
|
}
|
|
|
|
_inherits(FileSelect, _FileDirective);
|
|
|
|
_createClass(FileSelect, {
|
|
getOptions: {
|
|
/**
|
|
* Returns options
|
|
* @return {Object|undefined}
|
|
*/
|
|
|
|
value: function getOptions() {}
|
|
},
|
|
getFilters: {
|
|
/**
|
|
* Returns filters
|
|
* @return {Array<Function>|String|undefined}
|
|
*/
|
|
|
|
value: function getFilters() {}
|
|
},
|
|
isEmptyAfterSelection: {
|
|
/**
|
|
* If returns "true" then HTMLInputElement will be cleared
|
|
* @returns {Boolean}
|
|
*/
|
|
|
|
value: function isEmptyAfterSelection() {
|
|
return !!this.element.attr("multiple");
|
|
}
|
|
},
|
|
onChange: {
|
|
/**
|
|
* Event handler
|
|
*/
|
|
|
|
value: function onChange() {
|
|
var files = this.uploader.isHTML5 ? this.element[0].files : this.element[0];
|
|
var options = this.getOptions();
|
|
var filters = this.getFilters();
|
|
|
|
if (!this.uploader.isHTML5) this.destroy();
|
|
this.uploader.addToQueue(files, options, filters);
|
|
if (this.isEmptyAfterSelection()) {
|
|
this.element.prop("value", null);
|
|
this.element.replaceWith(this.element = this.element.clone(true)); // IE fix
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
return FileSelect;
|
|
})(FileDirective);
|
|
|
|
return FileSelect;
|
|
};
|
|
|
|
module.exports.$inject = ["FileDirective"];
|
|
|
|
/***/ },
|
|
/* 8 */
|
|
/***/ 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 _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc && desc.writable) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
|
|
|
|
var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };
|
|
|
|
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 extend = angular.extend;
|
|
var forEach = angular.forEach;
|
|
|
|
module.exports = function (FileDirective) {
|
|
var FileDrop = (function (_FileDirective) {
|
|
/**
|
|
* Creates instance of {FileDrop} object
|
|
* @param {Object} options
|
|
* @constructor
|
|
*/
|
|
|
|
function FileDrop(options) {
|
|
_classCallCheck(this, FileDrop);
|
|
|
|
var extendedOptions = extend(options, {
|
|
// Map of events
|
|
events: {
|
|
$destroy: "destroy",
|
|
drop: "onDrop",
|
|
dragover: "onDragOver",
|
|
dragleave: "onDragLeave"
|
|
},
|
|
// Name of property inside uploader._directive object
|
|
prop: "drop"
|
|
});
|
|
|
|
_get(Object.getPrototypeOf(FileDrop.prototype), "constructor", this).call(this, extendedOptions);
|
|
}
|
|
|
|
_inherits(FileDrop, _FileDirective);
|
|
|
|
_createClass(FileDrop, {
|
|
getOptions: {
|
|
/**
|
|
* Returns options
|
|
* @return {Object|undefined}
|
|
*/
|
|
|
|
value: function getOptions() {}
|
|
},
|
|
getFilters: {
|
|
/**
|
|
* Returns filters
|
|
* @return {Array<Function>|String|undefined}
|
|
*/
|
|
|
|
value: function getFilters() {}
|
|
},
|
|
onDrop: {
|
|
/**
|
|
* Event handler
|
|
*/
|
|
|
|
value: function onDrop(event) {
|
|
var transfer = this._getTransfer(event);
|
|
if (!transfer) {
|
|
return;
|
|
}var options = this.getOptions();
|
|
var filters = this.getFilters();
|
|
this._preventAndStop(event);
|
|
forEach(this.uploader._directives.over, this._removeOverClass, this);
|
|
this.uploader.addToQueue(transfer.files, options, filters);
|
|
}
|
|
},
|
|
onDragOver: {
|
|
/**
|
|
* Event handler
|
|
*/
|
|
|
|
value: function onDragOver(event) {
|
|
var transfer = this._getTransfer(event);
|
|
if (!this._haveFiles(transfer.types)) {
|
|
return;
|
|
}transfer.dropEffect = "copy";
|
|
this._preventAndStop(event);
|
|
forEach(this.uploader._directives.over, this._addOverClass, this);
|
|
}
|
|
},
|
|
onDragLeave: {
|
|
/**
|
|
* Event handler
|
|
*/
|
|
|
|
value: function onDragLeave(event) {
|
|
if (event.currentTarget === this.element[0]) {
|
|
return;
|
|
}this._preventAndStop(event);
|
|
forEach(this.uploader._directives.over, this._removeOverClass, this);
|
|
}
|
|
},
|
|
_getTransfer: {
|
|
/**
|
|
* Helper
|
|
*/
|
|
|
|
value: function _getTransfer(event) {
|
|
return event.dataTransfer ? event.dataTransfer : event.originalEvent.dataTransfer; // jQuery fix;
|
|
}
|
|
},
|
|
_preventAndStop: {
|
|
/**
|
|
* Helper
|
|
*/
|
|
|
|
value: function _preventAndStop(event) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
}
|
|
},
|
|
_haveFiles: {
|
|
/**
|
|
* Returns "true" if types contains files
|
|
* @param {Object} types
|
|
*/
|
|
|
|
value: function _haveFiles(types) {
|
|
if (!types) {
|
|
return false;
|
|
}if (types.indexOf) {
|
|
return types.indexOf("Files") !== -1;
|
|
} else if (types.contains) {
|
|
return types.contains("Files");
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
},
|
|
_addOverClass: {
|
|
/**
|
|
* Callback
|
|
*/
|
|
|
|
value: function _addOverClass(item) {
|
|
item.addOverClass();
|
|
}
|
|
},
|
|
_removeOverClass: {
|
|
/**
|
|
* Callback
|
|
*/
|
|
|
|
value: function _removeOverClass(item) {
|
|
item.removeOverClass();
|
|
}
|
|
}
|
|
});
|
|
|
|
return FileDrop;
|
|
})(FileDirective);
|
|
|
|
return FileDrop;
|
|
};
|
|
|
|
module.exports.$inject = ["FileDirective"];
|
|
|
|
/***/ },
|
|
/* 9 */
|
|
/***/ 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 _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc && desc.writable) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
|
|
|
|
var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };
|
|
|
|
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 extend = angular.extend;
|
|
|
|
module.exports = function (FileDirective) {
|
|
var FileOver = (function (_FileDirective) {
|
|
/**
|
|
* Creates instance of {FileDrop} object
|
|
* @param {Object} options
|
|
* @constructor
|
|
*/
|
|
|
|
function FileOver(options) {
|
|
_classCallCheck(this, FileOver);
|
|
|
|
var extendedOptions = extend(options, {
|
|
// Map of events
|
|
events: {
|
|
$destroy: "destroy"
|
|
},
|
|
// Name of property inside uploader._directive object
|
|
prop: "over",
|
|
// Over class
|
|
overClass: "nv-file-over"
|
|
});
|
|
|
|
_get(Object.getPrototypeOf(FileOver.prototype), "constructor", this).call(this, extendedOptions);
|
|
}
|
|
|
|
_inherits(FileOver, _FileDirective);
|
|
|
|
_createClass(FileOver, {
|
|
addOverClass: {
|
|
/**
|
|
* Adds over class
|
|
*/
|
|
|
|
value: function addOverClass() {
|
|
this.element.addClass(this.getOverClass());
|
|
}
|
|
},
|
|
removeOverClass: {
|
|
/**
|
|
* Removes over class
|
|
*/
|
|
|
|
value: function removeOverClass() {
|
|
this.element.removeClass(this.getOverClass());
|
|
}
|
|
},
|
|
getOverClass: {
|
|
/**
|
|
* Returns over class
|
|
* @returns {String}
|
|
*/
|
|
|
|
value: function getOverClass() {
|
|
return this.overClass;
|
|
}
|
|
}
|
|
});
|
|
|
|
return FileOver;
|
|
})(FileDirective);
|
|
|
|
return FileOver;
|
|
};
|
|
|
|
module.exports.$inject = ["FileDirective"];
|
|
|
|
/***/ },
|
|
/* 10 */
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
"use strict";
|
|
|
|
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
|
|
|
|
var CONFIG = _interopRequire(__webpack_require__(1));
|
|
|
|
module.exports = function ($parse, FileUploader, FileSelect) {
|
|
|
|
return {
|
|
link: function (scope, element, attributes) {
|
|
var uploader = scope.$eval(attributes.uploader);
|
|
|
|
if (!(uploader instanceof FileUploader)) {
|
|
throw new TypeError("\"Uploader\" must be an instance of FileUploader");
|
|
}
|
|
|
|
var object = new FileSelect({
|
|
uploader: uploader,
|
|
element: element
|
|
});
|
|
|
|
object.getOptions = $parse(attributes.options).bind(object, scope);
|
|
object.getFilters = function () {
|
|
return attributes.filters;
|
|
};
|
|
}
|
|
};
|
|
};
|
|
|
|
module.exports.$inject = ["$parse", "FileUploader", "FileSelect"];
|
|
|
|
/***/ },
|
|
/* 11 */
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
"use strict";
|
|
|
|
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
|
|
|
|
var CONFIG = _interopRequire(__webpack_require__(1));
|
|
|
|
module.exports = function ($parse, FileUploader, FileDrop) {
|
|
|
|
return {
|
|
link: function (scope, element, attributes) {
|
|
var uploader = scope.$eval(attributes.uploader);
|
|
|
|
if (!(uploader instanceof FileUploader)) {
|
|
throw new TypeError("\"Uploader\" must be an instance of FileUploader");
|
|
}
|
|
|
|
if (!uploader.isHTML5) return;
|
|
|
|
var object = new FileDrop({
|
|
uploader: uploader,
|
|
element: element
|
|
});
|
|
|
|
object.getOptions = $parse(attributes.options).bind(object, scope);
|
|
object.getFilters = function () {
|
|
return attributes.filters;
|
|
};
|
|
}
|
|
};
|
|
};
|
|
|
|
module.exports.$inject = ["$parse", "FileUploader", "FileDrop"];
|
|
|
|
/***/ },
|
|
/* 12 */
|
|
/***/ function(module, exports, __webpack_require__) {
|
|
|
|
"use strict";
|
|
|
|
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
|
|
|
|
var CONFIG = _interopRequire(__webpack_require__(1));
|
|
|
|
module.exports = function (FileUploader, FileOver) {
|
|
|
|
return {
|
|
link: function (scope, element, attributes) {
|
|
var uploader = scope.$eval(attributes.uploader);
|
|
|
|
if (!(uploader instanceof FileUploader)) {
|
|
throw new TypeError("\"Uploader\" must be an instance of FileUploader");
|
|
}
|
|
|
|
var object = new FileOver({
|
|
uploader: uploader,
|
|
element: element
|
|
});
|
|
|
|
object.getOverClass = function () {
|
|
return attributes.overClass || object.overClass;
|
|
};
|
|
}
|
|
};
|
|
};
|
|
|
|
module.exports.$inject = ["FileUploader", "FileOver"];
|
|
|
|
/***/ }
|
|
/******/ ])
|
|
});
|
|
;
|
|
//# sourceMappingURL=angular-file-upload.js.map
|