GithubHelp home page GithubHelp logo

brucewu16899 / filereader.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bgrins/filereader.js

0.0 2.0 0.0 474 KB

A lightweight wrapper for the JavaScript FileReader interface

Home Page: http://bgrins.github.com/filereader.js/

License: MIT License

JavaScript 47.07% HTML 52.93%

filereader.js's Introduction

FileReader.js

http://bgrins.github.com/filereader.js/

A small library independant wrapper for the JavaScript FileReader interface.

This plugin is open source under the MIT License. It was developed in conjunction with a CSS sprite generator project: http://instantsprite.com.

Specifications

Usage:

FileReaderJS.setupInput(document.getElementById('file-input'), opts);
FileReaderJS.setupDrop(document.getElementById('dropzone'), opts);
FileReaderJS.setupClipboard(document.body, opts);

If you have jQuery:

$("#file-input, #dropzone").fileReaderJS(opts);
$("body").fileClipboard(opts);

FileReaderJS.sync

Use the FileReaderSync object when available to load the files in a separate worker. false by default. This will cause only the load or error events to fire (there will be none of the other ProgressEvents, as the operation is synchronous).

Options

readAsMap: A collection taking key as a string that will be matched with regex against
	file types and the type to read as.  If no match is found, it will use readAsDefault.
	The default map is:
	{
		'image/*': 'DataURL',
		'text/*' : 'Text'
	}
readAsDefault: 'ArrayBuffer' | 'Text' | 'DataURL' (default)
accept: A regex string to match the contenttype of a given file.
		For example: 'image/*' to only accept images.
		on.skip will be called when a file does not match the filter.
dragClass: A CSS class to add onto the element called with setupDrop while dragging
on:
	loadstart: function(e, file) { }
	progress: function(e, file) { }
	load: function(e, file) { }
	abort: function(e, file) { }
	error: function(e, file) { }
	loadend: function(e, file) { }
	beforestart: function(file) { } Called before a file is passed to the FileReader.  Return false to prevent processing.  This is used along with the 'accept' parameter to skip a file (ex: an image is too big to process).  This wouldn't be needed, except that Chrome sometimes crashes when calling abort(): http://code.google.com/p/chromium/issues/detail?id=60979
	skip: function(file) { } Called only when a read has been skipped because of the accept string
	groupstart: function(group) { }
	groupend: function(group) { }

Parameters to events:

e - the native ProgressEvent created by the FileReader

file - an extension of the original File object.  See W3 link above for all native parameters.  Here are the extra fields

file.extra = {
	fileID: a generated int id for this file.
	groupID: the group that it belongs to
	nameNoExtension: 'myImage' instead of 'myImage.png'
	extension: 'png' instead of 'myImage.png'
	prettySize: '46.47' kb instead of 47585 (size field)
}

group: simple grouping of files.  Each time a change event or drop even happens and a FileList is created, and all of these files are stored inside a group object.

	groupID: a generated int id for this group
	files: the FileList associated with the group
	started: the Date the group was recieved as input
	ended: the Date all files in the group finished loading

Any contributions are welcome. Author: Brian Grinstead.

filereader.js's People

Contributors

bgrins avatar waynesan avatar laoneo avatar

Watchers

Bruce.Wu avatar  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.