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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
| // Pattern 1
// Provide a function that returns an object
(function( Popcorn ) {
Popcorn.plugin( "pluginName" , function( options ) {
// do stuff
// this refers to the popcorn object
// You are required to return an object
// with a start and end property
return {
_setup: function( track ) {
// setup code, fire on initialization
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
_update: function( track, updates ) {
// update code, fire on update/modification of a plugin created track event.
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// |updates| refers to the new plugin data to be applied,
// loop through this and apply the necessary updates to track
// this refers to the popcorn object
},
_teardown: function( track ) {
// teardown code, fire on removal of plugin or destruction of instance
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
start: function( event, track ) {
// fire on track.start
// |event| refers to the event object
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
end: function( event, track ) {
// fire on track.end
// |event| refers to the event object
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
frame: function( event, track ) {
// when frameAnimation is enabled, fire on every frame between start and end
// |event| refers to the event object
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
toString: function() {
// provide a custom toString method for each plugin
// defaults to return start, end, id, and target
// this refers to the popcorn object
}
};
});
})(Popcorn);
// Pattern 2
// Provide an object
// Popcorn will manage the events
(function( Popcorn ) {
Popcorn.plugin( "pluginName" , {
_setup: function( track ) {
// setup code, fire on initialization
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
_update: function( track ) {
// update code, fire on update/modification of a plugin created track event.
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
_teardown: function( track ) {
// teardown code, fire on removal of plugin or destruction of instance
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
start: function( event, track ) {
// fire on track.start
// |event| refers to the event object
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
end: function( event, track ) {
// fire on track.end
// |event| refers to the event object
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
frame: function( event, track ) {
// when frameAnimation is enabled, fire on every frame between start and end
// |event| refers to the event object
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
toString: function() {
// provide a custom toString method for each plugin
// defaults to return start, end, id, and target
// this refers to the popcorn object
}
});
})(Popcorn);
// Pattern 3
// Provide an object with a plugin wide name space
// Popcorn will manage the events
(function( Popcorn ) {
Popcorn.plugin( "pluginName", (function() {
// Define plugin wide variables out here
return {
_setup: function( track ) {
// setup code, fire on initialization
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
_update: function( track ) {
// update code, fire on update/modification of a plugin created track event.
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
_teardown: function( track ) {
// teardown code, fire on removal of plugin or destruction of instance
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
start: function( event, track ) {
// fire on track.start
// |event| refers to the event object
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
end: function( event, track ) {
// fire on track.end
// |event| refers to the event object
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
frame: function( event, track ) {
// when frameAnimation is enabled, fire on every frame between start and end
// |event| refers to the event object
// |track| refers to the TrackEvent created by the options passed
// into the plugin on init
// this refers to the popcorn object
},
toString: function() {
// provide a custom toString method for each plugin
// defaults to return start, end, id, and target
// this refers to the popcorn object
}
};
})();
})(Popcorn);
|