From: rwldrn Date: Fri, 17 Dec 2010 01:11:00 +0000 (-0500) Subject: [#228] Remove Track Event; index integrity tests; minor bug fixes X-Git-Tag: v0.2~38 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=30483e59a80fecda9b91505ea088b282fddacbfa;p=popcorn-js.git [#228] Remove Track Event; index integrity tests; minor bug fixes --- diff --git a/popcorn.js b/popcorn.js index ac8e9a0..d5faf6d 100644 --- a/popcorn.js +++ b/popcorn.js @@ -1,4 +1,4 @@ -(function(global) { +(function(global, document) { // Cache refs to speed up calls to native utils var @@ -156,7 +156,9 @@ Popcorn.forEach( src, function( copy ) { for ( var prop in copy ) { - dest[prop] = copy[prop]; + if ( copy[prop] ) { + dest[prop] = copy[prop]; + } } }); return dest; @@ -175,7 +177,9 @@ var size = 0; for ( var prop in obj ) { - size++; + if ( obj[prop] ) { + size++; + } } return size; @@ -347,11 +351,11 @@ // setup checks for custom event system if ( this.data.events[type] && Popcorn.sizeOf(this.data.events[type]) ) { - var interface = Popcorn.events.getInterface(type); + var eventInterface = Popcorn.events.getInterface(type); - if ( interface ) { + if ( eventInterface ) { - var evt = document.createEvent( interface ); + var evt = document.createEvent( eventInterface ); evt.initEvent(type, true, true, window, 1); this.video.dispatchEvent(evt); @@ -362,7 +366,7 @@ // Custom events Popcorn.forEach(this.data.events[type], function ( obj, key ) { - obj.call( this, evt, data ); + obj.call( this, data ); }, this); @@ -433,10 +437,10 @@ if ( track.natives ) { // supports user defined track event id - track["_id"] = !track.id ? track.natives.type + Popcorn.guid() : track.id; + track._id = !track.id ? track.natives.type + Popcorn.guid() : track.id; // Push track event ids into the history - obj.data.history.push( track["_id"] ); + obj.data.history.push( track._id ); } // Store this definition in an array sorted by times @@ -480,7 +484,7 @@ // Capture the position of the track being removed. if ( o._id === trackId ) { - indexAt = i; + indexWasAt = i; } } }); @@ -610,10 +614,13 @@ // Future support for plugin event definitions // for all of the native events Popcorn.forEach( setup, function ( callback, type ) { + + if ( type !== "type" ) { - if ( reserved.indexOf(type) === -1 ) { - - this.listen( type, callback ); + if ( reserved.indexOf(type) === -1 ) { + + this.listen( type, callback ); + } } }, this); @@ -692,7 +699,7 @@ json = JSON.parse(settings.ajax.responseText); } catch(e) { //suppress - }; + } data = { xml: settings.ajax.responseXML, @@ -710,4 +717,4 @@ global.Popcorn = Popcorn; -})(window); +})(window, document); diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 1f9ddc3..2063a36 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -774,12 +774,11 @@ test("Functions", function () { test("Index Integrity", function () { - stop(); - var popped = Popcorn("#video"), trackLen; - popped.currentTime(0).pause(); - + var trackLen, hasrun = false, lastrun = false; + + Popcorn.plugin("ff", function () { return { start: function () { @@ -795,51 +794,67 @@ test("Index Integrity", function () { }; }); - popped.ff({ + + var p = Popcorn("#video"); + + p.ff({ id: "removeable-track-event", - start: 1, - end: 3 + start: 40, + end: 45 }); - equals(popped.data.trackEvents.endIndex, 0, "popped.data.trackEvents.endIndex is 0"); - equals(popped.data.trackEvents.startIndex, 0, "popped.data.trackEvents.startIndex is 0"); - equals(popped.data.trackEvents.byStart.length, 3, "popped.data.trackEvents.byStart.length is 3 - before play" ); + p.currentTime(39).pause(); - - popped.listen("timeupdate", function () { + stop(); + + equals(p.data.trackEvents.endIndex, 0, "p.data.trackEvents.endIndex is 0"); + equals(p.data.trackEvents.startIndex, 0, "p.data.trackEvents.startIndex is 0"); + equals(p.data.trackEvents.byStart.length, 3, "p.data.trackEvents.byStart.length is 3 - before play" ); + + + + + p.listen("timeupdate", function () { + + if ( p.roundTime() > 40 && p.roundTime() < 46 && !hasrun ) { + } - if ( this.roundTime() >= 5 ) { + if ( p.roundTime() > 40 && p.roundTime() < 46 && hasrun && !lastrun ) { + + lastrun = true; + + equals( document.getElementById('index-test'), null, "document.getElementById('index-test') is null on second run - after removeTrackEvent" ); + + start(); + } - this.pause(); + if ( p.roundTime() >= 46 && !hasrun ) { - equals(popped.data.trackEvents.byStart.length, 3, "popped.data.trackEvents.byStart.length is 3 - after play, before removeTrackEvent" ); + hasrun = true; + p.pause(); + + equals(p.data.trackEvents.byStart.length, 3, "p.data.trackEvents.byStart.length is 3 - after play, before removeTrackEvent" ); + equals(p.data.trackEvents.startIndex, 2, "p.data.trackEvents.startIndex is 2 - after play, before removeTrackEvent"); + equals(p.data.trackEvents.endIndex, 2, "p.data.trackEvents.endIndex is 2 - after play, before removeTrackEvent"); - equals(popped.data.trackEvents.endIndex, 2, "popped.data.trackEvents.endIndex is 2 - after play, before removeTrackEvent"); - equals(popped.data.trackEvents.startIndex, 2, "popped.data.trackEvents.startIndex is 2 - after play, before removeTrackEvent"); - this.removeTrackEvent("removeable-track-event"); + p.removeTrackEvent("removeable-track-event"); + + equals(p.data.trackEvents.byStart.length, 2, "p.data.trackEvents.byStart.length is 2 - after removeTrackEvent" ); + equals(p.data.trackEvents.startIndex, 1, "p.data.trackEvents.startIndex is 1 - after removeTrackEvent"); + equals(p.data.trackEvents.endIndex, 1, "p.data.trackEvents.endIndex is 1 - after removeTrackEvent"); + + + + p.currentTime(39).play(); - equals(popped.data.trackEvents.byStart.length, 2, "popped.data.trackEvents.byStart.length is 2 - after removeTrackEvent" ); - equals(popped.data.trackEvents.endIndex, 1, "popped.data.trackEvents.endIndex is 1 - after removeTrackEvent"); - equals(popped.data.trackEvents.startIndex, 1, "popped.data.trackEvents.startIndex is 1 - after removeTrackEvent"); - this.listen("timeupdate", function () { - - if ( this.roundTime() >= 4 ) { - - this.pause(); - start(); - - } - }); - this.currentTime(0).play(); } - }); - popped.play(); + p.play(); });