From cc351dd3f70f1bf4c21ceddfb4b767608450fdd6 Mon Sep 17 00:00:00 2001 From: Daniel Brooks Date: Mon, 14 Feb 2011 11:28:26 -0600 Subject: [PATCH] initial impl, not tested yet. will probably have to write additional tests --- popcorn.js | 115 ++++++++++++++++++++++------------------------------- 1 file changed, 47 insertions(+), 68 deletions(-) diff --git a/popcorn.js b/popcorn.js index 6ae2e38..12053e6 100644 --- a/popcorn.js +++ b/popcorn.js @@ -626,90 +626,69 @@ var reserved = [ "start", "end"], plugin = {}, - pluginFn, setup; - if ( typeof definition === "object" ) { + function pluginFn ( setup, options ) { - setup = definition; + if ( !options ) { + return this; + } - /*if ( !( "timeupdate" in setup ) ) { - setup.timeupdate = Popcorn.nop; - }*/ + // storing the plugin natives + options._natives = setup; + options._natives.type = name; + options._running = false; - 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 ( !( "end" in options ) ) { + options.end = this.duration(); + } - // If a _setup was declared, then call it before - // the events commence + // If a _setup was declared, then call it before + // the events commence + + if ( "_setup" in setup && typeof setup._setup === "function" ) { - if ( "_setup" in setup && typeof setup._setup === "function" ) { - - // Resolves 239, 241, 242 - options.target || - ( setup.manifest.options.target && - ( options.target = setup.manifest.options.target ) ); + // Resolves 239, 241, 242 + options.target || + ( setup.manifest.options.target && + ( options.target = setup.manifest.options.target ) ); - setup._setup.call( this, options ); - } - + setup._setup.call( this, options ); + } + - Popcorn.addTrackEvent( this, options ); + 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" ) { - // 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 ) { + if ( reserved.indexOf(type) === -1 ) { - this.listen( type, callback ); - } + this.listen( type, callback ); } - - }, this); + } - return this; - }; - } - - // If a function is passed... - if ( typeof definition === "function" ) { + }, this); - // 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; - } - + return this; + }; + // Assign new named definition - plugin[ name ] = pluginFn; + if ( typeof definition === "object" ) { + plugin[ name ] = function(options) { return pluginFn(definition, options); }; + } + else if ( typeof definition === "function" ) { + plugin[ name ] = function(options) { return pluginFn(definition(), options); }; + } // Extend Popcorn.p with new named definition Popcorn.extend( Popcorn.p, plugin ); -- 2.43.0