# j-FileReader

> j-FileReader: singleton; easy usage

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: 5c394280e9c16c796e245f9c9667eb9d2b862d74ce3500d6ec431a99a3b68d3f
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

- singleton
- only for text files

__Methods__:
- `component.open(opt)` - opens file browser
	- `opt.multiple {Boolean}` enables multiple files (default: `false`)
	- `opt.accept {String}` allows only specified content-type (default: `undefined`)
	- `opt.base64 {Boolean}` reads a file in Base64 encoding (default: `false`)
	- __NEW__: `opt.files {HTTP Files}` reads files e.g. from Drag & Drop
	- `opt.callback {Function(file)}` a callback
	- __NEW__: `opt.progress {Function(percentage, file)}` optional

```js
var opt = {};
opt.accept = 'text/*';
// opt.files = e.files;
opt.callback = function(file) {
	console.log(file);
};
SETTER('filereader/open', opt);
```

Use it with `<ui-component name="filereader">`. When the component is not loaded yet, jComponent downloads it on first use from the address in `DEF.fallback` (the Componentator CDN by default). Author: Peter Širka. Source: the Componentator components repository, MIT license.

```html example.html
<ui-component name="filereader"></ui-component>
<a href="javascript:fopen()">OPEN FILE</a>

<script>
	function fopen() {
		var opt = {};
		opt.accept = 'text/*';
		opt.callback = function(file) {
			$(document.body).append('<div><pre><code>{0}</code></pre></div>'.format(JSON.stringify(file, null, '    ').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')));
		};
		SETTER('filereader/open', opt);
	}
</script>
```
