Skip to content

Instantly share code, notes, and snippets.

@codingisacopingstrategy
Created December 4, 2013 17:29
Show Gist options
  • Save codingisacopingstrategy/7791856 to your computer and use it in GitHub Desktop.
Save codingisacopingstrategy/7791856 to your computer and use it in GitHub Desktop.
Example on http://popcornjs.org/popcorn-docs/addon-development/ with the hardcoded linenumbers removed. var nodes = document.querySelectorAll(".lineno"); for (var i=0; i < nodes.length; i++) { var node = nodes[i]; node.parentNode.removeChild(node) };
// 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 ) {
// 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 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment