Skip to content

Commit 32dbffc

Browse files
committed
import friendly helper
1 parent 3640cf6 commit 32dbffc

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

_attachments/script/app.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
// Apache 2.0 J Chris Anderson 2011
22
$(function() {
3+
// friendly helper http://tinyurl.com/6aow6yn
4+
$.fn.serializeObject = function() {
5+
var o = {};
6+
var a = this.serializeArray();
7+
$.each(a, function() {
8+
if (o[this.name]) {
9+
if (!o[this.name].push) {
10+
o[this.name] = [o[this.name]];
11+
}
12+
o[this.name].push(this.value || '');
13+
} else {
14+
o[this.name] = this.value || '';
15+
}
16+
});
17+
return o;
18+
};
19+
320
var path = unescape(document.location.pathname).split('/'),
421
design = path[3],
522
db = $.couch.db(path[1]);
@@ -31,10 +48,11 @@ $(function() {
3148
loggedIn : function(r) {
3249
$("#profile").couchProfile(r, {
3350
profileReady : function(profile) {
34-
$("#create-message").submit(function(){
35-
var form = this, doc = {};
36-
doc.created_at = new Date();
37-
doc.profile = profile;
51+
$("#create-message").submit(function(e){
52+
e.preventDefault();
53+
var form = this, doc = $(form).serializeObject();
54+
doc.created_at = new Date();
55+
doc.profile = profile;
3856
db.saveDoc(doc, {success : function() {form.reset();}});
3957
return false;
4058
}).find("input").focus();

0 commit comments

Comments
 (0)