Comparing version 0.0.1 to 0.0.2
/*! | ||
filebokz v0.0.1 (https://github.com/kodie/filebokz) | ||
filebokz v0.0.2 (https://github.com/kodie/filebokz) | ||
by Kodie Grantham (https://kodieg.com) | ||
*/ | ||
var filebokz=function(e,i){e=e||".filebokz","string"!=typeof i&&(i="filebokz");var b=["apng","bmp","gif","x-icon","jpeg","png","svg+xml","tiff","webp"],r=["kB","MB","GB","TB","PB","EB","ZB","YB"],t=document.createElement("div"),L="draggable"in t||"ondragstart"in t&&"ondrop"in t,s="FormData"in window&&"FileReader"in window;filebokz.count||(filebokz.count=0),"string"==typeof e?e=document.querySelectorAll(e):e instanceof HTMLElement&&(e=[e]);function z(e,t,i,r){return e.hasOwnProperty(t+r)?e[t+r]:e.hasOwnProperty(t+i)?e[t+i]:void 0}function h(e){if(Math.abs(e)<1024)return e+" B";for(var t=-1;e/=1024,++t,1024<=Math.round(10*Math.abs(e))/10&&t<r.length-1;);return+e.toFixed(1)+" "+r[t]}function o(e,l,f){var t=f.files,i=f.originalFiles||[],r="remove"===e.filebokzAction;if(t.length){var a=!l.dataset.appendable||"false"!==l.dataset.appendable.toLowerCase(),e=f.hasAttribute("multiple")&&"false"!==f.getAttribute("multiple").toLowerCase();if(a&&e&&!r&&i.length){for(var n=Array.from(t),s=Array.from(i),o=0;o<n.length;o++){for(var d=!1,c=0;c<s.length;c++)n[o].lastModifed===s[c].lastModifed&&n[o].name===s[c].name&&n[o].size===s[c].size&&n[o].type===s[c].type&&(d=!0);d||s.push(n[o])}f.files=filebokz.newFileList(s),t=f.files}y(t,l,f)?l.classList.add("has-files"):t=[]}t.length||r||(f.files=filebokz.newFileList(i),t=f.files),t.length||l.classList.remove("has-files"),f.originalFiles=t,l.dataset.fileCount=t.length,(r=l.querySelector(".file-count"))&&(r.innerHTML=t.length);for(var g=0,o=0;o<t.length;o++)g+=t[o].size;l.dataset.size=g,(r=l.querySelector(".size"))&&(r.innerHTML=h(g));var u=l.querySelector(".files");if(u){var v=u.dataset,m=u.querySelectorAll(".file");if(m)for(o=0;o<m.length;o++)u.removeChild(m[o]);if(t.length)for(var p=!v.draggable||"false"!==v.draggable.toLowerCase(),o=0;o<t.length;o++)!function(e,r){var t=e.type.split("/")[0],i=e.type.replace(/[\/\+\-](\w{1})/g,function(e){return e.toUpperCase()}).replace(/[\/\+\-]/g,""),t=t.charAt(0).toUpperCase()+t.slice(1),a=(a=z(v,"element",t,i))||v.element||"span",n=(n=z(v,"content",t,i))||v.content||"{name}",s=(s=z(v,"contentBefore",t,i))||v.contentBefore||"",o=(o=z(v,"contentAfter",t,i))||v.contentAfter||"",i=(i=z(v,"url",t,i))||(b.includes(e.type.replace("image/",""))?window.URL.createObjectURL(e):v.url||"");n=(n=(n=(n=(n=s+n+o).replace(/{name}/gi,e.name)).replace(/{type}/gi,e.type)).replace(/{size}/gi,h(e.size))).replace(/{url}/gi,i);a=document.createElement(a);a.className="file",a.innerHTML=n,L&&p&&(a.draggable="true",a.addEventListener("drag",function(e){!function(e,t){e.preventDefault(),e.stopPropagation();var i=document.elementFromPoint(e.pageX,e.pageY);if(i){var r=document.getElementById(t);var a=i.closest("[filebokz-id]");if(a&&a.classList.contains("js-enabled")){if(a.id!==t){e.target.classList.add("is-transferring");r.classList.add("is-transferring")}e.target.classList.remove("is-removing");r.classList.remove("is-removing")}else{e.target.classList.add("is-removing");r.classList.add("is-removing");e.target.classList.remove("is-transferring");r.classList.remove("is-transferring")}}}(e,l.id)},!1),a.addEventListener("dragstart",function(e){!function(e,t){e.target.classList.add("is-dragging");var i=Array.from(e.target.parentNode.children).indexOf(e.target);e.dataTransfer.setData("fileBoxId",t),e.dataTransfer.setData("fileIndex",i)}(e,l.id)},!1));n=a.querySelector(".remove");n&&n.addEventListener("click",function(e){var t,i;t=f,i=r,(e=e).preventDefault(),e.stopPropagation(),filebokz.removeFiles(t,i)},!1),u.append(a)}(t[o],o)}t.length>i.length?filebokz.triggerEvent("file-added",l):t.length<i.length&&filebokz.triggerEvent("file-removed",l)}function l(e,t,i){e.preventDefault(),e.stopPropagation(),t.classList.add("is-dragging")}function y(e,t,i){var r=t.dataset,i=i.hasAttribute("multiple")&&"false"!==i.getAttribute("multiple").toLowerCase()?r.hasOwnProperty("maxFiles")?r.maxFiles:null:1,a=r.maxFileSize,n=r.maxSize,s=r.allowedExtensions?r.allowedExtensions.split(","):null,o=0;if(i&&e.length>i)return d(t,"maxFiles",i),0;for(var l=0;l<e.length;l++){var f=(f=e[l].name.split("."))?f.pop().toLowerCase():"[none]";if(o+=e[l].size,a&&e[l].size>a)return d(t,"maxFileSize",a),0;if(n&&n<o)return d(t,"maxSize",n),0;if(s&&!s.includes(f))return d(t,"allowedExtensions",s.join(", ")),0}return 1}for(var d=function(e,t,i){var r=e.querySelector(".error-msg"),a=e.dataset.errorDisplayDuration||3e3;e.classList.add("error");var n=e.dataset,s="";"maxFiles"===t&&(s=(s=(s=n.maxFilesErrorMsg||"A maximum of {variable} file{s} can be uploaded.").replace(/{variable}/gi,i)).replace(/{s}/gi,1<i?"s":"")),"maxFileSize"===t&&(s=(s=n.maxFileSizeErrorMsg||"File size cannot exceed {variable}.").replace(/{variable}/gi,h(i))),"maxSize"===t&&(s=(s=n.maxSizeErrorMsg||"Total combined file size cannot exceed {variable}.").replace(/{variable}/gi,h(i))),"allowedExtensions"===t&&(s=(s=n.allowedExtensionsErrorMsg||"Only the following file types are allowed: {variable}.").replace(/{variable}/gi,i)),r&&(r.innerHTML=s,i=250,e.dataset.hasOwnProperty("errorAnimationDuration")&&(i=e.dataset.errorAnimationDuration),setTimeout(function(){r.innerHTML=""},a+i)),setTimeout(function(){e.classList.remove("error")},a),filebokz.triggerEvent("error",e,{errorMessage:s,errorType:t})},a=0;a<e.length;a++)!function(a){var t=a.closest("form"),n=a.querySelector('input[type="file"]');!n||a.classList.contains("no-js")||a.dataset.hasOwnProperty("filebokzId")||(filebokz.count++,a.dataset.filebokzId=filebokz.count,a.classList.add("js-enabled"),i&&!a.classList.contains(i)&&a.classList.add(i),s&&a.classList.add("is-advanced"),L&&a.classList.add("is-draggable"),a.id||(a.id="filebokz-"+filebokz.count),a.addEventListener("dragover",function(e){l(e,a)},!1),a.addEventListener("dragenter",function(e){l(e,a)},!1),a.addEventListener("dragleave",function(e){var t;t=a,(e=e).preventDefault(),e.stopPropagation(),t.classList.remove("is-dragging")},!1),a.addEventListener("drop",function(e){!function(e,t,i){e.preventDefault(),e.stopPropagation(),t.classList.remove("is-dragging");var r=e.dataTransfer.files,a=e.dataTransfer.getData("fileBoxId");if(a){var n=e.dataTransfer.getData("fileIndex"),s=document.getElementById(a),o=s.querySelector("input"),e=s.querySelector(".files").children[n];if(s.classList.remove("is-dragging"),s.classList.remove("is-removing"),s.classList.remove("is-transferring"),e.classList.remove("is-dragging"),e.classList.remove("is-removing"),e.classList.remove("is-transferring"),a===t.id)return;s=Array.from(o.files),e=s[n],a=Array.from(i.files);i.hasAttribute("multiple")&&"false"!==i.getAttribute("multiple").toLowerCase()?a.push(e):a=[e],y(a,t,i)&&(r=filebokz.newFileList(a),s.splice(n,1),o.files=filebokz.newFileList(s),filebokz.triggerEvent("change",o,{filebokzAction:"remove"}))}r&&r.length&&(i.files=r,filebokz.triggerEvent("change",i))}(e,a,n)},!1),n.addEventListener("change",function(e){o(e,a,n)},!1),n.addEventListener("focus",function(e){a.classList.add("in-focus")},!1),n.addEventListener("blur",function(e){a.classList.remove("in-focus")},!1),t&&(a.dataset.autoSubmit&&"false"!==a.dataset.autoSubmit.toLowerCase()&&n.addEventListener("change",function(e){t.submit()},!1),t.addEventListener("reset",function(e){var t,i,r;i=n,(r=(t=a).querySelector(".error"))&&(r.innerHTML=""),t.classList.remove("error"),filebokz.triggerEvent("change",i)},!1),t.addEventListener("submit",function(e){a.classList.add("is-uploading")},!1)),o(new Event("change"),a,n))}(e[a]);return window.addEventListener("dragover",function(e){e.preventDefault()},!1),window.addEventListener("drop",function(e){!function(e){e.preventDefault();var t=e.dataTransfer.getData("fileBoxId");t&&(t=document.getElementById(t).querySelector("input"),e=e.dataTransfer.getData("fileIndex"),filebokz.removeFiles(t,e))}(e)},!1),e};filebokz.addFiles=function(e,t){var i=Array.from(e.files);i.concat(Array.from(t)),e.files=filebokz.newFileList(i),filebokz.triggerEvent("change",e)},filebokz.newFileList=function(e){try{var t=new DataTransfer}catch(e){t=new ClipboardEvent("")}for(var i=0;i<e.length;i++)t.items.add(e[i]);return t.files},filebokz.removeFiles=function(e,t,i){var r=Array.from(e.files);r.splice(t||0,i||1),e.files=filebokz.newFileList(r),filebokz.triggerEvent("change",e,{filebokzAction:"remove"})},filebokz.triggerEvent=function(i,r,a,e){return setTimeout(function(){var e,t=new Event(i);for(e in a)a.hasOwnProperty(e)&&(t[e]=a[e]);r.dispatchEvent(t)},e||1)}; | ||
var filebokz=function(e,i){e=e||".filebokz","string"!=typeof i&&(i="filebokz");var h=["apng","bmp","gif","x-icon","jpeg","png","svg+xml","tiff","webp"],r=["kB","MB","GB","TB","PB","EB","ZB","YB"],t=document.createElement("div"),y="draggable"in t||"ondragstart"in t&&"ondrop"in t,s="FormData"in window&&"FileReader"in window;filebokz.count||(filebokz.count=0),"string"==typeof e?e=document.querySelectorAll(e):e instanceof HTMLElement&&(e=[e]);function E(e,t,i,r){return e.hasOwnProperty(t+r)?e[t+r]:e.hasOwnProperty(t+i)?e[t+i]:void 0}function w(e){if(Math.abs(e)<1024)return e+" B";for(var t=-1;e/=1024,++t,1024<=Math.round(10*Math.abs(e))/10&&t<r.length-1;);return+e.toFixed(1)+" "+r[t]}function o(e,l,f){var t=f.files,i=f.originalFiles||[],r="remove"===e.filebokzAction;if(t.length){var a=!l.dataset.appendable||"false"!==l.dataset.appendable.toLowerCase(),e=f.hasAttribute("multiple")&&"false"!==f.getAttribute("multiple").toLowerCase();if(a&&e&&!r&&i.length){for(var n=Array.from(t),s=Array.from(i),o=0;o<n.length;o++){for(var d=!1,c=0;c<s.length;c++)n[o].lastModifed===s[c].lastModifed&&n[o].name===s[c].name&&n[o].size===s[c].size&&n[o].type===s[c].type&&(d=!0);d||s.push(n[o])}f.files=filebokz.newFileList(s),t=f.files}k(t,l,f)?l.classList.add("has-files"):t=[]}t.length||r||(f.files=filebokz.newFileList(i),t=f.files),t.length||l.classList.remove("has-files"),f.originalFiles=t,l.dataset.fileCount=t.length,(r=l.querySelector(".file-count"))&&(r.innerHTML=t.length);for(var g=0,u=0;u<t.length;u++)g+=t[u].size;l.dataset.size=g,(r=l.querySelector(".size"))&&(r.innerHTML=w(g));var v=l.querySelector(".files");if(v){var m=v.dataset,p=v.querySelectorAll(".file");if(p)for(var b=0;b<p.length;b++)v.removeChild(p[b]);if(t.length)for(var L=!m.draggable||"false"!==m.draggable.toLowerCase(),z=0;z<t.length;z++)!function(e,r){var t=e.type.split("/")[0],i=e.type.replace(/[/+-](\w{1})/g,function(e){return e.toUpperCase()}).replace(/[/+-]/g,""),t=t.charAt(0).toUpperCase()+t.slice(1),a=(a=E(m,"element",t,i))||m.element||"span",n=(n=E(m,"content",t,i))||m.content||"{name}",s=(s=E(m,"contentBefore",t,i))||m.contentBefore||"",o=(o=E(m,"contentAfter",t,i))||m.contentAfter||"",i=(i=E(m,"url",t,i))||(h.includes(e.type.replace("image/",""))?window.URL.createObjectURL(e):m.url||"");n=(n=(n=(n=(n=s+n+o).replace(/{name}/gi,e.name)).replace(/{type}/gi,e.type)).replace(/{size}/gi,w(e.size))).replace(/{url}/gi,i);a=document.createElement(a);a.className="file",a.innerHTML=n,y&&L&&(a.draggable="true",a.addEventListener("drag",function(e){!function(e,t){e.preventDefault(),e.stopPropagation();var i=document.elementFromPoint(e.pageX,e.pageY);if(i){var r=document.getElementById(t);var a=i.closest("[filebokz-id]");if(a&&a.classList.contains("js-enabled")){if(a.id!==t){e.target.classList.add("is-transferring");r.classList.add("is-transferring")}e.target.classList.remove("is-removing");r.classList.remove("is-removing")}else{e.target.classList.add("is-removing");r.classList.add("is-removing");e.target.classList.remove("is-transferring");r.classList.remove("is-transferring")}}}(e,l.id)},!1),a.addEventListener("dragstart",function(e){!function(e,t){e.target.classList.add("is-dragging");var i=Array.from(e.target.parentNode.children).indexOf(e.target);e.dataTransfer.setData("fileBoxId",t),e.dataTransfer.setData("fileIndex",i)}(e,l.id)},!1));n=a.querySelector(".remove");n&&n.addEventListener("click",function(e){var t,i;t=f,i=r,(e=e).preventDefault(),e.stopPropagation(),filebokz.removeFiles(t,i)},!1),v.append(a)}(t[z],z)}t.length>i.length?filebokz.triggerEvent("file-added",l):t.length<i.length&&filebokz.triggerEvent("file-removed",l)}function l(e,t,i){e.preventDefault(),e.stopPropagation(),t.classList.add("is-dragging")}function k(e,t,i){var r=t.dataset,i=i.hasAttribute("multiple")&&"false"!==i.getAttribute("multiple").toLowerCase()?r.hasOwnProperty("maxFiles")?r.maxFiles:null:1,a=r.maxFileSize,n=r.maxSize,s=r.allowedExtensions?r.allowedExtensions.split(","):null,o=0;if(i&&e.length>i)return d(t,"maxFiles",i),0;for(var l=0;l<e.length;l++){var f=(f=e[l].name.split("."))?f.pop().toLowerCase():"[none]";if(o+=e[l].size,a&&e[l].size>a)return d(t,"maxFileSize",a),0;if(n&&n<o)return d(t,"maxSize",n),0;if(s&&!s.includes(f))return d(t,"allowedExtensions",s.join(", ")),0}return 1}for(var d=function(e,t,i){var r=e.querySelector(".error-msg"),a=e.dataset.errorDisplayDuration||3e3;e.classList.add("error");var n=e.dataset,s="";"maxFiles"===t&&(s=(s=(s=n.maxFilesErrorMsg||"A maximum of {variable} file{s} can be uploaded.").replace(/{variable}/gi,i)).replace(/{s}/gi,1<i?"s":"")),"maxFileSize"===t&&(s=(s=n.maxFileSizeErrorMsg||"File size cannot exceed {variable}.").replace(/{variable}/gi,w(i))),"maxSize"===t&&(s=(s=n.maxSizeErrorMsg||"Total combined file size cannot exceed {variable}.").replace(/{variable}/gi,w(i))),"allowedExtensions"===t&&(s=(s=n.allowedExtensionsErrorMsg||"Only the following file types are allowed: {variable}.").replace(/{variable}/gi,i)),r&&(r.innerHTML=s,i=250,e.dataset.hasOwnProperty("errorAnimationDuration")&&(i=e.dataset.errorAnimationDuration),setTimeout(function(){r.innerHTML=""},a+i)),setTimeout(function(){e.classList.remove("error")},a),filebokz.triggerEvent("error",e,{errorMessage:s,errorType:t})},a=0;a<e.length;a++)!function(a){var t=a.closest("form"),n=a.querySelector('input[type="file"]');!n||a.classList.contains("no-js")||a.dataset.hasOwnProperty("filebokzId")||(filebokz.count++,a.dataset.filebokzId=filebokz.count,a.classList.add("js-enabled"),i&&!a.classList.contains(i)&&a.classList.add(i),s&&a.classList.add("is-advanced"),y&&a.classList.add("is-draggable"),a.id||(a.id="filebokz-"+filebokz.count),a.addEventListener("dragover",function(e){l(e,a)},!1),a.addEventListener("dragenter",function(e){l(e,a)},!1),a.addEventListener("dragleave",function(e){var t;t=a,(e=e).preventDefault(),e.stopPropagation(),t.classList.remove("is-dragging")},!1),a.addEventListener("drop",function(e){!function(e,t,i){e.preventDefault(),e.stopPropagation(),t.classList.remove("is-dragging");var r=e.dataTransfer.files,a=e.dataTransfer.getData("fileBoxId");if(a){var n=e.dataTransfer.getData("fileIndex"),s=document.getElementById(a),o=s.querySelector("input"),e=s.querySelector(".files").children[n];if(s.classList.remove("is-dragging"),s.classList.remove("is-removing"),s.classList.remove("is-transferring"),e.classList.remove("is-dragging"),e.classList.remove("is-removing"),e.classList.remove("is-transferring"),a===t.id)return;s=Array.from(o.files),e=s[n],a=Array.from(i.files);i.hasAttribute("multiple")&&"false"!==i.getAttribute("multiple").toLowerCase()?a.push(e):a=[e],k(a,t,i)&&(r=filebokz.newFileList(a),s.splice(n,1),o.files=filebokz.newFileList(s),filebokz.triggerEvent("change",o,{filebokzAction:"remove"}))}r&&r.length&&(i.files=r,filebokz.triggerEvent("change",i))}(e,a,n)},!1),n.addEventListener("change",function(e){o(e,a,n)},!1),n.addEventListener("focus",function(e){a.classList.add("in-focus")},!1),n.addEventListener("blur",function(e){a.classList.remove("in-focus")},!1),t&&(a.dataset.autoSubmit&&"false"!==a.dataset.autoSubmit.toLowerCase()&&n.addEventListener("change",function(e){t.submit()},!1),t.addEventListener("reset",function(e){var t,i,r;i=n,(r=(t=a).querySelector(".error"))&&(r.innerHTML=""),t.classList.remove("error"),filebokz.triggerEvent("change",i)},!1),t.addEventListener("submit",function(e){a.classList.add("is-uploading")},!1)),o(new Event("change"),a,n))}(e[a]);return window.addEventListener("dragover",function(e){e.preventDefault()},!1),window.addEventListener("drop",function(e){!function(e){e.preventDefault(),e.stopImmediatePropagation();var t=e.dataTransfer.getData("fileBoxId");t&&(t=document.getElementById(t).querySelector("input"),e=e.dataTransfer.getData("fileIndex"),filebokz.removeFiles(t,e))}(e)},!1),e};filebokz.addFiles=function(e,t){var i=Array.from(e.files);i.concat(Array.from(t)),e.files=filebokz.newFileList(i),filebokz.triggerEvent("change",e)},filebokz.newFileList=function(e){var t;try{t=new DataTransfer}catch(e){t=new ClipboardEvent("")}for(var i=0;i<e.length;i++)t.items.add(e[i]);return t.files},filebokz.removeFiles=function(e,t,i){var r=Array.from(e.files);r.splice(t||0,i||1),e.files=filebokz.newFileList(r),filebokz.triggerEvent("change",e,{filebokzAction:"remove"})},filebokz.triggerEvent=function(i,r,a,e){return setTimeout(function(){var e,t=new Event(i);for(e in a)a.hasOwnProperty(e)&&(t[e]=a[e]);r.dispatchEvent(t)},e||1)}; | ||
//# sourceMappingURL=filebokz.min.js.map |
/*! | ||
filebokz v0.0.1 (https://github.com/kodie/filebokz) | ||
filebokz v0.0.2 (https://github.com/kodie/filebokz) | ||
by Kodie Grantham (https://kodieg.com) | ||
@@ -157,4 +157,4 @@ */ | ||
var size = 0 | ||
for (var i = 0; i < files.length; i++) { | ||
size += files[i].size | ||
for (var s = 0; s < files.length; s++) { | ||
size += files[s].size | ||
} | ||
@@ -173,4 +173,4 @@ | ||
if (fileElements) { | ||
for (var i = 0; i < fileElements.length; i++) { | ||
filesElement.removeChild(fileElements[i]); | ||
for (var fe = 0; fe < fileElements.length; fe++) { | ||
filesElement.removeChild(fileElements[fe]) | ||
} | ||
@@ -182,8 +182,8 @@ } | ||
for (var i = 0; i < files.length; i++) { | ||
for (var f = 0; f < files.length; f++) { | ||
(function (file, index) { | ||
var typePrefix = file.type.split('/')[0] | ||
var typeKey = file.type | ||
.replace(/[\/\+\-](\w{1})/g, function (c) { return c.toUpperCase() }) | ||
.replace(/[\/\+\-]/g, '') | ||
.replace(/[/+-](\w{1})/g, function (c) { return c.toUpperCase() }) | ||
.replace(/[/+-]/g, '') | ||
@@ -202,3 +202,3 @@ typePrefix = typePrefix.charAt(0).toUpperCase() + typePrefix.slice(1) | ||
var contentAfter = fileAttribute(filesElementData, 'contentAfter', typePrefix, typeKey) | ||
contentAfter = contentAfter|| filesElementData.contentAfter || '' | ||
contentAfter = contentAfter || filesElementData.contentAfter || '' | ||
@@ -238,3 +238,3 @@ var url = fileAttribute(filesElementData, 'url', typePrefix, typeKey) | ||
filesElement.append(fileElement) | ||
})(files[i], i) | ||
})(files[f], f) | ||
} | ||
@@ -379,2 +379,3 @@ } | ||
e.preventDefault() | ||
e.stopImmediatePropagation() | ||
@@ -491,6 +492,8 @@ var fileBoxId = e.dataTransfer.getData('fileBoxId') | ||
filebokz.newFileList = function (files) { | ||
var dt | ||
try { | ||
var dt = new DataTransfer() | ||
dt = new DataTransfer() | ||
} catch (e) { | ||
var dt = new ClipboardEvent('') | ||
dt = new ClipboardEvent('') | ||
} | ||
@@ -497,0 +500,0 @@ |
{ | ||
"name": "filebokz", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A tiny, dependency-free, highly customizable and configurable, easy to use file input with some pretty sweet features.", | ||
@@ -33,6 +33,2 @@ "keywords": [ | ||
"license": "MIT", | ||
"devDependencies": { | ||
"clean-css-cli": "^5.3.3", | ||
"uglify-js": "^3.10.4" | ||
}, | ||
"scripts": { | ||
@@ -42,4 +38,9 @@ "build": "npm run build-css && npm run build-js", | ||
"build-js": "uglifyjs filebokz.js --comments /^!/ --compress --mangle --output dist/filebokz.min.js --source-map \"url='filebokz.min.js.map'\" --verbose", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "standard --env browser" | ||
}, | ||
"devDependencies": { | ||
"clean-css-cli": "^5.3.3", | ||
"standard": "^11.0.1", | ||
"uglify-js": "^3.10.4" | ||
} | ||
} |
113
readme.md
# filebokz | ||
[![npm package version](https://img.shields.io/npm/v/filebokz.svg?style=flat-square)](https://www.npmjs.com/package/filebokz) | ||
[![Travis build status](https://img.shields.io/travis/com/kodie/filebokz.svg?style=flat-square)](https://travis-ci.com/kodie/filebokz) | ||
[![npm package downloads](https://img.shields.io/npm/dt/filebokz.svg?style=flat-square)](https://www.npmjs.com/package/filebokz) | ||
[![code style](https://img.shields.io/badge/code_style-standard-yellow.svg?style=flat-square)](https://github.com/standard/standard) | ||
[![license](https://img.shields.io/github/license/kodie/filebokz.svg?style=flat-square)](license.md) | ||
A tiny, dependency-free, highly customizable and configurable, easy to use file input with some pretty sweet features. | ||
@@ -6,2 +13,3 @@ | ||
# Features | ||
* Tiny (JS ~9kb + CSS ~1kb = ~10kb total minified [add an additional ~4kb if using the theme]) | ||
@@ -34,2 +42,3 @@ * Zero dependencies | ||
## Demo | ||
Visit https://kodie.github.io/filebokz | ||
@@ -39,2 +48,3 @@ | ||
## Usage | ||
Add the CSS: | ||
@@ -76,9 +86,14 @@ | ||
### The `filebokz([elements], [applyClass])` Function | ||
Initiates filebokz. | ||
#### Parameters | ||
* elements - The elements to target. Accepts a string to pass into `document.querySelectorAll()`, a `NodeList` instance, or an `HTMLElement` instance. (Defaults to `.filebokz`) | ||
* applyClass - A class name to apply to all matching elements. Set to `false` to not apply any class. (Defaults to `filebokz`) | ||
#### Examples | ||
```js | ||
@@ -95,74 +110,123 @@ window.addEventListener('load', function () { | ||
## Classes | ||
Use these classes on elements inside of the `filebokz` element to customize your input. | ||
### error | ||
Elements with this class will be hidden unless the root `filebokz` element has this class which is added if any errors occur. | ||
### error-msg | ||
Elements with this class will have their contents replaced with any errors that occur. | ||
### file | ||
If any elements have the `files` class, elements are appended to them with this class for displaying file names and/or previews when files are added to the input. | ||
### file-count | ||
Elements with this class will have their contents replaced with the number of files in the input. | ||
### files | ||
Elements with this class will have elements appended to them with the `file` class for displaying file names and/or previews when files are added to the input. | ||
### file-previews | ||
If displaying file previews, apply this class to any elements with the `files` class for fancier styling (when `filebokz-theme.css` is used). | ||
### has-files | ||
Elements with this class will be hidden unless the root `filebokz` element has this class which is added if the input has files. | ||
### in-focus | ||
Elements with this class will be hidden unless the root `filebokz` element has this class which is added if the input is in focus. | ||
### is-advanced | ||
Elements with this class will be hidden unless the root `filebokz` element has this class which is added if the browser supports advanced features. | ||
### is-draggable | ||
Elements with this class will be hidden unless the root `filebokz` element has this class which is added if the browser supports drag-and-drop. | ||
### is-dragging | ||
Elements with this class will be hidden unless the root `filebokz` element has this class which is added if a file is being dragged over it. | ||
### is-removing | ||
Elements with this class will be hidden unless the root `filebokz` element has this class which is added if a file is being dragged out of the file box and being removed. | ||
### is-transferring | ||
Elements with this class will be hidden unless the root `filebokz` element has this class which is added if a file is being dragged out of the file box and being moved to another `filebokz` element. | ||
### js-enabled | ||
Elements with this class will be hidden unless the root `filebokz` element has this class which is added after the JavaScript has been ran (thus meaning the browser supports JavaScript). | ||
### no-files | ||
Elements with this class will be hidden if the root `filebokz` element has the class `has-files` which is added if the input has files. | ||
### no-js | ||
Add this class to your root `filebokz` element if you do not wish for the JavaScript to do anything with it (mainly used for demo purposes). | ||
### not-in-focus | ||
Elements with this class will be hidden if the root `filebokz` element has the `in-focus` class which is added if the input is in focus. | ||
### not-advanced | ||
Elements with this class will be hidden if the root `filebokz` element has the `is-advanced` class which is added if the browser supports advanced features. | ||
### not-draggable | ||
Elements with this class will be hidden if the root `filebokz` element has the `is-draggable` class which is added if the browser supports drag-and-drop. | ||
### not-dragging | ||
Elements with this class will be hidden if the root `filebokz` element has the `is-dragging` class which is added if a file is being dragged over it. | ||
### not-removing | ||
Elements with this class will be hidden if the root `filebokz` element has the `is-removing` class which is added if a file is being dragged out of the file box and being removed. | ||
### not-transferring | ||
Elements with this class will be hidden if the root `filebokz` element has the `is-transferring` class which is added if a file is being dragged out of the file box and being moved to another `filebokz` element. | ||
### remove | ||
Add this class to an element inside of the `files` element's `content`, `content-before`, or `content-after` data attributes so that when the element is clicked, it removes the file from the input. | ||
### size | ||
Elements with this class will have their contents replaced with the combined file size of all files in the input. | ||
@@ -172,38 +236,63 @@ | ||
## Root Element Attributes | ||
Apply these attributes with the `data-` prefix to your `filebokz` element to configure your input. (ex. `data-max-file-size="5120"`) | ||
### allowed-extensions | ||
A comma seperated (no spaces) list of allowed file extensions. Defaults to allowing any file extension. Add `[none]` to this list to allow files without extensions. | ||
### allowed-extensions-error-msg | ||
The error message that is displayed when a user tries to upload a file that isn't in the `allowed-extensions` list. Any instances of `{variable}` will be replaced with the list of allowed file extensions. (Defaults to `Only the following file types are allowed: {variable}.`) | ||
### appendable | ||
Set this to `false` to replace the files in the input when a file is selected rather than adding it. (Defaults to `true`) | ||
### auto-submit | ||
Set this to `true` to automatically submit the parent form when a file is uploaded. (Defaults to `false`) | ||
### error-display-animation-duration | ||
The number of milliseconds after the `error-display-duration` before clearing out the contents of the `error-msg` element after an error has occurred. (Defaults to `250`) | ||
### error-display-duration | ||
The number of milliseconds before removing the `error` class from the filebokz after an error has occurred. (Defaults to `3000`) | ||
### max-files | ||
The maximum number of files that are allowed to be uploaded. This is only applied if the input has the `multiple` attribute. (Defaults to `null` [no limit]) | ||
### max-files-error-msg | ||
The error message that is displayed when a user tries to upload more files than `max-files` allows. Instances of `{variable}` are replaced with the value of `max-files` and instances of `{s}` are replaced with an "s" if that number is more than 1, otherwise it is replaced with nothing. (Defaults to `A maximum of {variable} file{s} can be uploaded.`) | ||
### max-file-size | ||
The maximum size of a single file that is allowed to be uploaded. (Defaults to `null` [no limit]) | ||
### max-file-size-error-msg | ||
The error message that is displayed when a user tries to upload a file that is bigger than what `max-file-size` allows. Instances of `{variable}` are replaced with the value of `max-file-size`. (Defaults to `File size cannot exceed {variable}.`) | ||
### max-size | ||
The maximum size of all files combined that is allowed to be uploaded. (Defaults to `null` [no limit]) | ||
### max-size-error-msg | ||
The error message that is displayed when a user tries to upload files whose combined file size is bigger than what `max-size` allows. (Defaults to `Total combined file size cannot exceed {variable}.`) | ||
@@ -213,2 +302,3 @@ | ||
## Files Element Attributes | ||
Apply these attributes with the `data-` prefix to any element with the `files` class inside of your `filebokz` element to customize how each file is displayed. | ||
@@ -225,18 +315,30 @@ | ||
### content | ||
The content that is placed inside of the `file` element. (Defaults to `{name}`) | ||
### content-before | ||
The content that is prepended to `content`. (Defaults to `null` [blank]) | ||
### content-after | ||
The content that is appended to `content`. (Defaults to `null` [blank]) | ||
### draggable | ||
Set this to `false` to disable the dragging of `file` elements. (Defaults to `true`) | ||
### element | ||
The type of HTML element that the `file` element should be. (Defaults to `span`) | ||
### url | ||
The URL of the file preview. This is what `{url}` is set to in the `content`, `content-before`, and `content-after` attributes. (Defaults to `null` [blank] unless the file is an image, in which case it is set to a temporary URL of the file for previewing.) | ||
@@ -249,2 +351,3 @@ | ||
### Examples | ||
@@ -269,3 +372,13 @@ | ||
## Related | ||
- [minitaur](https://github.com/kodie/minitaur) - The ultimate, dependency-free, easy to use, JavaScript plugin for creating and managing modals. | ||
- [colorfield](https://github.com/kodie/colorfield) - A tiny, dependency-free, color input field helper that utilizes the native color picker. | ||
- [vanishing-fields](https://github.com/kodie/vanishing-fields) - A dependency-free, easy to use, JavaScript plugin for hiding and showing fields. | ||
## License | ||
MIT. See the [license file](license.md) for more info. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
80464
14
727
1
375
3