/*! UIkit 2.26.4 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */ (function(addon) { var component; if (window.UIkit) { component = addon(UIkit); } if (typeof define == "function" && define.amd) { define("uikit-upload", ["uikit"], function(){ return component || addon(UIkit); }); } })(function(UI){ "use strict"; UI.component('uploadSelect', { init: function() { var $this = this; this.on("change", function() { xhrupload($this.element[0].files, $this.options); var twin = $this.element.clone(true).data('uploadSelect', $this); $this.element.replaceWith(twin); $this.element = twin; }); } }); UI.component('uploadDrop', { defaults: { 'dragoverClass': 'uk-dragover' }, init: function() { var $this = this, hasdragCls = false; this.on("drop", function(e){ if (e.originalEvent.dataTransfer && e.originalEvent.dataTransfer.files) { e.stopPropagation(); e.preventDefault(); $this.element.removeClass($this.options.dragoverClass); $this.element.trigger('dropped.uk.upload', [e.originalEvent.dataTransfer.files]); xhrupload(e.originalEvent.dataTransfer.files, $this.options); } }).on("dragenter", function(e){ e.stopPropagation(); e.preventDefault(); }).on("dragover", function(e){ e.stopPropagation(); e.preventDefault(); if (!hasdragCls) { $this.element.addClass($this.options.dragoverClass); hasdragCls = true; } }).on("dragleave", function(e){ e.stopPropagation(); e.preventDefault(); $this.element.removeClass($this.options.dragoverClass); hasdragCls = false; }); } }); UI.support.ajaxupload = (function() { function supportFileAPI() { var fi = document.createElement('INPUT'); fi.type = 'file'; return 'files' in fi; } function supportAjaxUploadProgressEvents() { var xhr = new XMLHttpRequest(); return !! (xhr && ('upload' in xhr) && ('onprogress' in xhr.upload)); } function supportFormData() { return !! window.FormData; } return supportFileAPI() && supportAjaxUploadProgressEvents() && supportFormData(); })(); function xhrupload(files, settings) { if (!UI.support.ajaxupload){ return this; } settings = UI.$.extend({}, xhrupload.defaults, settings); if (!files.length){ return; } if (settings.allow !== '*.*') { for(var i=0,file;file=files[i];i++) { if(!matchName(settings.allow, file.name)) { if(typeof(settings.notallowed) == 'string') { alert(settings.notallowed); } else { settings.notallowed(file, settings); } return; } } } var complete = settings.complete; if (settings.single){ var count = files.length, uploaded = 0, allow = true; settings.beforeAll(files); settings.complete = function(response, xhr){ uploaded = uploaded + 1; complete(response, xhr); if (settings.filelimit && uploaded >= settings.filelimit){ allow = false; } if (allow && uploaded