-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracker-ejs-helpers.js
40 lines (32 loc) · 1.35 KB
/
tracker-ejs-helpers.js
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
33
34
35
36
37
38
39
40
steal('can/view/ejs', 'tracker', function(ejs, Tracker) {
can.EJS.Helpers.prototype.tracked_input = function(obs, attr, props) {
return "<input " + can.view.hook(function(el) {
el.value = obs.attr(attr);
el.id = attr;
el.name = attr;
can.$(el).data('tracker', new Tracker(can.$(el), {
linkedObj: obs,
changeCallback: props && props.changeCallback ? props.changeCallback : can.noop
}));
}) + "/>";
};
can.EJS.Helpers.prototype.tracked_select = function(options, obs, attr, props) {
var htmlStr = "<select " + can.view.hook(function(el) {
el.id = attr;
el.name = attr;
if(can.$(el).data('tracker')) {
can.$(el).data('tracker').destroy();
}
can.$(el).data('tracker', new Tracker(can.$(el), {
linkedObj: obs,
changeCallback: props && props.changeCallback ? props.changeCallback : can.noop
}));
}) + ">";
for(var i=0; i<options.length; ++i) {
var opt = options[i];
htmlStr += "<option value='" + opt.value + "' " + (opt.value===obs.attr(attr)?'selected':'') + ">" + opt.text + "</option>";
}
return htmlStr + "</select>";
};
return can.EJS.Helpers.prototype;
});