-
Notifications
You must be signed in to change notification settings - Fork 5
/
file-input-drop-zone.js
2 lines (2 loc) · 1.05 KB
/
file-input-drop-zone.js
1
2
// Generated by CoffeeScript 1.3.3
(function(){$.fn.extend({fileInputDropZone:function(e){var t,n,r;n={disablePreview:!1,selectImg:function(e){return e.find("img")},selectInput:function(e){return e.find(":file")}};n=$.extend(n,e);t=function(e,t){if(e)return e[0].tagName==="IMG"?e.prop("src",t):e.css({"background-image":"url("+t+")","background-repeat":"no-repeat"})};r=function(e,r){var i;if(!n.disablePreview&&e){if(r.type.match(/image[\/\-\w]*/)){i=new FileReader;i.onload=function(n){return t(e,n.target.result)};return i.readAsDataURL(r)}return t(e,"")}};return this.each(function(){var e,i,s;e=$(this);n.disablePreview||(i=n.selectImg(e));s=n.selectInput(e);this.ondrop=function(e){var t;if(e.dataTransfer&&(t=e.dataTransfer.files)){s.prop("files",t);if(s.prop("files")===t){e.preventDefault();r(i,t[0]);return!1}}};this.ondragover=function(e){if(e.dataTransfer&&e.dataTransfer.files)return e.preventDefault()};return s.change(function(){var e;return(e=this.files)?r(i,e[0]):t(i,"")})})}});$(function(){return $(".file-input-drop-zone").fileInputDropZone()})}).call(this);