Coder Social home page Coder Social logo

jquery-image-uploader's Introduction

jquery-image-uploader

jquery-image-uploader is a jquery plugin to upload file. It supports drag&drop and file API. The plugin has a automatic "fallback" mode.

This plugin is not really production-ready.

Installation

bower install jquery-image-uploader

Or copy the src/jquery-image-uploader.min.js file on your server.

Usage

Basic usage

$('#dropZone').imageUploader({
	fileField: '#files',
	urlField: '#url',
	url: 'ajaxUpload.php',
	afterUpload: function (data) {
		console.log(data);
	}, 
    error: function(msg) {
        alert(msg);
    }
});

If you drag and drop an image on the "dropZone" or if you use the classic file button, it will call the url, with the file as an argument. If you specify a url in the "urlField" field, it will call the url with a POST['url'] attribute containing the image url.

Possible options (with default values)

$('#dropZone').imageUploader({
	fileField: null, // the "simple" file input
	urlField: null, // a field which accept an "url", and trigger the upload
	urlFieldSubmit: null, // the submit button for urlField. If null, the urlField gets a "onChange" event

    hideFileField: true, // hide the file field to show only the drop zone
    hideUrlField: true, // hide the url field to show only the drop zone

	url: 'ajaxUpload.php', // the url called for ajax upload

	thumbnails: { // thumbnails options. Set to "false" to hide thumbnails
		div: null, // thumbnails div (ex: "$('#thumbnailsDiv')"), do not set to generate it
		width: null, // thumbnail width, null = image width
		height: null, // thumbnail height, null = image height
        crop: null // null|zoom|fit : null does not crop the image, zoom or fit crop if "width" and "height" are set
	},

    maxFileSize: 0, // an error is thrown if the file is bigger than max. 0 means no validation
    allowDuplicate: false, // set to true to allow multiple upload of a file

    // all callbacks. The most importants are 'afterUpload' and 'error'
    onFilesSelected: function() { return false; },
    onDragLeave: function(event) { return false; },
    onDragEnter: function(event) { return false; },
    onDragOver: function(event) { return false; },
    onDrop: function(event) { return false; },
    onUploadProgress: function(event) { return false; },
    beforeUpload: function() { return true; },
    afterUpload: function() { return false; },
    error: function(msg) { alert(msg); },
    thumbnailReady: $.noop // if you want to change the thumbnail action
});

Advange usage

You can acces the ImageUploader object by getting the imageUploader data attribute. You can then interact on the object itself.

Example

var imgUrl = 'http://octodex.github.com/images/original.png';
$('#dropZone').data('imageUploader').addFileByUrl(imgUrl);

jquery-image-uploader's People

Contributors

dallegoet avatar jdeniau avatar

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.