-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathstickit.backbone.txt
83 lines (79 loc) · 8.01 KB
/
stickit.backbone.txt
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
┏━━━━━━━━━━━━━┓
┃ STICKIT ┃
┗━━━━━━━━━━━━━┛
VERSION ==> #0.9.2
SUMMARY ==> #VIEW.bindings { SELECTOR: "VAR" }, then VIEW.stickit() will maintain VIEW.model.VAR and
#$(SELECTOR).text() in sync.
#For forms: checked attribute for radio|checkbox, <select> must specify <option>
#Can customize: getters/setters (including setting HTML attribute/class/visibility),
#listened DOM events, stop flag, callbacks
VIEW.bindings #{ SELECTOR: CONF ... }[()], def. value of BIND_OBJ
#SELECTOR can be ":el", i.e. VIEW.$el
#CONF is OBJ or STR (same as { observe: STR })
VIEW.[un]stickit #Sets-up two-way data binding between:
([[MODEL, ]BIND_OBJ]) # - JQ $(SELECTOR)
VIEW.addBinding # - and MODEL.VAR, using MODEL (def: VIEW.model) and CONF.observe "VAR"[_ARR][()]
(MODEL|null, SELECTOR, CONF) # - if ARR, must use CONF.onGet(ARR)->STR and CONF.onSet(STR)->ARR
#Must be called once DOM is setup, e.g. at end of VIEW.render() or in onRender(). Does:
# +-----------------------------------------+----------------------------------------------+
# | MODEL TO VIEW | VIEW TO MODEL |
# +-----------------------------------------+----------------------------------------------+
LISTEN TO EVENTS ==> # | "change:VAR" | CONF.events STR_ARR (def: ["change","input"])|
# | | (jQuery events) |
# +-----------------------------------------+----------------------------------------------+
GETS VALUE ==> # | MODEL.get|escape("VAR"), according to | JQ.UMETHOD, with CONF.updateMethod "UMETHOD" |
# | CONF.escape BOOL[(VAR, CONF)] | (def: "text"), |
# | (def: false) | or CONF.getVal(JQ, JQEVENT, CONF)->VAL |
# +-----------------------------------------+----------------------------------------------+
CAN MODIFY GET VALUE ==> # | CONF.onGet(VAL, CONF)->VAL | CONF.onSet(VAL, CONF)->VAL |
# +-----------------------------------------+----------------------------------------------+
SETS VALUE ==> # | - JQ.UMETHOD(VAL), | MODEL.set("VAR", VAL, CONF.setOptions) |
# | with CONF.updateMethod "UMETHOD" | with CONF.setOptions.stickitChange CONF |
# | (def: "text"), | |
# | or CONF.update(JQ, VAL, MODEL, CONF) | |
# | - if CONF.visible BOOL[(VAL, CONF)] true| |
# | - MODEL.VAR must be BOOL | |
# | - use JQ.toggle(BOOL), | |
# | or CONF.visibleFn(JQ, BOOL, CONF) | |
# | - CONF.updateView def to false | |
# | - sets HTML attribute with | |
# | CONF.attributes OBJ_ARR: | |
# | - name "ATTR" | |
# | - observe (def: CONF.observe) | |
# | and onGet(): same as CONF | |
# | - sets HTML classes with CONF.classes | |
# | { CLASS: "VAR"[_ARR][()] } | |
# | Use JQ.toggleClass() | |
# +-----------------------------------------+----------------------------------------------+
UNLESS ==> # | CONF.updateView BOOL[(VAL,JQEVENT,CONF)]| CONF.updateModel BOOL[(VAL, JQEVENT, CONF)] |
# | false (def: true) | false (def, except if form element or |
# | | contenteditable) |
# +-----------------------------------------+----------------------------------------------+
#All FUNC above can also be "FUNC", i.e. VIEW.FUNC()
#Forms use CONF.updateMethod "val" (so MODEL will get a STR), except contenteditable,
#using "html". Also:
# - radio: sets HTML attribute "checked"
# - checkbox: same but MODEL.VAR can be an ARR for checkbox
# - select:
# - sets like checkbox but for <option> HTML attribute "selected"
# - <option> are:
# - CONF.selectOptions S_OBJ:
# - collection S_VAL[()], where S_VAL can be:
# - { LABEL: VALUE ... }
# - OBJ_ARR:
# - label LABEL (can change attribute name with S_OBJ.valuePath)
# - value VALUE (can change attribute name with S_OBJ.valuePath)
# - disabled BOOL (can change attribute name with S_OBJ.disabledPath)
# - COLL, with toJSON()->OBJ_ARR
# Will listen to COLL add|remove|reset|sort events.
# - VARR: _.get(window,VARR)->S_VAL
# - { opt_labels: OLABEL_STR_ARR, OLABEL: S_VAL[()] ... }, for <optgroup>
# - defaultOption: same as above, but single element for default choice
# - or HTML attributes data-stickit-bind-val="VALUE" or value="VALUE"
# - cannot use CONF.updateView false
#Callbacks:
# - CONF.afterUpdate(JQ, VAL, CONF): after VIEW updated
# - CONF.initialize(JQ, MODEL, CONF): after stickit() done
# - CONF.destroy(JQ, MODEL, CONF)
Backbone.Stickit.addHandler
(CONF[_ARR]) #Define default CONF values, when BIND_OBJ.SELECTOR matches CONF.selector SELECTOR