diff --git a/dist/example.js b/dist/example.js index b3cab5a..0a45752 100644 --- a/dist/example.js +++ b/dist/example.js @@ -46,2148 +46,831 @@ 'use strict'; - var FileUpload = __webpack_require__(38); + var _FileUpload = __webpack_require__(5); - console.log(FileUpload); + var _FileUpload2 = _interopRequireDefault(_FileUpload); + + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + + new Vue({ + el: '#app', + components: { + FileUpload: _FileUpload2.default + }, + data: { + accept: 'image/*', + size: 1024 * 1024 * 10, + multiple: true + }, + compiled: function compiled() { + this.$refs.upload.request = { + headers: { + "X-Csrf-Token": "xxxx" + }, + data: { + "_csrf_token": "xxxxxx" + } + }; + }, + methods: { + remove: function remove(file) { + this.$refs.upload.files.$remove(file); + } + } + }); /***/ }, /* 1 */ /***/ function(module, exports) { - // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 - var global = module.exports = typeof window != 'undefined' && window.Math == Math - ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')(); - if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef - -/***/ }, -/* 2 */ -/***/ function(module, exports) { - - var hasOwnProperty = {}.hasOwnProperty; - module.exports = function(it, key){ - return hasOwnProperty.call(it, key); - }; - -/***/ }, -/* 3 */ -/***/ function(module, exports, __webpack_require__) { - - // to indexed object, toObject with fallback for non-array-like ES3 strings - var IObject = __webpack_require__(54) - , defined = __webpack_require__(15); - module.exports = function(it){ - return IObject(defined(it)); - }; - -/***/ }, -/* 4 */ -/***/ function(module, exports) { - - var core = module.exports = {version: '2.4.0'}; - if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef - -/***/ }, -/* 5 */ -/***/ function(module, exports, __webpack_require__) { - - // Thank's IE8 for his funny defineProperty - module.exports = !__webpack_require__(9)(function(){ - return Object.defineProperty({}, 'a', {get: function(){ return 7; }}).a != 7; - }); - -/***/ }, -/* 6 */ -/***/ function(module, exports, __webpack_require__) { - - var dP = __webpack_require__(7) - , createDesc = __webpack_require__(13); - module.exports = __webpack_require__(5) ? function(object, key, value){ - return dP.f(object, key, createDesc(1, value)); - } : function(object, key, value){ - object[key] = value; - return object; - }; - -/***/ }, -/* 7 */ -/***/ function(module, exports, __webpack_require__) { - - var anObject = __webpack_require__(11) - , IE8_DOM_DEFINE = __webpack_require__(30) - , toPrimitive = __webpack_require__(25) - , dP = Object.defineProperty; - - exports.f = __webpack_require__(5) ? Object.defineProperty : function defineProperty(O, P, Attributes){ - anObject(O); - P = toPrimitive(P, true); - anObject(Attributes); - if(IE8_DOM_DEFINE)try { - return dP(O, P, Attributes); - } catch(e){ /* empty */ } - if('get' in Attributes || 'set' in Attributes)throw TypeError('Accessors not supported!'); - if('value' in Attributes)O[P] = Attributes.value; - return O; - }; - -/***/ }, -/* 8 */ -/***/ function(module, exports, __webpack_require__) { - - var store = __webpack_require__(23)('wks') - , uid = __webpack_require__(14) - , Symbol = __webpack_require__(1).Symbol - , USE_SYMBOL = typeof Symbol == 'function'; - - var $exports = module.exports = function(name){ - return store[name] || (store[name] = - USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : uid)('Symbol.' + name)); - }; + 'use strict'; - $exports.store = store; - -/***/ }, -/* 9 */ -/***/ function(module, exports) { - - module.exports = function(exec){ - try { - return !!exec(); - } catch(e){ - return true; - } - }; - -/***/ }, -/* 10 */ -/***/ function(module, exports, __webpack_require__) { - - // 19.1.2.14 / 15.2.3.14 Object.keys(O) - var $keys = __webpack_require__(35) - , enumBugKeys = __webpack_require__(16); - - module.exports = Object.keys || function keys(O){ - return $keys(O, enumBugKeys); - }; - -/***/ }, -/* 11 */ -/***/ function(module, exports, __webpack_require__) { - - var isObject = __webpack_require__(12); - module.exports = function(it){ - if(!isObject(it))throw TypeError(it + ' is not an object!'); - return it; - }; - -/***/ }, -/* 12 */ -/***/ function(module, exports) { - - module.exports = function(it){ - return typeof it === 'object' ? it !== null : typeof it === 'function'; - }; - -/***/ }, -/* 13 */ -/***/ function(module, exports) { - - module.exports = function(bitmap, value){ - return { - enumerable : !(bitmap & 1), - configurable: !(bitmap & 2), - writable : !(bitmap & 4), - value : value - }; - }; - -/***/ }, -/* 14 */ -/***/ function(module, exports) { - - var id = 0 - , px = Math.random(); - module.exports = function(key){ - return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36)); - }; - -/***/ }, -/* 15 */ -/***/ function(module, exports) { - - // 7.2.1 RequireObjectCoercible(argument) - module.exports = function(it){ - if(it == undefined)throw TypeError("Can't call method on " + it); - return it; - }; - -/***/ }, -/* 16 */ -/***/ function(module, exports) { - - // IE 8- don't enum bug keys - module.exports = ( - 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf' - ).split(','); - -/***/ }, -/* 17 */ -/***/ function(module, exports, __webpack_require__) { - - var global = __webpack_require__(1) - , core = __webpack_require__(4) - , ctx = __webpack_require__(51) - , hide = __webpack_require__(6) - , PROTOTYPE = 'prototype'; - - var $export = function(type, name, source){ - var IS_FORCED = type & $export.F - , IS_GLOBAL = type & $export.G - , IS_STATIC = type & $export.S - , IS_PROTO = type & $export.P - , IS_BIND = type & $export.B - , IS_WRAP = type & $export.W - , exports = IS_GLOBAL ? core : core[name] || (core[name] = {}) - , expProto = exports[PROTOTYPE] - , target = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE] - , key, own, out; - if(IS_GLOBAL)source = name; - for(key in source){ - // contains in native - own = !IS_FORCED && target && target[key] !== undefined; - if(own && key in exports)continue; - // export native or passed - out = own ? target[key] : source[key]; - // prevent global pollution for namespaces - exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key] - // bind timers to global for call from export context - : IS_BIND && own ? ctx(out, global) - // wrap global constructors for prevent change them in library - : IS_WRAP && target[key] == out ? (function(C){ - var F = function(a, b, c){ - if(this instanceof C){ - switch(arguments.length){ - case 0: return new C; - case 1: return new C(a); - case 2: return new C(a, b); - } return new C(a, b, c); - } return C.apply(this, arguments); - }; - F[PROTOTYPE] = C[PROTOTYPE]; - return F; - // make static versions for prototype methods - })(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out; - // export proto methods to core.%CONSTRUCTOR%.methods.%NAME% - if(IS_PROTO){ - (exports.virtual || (exports.virtual = {}))[key] = out; - // export proto methods to core.%CONSTRUCTOR%.prototype.%NAME% - if(type & $export.R && expProto && !expProto[key])hide(expProto, key, out); + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.default = { + props: { + title: { + type: String, + default: 'Upload file' + }, + name: { + type: String, + required: true + }, + id: { + type: String + }, + action: { + type: String, + required: true + }, + accept: { + type: String + }, + multiple: { + type: String + }, + timeout: { + type: Number + }, + size: { + type: Number + } + }, + + components: { + inputFile: { + template: '', + methods: { + change: function change(e) { + this.$parent._addFileUploads(e.target); + this.$destroy(); + } + } + } + }, + + data: function data() { + return { + files: [], + active: false, + uploaded: true, + request: { + data: {}, + headers: {} + } + }; + }, + init: function init() { + var input = document.createElement('input'); + input.type = 'file'; + if (window.FormData && input.files) { + this.$mode = 'html5'; + } else { + this.$mode = 'html4'; + } + this._index = 0; + this._files = {}; + }, + + watch: { + files: function files(_files) { + var ids = []; + for (var i = 0; i < _files.length; i++) { + var file = _files[i]; + if (!file.errno && !file.success) { + this.uploaded = false; + } + ids.push(file.id); + } + for (var id in this._files) { + if (ids.indexOf(id) != -1) { + continue; + } + + var file = this._files[id]._file; + + file.removed = true; + var xhr = this._files[id].xhr; + if (xhr) { + xhr.abort(); + xhr.timeout = 1; + } + var iframe = this._files[id].iframe; + if (iframe) { + iframe.onabort({ type: 'abort' }); + } + delete this._files[id]; + this.$dispatch('removeFileUpload', file, this); + } + this._index = 0; + }, + active: function active(newValue, oldValue) { + if (newValue && !oldValue) { + this._fileUploads(); + } + }, + uploaded: function uploaded(_uploaded) { + if (_uploaded) { + this.active = false; + } + } + }, + + methods: { + _addFileUploads: function _addFileUploads(el) { + var Component = this.$options.components.inputFile; + new Component({ + parent: this, + el: el + }); + this.uploaded = false; + + if (el.files) { + for (var i = 0; i < el.files.length; i++) { + var file = el.files[i]; + var id = 'upload-file-' + Math.random().toString(36).substr(2); + var value = { id: id, size: file.size, name: file.name, progress: '0.00', active: false, error: '', errno: '', success: false, data: {}, request: { headers: {}, data: {} } }; + this._files[id] = { el: el, file: file }; + + var len; + if (this.multiple) { + len = this.files.push(value); + } else { + this.files = [value]; + len = 1; + } + this._files[id]._file = this.files[len - 1]; + this.$dispatch('addFileUpload', this.files[len - 1], this); + } + } else { + var id = 'upload-file-' + Math.random().toString(36).substr(2); + var value = { id: id, size: -1, name: el.value.replace(/^.*?([^\/\\\r\n]+)$/, '$1'), progress: '0.00', active: false, error: '', errno: '', success: false, data: {}, request: { headers: {}, data: {} } }; + this._files[id] = { el: el }; + var len; + if (this.multiple) { + len = this.files.push(value); + } else { + this.files = [value]; + len = 1; + } + var len = this.files.push(file); + this._files[id]._file = this.files[len - 1]; + this.$dispatch('addFileUpload', this.files[len - 1], this); + } + }, + _fileUploads: function _fileUploads() { + if (!this.active) { + return; + } + for (; this._index < this.files.length; this._index++) { + var file = this.files[this._index]; + if (file.active || file.success || file.errno) { + continue; + } + if (this.size && this.size > 0 && file.size >= 0 && file.size > this.size) { + file.error = 'Size'; + file.errno = 'size'; + continue; + } + + if (this.$mode == 'html5') { + this._fileUploadHtml5(file); + } else { + this._fileUploadHtml4(file); + } + return; + } + this.active = false; + this.uploaded = true; + }, + _fileUploadHtml5: function _fileUploadHtml5(file) { + var _self = this; + var file2 = this._files[file.id]; + + var fileUploads = false; + + var form = new window.FormData(); + form.append(this.name, file2.file); + for (var key in this.request.data) { + form.append(key, this.request.data[key]); + } + + for (var key in file.request.data) { + form.append(key, file.request.data[key]); + } + + var xhr = new XMLHttpRequest(); + + xhr.upload.onprogress = function (e) { + if (file.removed) { + xhr.abort(); + return; + } + if (!_self.active || !file.active) { + xhr.abort(); + return; + } + if (e.lengthComputable) { + file.progress = (e.loaded / e.total * 100).toFixed(2); + } + _self.$dispatch('fileUploadProgress', file, _self); + }; + + var callback = function callback(e) { + switch (e.type) { + case 'timeout': + file.errno = 'timeout'; + file.error = 'Timeout'; + break; + case 'abort': + file.errno = 'abort'; + file.error = 'Abort'; + break; + case 'error': + if (!xhr.status) { + file.errno = 'network'; + file.error = 'Network'; + } else if (xhr.status >= 500) { + file.errno = 'server'; + file.error = 'Server'; + } else if (xhr.status >= 400) { + file.errno = 'denied'; + file.error = 'Denied'; + } + break; + default: + if (xhr.status >= 500) { + file.errno = 'server'; + file.error = 'Server'; + } else if (xhr.status >= 400) { + file.errno = 'denied'; + file.error = 'Denied'; + } else { + file.progress = '100.00'; + file.success = true; + } + } + file.active = false; + if (xhr.responseText) { + var contentType = xhr.getResponseHeader('Content-Type'); + if (contentType && contentType.indexOf('/json') != -1) { + file.data = JSON.parse(xhr.responseText); + } else { + file.data = xhr.responseText; + } + } + if (!fileUploads) { + fileUploads = true; + if (!file.removed) { + _self.$dispatch('afterFileUpload', file, _self); + } + setTimeout(function () { + _self._fileUploads(); + }, 50); + } + }; + + xhr.onload = callback; + xhr.onerror = callback; + xhr.onabort = callback; + xhr.ontimeout = callback; + + if (this.timeout) { + xhr.timeout = this.timeout; + } + + xhr.open('POST', this.action); + + for (var key in this.request.headers) { + xhr.setRequestHeader(key, this.request.headers[key]); + } + + for (var key in file.request.headers) { + xhr.setRequestHeader(key, file.request.headers[key]); + } + + xhr.send(form); + + file.active = true; + + file2.xhr = xhr; + + var interval = setInterval(function () { + if (!_self.active || !file.active || file.success || file.errno) { + clearInterval(interval); + if (!file.success && !file.errno) { + xhr.abort(); + } + } + }, 50); + this.$dispatch('beforeFileUpload', file, this); + }, + _fileUploadHtml4: function _fileUploadHtml4(file) { + var _self = this; + var file2 = this._files[file.id]; + + var fileUploads = false; + + var keydown = function keydown(e) { + if (e.keyCode == 27) { + e.preventDefault(); + } + }; + + var iframe = document.createElement('iframe'); + iframe.id = 'upload-iframe-' + file.id; + iframe.name = 'upload-iframe-' + file.id; + iframe.src = 'about:blank'; + iframe.style.width = '1px'; + iframe.style.height = '1px'; + iframe.style.top = '-9999px'; + iframe.style.left = '-9999px'; + iframe.style.position = 'absolute'; + iframe.style.marginTop = '-9999em'; + + var form = document.createElement('form'); + form.action = this.action; + form.name = 'upload-form-' + file.id; + form.setAttribute('method', 'POST'); + form.setAttribute('target', 'upload-iframe-' + file.id); + form.setAttribute('enctype', 'multipart/form-data'); + form.appendChild(file2.el); + for (var key in this.request.data) { + var input = document.createElement('input'); + input.type = 'hidden'; + input.name = key; + input.value = this.request.data[key]; + form.appendChild(input); + } + + for (var key in file.request.data) { + var input = document.createElement('input'); + input.type = 'hidden'; + input.name = key; + input.value = file.request.data[key]; + form.appendChild(input); + } + + var getDocumentData = function getDocumentData() { + var doc; + try { + if (iframe.contentWindow) { + doc = iframe.contentWindow.document; + } + } catch (err) {} + if (!doc) { + try { + doc = iframe.contentDocument ? iframe.contentDocument : iframe.document; + } catch (err) { + doc = iframe.document; + } + } + if (doc && doc.body) { + return doc.body.innerHTML; + } + return null; + }; + + var callback = function callback(e) { + switch (e.type) { + case 'abort': + file.errno = 'abort'; + file.error = 'Abort'; + break; + case 'error': + var data = getDocumentData(); + if (file.errno) {} else if (data === null) { + file.errno = 'network'; + file.error = 'Network'; + } else { + file.errno = 'denied'; + file.error = 'Denied'; + } + break; + default: + var data = getDocumentData(); + if (file.errno) {} else if (data === null) { + file.errno = 'network'; + file.error = 'Network'; + } else { + file.progress = '100.00'; + file.success = true; + } + } + + file.active = false; + if (typeof data != "undefined") { + if (data && data.substr(0, 1) == '{' && data.substr(data.length - 1, 1) == '}') { + try { + data = JSON.parse(data); + } catch (err) {} + } + file.data = data; + } + if (!fileUploads) { + document.body.removeEventListener('keydown', keydown); + document.body.removeEventListener('keydown', keydown); + fileUploads = true; + iframe.parentNode && iframe.parentNode.removeChild(iframe); + if (!file.removed) { + _self.$dispatch('afterFileUpload', file, _self); + } + setTimeout(function () { + _self._fileUploads(); + }, 50); + } + }; + + setTimeout(function () { + document.body.appendChild(iframe).appendChild(form).submit(); + iframe.onload = callback; + iframe.onerror = callback; + iframe.onabort = callback; + + file.active = true; + + file2.iframe = iframe; + + document.body.addEventListener('keydown', keydown); + var interval = setInterval(function () { + if (!_self.active || !file.active || file.success || file.errno) { + clearInterval(interval); + if (!file.success && !file.errno) { + iframe.onabort({ type: 'abort' }); + } + } + }, 50); + _self.$dispatch('beforeFileUpload', file, this); + }, 10); + } } - } }; - // type bitmap - $export.F = 1; // forced - $export.G = 2; // global - $export.S = 4; // static - $export.P = 8; // proto - $export.B = 16; // bind - $export.W = 32; // wrap - $export.U = 64; // safe - $export.R = 128; // real proto method for `library` - module.exports = $export; - -/***/ }, -/* 18 */ -/***/ function(module, exports) { - - module.exports = {}; - -/***/ }, -/* 19 */ -/***/ function(module, exports) { - - module.exports = true; /***/ }, -/* 20 */ -/***/ function(module, exports) { - - exports.f = {}.propertyIsEnumerable; - -/***/ }, -/* 21 */ +/* 2 */ /***/ function(module, exports, __webpack_require__) { - var def = __webpack_require__(7).f - , has = __webpack_require__(2) - , TAG = __webpack_require__(8)('toStringTag'); + exports = module.exports = __webpack_require__(3)(); + // imports - module.exports = function(it, tag, stat){ - if(it && !has(it = stat ? it : it.prototype, TAG))def(it, TAG, {configurable: true, value: tag}); - }; - -/***/ }, -/* 22 */ -/***/ function(module, exports, __webpack_require__) { - - var shared = __webpack_require__(23)('keys') - , uid = __webpack_require__(14); - module.exports = function(key){ - return shared[key] || (shared[key] = uid(key)); - }; - -/***/ }, -/* 23 */ -/***/ function(module, exports, __webpack_require__) { - - var global = __webpack_require__(1) - , SHARED = '__core-js_shared__' - , store = global[SHARED] || (global[SHARED] = {}); - module.exports = function(key){ - return store[key] || (store[key] = {}); - }; - -/***/ }, -/* 24 */ -/***/ function(module, exports) { - - // 7.1.4 ToInteger - var ceil = Math.ceil - , floor = Math.floor; - module.exports = function(it){ - return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it); - }; - -/***/ }, -/* 25 */ -/***/ function(module, exports, __webpack_require__) { - - // 7.1.1 ToPrimitive(input [, PreferredType]) - var isObject = __webpack_require__(12); - // instead of the ES6 spec version, we didn't implement @@toPrimitive case - // and the second argument - flag - preferred type is a string - module.exports = function(it, S){ - if(!isObject(it))return it; - var fn, val; - if(S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val; - if(typeof (fn = it.valueOf) == 'function' && !isObject(val = fn.call(it)))return val; - if(!S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val; - throw TypeError("Can't convert object to primitive value"); - }; - -/***/ }, -/* 26 */ -/***/ function(module, exports, __webpack_require__) { - - var global = __webpack_require__(1) - , core = __webpack_require__(4) - , LIBRARY = __webpack_require__(19) - , wksExt = __webpack_require__(27) - , defineProperty = __webpack_require__(7).f; - module.exports = function(name){ - var $Symbol = core.Symbol || (core.Symbol = LIBRARY ? {} : global.Symbol || {}); - if(name.charAt(0) != '_' && !(name in $Symbol))defineProperty($Symbol, name, {value: wksExt.f(name)}); - }; - -/***/ }, -/* 27 */ -/***/ function(module, exports, __webpack_require__) { - - exports.f = __webpack_require__(8); - -/***/ }, -/* 28 */ -/***/ function(module, exports) { - - var toString = {}.toString; - module.exports = function(it){ - return toString.call(it).slice(8, -1); - }; - -/***/ }, -/* 29 */ -/***/ function(module, exports, __webpack_require__) { - - var isObject = __webpack_require__(12) - , document = __webpack_require__(1).document - // in old IE typeof document.createElement is 'object' - , is = isObject(document) && isObject(document.createElement); - module.exports = function(it){ - return is ? document.createElement(it) : {}; - }; - -/***/ }, -/* 30 */ -/***/ function(module, exports, __webpack_require__) { - - module.exports = !__webpack_require__(5) && !__webpack_require__(9)(function(){ - return Object.defineProperty(__webpack_require__(29)('div'), 'a', {get: function(){ return 7; }}).a != 7; - }); - -/***/ }, -/* 31 */ -/***/ function(module, exports, __webpack_require__) { + // module + exports.push([module.id, "\n.file-uploads-label {\n overflow: hidden;\n position: relative;\n text-align: center;\n}\n.file-uploads-label span{\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n -o-user-select: none;\n user-select: none;\n}\n.file-uploads-label input{\n z-index: 1;\n opacity: 0;\n font-size: 20em;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n position: absolute;\n width: 100%;\n height: 100%;\n}\n.file-uploads-label.file-uploads-html5 input{\n width: 1px !important;\n height: 1px !important;\n top:-1px !important;\n left:-1px !important;\n right:auto !important;\n bottom:auto !important;\n}\n", ""]); + + // exports - 'use strict'; - var LIBRARY = __webpack_require__(19) - , $export = __webpack_require__(17) - , redefine = __webpack_require__(36) - , hide = __webpack_require__(6) - , has = __webpack_require__(2) - , Iterators = __webpack_require__(18) - , $iterCreate = __webpack_require__(56) - , setToStringTag = __webpack_require__(21) - , getPrototypeOf = __webpack_require__(63) - , ITERATOR = __webpack_require__(8)('iterator') - , BUGGY = !([].keys && 'next' in [].keys()) // Safari has buggy iterators w/o `next` - , FF_ITERATOR = '@@iterator' - , KEYS = 'keys' - , VALUES = 'values'; - - var returnThis = function(){ return this; }; - - module.exports = function(Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED){ - $iterCreate(Constructor, NAME, next); - var getMethod = function(kind){ - if(!BUGGY && kind in proto)return proto[kind]; - switch(kind){ - case KEYS: return function keys(){ return new Constructor(this, kind); }; - case VALUES: return function values(){ return new Constructor(this, kind); }; - } return function entries(){ return new Constructor(this, kind); }; - }; - var TAG = NAME + ' Iterator' - , DEF_VALUES = DEFAULT == VALUES - , VALUES_BUG = false - , proto = Base.prototype - , $native = proto[ITERATOR] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT] - , $default = $native || getMethod(DEFAULT) - , $entries = DEFAULT ? !DEF_VALUES ? $default : getMethod('entries') : undefined - , $anyNative = NAME == 'Array' ? proto.entries || $native : $native - , methods, key, IteratorPrototype; - // Fix native - if($anyNative){ - IteratorPrototype = getPrototypeOf($anyNative.call(new Base)); - if(IteratorPrototype !== Object.prototype){ - // Set @@toStringTag to native iterators - setToStringTag(IteratorPrototype, TAG, true); - // fix for some old engines - if(!LIBRARY && !has(IteratorPrototype, ITERATOR))hide(IteratorPrototype, ITERATOR, returnThis); - } - } - // fix Array#{values, @@iterator}.name in V8 / FF - if(DEF_VALUES && $native && $native.name !== VALUES){ - VALUES_BUG = true; - $default = function values(){ return $native.call(this); }; - } - // Define iterator - if((!LIBRARY || FORCED) && (BUGGY || VALUES_BUG || !proto[ITERATOR])){ - hide(proto, ITERATOR, $default); - } - // Plug for library - Iterators[NAME] = $default; - Iterators[TAG] = returnThis; - if(DEFAULT){ - methods = { - values: DEF_VALUES ? $default : getMethod(VALUES), - keys: IS_SET ? $default : getMethod(KEYS), - entries: $entries - }; - if(FORCED)for(key in methods){ - if(!(key in proto))redefine(proto, key, methods[key]); - } else $export($export.P + $export.F * (BUGGY || VALUES_BUG), NAME, methods); - } - return methods; - }; /***/ }, -/* 32 */ -/***/ function(module, exports, __webpack_require__) { +/* 3 */ +/***/ function(module, exports) { - // 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties]) - var anObject = __webpack_require__(11) - , dPs = __webpack_require__(60) - , enumBugKeys = __webpack_require__(16) - , IE_PROTO = __webpack_require__(22)('IE_PROTO') - , Empty = function(){ /* empty */ } - , PROTOTYPE = 'prototype'; + /* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra + */ + // css base code, injected by the css-loader + module.exports = function() { + var list = []; - // Create object with fake `null` prototype: use iframe Object with cleared prototype - var createDict = function(){ - // Thrash, waste and sodomy: IE GC bug - var iframe = __webpack_require__(29)('iframe') - , i = enumBugKeys.length - , gt = '>' - , iframeDocument; - iframe.style.display = 'none'; - __webpack_require__(53).appendChild(iframe); - iframe.src = 'javascript:'; // eslint-disable-line no-script-url - // createDict = iframe.contentWindow.Object; - // html.removeChild(iframe); - iframeDocument = iframe.contentWindow.document; - iframeDocument.open(); - iframeDocument.write('\n \n\n"; /***/ }, -/* 35 */ -/***/ function(module, exports, __webpack_require__) { - - var has = __webpack_require__(2) - , toIObject = __webpack_require__(3) - , arrayIndexOf = __webpack_require__(50)(false) - , IE_PROTO = __webpack_require__(22)('IE_PROTO'); - - module.exports = function(object, names){ - var O = toIObject(object) - , i = 0 - , result = [] - , key; - for(key in O)if(key != IE_PROTO)has(O, key) && result.push(key); - // Don't enum bug & hidden keys - while(names.length > i)if(has(O, key = names[i++])){ - ~arrayIndexOf(result, key) || result.push(key); - } - return result; - }; - -/***/ }, -/* 36 */ +/* 5 */ /***/ function(module, exports, __webpack_require__) { - module.exports = __webpack_require__(6); + var __vue_script__, __vue_template__ + __webpack_require__(7) + __vue_script__ = __webpack_require__(1) + if (__vue_script__ && + __vue_script__.__esModule && + Object.keys(__vue_script__).length > 1) { + console.warn("[vue-loader] src/FileUpload.vue: named exports in *.vue files are ignored.")} + __vue_template__ = __webpack_require__(4) + module.exports = __vue_script__ || {} + if (module.exports.__esModule) module.exports = module.exports.default + if (__vue_template__) { + (typeof module.exports === "function" ? (module.exports.options || (module.exports.options = {})) : module.exports).template = __vue_template__ + } -/***/ }, -/* 37 */ -/***/ function(module, exports, __webpack_require__) { - - // 7.1.13 ToObject(argument) - var defined = __webpack_require__(15); - module.exports = function(it){ - return Object(defined(it)); - }; /***/ }, -/* 38 */ +/* 6 */ /***/ function(module, exports, __webpack_require__) { - var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(module) {'use strict'; - - var _stringify = __webpack_require__(39); - - var _stringify2 = _interopRequireDefault(_stringify); - - var _keys = __webpack_require__(40); - - var _keys2 = _interopRequireDefault(_keys); - - var _typeof2 = __webpack_require__(43); - - var _typeof3 = _interopRequireDefault(_typeof2); - - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - - (function webpackUniversalModuleDefinition(root, factory) { - if (( false ? 'undefined' : (0, _typeof3.default)(exports)) === 'object' && ( false ? 'undefined' : (0, _typeof3.default)(module)) === 'object') module.exports = factory();else if (true) !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));else if ((typeof exports === 'undefined' ? 'undefined' : (0, _typeof3.default)(exports)) === 'object') exports["VueUploadComponent"] = factory();else root["VueUploadComponent"] = factory(); - })(undefined, function () { - return function (modules) { - var installedModules = {}; - function __webpack_require__(moduleId) { - if (installedModules[moduleId]) return installedModules[moduleId].exports; - var module = installedModules[moduleId] = { exports: {}, - id: moduleId, - loaded: false - }; - modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); - module.loaded = true; - return module.exports; - } - __webpack_require__.m = modules; - __webpack_require__.c = installedModules; - __webpack_require__.p = "/dist/"; - return __webpack_require__(0); - }([function (module, exports, __webpack_require__) { - - 'use strict'; - - module.exports = __webpack_require__(5); - console.log(module.exports); - }, function (module, exports) { - - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - exports.default = { - props: { - title: { - type: String, - default: 'Upload file' - }, - name: { - type: String, - required: true - }, - id: { - type: String - }, - action: { - type: String, - required: true - }, - accept: { - type: String - }, - multiple: { - type: String - }, - timeout: { - type: Number - }, - size: { - type: Number - } - }, - - components: { - inputFile: { - template: '', - methods: { - change: function change(e) { - this.$parent._addFileUploads(e.target); - this.$destroy(); - } - } - } - }, - - data: function data() { - return { - files: [], - active: false, - uploaded: true, - request: { - data: {}, - headers: {} - } - }; - }, - init: function init() { - var input = document.createElement('input'); - input.type = 'file'; - if (window.FormData && input.files) { - this.$mode = 'html5'; - } else { - this.$mode = 'html4'; - } - this._index = 0; - this._files = {}; - }, - - watch: { - files: function files(_files) { - var ids = []; - for (var i = 0; i < _files.length; i++) { - var file = _files[i]; - if (!file.errno && !file.success) { - this.uploaded = false; - } - ids.push(file.id); - } - for (var id in this._files) { - if (ids.indexOf(id) != -1) { - continue; - } - - var file = this._files[id]._file; - - file.removed = true; - var xhr = this._files[id].xhr; - if (xhr) { - xhr.abort(); - xhr.timeout = 1; - } - var iframe = this._files[id].iframe; - if (iframe) { - iframe.onabort({ type: 'abort' }); - } - delete this._files[id]; - this.$dispatch('removeFileUpload', file, this); - } - this._index = 0; - }, - active: function active(newValue, oldValue) { - if (newValue && !oldValue) { - this._fileUploads(); - } - }, - uploaded: function uploaded(_uploaded) { - if (_uploaded) { - this.active = false; - } - } - }, - - methods: { - _addFileUploads: function _addFileUploads(el) { - var Component = this.$options.components.inputFile; - new Component({ - parent: this, - el: el - }); - this.uploaded = false; - - if (el.files) { - for (var i = 0; i < el.files.length; i++) { - var file = el.files[i]; - var id = 'upload-file-' + Math.random().toString(36).substr(2); - var value = { id: id, size: file.size, name: file.name, progress: '0.00', active: false, error: '', errno: '', success: false, data: {}, request: { headers: {}, data: {} } }; - this._files[id] = { el: el, file: file }; - - var len; - if (this.multiple) { - len = this.files.push(value); - } else { - this.files = [value]; - len = 1; - } - this._files[id]._file = this.files[len - 1]; - this.$dispatch('addFileUpload', this.files[len - 1], this); - } - } else { - var id = 'upload-file-' + Math.random().toString(36).substr(2); - var value = { id: id, size: -1, name: el.value.replace(/^.*?([^\/\\\r\n]+)$/, '$1'), progress: '0.00', active: false, error: '', errno: '', success: false, data: {}, request: { headers: {}, data: {} } }; - this._files[id] = { el: el }; - var len; - if (this.multiple) { - len = this.files.push(value); - } else { - this.files = [value]; - len = 1; - } - var len = this.files.push(file); - this._files[id]._file = this.files[len - 1]; - this.$dispatch('addFileUpload', this.files[len - 1], this); - } - }, - _fileUploads: function _fileUploads() { - if (!this.active) { - return; - } - for (; this._index < this.files.length; this._index++) { - var file = this.files[this._index]; - if (file.active || file.success || file.errno) { - continue; - } - if (this.size && this.size > 0 && file.size >= 0 && file.size > this.size) { - file.error = 'Size'; - file.errno = 'size'; - continue; - } - - if (this.$mode == 'html5') { - this._fileUploadHtml5(file); - } else { - this._fileUploadHtml4(file); - } - return; - } - this.active = false; - this.uploaded = true; - }, - _fileUploadHtml5: function _fileUploadHtml5(file) { - var _self = this; - var file2 = this._files[file.id]; - - var fileUploads = false; - - var form = new window.FormData(); - form.append(this.name, file2.file); - for (var key in this.request.data) { - form.append(key, this.request.data[key]); - } - - for (var key in file.request.data) { - form.append(key, file.request.data[key]); - } - - var xhr = new XMLHttpRequest(); - - xhr.upload.onprogress = function (e) { - if (file.removed) { - xhr.abort(); - return; - } - if (!_self.active || !file.active) { - xhr.abort(); - return; - } - if (e.lengthComputable) { - file.progress = (e.loaded / e.total * 100).toFixed(2); - } - _self.$dispatch('fileUploadProgress', file, _self); - }; - - var callback = function callback(e) { - switch (e.type) { - case 'timeout': - file.errno = 'timeout'; - file.error = 'Timeout'; - break; - case 'abort': - file.errno = 'abort'; - file.error = 'Abort'; - break; - case 'error': - if (!xhr.status) { - file.errno = 'network'; - file.error = 'Network'; - } else if (xhr.status >= 500) { - file.errno = 'server'; - file.error = 'Server'; - } else if (xhr.status >= 400) { - file.errno = 'denied'; - file.error = 'Denied'; - } - break; - default: - if (xhr.status >= 500) { - file.errno = 'server'; - file.error = 'Server'; - } else if (xhr.status >= 400) { - file.errno = 'denied'; - file.error = 'Denied'; - } else { - file.progress = '100.00'; - file.success = true; - } - } - file.active = false; - if (xhr.responseText) { - var contentType = xhr.getResponseHeader('Content-Type'); - if (contentType && contentType.indexOf('/json') != -1) { - file.data = JSON.parse(xhr.responseText); - } else { - file.data = xhr.responseText; - } - } - if (!fileUploads) { - fileUploads = true; - if (!file.removed) { - _self.$dispatch('afterFileUpload', file, _self); - } - setTimeout(function () { - _self._fileUploads(); - }, 50); - } - }; - - xhr.onload = callback; - xhr.onerror = callback; - xhr.onabort = callback; - xhr.ontimeout = callback; - - if (this.timeout) { - xhr.timeout = this.timeout; - } - - xhr.open('POST', this.action); - - for (var key in this.request.headers) { - xhr.setRequestHeader(key, this.request.headers[key]); - } - - for (var key in file.request.headers) { - xhr.setRequestHeader(key, file.request.headers[key]); - } - - xhr.send(form); - - file.active = true; - - file2.xhr = xhr; - - var interval = setInterval(function () { - if (!_self.active || !file.active || file.success || file.errno) { - clearInterval(interval); - if (!file.success && !file.errno) { - xhr.abort(); - } - } - }, 50); - this.$dispatch('beforeFileUpload', file, this); - }, - _fileUploadHtml4: function _fileUploadHtml4(file) { - var _self = this; - var file2 = this._files[file.id]; - - var fileUploads = false; - - var keydown = function keydown(e) { - if (e.keyCode == 27) { - e.preventDefault(); - } - }; - - var iframe = document.createElement('iframe'); - iframe.id = 'upload-iframe-' + file.id; - iframe.name = 'upload-iframe-' + file.id; - iframe.src = 'about:blank'; - iframe.style.width = '1px'; - iframe.style.height = '1px'; - iframe.style.top = '-9999px'; - iframe.style.left = '-9999px'; - iframe.style.position = 'absolute'; - iframe.style.marginTop = '-9999em'; - - var form = document.createElement('form'); - form.action = this.action; - form.name = 'upload-form-' + file.id; - form.setAttribute('method', 'POST'); - form.setAttribute('target', 'upload-iframe-' + file.id); - form.setAttribute('enctype', 'multipart/form-data'); - form.appendChild(file2.el); - for (var key in this.request.data) { - var input = document.createElement('input'); - input.type = 'hidden'; - input.name = key; - input.value = this.request.data[key]; - form.appendChild(input); - } - - for (var key in file.request.data) { - var input = document.createElement('input'); - input.type = 'hidden'; - input.name = key; - input.value = file.request.data[key]; - form.appendChild(input); - } - - var getDocumentData = function getDocumentData() { - var doc; - try { - if (iframe.contentWindow) { - doc = iframe.contentWindow.document; - } - } catch (err) {} - if (!doc) { - try { - doc = iframe.contentDocument ? iframe.contentDocument : iframe.document; - } catch (err) { - doc = iframe.document; - } - } - if (doc && doc.body) { - return doc.body.innerHTML; - } - return null; - }; - - var callback = function callback(e) { - switch (e.type) { - case 'abort': - file.errno = 'abort'; - file.error = 'Abort'; - break; - case 'error': - var data = getDocumentData(); - if (file.errno) {} else if (data === null) { - file.errno = 'network'; - file.error = 'Network'; - } else { - file.errno = 'denied'; - file.error = 'Denied'; - } - break; - default: - var data = getDocumentData(); - if (file.errno) {} else if (data === null) { - file.errno = 'network'; - file.error = 'Network'; - } else { - file.progress = '100.00'; - file.success = true; - } - } - - file.active = false; - if (typeof data != "undefined") { - if (data && data.substr(0, 1) == '{' && data.substr(data.length - 1, 1) == '}') { - try { - data = JSON.parse(data); - } catch (err) {} - } - file.data = data; - } - if (!fileUploads) { - document.body.removeEventListener('keydown', keydown); - document.body.removeEventListener('keydown', keydown); - fileUploads = true; - iframe.parentNode && iframe.parentNode.removeChild(iframe); - if (!file.removed) { - _self.$dispatch('afterFileUpload', file, _self); - } - setTimeout(function () { - _self._fileUploads(); - }, 50); - } - }; - - setTimeout(function () { - document.body.appendChild(iframe).appendChild(form).submit(); - iframe.onload = callback; - iframe.onerror = callback; - iframe.onabort = callback; - - file.active = true; - - file2.iframe = iframe; - - document.body.addEventListener('keydown', keydown); - var interval = setInterval(function () { - if (!_self.active || !file.active || file.success || file.errno) { - clearInterval(interval); - if (!file.success && !file.errno) { - iframe.onabort({ type: 'abort' }); - } - } - }, 50); - _self.$dispatch('beforeFileUpload', file, this); - }, 10); - } - } - }; - }, function (module, exports, __webpack_require__) { - - exports = module.exports = __webpack_require__(3)(); - - exports.push([module.id, "\n.file-uploads-label {\n overflow: hidden;\n position: relative;\n text-align: center;\n}\n.file-uploads-label span{\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n -o-user-select: none;\n user-select: none;\n}\n.file-uploads-label input{\n z-index: 1;\n opacity: 0;\n font-size: 20em;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n position: absolute;\n width: 100%;\n height: 100%;\n}\n.file-uploads-label.file-uploads-html5 input{\n width: 1px !important;\n height: 1px !important;\n top:-1px !important;\n left:-1px !important;\n right:auto !important;\n bottom:auto !important;\n}\n", ""]); - }, function (module, exports) { - module.exports = function () { - var list = []; - - list.toString = function toString() { - var result = []; - for (var i = 0; i < this.length; i++) { - var item = this[i]; - if (item[2]) { - result.push("@media " + item[2] + "{" + item[1] + "}"); - } else { - result.push(item[1]); - } - } - return result.join(""); - }; - - list.i = function (modules, mediaQuery) { - if (typeof modules === "string") modules = [[null, modules, ""]]; - var alreadyImportedModules = {}; - for (var i = 0; i < this.length; i++) { - var id = this[i][0]; - if (typeof id === "number") alreadyImportedModules[id] = true; - } - for (i = 0; i < modules.length; i++) { - var item = modules[i]; - - if (typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) { - if (mediaQuery && !item[2]) { - item[2] = mediaQuery; - } else if (mediaQuery) { - item[2] = "(" + item[2] + ") and (" + mediaQuery + ")"; - } - list.push(item); - } - } - }; - return list; + /* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra + */ + var stylesInDom = {}, + memoize = function(fn) { + var memo; + return function () { + if (typeof memo === "undefined") memo = fn.apply(this, arguments); + return memo; }; - }, function (module, exports) { - - module.exports = "\n