From: ScottDowne Date: Tue, 12 Apr 2011 17:58:06 +0000 (-0400) Subject: [#470] inherit options object X-Git-Tag: v0.5~29^2~1 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=be7a95eaef198f901b22fe09220e089f6738006a;p=popcorn-js.git [#470] inherit options object --- diff --git a/popcorn.js b/popcorn.js index 42b1fee..6266539 100644 --- a/popcorn.js +++ b/popcorn.js @@ -872,10 +872,11 @@ 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, arguments ); + plugin[ name ] && plugin[ name ].apply( instance, args ); }); }; }; diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index e60e8f2..e1e5a2c 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -817,7 +817,7 @@ test("Plugin Factory", function () { var popped = Popcorn("#video"), methods = "load play pause currentTime mute volume roundTime exec removePlugin", - expects = 80, // 15*2+16*2+6+12. executor/complicator each do 15 + expects = 96, // 15*2+16*2+6+12. executor/complicator each do 15 count = 0; function plus() { @@ -832,6 +832,8 @@ test("Plugin Factory", function () { Popcorn.removePlugin("D"); Popcorn.removePlugin("E"); Popcorn.removePlugin("F"); + Popcorn.removePlugin("optionTest1"); + Popcorn.removePlugin("optionTest2"); start(); } } @@ -1008,6 +1010,59 @@ test("Plugin Factory", function () { plus(); }, 10000); + Popcorn.plugin( "optionTest1", { + _setup: function( options ) { + options.item = "exist"; + equals( options.data[ 0 ], "parent", "parent plugin _setup options.data" ); + plus(); + }, + start: function( event, options ) { + equals( options.item, "exist", "parent plugin start options.item" ); + plus(); + equals( options.data[ 0 ], "parent", "parent plugin start options.data" ); + plus(); + }, + end: function( event, options ) { + equals( options.item, "exist", "parent plugin end options.item" ); + plus(); + equals( options.data[ 0 ], "parent", "parent plugin end options.data" ); + plus(); + } + }); + + Popcorn.inherit( "optionTest2", "optionTest1", { + _setup: function( options ) { + equals( options.item, "exist", "child plugin _setup options.item" ); + plus(); + equals( options.data[ 1 ], "child", "child plugin _setup options.data" ); + plus(); + }, + start: function( event, options ) { + equals( options.item, "exist", "child plugin start options.item" ); + plus(); + equals( options.data[ 1 ], "child", "child plugin start options.data" ); + plus(); + }, + end: function( event, options ) { + equals( options.item, "exist", "child plugin end options.item" ); + plus(); + equals( options.data[ 1 ], "child", "child plugin end options.data" ); + plus(); + } + }); + + popped.optionTest1({ + start: 6, + end: 7, + data: [ "parent" ] + }) + .optionTest2({ + start: 7, + end: 8, + data: [ "parent", "child" ] + }) + + popped.currentTime(0).play(); });