--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Popcorn footnote Plug-in Demo</title>
+
+ <script src="../../popcorn.js"></script>
+ <script src="popcorn.redflash.js"></script>
+ <script>
+ document.addEventListener('DOMContentLoaded', function () {
+
+ Popcorn.plugin( "test" , {
+
+ manifest: {
+ about:{
+ name: "Popcorn Redflash Effect",
+ version: "0.1",
+ author: "@scottdowne",
+ website: "scottdowne.wordpress.com"
+ },
+ options:{
+ plugin: true
+ }
+ },
+ _setup: function( options ) {
+
+ console.log( "in test setup " );
+ },
+ start: function( event, options ){
+
+ console.log( "in test start" );
+ },
+ end: function( event, options ){
+
+ console.log( "in test end" );
+ },
+ _teardown: function( options ) {
+
+ console.log( "in test teardown" );
+ }
+ });
+
+ var p = Popcorn('#video')
+ .play()
+ .test({
+ start: 5, // seconds
+ end: 15, // seconds
+ text: 'This video made exclusively for drumbeat.org',
+ effect: "redflash redflash2"
+ })
+ .test({
+ start: 20, // seconds
+ end: 45, // seconds
+ text: 'Visit webmademovies.org for more details'
+ })
+
+ }, false);
+
+ </script>
+</head>
+<body>
+ <h1 id="qunit-header">Popcorn Footnote Plug-in Demo</h1>
+ <p> A footnote displaying This video made exclusively for drumbeat.org' will appear at 5 seconds and disappear at 15 seconds.</p>
+ <p> A footnote displaying 'Visit webmademovies.org for more details' will appear at 20 seconds and disappear at 45 seconds.</p>
+ <div>
+ <video id='video'
+ controls preload='none'
+ width= '250px'
+ poster="../../test/poster.png">
+
+ <source id='mp4'
+ src="../../test/trailer.mp4"
+ type='video/mp4; codecs="avc1, mp4a"'>
+
+ <source id='ogv'
+ src="../../test/trailer.ogv"
+ type='video/ogg; codecs="theora, vorbis"'>
+
+ <p>Your user agent does not support the HTML5 Video element.</p>
+
+ </video>
+ </div>
+ </div>
+</body>
+</html>
--- /dev/null
+// EFFECT: Redflash
+
+(function (Popcorn) {
+
+ /**
+ * Footnote popcorn plug-in
+ * Adds text to an element on the page.
+ * Options parameter will need a start, end, target and text.
+ * Start is the time that you want this plug-in to execute
+ * End is the time that you want this plug-in to stop executing
+ * Text is the text that you want to appear in the target
+ * Target is the id of the document element that the text needs to be
+ * attached to, this target element must exist on the DOM
+ *
+ * @param {Object} options
+ *
+ * Example:
+ var p = Popcorn('#video')
+ .footnote({
+ start: 5, // seconds
+ end: 15, // seconds
+ text: 'This video made exclusively for drumbeat.org',
+ target: 'footnotediv'
+ } )
+ *
+ */
+ Popcorn.effect( "redflash" , {
+
+ manifest: {
+ about:{
+ name: "Popcorn Redflash Effect",
+ version: "0.1",
+ author: "@scottdowne",
+ website: "scottdowne.wordpress.com"
+ },
+ options:{
+ effect: true
+ }
+ },
+ _setup: function( options ) {
+
+ console.log( "in effect setup" );
+ },
+ start: function( event, options ){
+
+ console.log( "in effect start" );
+ },
+ end: function( event, options ){
+
+ console.log( "in effect end" );
+ },
+ _teardown: function( options ) {
+
+ console.log( "in effect teardown" );
+ }
+ });
+ Popcorn.effect( "redflash2" , {
+
+ manifest: {
+ about:{
+ name: "Popcorn Redflash Effect",
+ version: "0.1",
+ author: "@scottdowne",
+ website: "scottdowne.wordpress.com"
+ },
+ options:{
+ effect: true
+ }
+ },
+ _setup: function( options ) {
+
+ console.log( "in effect 2 setup" );
+ },
+ start: function( event, options ){
+
+ console.log( "in effect start" );
+ },
+ end: function( event, options ){
+
+ console.log( "in effect end" );
+ },
+ _teardown: function( options ) {
+
+ console.log( "in effect teardown" );
+ }
+ });
+
+})( Popcorn );
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Popcorn API</title>
+ <link rel="stylesheet" href="../../test/qunit/qunit.css" type="text/css" media="screen">
+ <script src="../../test/qunit/qunit.js"></script>
+ <!--
+ do not move - this must be called immediately prior to
+ popcorn-api-draft.js
+ -->
+
+ <script src="../../popcorn.js"></script>
+ <script src="popcorn.footnote.js"></script>
+
+ <script src="popcorn.footnote.unit.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Popcorn Footnote Plugin</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-fixture"> </div>
+
+ <video id='video'
+ controls preload='none'
+ width= '250px'
+ poster="../../test/poster.png">
+
+ <source id='mp4'
+ src="../../test/trailer.mp4"
+ type='video/mp4; codecs="avc1, mp4a"'>
+
+ <source id='ogv'
+ src="../../test/trailer.ogv"
+ type='video/ogg; codecs="theora, vorbis"'>
+
+ <p>Your user agent does not support the HTML5 Video element.</p>
+
+ </video>
+ <div id="footnotediv"></div>
+</body>
+</html>
--- /dev/null
+test("Popcorn Footnote Plugin", function () {
+
+ var popped = Popcorn("#video"),
+ expects = 8,
+ count = 0,
+ setupId,
+ footnotediv = document.getElementById('footnotediv');
+
+ expect(expects);
+
+ function plus() {
+ if ( ++count===expects) {
+ start();
+ }
+ }
+
+ stop();
+
+ ok ('footnote' in popped, "footnote is a mehtod of the popped instance");
+ plus();
+
+ equals ( footnotediv.childElementCount, 0, "initially, there is nothing inside the footnotediv" );
+ plus();
+
+ popped.footnote({
+ start: 0, // seconds
+ end: 2, // seconds
+ text: 'This video made exclusively for drumbeat.org',
+ target: 'footnotediv'
+ })
+ .footnote({
+ start: 2, // seconds
+ end: 4, // seconds
+ text: 'Visit webmademovies.org for more details',
+ target: 'footnotediv'
+ });
+
+ setupId = popped.getLastTrackEventId();
+
+ popped.exec( 0, function() {
+ equals ( footnotediv.childElementCount, 2, "footnotediv now has two inner elements" );
+ plus();
+ equals (footnotediv.children[0].innerHTML , "This video made exclusively for drumbeat.org", "footnote displaing correct information" );
+ plus();
+ equals (footnotediv.children[0].style.display , "inline", "footnote is visible on the page" );
+ plus();
+ });
+
+ popped.exec( 3, function() {
+ equals (footnotediv.children[1].style.display , "inline", "second footnote is visible on the page" );
+ plus();
+ });
+
+ popped.exec( 4, function() {
+ ok (footnotediv.children[1].style.display === 'none' && footnotediv.children[0].style.display === 'none', "footnote are no longer vidible on the page" );
+ plus();
+
+ popped.pause().removeTrackEvent( setupId );
+ ok( !footnotediv.children[1], "removed footnote was properly destroyed" );
+ plus();
+ });
+ popped.play().volume(0);
+
+});
setup,
isfn = typeof definition === "function";
+ var extendFunction = function( first, second ) {
+
+ return function() {
+
+ first.apply( this, arguments );
+ second.apply( this, arguments );
+ };
+ };
+
// If `manifest` arg is undefined, check for manifest within the `definition` object
// If no `definition.manifest`, an empty object is a sufficient fallback
if ( !manifest ) {
}
// Storing the plugin natives
- options._natives = setup;
+ options._natives = {}; //setup;
+
+ Popcorn.extend( options._natives, setup );
+
options._natives.type = name;
options._running = false;
+ // default to an empty string if no effect exists
+ // split string into an array of effects
+ options.effect = options.effect && options.effect.split( " " ) || [];
+
+ for ( var i = 0; i < options.effect.length; i++ ) {
+
+ options._natives._setup = extendFunction( options._natives._setup, Popcorn.effects[ options.effect[ i ] ]._setup );
+ options._natives._teardown = extendFunction( options._natives._teardown, Popcorn.effects[ options.effect[ i ] ]._teardown );
+ options._natives.start = extendFunction( options._natives.start, Popcorn.effects[ options.effect[ i ] ].start );
+ options._natives.end = extendFunction( options._natives.end, Popcorn.effects[ options.effect[ i ] ].end );
+ }
+
// Ensure a manifest object, an empty object is a sufficient fallback
options._natives.manifest = manifest;
options.end = this.duration() || Number.MAX_VALUE;
}
- // If a _setup was declared, then call it before
- // the events commence
- if ( "_setup" in setup && typeof setup._setup === "function" ) {
+ // Resolves 239, 241, 242
+ if ( !options.target ) {
- // Resolves 239, 241, 242
- if ( !options.target ) {
+ // Sometimes the manifest may be missing entirely
+ // or it has an options object that doesn't have a `target` property
- // Sometimes the manifest may be missing entirely
- // or it has an options object that doesn't have a `target` property
+ var manifestopts = "options" in manifest && manifest.options;
- var manifestopts = "options" in manifest && manifest.options;
-
- options.target = manifestopts && "target" in manifestopts && manifestopts.target;
- }
-
- setup._setup.call( this, options );
+ options.target = manifestopts && "target" in manifestopts && manifestopts.target;
}
+ options._natives._setup && options._natives._setup.call( this, options );
+
Popcorn.addTrackEvent( this, options );
// Future support for plugin event definitions
}
};
-
- // Popcorn Plugin Inheritance Helper Methods
- // Internal use only
- Popcorn.plugin.getDefinition = function( name ) {
-
- var registry = Popcorn.registryByName;
-
- if ( registry[ name ] ) {
- return registry[ name ];
- }
-
- Popcorn.error( "Cannot inherit from " + name + "; Object does not exist" );
- };
-
- // Internal use only
- Popcorn.plugin.delegate = function( instance, name, plugins ) {
-
- return function() {
- var args = arguments;
- plugins.forEach( function( plugin ) {
- // The new plugin simply calls the delegated methods on
- // all of its parents in the order they were specified.
- plugin[ name ] && plugin[ name ].apply( instance, args );
- });
- };
- };
+ Popcorn.effects = {};
// Plugin inheritance
- Popcorn.plugin.inherit = function( name, parents, definition, manifest ) {
-
-
- // Get the names of all of the ancestor classes, in the order that
- // we will be calling them. The override is for the class we're
- // currently defining, since it's not in the registry yet.
- var ancestors = [],
- pluginFn, entry;
-
- function getAncestors( name, override ) {
- var parents = override || Popcorn.plugin.getDefinition( name ).parents;
- for ( var i in parents ) {
- if ( hasOwn.call( parents, i ) ) {
- var p = parents[ i ];
- getAncestors( p );
- if ( ancestors.indexOf( p ) === -1 ) {
- ancestors.push( p );
- }
- }
- }
- }
-
- getAncestors( name, Popcorn.isArray( parents ) ? parents : [ parents ] );
- ancestors.push( name );
-
- // Now create the requested plugin under the reqested name.
- pluginFn = Popcorn.plugin( name, function( options ) {
-
- var self = this,
- plugins;
+ Popcorn.effect = function( name, definition, manifest ) {
- function instantiate( definition ) {
- return definition.call && definition.call( self, options ) || definition;
- }
-
- // When the newly-defined plugin is instantiated, it must
- // explicitly instantiate all of its ancestors.
- plugins = ancestors.map( function( name ) {
- return instantiate( Popcorn.plugin.getDefinition( name ).base );
- });
-
- return {
- _setup: Popcorn.plugin.delegate( self, "_setup", plugins ),
- start: Popcorn.plugin.delegate( self, "start", plugins ),
- end: Popcorn.plugin.delegate( self, "end", plugins )
- };
-
- }, manifest || definition.manifest );
-
- entry = Popcorn.plugin.getDefinition( name );
- entry.base = definition;
- entry.parents = parents;
+ // If `manifest` arg is undefined, check for manifest within the `definition` object
+ // If no `definition.manifest`, an empty object is a sufficient fallback
+ Popcorn.manifest[ name ] = manifest = manifest || definition.manifest || {};
- return pluginFn;
+ // register the effect by name
+ Popcorn.effects[ name ] = definition;
};
- // Augment Popcorn;
- Popcorn.inherit = Popcorn.plugin.inherit;
-
// stores parsers keyed on filetype
Popcorn.parsers = {};