From: rwldrn Date: Sun, 5 Dec 2010 17:15:29 +0000 (-0500) Subject: [#181] Setup for future support for plugin event definitions X-Git-Tag: v0.2~68^2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=9768f67d85c501439b78ba554b0e3b22e21f3fc1;p=popcorn-js.git [#181] Setup for future support for plugin event definitions --- diff --git a/popcorn.js b/popcorn.js index e523ee8..13d697a 100644 --- a/popcorn.js +++ b/popcorn.js @@ -198,7 +198,7 @@ }, listen: function ( type, fn ) { - var self = this, hasEvents = true; + var self = this, hasEvents = true, ns = ''; if ( !this.data.events[type] ) { this.data.events[type] = {}; @@ -261,7 +261,10 @@ setup = definition; - + if ( !( "timeupdate" in setup ) ) { + setup.timeupdate = Popcorn.nop; + } + definition = function ( options ) { var self = this; @@ -279,10 +282,6 @@ options.end = this.duration(); } - if ( !( "timeupdate" in options ) ) { - options.timeupdate = Popcorn.nop; - } - // If a _setup was declared, then call it before // the events commence @@ -291,7 +290,7 @@ } // Plugin timeline handler - this.video.addEventListener( "timeupdate", function( event ) { + this.listen( "timeupdate", function( event ) { if ( ~~self.currentTime() === options.start || @@ -313,18 +312,19 @@ setup.end.call(self, event, options); } - }, false); - - - // Future support plugin definitions for all of the native events - Popcorn.forEach( options, function ( key ) { - - console.log(key); }); - - + // Future support for plugin event definitions + // for all of the native events + Popcorn.forEach( setup, function ( callback, type ) { + + if ( reserved.indexOf(type) === -1 ) { + + this.listen( type, callback ); + } + + }, this); return this; }; diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index d13c5ac..9162feb 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -140,14 +140,10 @@ test("Popcorn Events Simulated", function () { QUnit.reset(); var p = Popcorn("#video"), - completed = [], - eventtest = "loadstart progress suspend emptied stalled play pause " + - "loadedmetadata loadeddata waiting playing canplay canplaythrough " + - "seeking seeked timeupdate ended ratechange durationchange volumechange", - events = eventtest.split(/\s+/g); + completed = []; - var expects = events.length, + var expects = Setup.events.length, count = 0; expect(expects); @@ -159,7 +155,7 @@ test("Popcorn Events Simulated", function () { stop(); - events.forEach(function ( name ) { + Setup.events.forEach(function ( name ) { p.listen( name, function (event) { if ( completed.indexOf(name) === -1 ) { @@ -173,7 +169,7 @@ test("Popcorn Events Simulated", function () { }); }); - events.forEach(function ( name ) { + Setup.events.forEach(function ( name ) { p.trigger( name ); }); @@ -186,11 +182,7 @@ test("Popcorn Events Real", function () { QUnit.reset(); var p = Popcorn("#video"), - completed = [], - eventtest = "loadstart progress suspend emptied stalled play pause " + - "loadedmetadata loadeddata waiting playing canplay canplaythrough " + - "seeking seeked timeupdate ended ratechange durationchange volumechange", - events = eventtest.split(/\s+/g); + completed = []; var expects = 11, @@ -205,7 +197,7 @@ test("Popcorn Events Real", function () { stop(); - events.forEach(function ( name ) { + Setup.events.forEach(function ( name ) { p.listen( name, function (event) { if ( completed.indexOf(name) === -1 ) { @@ -308,7 +300,7 @@ test("Popcorn Plugin", function () { }, end: function () { - start(); + //start(); }, timeupdate: function () { @@ -328,5 +320,132 @@ test("Popcorn Plugin", function () { end: 2 }); + + Popcorn.plugin("breaker", { + + start: function () { + ok(true, "plugin:breaker started"); + }, + end: function () { + ok(true, "plugin:ended started"); + start(); + } + }); + + + + popped.currentTime(0); + + popped.breaker({ + start: 1, + end: 2 + }); +}); + + + + + + + + + + + + + + + + + + + + + +test("Popcorn Plugin Extended Events", function () { + + //QUnit.reset(); + + // needs expectation + + var popped = Popcorn("#video"), + expects = 11, + count = 0; + + //expect(expects); + // not in full use + function plus(){ + if ( ++count == expects ) start(); + } + + stop(); + + + Popcorn.plugin("extendedEvents", (function () { + + + var pluginObj = { + + start: function() { + + }, + end: function() { + + } + }; + + $.each( Setup.events, function ( k, type ) { + + pluginObj[type] = function (event, opts) { + ok( true, type + " fired!" ); + + plus(); + }; + + }); + + return pluginObj; + + })()); + -}); \ No newline at end of file + + + popped.extendedEvents({ + + start: 20, + end: 21 + + }); + + + popped.currentTime(19).play(); + + +}); + +/* +module("Popcorn Video Object") +test("wait()", function () { + + //QUnit.reset(); + + // needs expectation + + var popped = Popcorn("#video"), + startat = +new Date(); + + + + + popped.play().wait(2).exec(function () { + + console.log( +new Date() - startat ); + + ok(true) + + }).pause(); + + +}); +*/ \ No newline at end of file diff --git a/test/popcorn.unit.setup.js b/test/popcorn.unit.setup.js index 5999b04..999adaa 100644 --- a/test/popcorn.unit.setup.js +++ b/test/popcorn.unit.setup.js @@ -29,6 +29,15 @@ }; + + Setup.eventset = "loadstart progress suspend emptied stalled play pause " + + "loadedmetadata loadeddata waiting playing canplay canplaythrough " + + "seeking seeked timeupdate ended ratechange durationchange volumechange"; + + Setup.events = Setup.eventset.split(/\s+/g); + + + global.Setup = Setup; })(window);