Created
June 16, 2014 23:22
-
-
Save jxson/a39802d00ed04d1c36c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function submit(sink, data) { | |
if (!(this instanceof submit)) { | |
return new submit(sink, data) | |
} | |
this.sink = sink | |
this.data = data | |
this.id = sink.id | |
this.type = 'submit' | |
} | |
submit.prototype.handleEvent = function(event) { | |
var isValid = event.target.tagName === 'FORM' && event.type === 'submit' | |
if (! isValid) return; | |
event.preventDefault() | |
var values = serialize(event.currentTarget, { hash: true }); | |
var data = extend(values, this.data); | |
if (typeof this.sink === 'function') { | |
this.sink(data) | |
} else { | |
this.sink.write(data) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment