-
Notifications
You must be signed in to change notification settings - Fork 253
Expand file tree
/
Copy pathbackbone_datalink.js
More file actions
32 lines (29 loc) · 920 Bytes
/
backbone_datalink.js
File metadata and controls
32 lines (29 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(function($) {
return $.extend($.fn, {
backboneLink: function(model) {
return $(this).find(":input").each(function() {
var el, name;
el = $(this);
name = el.attr("name");
if(typeof name !== "undefined" && name !== null) {
model.bind("change:" + name, function() {
val = model.get(name)
if ( el.is("input[type='checkbox']") && (val == true || val == false) )
el.prop('checked', val);
return el.val(val);
});
return $(this).bind("change", function() {
var attrs;
el = $(this);
attrs = {};
if ( el.is("input[type='checkbox']") )
attrs[el.attr("name")] = el.prop('checked');
else
attrs[el.attr("name")] = el.val();
return model.set(attrs);
});
}
});
}
});
})(jQuery);