-
Notifications
You must be signed in to change notification settings - Fork 487
/
Copy pathrivets-config.coffee
49 lines (40 loc) · 1.3 KB
/
rivets-config.coffee
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
41
42
43
44
45
46
47
48
49
rivets.binders.append =
routine: (el, value) ->
el.checked = _.find(value, (item) -> String(item) == String(el.value)) != undefined
bind: (el) ->
@callback = () =>
currentValue = _.clone(@model.get(@keypath)) || []
if _.contains(currentValue, el.value)
newValue = _.without(currentValue, el.value)
@model.set(@keypath, newValue)
else
currentValue.push(el.value)
@model.set(@keypath, currentValue)
$(el).on('change', @callback)
unbind: (el) ->
$(el).off('change', @callback)
rivets.formatters.length = (value) ->
if value then value.length else 0
rivets.binders.input =
publishes: true
routine: rivets.binders.value.routine
bind: (el) ->
$(el).bind('input.rivets', this.publish)
unbind: (el) ->
$(el).unbind('input.rivets')
rivets.configure
prefix: "rv"
adapter:
subscribe: (obj, keypath, callback) ->
callback.wrapped = (m, v) -> callback(v)
obj.on('change:' + keypath, callback.wrapped)
unsubscribe: (obj, keypath, callback) ->
obj.off('change:' + keypath, callback.wrapped)
read: (obj, keypath) ->
if keypath is "cid" then return obj.cid
obj.get(keypath)
publish: (obj, keypath, value) ->
if obj.cid
obj.set(keypath, value);
else
obj[keypath] = value