diff --git a/popcorn.js b/popcorn.js index b4c759e82..bf5004c9f 100644 --- a/popcorn.js +++ b/popcorn.js @@ -1378,7 +1378,7 @@ // Storing the plugin natives var natives = options._natives = {}, compose = "", - defaults, originalOpts, manifestOpts, mergedSetupOpts; + originalOpts, manifestOpts; Popcorn.extend( natives, setup ); @@ -1401,9 +1401,6 @@ args[ 1 ]._running && natives.end.apply( this, args ); }, natives._teardown ); - // Check for previously set default options - defaults = this.options.defaults && this.options.defaults[ options._natives && options._natives.type ]; - // default to an empty string if no effect exists // split string into an array of effects options.compose = options.compose && options.compose.split( " " ) || []; @@ -1454,25 +1451,21 @@ }; } - // Merge with defaults if they exist, make sure per call is prioritized - mergedSetupOpts = defaults ? Popcorn.extend( {}, defaults, options ) : - options; - // Resolves 239, 241, 242 - if ( !mergedSetupOpts.target ) { + if ( !options.target ) { // Sometimes the manifest may be missing entirely // or it has an options object that doesn't have a `target` property manifestOpts = "options" in manifest && manifest.options; - mergedSetupOpts.target = manifestOpts && "target" in manifestOpts && manifestOpts.target; + options.target = manifestOpts && "target" in manifestOpts && manifestOpts.target; } // Trigger _setup method if exists - options._natives._setup && options._natives._setup.call( this, mergedSetupOpts ); + options._natives._setup && options._natives._setup.call( this, options ); // Create new track event for this instance - Popcorn.addTrackEvent( this, Popcorn.extend( mergedSetupOpts, options ) ); + Popcorn.addTrackEvent( this, Popcorn.extend( options, options ) ); // Future support for plugin event definitions // for all of the native events @@ -1494,8 +1487,13 @@ // Extend Popcorn.p with new named definition // Assign new named definition Popcorn.p[ name ] = plugin[ name ] = function( options ) { - return pluginFn.call( this, isfn ? definition.call( this, options ) : definition, - options ); + + // Merge with defaults if they exist, make sure per call is prioritized + var defaults = ( this.options.defaults && this.options.defaults[ name ] ) || {}, + mergedSetupOpts = Popcorn.extend( {}, defaults, options ); + + return pluginFn.call( this, isfn ? definition.call( this, mergedSetupOpts ) : definition, + mergedSetupOpts ); }; // Push into the registry diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 0f9972084..03b94854f 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -1630,13 +1630,13 @@ test( "Manifest removal", function() { test( "Configurable Defaults", function() { - var expects = 13, + var expects = 14, count = 0, p; function plus() { if ( ++count === expects ) { - [ "configurable", "multiconfig", "overridden" ].forEach(function( val ) { + [ "configurable", "multiconfig", "overridden", "funtionInitDefaults" ].forEach(function( val ) { Popcorn.removePlugin( val ); delete Popcorn.manifest[ val ]; }); @@ -1723,6 +1723,17 @@ test( "Configurable Defaults", function() { }; }); + Popcorn.plugin( "funtionInitDefaults", function( options ) { + + equal( options.defaultItem, "foo bar", "defaults work inside auto setup function" ); + plus(); + + return { + start: Popcorn.nop, + end: Popcorn.nop + }; + }); + p = Popcorn( "#video", { defaults: { overridden: { @@ -1731,6 +1742,12 @@ test( "Configurable Defaults", function() { } }); + p.defaults( "funtionInitDefaults", { + defaultItem: "foo bar" + }); + + p.funtionInitDefaults({}); + p.defaults( "configurable", { // set a default element target id