From c94fb32c7a3c28b18a27460aa2447eeec1fac1de Mon Sep 17 00:00:00 2001 From: Pascal Szewczyk Date: Mon, 18 Jul 2016 23:23:54 +0200 Subject: uikit added --- js/components/upload.js | 257 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100755 js/components/upload.js (limited to 'js/components/upload.js') diff --git a/js/components/upload.js b/js/components/upload.js new file mode 100755 index 0000000..f80f26e --- /dev/null +++ b/js/components/upload.js @@ -0,0 +1,257 @@ +/*! 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