@@ -6,63 +6,93 @@ vim: ft=javascript
6
6
7
7
### Initialization
8
8
9
- new Ractive ( {
10
- el : $ ( '..' ) ,
11
- el : '#box' ,
12
- template : '...' , // required
13
-
14
- // callbacks
15
- init : function ( ) // on instanciate
16
- complete : function ( ) // on finish animations
17
-
18
- // objs
19
- data : { ... }
20
- partials : { ... } // global: Ractive.partials
21
- transitions : { ... } // global: Ractive.transitions
22
- components : { ... }
23
- adaptors : [ ... ]
24
-
25
- // options
26
- magic : false
27
- modifyArrays : true
28
- twoway : true
29
- noIntro : true // true = disable transition on initial render
30
- lazy : false // false = use keyevents, true = use change/blur
31
- append : false // false = overwrite element, true = append
32
- debug : false
33
- sanitize : false
34
- } )
9
+ new Ractive ( {
10
+ el : $ ( '..' ) ,
11
+ el : '#box' ,
12
+ template : '...' , // required
13
+
14
+ // callbacks
15
+ init : function ( ) // on instanciate
16
+ complete : function ( ) // on finish animations
17
+
18
+ // objs
19
+ data : { ... }
20
+ partials : { ... } // global: Ractive.partials
21
+ transitions : { ... } // global: Ractive.transitions
22
+ components : { ... }
23
+ adaptors : [ ... ]
24
+
25
+ // options
26
+ magic : false
27
+ modifyArrays : true
28
+ twoway : true
29
+ noIntro : true // true = disable transition on initial render
30
+ lazy : false // false = use keyevents, true = use change/blur
31
+ append : false // false = overwrite element, true = append
32
+ debug : false
33
+ sanitize : false
34
+ } )
35
35
36
+ http :/ / docs . ractivejs . org / latest / initialisation - options
37
+
38
+ ### Instance methods
39
+
40
+ view . set ( 'a' , true )
41
+ view . set ( { a : true } )
42
+ view . merge ( ...)
43
+ view . get ( 'a' )
44
+
45
+ view . on ( 'event' , function ( ) { ... } ) ;
46
+ view . fire ( 'event' ) ;
47
+
48
+ view . update ( )
49
+ view . updateModel ( )
50
+
51
+ view . find ( '.klass' )
52
+ view . findAll ( '.klass' )
53
+ view . nodes
54
+ view . nodes [ 'hello' ] // .find('#hello')
36
55
37
56
http :/ / docs . ractivejs . org / latest / initialisation - options
38
57
58
+ ### Extend
59
+
60
+ View = Ractive . extend ( {
61
+ ...
62
+ } )
63
+ new View ( )
64
+
39
65
### Components
40
66
41
- Widget = Ractive . extend ( { ... } )
67
+ Widget = Ractive . extend ( { ... } )
42
68
43
- ractive = new Ractive ( {
44
- el : 'main' ,
45
- template : '<widget foo="bar"/>' ,
46
- components : {
47
- widget : Widget
48
- }
49
- } ) ;
69
+ ractive = new Ractive ( {
70
+ el : 'main' ,
71
+ template : '<widget foo="bar"/>' ,
72
+ components : {
73
+ widget : Widget
74
+ }
75
+ } ) ;
50
76
51
77
https :/ / github . com / RactiveJS / Ractive / issues / 74
52
78
https :/ / github . com / RactiveJS / Ractive / wiki / Components
53
79
54
80
### Partials
55
81
56
- // Global partials
57
- Ractive . partials . x = "<..>"
82
+ // Global partials
83
+ Ractive . partials . x = "<..>"
58
84
59
85
### Events
60
86
61
- < button on - click = 'activate' > Activate ! </ button >
87
+ view . on ( 'teardown' )
62
88
63
- view . on ( {
64
- activate : function ( ) { ... }
65
- } ) ;
89
+ ### DOM Events
90
+
91
+ < button on - click = 'activate' > Activate ! </button >
92
+
93
+ view . on ( {
94
+ activate : function ( ) { ... }
95
+ } ) ;
66
96
67
97
< button on - click = 'sort:name' > Sort by name < / b u t t o n >
68
98
view . on ( 'sort' , function ( e , column ) {
@@ -77,23 +107,23 @@ https://github.com/RactiveJS/Ractive/wiki/Components
77
107
78
108
### Markup
79
109
80
- Hello , { { name} }
110
+ Hello , { { name} }
81
111
Body : { { { unescaped} } }
82
112
83
113
<!-- each -->
84
- { { #list :i } }
85
- < li > { { this . name} } </ li >
86
- < li > { { name} } < / l i >
87
- < li > { { . } } < / l i > < ! - - s a m e a s ' t h i s ' - - >
88
- { { / #list } }
114
+ { { #mylist :i } }
115
+ < li > { { this . name} } </ li >
116
+ < li > { { name} } < / l i >
117
+ < li > { { . } } < / l i > < ! - - s a m e a s ' t h i s ' - - >
118
+ { { / mylist } }
89
119
90
120
{ { ^ user } } Not logged in { { / u s e r } } < ! - - i f f a l s e - - >
91
121
{ { #user} } Welcome , sire { { / u s e r } } < ! - - i f t r u e - - >
92
122
93
- { { > partialName } }
94
- < component >
123
+ { { > partialName} }
124
+ < component >
95
125
96
- { { #statusDogs[ selected ] } }
126
+ { { #statusDogs[ selected ] } }
97
127
98
128
### Transformed attributes
99
129
@@ -109,21 +139,67 @@ This transforms the `list` attribute via a helper function called `sort()`.
109
139
110
140
### Transitions
111
141
112
- < div intro = "fade" >
113
- < div intro = "bump" >
114
- < div intro = "bump:{duration:400}" >
142
+ < div intro = "fade" >
143
+ < div intro = "bump" >
144
+ < div intro = "bump:{duration:400}" >
145
+
146
+ Ractive.transitions.bump = function(t, params) {
147
+ params = t . processParams ( params , {
148
+ duration : 400 ,
149
+ color : t . isIntro ? 'rgb(0,255,0)' : 'rgb(255,0,0)'
150
+ } ) ;
151
+
152
+ if ( t . isIntro ) {
153
+ /* enter */
154
+ } else {
155
+ /* exit */
156
+ }
157
+
158
+ t.complete();
159
+ } ;
160
+
161
+ ### Decorators
162
+
163
+ < span decorator = "tooltip:hello there" > Hover me</ span >
164
+
165
+ decorators: {
166
+ tooltip : function ( node , content ) {
167
+ // setup code here
168
+ return {
169
+ teardown : function ( ) {
170
+ // cleanup code here
171
+ }
172
+ }
173
+ }
174
+ }
175
+
176
+ < span decorator = "tooltip:'a','b',2,'c'" > Hover me</ span >
177
+
178
+ tooltip: function (node, a, b, two, c) { ... }
179
+
180
+ http://docs.ractivejs.org/latest/decorators
181
+
182
+ ### Adaptors
115
183
116
- Ractive.transitions.bump = function(t, params) {
117
- params = t . processParams ( params , {
118
- duration : 400 ,
119
- color : t . isIntro ? 'rgb(0,255,0)' : 'rgb(255,0,0)'
120
- } ) ;
184
+ myAdaptor = {
185
+ filter : function ( object , keypath , ractive ) {
186
+ // return `true` if a particular object is of the type we want to adapt
187
+ } ,
188
+ wrap : function ( ractive , object , keypath , prefixer ) {
189
+ // set up event bindings here
190
+ object . on ( 'change' , function ( ) { ractive . set ( prefixer ( { ...} ) ) ; } ) ;
191
+ // then return a wrapper:
192
+ return {
193
+ teardown : function ( ) { . . } ,
194
+ // json representation
195
+ get : function ( ) { return { a :2 , b :3 , c :4 , ... } ; } ,
196
+ // called on ractive.set
197
+ set : function ( key , val ) { } ,
198
+ // called on ractive.set on root (return false = die)
199
+ reset : function ( data ) { return false ; }
200
+ } ;
201
+ }
202
+ } ;
121
203
122
- if ( t . isIntro ) {
123
- /* enter */
124
- } else {
125
- /* exit */
126
- }
127
204
128
- t.complete();
129
- } ;
205
+ http://docs.ractivejs.org/latest/adaptors
0 commit comments