From: rwldrn Date: Mon, 10 Jan 2011 18:41:03 +0000 (-0500) Subject: [#251] Issue with object addressing of registered exec callbacks X-Git-Tag: v0.2~3^2~2^2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=46e8abbde43ea6b373c48d11ccf5626cc289c1b9;p=popcorn-js.git [#251] Issue with object addressing of registered exec callbacks --- diff --git a/popcorn.js b/popcorn.js index edc4779..48123cf 100644 --- a/popcorn.js +++ b/popcorn.js @@ -295,14 +295,15 @@ !fn && ( fn = Popcorn.nop ); - var self = this, + var self = this, + guid = Popcorn.guid( "execCallback" ), callback = function execCallback( event ) { if ( this.currentTime() >= time && !callback.fired ) { callback.fired = true; - this.unlisten("execCallback"); + this.unlisten("timeupdate", guid ); fn.call(self, event); @@ -310,6 +311,7 @@ }; callback.fired = false; + callback.name = guid; this.listen("timeupdate", callback); @@ -463,7 +465,9 @@ unlisten: function( type, fn ) { if ( this.data.events[type] && this.data.events[type][fn] ) { - this.data.events[type][fn] = null; + + delete this.data.events[type][ fn ]; + return this; } diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 8ffd6fc..a1f131e 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -174,7 +174,7 @@ test("exec", function () { QUnit.reset(); var popped = Popcorn("#video"), - expects = 1, + expects = 2, count = 0; expect(expects); @@ -190,7 +190,11 @@ test("exec", function () { popped.exec( 4, function () { - ok(true, "exec function"); + ok(true, "exec callback fired"); + plus(); + + + equal( popped.data.events.timeupdate, null, "exec callback removed"); plus(); }).currentTime(3).play();