component/file-picker — pull request #8 by MatthewMueller (2013-06-27 20:43:50+00:00)
Title: Refactor the API

This is a complete refactor of the API. We were running into the dialog occasionally not opening on certain browsers / devices with the immediate creation, insertion, then synthetic click triggering.

This API separates DOM creation with triggering the click. It also introduces a `

` element to allow `form.reset()` to clear the file input. This reset is called every time you trigger the dialog. The one downside of this is that DOM cleanup is now a manual process. For the most part you can reuse the `picker` instance for multiple file inputs, as long as you don't need to save the state of the file input.

---

Here's the new API (from the Readme):

## Usage

```js
var picker = FilePicker();

// single file upload on click

link.onclick = function() {
picker.choose(function(files) {
// ...
});
}

// upload multiple files (on supported web browsers)

picker.multiple()
link.onclick = function() {
picker.choose(function(files) {
// ...
});
}
```

## API

### FilePicker()

Initialize a `FilePicker` instance. Defaults to a single file upload.

### picker#multiple(multiple)

Upload multiple files (on supported browsers). Defaults to `false`.

```js
picker.multiple()
picker.choose(fn)
```

### picker#directory(directory)

Upload an entire directory (on supported browsers). Defaults to `false`

```js
picker.directory()
picker.choose(fn)
```

### picker#choose(fn)

Open the file dialog. Call `fn` upon file selection. If the user cancels the dialog without uploading a file, `fn` is not called.

```js
picker.choose(function(files, e) {
// ...
})
```

### picker#destroy()

Remove the picker from the DOM and unbind any events