Coder Social home page Coder Social logo

ezdz's Introduction

Ezdz [izy-dizy]

Ezdz is a jQuery plugin to turn any standard input type file into a nice drag & drop zone with validators and previews.

Ezdz uses HTML5 File, Drag and Drop API, so it works properly on modern browsers only. I've tested it on last version of Chrome, Firefox and Safari on MacOSX and IOS7 safari mobile only. Feedbacks are welcomed.

Demo

Ezdz is in an early stage of development. Some demos are coming... Meanwhile please check a quick demo on Codepen. Here is a screenshot โ€” Hey! Don't drag/drop files below, it's just a screenshot!

screenshot

Getting Started

Include jQuery.

<script src="jquery.min.js"></script>

Include Ezdz styles.

<link rel="stylesheet" href="ezdz/dist/jquery.ezdz.min.css">

Include Ezdz script.

<script src="ezdz/dist/jquery.ezdz.min.js"></script>

And apply Ezdz to your inputs type file.

$('input[type="file"]').ezdz();

Rails

To use Switchery in your Rails app, add this to your Gemfile. See ezdz Rails Gem page.

gem 'ezdz-rails'

Settings

className

Add a custom class to the container. By default none.

text

Set the dropzone text. By default "drop a file".

previewImage

Set if a image preview is displayed when an image is dropped. By default "true".

value

Set a link to a previously uploaded file. By default none. This value can also be set in the element.

<input type="file" name="file" data-value="img/previously-uploaded-logo.png" />

classes

Ezdz classes. By default they are:

{ classes: {
        main:   'ezdz-dropzone',
        enter:  'ezdz-enter',
        reject: 'ezdz-reject',
        accept: 'ezdz-accept',
        focus:  'ezdz-focus'
    }
}

validators

Ezdz allowed validators. By default they are:

{ validators: {
        maxSize:   null,
        width:     null,
        maxWidth:  null,
        minWidth:  null,
        height:    null,
        maxHeight: null,
        minHeight: null
    }
}

Self-explanatory I guess.

$('[type="file"]').ezdz({
    validators: {
        maxWidth: 600,
        maxHeight: 400,
        maxSize: 1000000
    }
});

mime-types

Allowed mime-types are defined in the input tag with a standard acceptattribute.

<input type="file" name="logo" accept="image/png, image/jpeg" />

Callbacks

init

Called when the dropzone is built.

enter

Called when the dropzone is entered by the mouse.

leave

Called when the dropzone is leaved by the mouse.

accept

Called when a dropped/added file is added and accepted by validators.

{   accept: function(file) {
        alert('The file "' + file.name + '" is ok.');
    }
}

reject

Called when a dropped/added file is rejected by validators.

{   reject: function(file, errors) {
        if (errors.maxWidth || errors.maxHeight) {
            alert('The file "' + file.name + '" is too big.');
        }
    }
}

format

Called before displaying the filename in the preview.

{   format: function(filename) {
        return filename.uppercase();
    }
}

Default settings

Settings can be set for all instances.

$.ezdz.default = {
    validators: {
        maxWidth: 600,
        maxHeight: 400,
        maxSize: 1000000
    }
}

Methods

preview

Inject a preview in the dropzone.

$('[type="file"]').ezdz('preview', 'img/previously-uploaded-logo.png');

Set to null the preview is removed.

$('[type="file"]').ezdz('preview', null);

options

Get or set the settings.

As a getter:

var options = $('[type="file"]').ezdz('options');

As a setter:

$('[type="file"]').ezdz('options', {
    validators: {
        maxSize: 10000
    }
});

destroy

Remove Ezdz from the input and get back to normal.

$('[type="file"]').ezdz('destroy');

Functions

isBrowserCompatible

Check if the browser is compatible with HTML5 api needed by Ezdz.

if ($.ezdz.isBrowserCompatible() === false) {
    console.log('No ezdz for this browser. Standard input file only.');
}

License

The MIT License (MIT)

Copyright (c) 2017 Jay Salvat

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ezdz's People

Contributors

agmcleod avatar jaysalvat avatar phiter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ezdz's Issues

Takes too long to load large files

I am using ezdz to load video file, which is around 64mb.
The dropzone seems to be hanged while loading the file. It takes few seconds before the file name is populated. Can this process be accelerated?

jQuery('#vidfile').ezdz({
		text: 'drop the Video',
		preview: null,
		// accept: function(file) {
		// 	var size = file.size;
		// 	size = size/1024;
		// 	var unit = " KB";
		// 	if(size>=1024){
		// 		size = size/1024;
		// 		unit = " MB";
		// 	}
		// 	jQuery("#sb_asset_vid_size").html(size.toFixed(2)+unit);

		// }
	});

Multiple input files into the same page conflict

There is a conflict with 2 input fields into the same page as following.
<input id="moreimages" accept="image/png, image/jpeg, image/gif" type="file" name="moreimages[]" multiple >
<input id="morefiles" accept="application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/pdf" type="file" name="morefiles[]" multiple >

