}
// Provides some sugar, but ultimately extends
- // the definition into Popcorn.p
-
- var reserved = [ "start", "end"],
+ // the definition into Popcorn.p
+
+ var reserved = [ "start", "end"],
plugin = {},
- pluginFn,
setup;
-
- if ( typeof definition === "object" ) {
-
- setup = definition;
+
+ function pluginFn ( setup, options ) {
+
+ if ( !options ) {
+ return this;
+ }
+
+ // storing the plugin natives
+ options._natives = setup;
+ options._natives.type = name;
+ options._running = false;
+
- /*if ( !( "timeupdate" in setup ) ) {
- setup.timeupdate = Popcorn.nop;
- }*/
++ // ensure a manifest object
++ options._natives.manifest = manifest || setup.manifest || {};
- pluginFn = function ( options ) {
-
- if ( !options ) {
- return this;
- }
-
- // storing the plugin natives
- options._natives = setup;
- options._natives.type = name;
- options._running = false;
-
- // Checks for expected properties
- if ( !( "start" in options ) ) {
- options.start = 0;
- }
-
- if ( !( "end" in options ) ) {
- options.end = this.duration();
- }
+ // Checks for expected properties
+ if ( !( "start" in options ) ) {
+ options.start = 0;
+ }
- // If a _setup was declared, then call it before
- // the events commence
-
- if ( "_setup" in setup && typeof setup._setup === "function" ) {
-
- // Resolves 239, 241, 242
- options.target ||
- ( setup.manifest.options.target &&
- ( options.target = setup.manifest.options.target ) );
+ if ( !( "end" in options ) ) {
+ options.end = this.duration();
+ }
+
+ // If a _setup was declared, then call it before
+ // the events commence
- setup._setup.call( this, options );
+ if ( "_setup" in setup && typeof setup._setup === "function" ) {
+
+ // Resolves 239, 241, 242
- if ( !options.target )
- options.target = (manifest && manifest.options.target) || ("manifest" in setup && setup.manifest.options.target);
++ if ( !options.target ) {
++ options.target = ( manifest && manifest.options.target ) ||
++ ( "manifest" in setup && setup.manifest.options.target );
+ }
+
- Popcorn.addTrackEvent( this, options );
+ setup._setup.call( this, options );
+ }
-
- // Future support for plugin event definitions
- // for all of the native events
- Popcorn.forEach( setup, function ( callback, type ) {
-
- if ( type !== "type" ) {
-
- if ( reserved.indexOf(type) === -1 ) {
- this.listen( type, callback );
- }
+ Popcorn.addTrackEvent( this, options );
+
+
+ // Future support for plugin event definitions
+ // for all of the native events
+ Popcorn.forEach( setup, function ( callback, type ) {
+
+ if ( type !== "type" ) {
+
+ if ( reserved.indexOf(type) === -1 ) {
+
+ this.listen( type, callback );
}
-
- }, this);
-
- return this;
- };
- }
-
- // If a function is passed...
- if ( typeof definition === "function" ) {
-
- // Execute and capture returned object
- setup = definition.call(this);
-
- // Ensure an object was returned
- // it has properties and isnt an array
- if ( typeof setup === "object" &&
- !( "length" in setup ) ) {
-
- Popcorn.plugin( name, setup );
- }
- return;
+ }
+
+ }, this);
+
+ return this;
+ };
+
+ // Augment the manifest object
- if ( manifest || ("manifest" in definition) ) {
++ if ( manifest || ( "manifest" in definition ) ) {
+ Popcorn.manifest[ name ] = manifest || definition.manifest;
}
-
- // Assign new named definition
- plugin[ name ] = pluginFn;
-
+
+ // Assign new named definition
- if ( typeof definition === "object" ) {
- plugin[ name ] = function( options ) {
- return pluginFn.call( this, definition, options );
- };
- }
- else if ( typeof definition === "function" ) {
- plugin[ name ] = function( options ) {
- return pluginFn.call( this, definition.call( this, options ), options );
- };
- }
++ plugin[ name ] = function( options ) {
++ return pluginFn.call( this, typeof definition === "function" ?
++ definition.call( this, options ) :
++ definition, options );
++ };
+
// Extend Popcorn.p with new named definition
Popcorn.extend( Popcorn.p, plugin );
-
+
// Push into the registry
Popcorn.registry.push( Popcorn.extend( plugin, {
type: name