From: Daniel Brooks Date: Tue, 29 Mar 2011 12:28:53 +0000 (-0500) Subject: merge branch 'annasob/0.5' into plugin-inheritance X-Git-Tag: v0.5~38 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=599e860ae9ee954dd3e033ad665f88bb4bbc2ea6;p=popcorn-js.git merge branch 'annasob/0.5' into plugin-inheritance --- 599e860ae9ee954dd3e033ad665f88bb4bbc2ea6 diff --cc popcorn.js index 51cda50,73df0f7..763bebf --- a/popcorn.js +++ b/popcorn.js @@@ -806,15 -807,12 +809,16 @@@ Popcorn.extend( Popcorn.p, plugin ); // Push into the registry - Popcorn.registry.push( - Popcorn.extend( plugin, { - type: name - }) - ); + var entry = { + function: plugin[ name ], + definition: definition, + base_definition: definition, + parents: [], + name: name + }; + Popcorn.registry.push( entry ); + Popcorn.registryHash[ name ] = entry; + return plugin; }; diff --cc test/popcorn.unit.js index 482ca88,0f63263..4054d39 mode 100644,100755..100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@@ -671,15 -673,15 +673,15 @@@ test("Update Timer", function () }); test("Plugin Factory", function () { - + QUnit.reset(); - var popped = Popcorn("#video"), + var popped = Popcorn("#video"), methods = "load play pause currentTime mute volume roundTime exec removePlugin", - expects = 34, - count = 0; + expects = 80, // 15*2+16*2+6+12. executor/complicator each do 15 + count = 0; - function plus() { + function plus() { if ( ++count == expects ) { Popcorn.removePlugin("executor"); Popcorn.removePlugin("complicator"); @@@ -696,12 -690,12 +698,12 @@@ } expect( expects ); - stop( 10000 ); + stop( 15000 ); Popcorn.plugin("executor", function () { - + return { - + start: function () { var self = this; @@@ -734,31 -728,21 +736,31 @@@ }; }); - + + Popcorn.pluginInherit("executor_inherits", "executor", function (options) { + return { + start: function() { ok(true, "child class method executed"); plus(); } + }; + }); + ok( "executor" in popped, "executor plugin is now available to instance" ); plus(); - equals( Popcorn.registry.length, 1, "One item in the registry"); + ok( "executor_inherits" in popped, "executor-inerits plugin is now available to instance" ); + plus(); + equals( Popcorn.registry.length, 2, "One item in the registry"); plus(); - - popped.executor({ - start: 1, + start: 1, end: 2 }); + popped.executor_inherits({ + start: 2, + end: 3 + }); Popcorn.plugin("complicator", { - + start: function ( event ) { var self = this; @@@ -783,89 -767,27 +785,89 @@@ ok( "trackEvents" in this.data, " complicatorinstance has `trackEvents` property" ); plus(); - ok( Object.prototype.toString.call(popped.data.trackEvents) === "[object Object]", "complicator trackEvents property is an object" ) - plus(); + ok( Object.prototype.toString.call(popped.data.trackEvents) === "[object Object]", "complicator trackEvents property is an object" ) + plus(); }, end: function () { - + //start(); - - }, + + }, timeupdate: function () { - } + } }); + Popcorn.pluginInherit("complicator_inherits", "executor", { + start: function() { ok(true, "child class method executed"); plus(); } + }); + ok( "complicator" in popped, "complicator plugin is now available to instance" ); plus(); - equals( Popcorn.registry.length, 2, "Two items in the registry"); + ok( "complicator_inherits" in popped, "complicator plugin is now available to instance" ); + plus(); + equals( Popcorn.registry.length, 4, "Two items in the registry"); plus(); - + popped.complicator({ - start: 3, - end: 4 + start: 4, + end: 5 + }); + popped.complicator_inherits({ + start: 5, + end: 6 + }); + + var counts = { a: 0, b: 0, c: 0, d: 0, e: 0, f: 0 }; + Popcorn.plugin("A", function(options) { + return { start: function() { counts.a++; } }; + }); + Popcorn.plugin("B", function(options) { + return { start: function() { counts.b++; } }; }); + Popcorn.pluginInherit("C", "B", function(options) { + return { start: function() { counts.c++; } }; + }); + Popcorn.pluginInherit("D", ["A", "B"], function(options) { + return { start: function() { counts.d++; } }; + }); + Popcorn.pluginInherit("E", ["B"], function(options) { + return { start: function() { counts.e++; } }; + }); + Popcorn.pluginInherit("F", ["E", "C"], function(options) { + return { start: function() { counts.f++; } }; + }); + + equals(counts.a, 0, "plugin A should not have been run yet"); + plus(); + equals(counts.b, 0, "plugin B should not have been run yet"); + plus(); + equals(counts.c, 0, "plugin C should not have been run yet"); + plus(); + equals(counts.d, 0, "plugin D should not have been run yet"); + plus(); + equals(counts.e, 0, "plugin E should not have been run yet"); + plus(); + equals(counts.f, 0, "plugin F should not have been run yet"); + plus(); + + popped.C({ start: 6, end: 7 }); + popped.D({ start: 7, end: 8 }); + popped.F({ start: 8, end: 9 }); + + setTimeout(function() { + equals(counts.a, 1, "plugin A should have been run once"); + plus(); + equals(counts.b, 3, "plugin B should have been run thrice"); + plus(); + equals(counts.c, 2, "plugin C should have been run twice"); + plus(); + equals(counts.d, 1, "plugin D should have been run once"); + plus(); + equals(counts.e, 1, "plugin E should have been run once"); + plus(); + equals(counts.f, 1, "plugin F should have been run once"); + plus(); + }, 10000); popped.currentTime(0).play();