The first accept images and it works properly.
The second doesn't. It gives errors.

I'm initialising these 2 like this:

$("#moreimages").ezdz({
        text: 'Drop images here',
        validators: {
            maxWidth:  1920,
            maxHeight: 800,
            maxNumber: 3
        },
        reject: function(file, errors) {
            if (errors.maxWidth || errors.maxHeight) {
                alert('The file "' + file.name + '" is too big. (1920x800 maximum)');
            }
            if (errors.maxNumber) {
                alert("You're allowed to upload 3 images maximum");
            }
        }
    });
    //Files
    $("#morefiles").ezdz({
        text: 'Drop files here',
        previewImage:  false,
        validators: {
            maxNumber: 3
        },
        reject: function(file, errors) {
            if (errors.maxNumber) {
                alert("You're allowed to upload 3 files maximum");
            }
        }
    });

Is there something I can do? Thanks in advance.

Co-operate with Refile (RoR)

Refile is a file upload gem gaining popularity in the rails community.

It has support for background uploads (see documentation on direct, true). When this feature is enabled, although ezdz correctly manipulates the form, refile no longer submits the input.

Hopefully that's an adequate explanation of the problem.

Using Ezdz without upload button

Hi;
Is there any way to use Ezdz without upload button, I want the upload to be started when the user drops the file, and what I want exactly is to use the drop event as the submit for my form;
And thanks alot

IE 11

Drag and drop does not work in IE 11.
Is this a known issue - as I did not a see any mention of IE in your list of compatible browsers.
Any workaround for this?

Regards

Compatibility with Microsoft EDGE

Hi :) !

Thank you for this great script :) !

My client is using EDGE and telling me the drag-and-drop is not working... Is it possible to fix that or not ?
Thank you in advance an wish you a happy new year !

Conflict with jQuery File Upload

I've got jQuery File Upload on another file input that is uploading files directly to S3. When I drag and drop an image into EZDZ (does not happen when file is selected by clicking the drag area), it automatically triggers the file uploading on the other file input.

To clarify, the form has two file inputs, both with different names, classes, and ids. The only thing that makes them the same is that they are both input type="file". One file input is controlled by ezdz, the other by jQuery File Upload.

The only way I could get around this, was by disable, then enabling jQuery File Upload using ezdz events.

This is more of a heads up. Is there something I'm missing instead of this monkey patch?

		enter:  function() {
			$('.file-direct-upload').fileupload('disable');
		},
		accept: function(){
			$('.file-direct-upload').fileupload('enable');
		},

Not working on Mozilla for Android

its working almost in all browsers, but i recently got to know that its not working on Mozilla Firefox for Android. i tested this on Mozilla Firefox 47 for Android.

call ezdz() more than one

hi @jaysalvat ! great plugin.
Btw i have some question how if i call ezdz() more than one, the example when i build input file with javascript after page load. I have try but that will show "Error: Ezdz error - Method undefined does not exist.".

Maybe you have an idea? thanks

Support for ie ?

Hi, I was working with your plugin ezdz, could you let me know if is possible support with internet explorer ?

Regards

demo page

Can you add a demo page, please ?

thanks

Chrome sometimes opens the file

Great small script for creating a dropzone. Thank you.

I have an intermittent problem.
When I drag a file from my desktop, Chrome sometimes opens the file instead of dropping it in the zone (file input).

Any ideas?

Multiple uploads?

How could I allow multiple uploads with multiple previews?
Thanks

Image Preview not Working

Hello, this is my code :


$('#brandLogo').ezdz({
                text: 'drop the logo',
                preview:'http://files.parsetfss.com/12917a88-ac80-4e5e-a009-fc634161b79c/tfss-ff7efb8e-d7dc-4ace-b789-53df51de9b08-Samsung.jpg',
                validators: {
                    maxWidth: 400,
                    maxHeight: 200
                },

                reject: function(file, errors) {
                    if (errors.mimeType) {
                        alert(file.name + ' must be an image');
                    }
                    if (errors.maxWidth) {
                        alert(file.name + ' must be width:400px max');
                    }
                    if (errors.maxHeight) {
                        alert(file.name + ' must be height:200px max');
                    }
                }
            });

No image preview is shown in the dropzone ?

Cursor pointer not working in chrome/opera

Hi,

Very nice plugin, on my chrome (or opera) browser, if i put my mouse on the top left position inside the dropzone, my mouse pointer is not a finger, but an arrow, and if i move the cursor a few pixel below, the cursor got the right icon.

It's because on the top left position it's the hidden "input" filed, and the cursor doesn't seems to inherit the right cursor property.

It's working fine on firefox, but not on the chromium/webkit browsers.

I used the following CSS to avoid this strange behaviour.

.ezdz-dropzone input[type=file]::-webkit-file-upload-button {
cursor: pointer;
}

http://codepen.io/anon/pen/dXyZZN

hope this help. Perhaps something to add to your CSS ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.