Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Separate form submission into another component #2

Closed
wants to merge 1 commit into from

2 participants

@ForbesLindesay

I realised my component ForbesLindesay/imgur shares a lot of code with this one, so I've separated it out into a different component, which simplifies this module to just adding a file to a form.

@Swatinem
Owner

Hm, this seems to be stale?

@Swatinem Swatinem closed this
@ForbesLindesay

Meh, I use browserify now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 25, 2012
  1. @ForbesLindesay
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 68 deletions.
  1. +1 −1  component.json
  2. +4 −67 index.js
View
2  component.json
@@ -8,7 +8,7 @@
"file"
],
"dependencies": {
- "component/emitter": "*"
+ "ForbesLindesay/submit": "*"
},
"development": {},
"scripts": [
View
71 index.js
@@ -3,7 +3,7 @@
* Module dependencies.
*/
-var Emitter = require('emitter');
+var Submit = require('submit');
/**
* Expose `Upload`.
@@ -28,73 +28,10 @@ module.exports = Upload;
function Upload(file) {
if (!(this instanceof Upload)) return new Upload(file);
- Emitter.call(this);
this.file = file;
-}
-
-/**
- * Mixin emitter.
- */
-
-Emitter(Upload.prototype);
-
-/**
- * Upload to the given `path`.
- *
- * @param {String} path
- * @api public
- */
-
-Upload.prototype.to = function(path){
- // TODO: x-browser
- var req = this.req = new XMLHttpRequest;
- req.open('POST', path);
- req.onload = this.onload.bind(this);
- req.onerror = this.onerror.bind(this);
- req.upload.onprogress = this.onprogress.bind(this);
var body = new FormData;
body.append('file', this.file);
- req.send(body);
-};
-
-/**
- * Abort the XHR.
- *
- * @api public
- */
-
-Upload.prototype.abort = function(){
- this.emit('abort');
- this.req.abort();
-};
-
-/**
- * Error handler.
- *
- * @api private
- */
-
-Upload.prototype.onerror = function(e){
- this.emit('error', e);
-};
-
-/**
- * Onload handler.
- *
- * @api private
- */
-
-Upload.prototype.onload = function(e){
- this.emit('end', this.req);
-};
-
-/**
- * Progress handler.
- *
- * @api private
- */
+ Submit.call(this, body);
+}
-Upload.prototype.onprogress = function(e){
- e.percent = e.loaded / e.total * 100;
- this.emit('progress', e);
-};
+Upload.prototype = Submit.prototype;
Something went wrong with that request. Please try again.