-(function(global) {
+(function(global, document) {
// Cache refs to speed up calls to native utils
var
Popcorn.forEach( src, function( copy ) {
for ( var prop in copy ) {
- dest[prop] = copy[prop];
+ if ( copy[prop] ) {
+ dest[prop] = copy[prop];
+ }
}
});
return dest;
var size = 0;
for ( var prop in obj ) {
- size++;
+ if ( obj[prop] ) {
+ size++;
+ }
}
return size;
// 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);
// Custom events
Popcorn.forEach(this.data.events[type], function ( obj, key ) {
- obj.call( this, evt, data );
+ obj.call( this, data );
}, this);
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
// Capture the position of the track being removed.
if ( o._id === trackId ) {
- indexAt = i;
+ indexWasAt = i;
}
}
});
// 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);
json = JSON.parse(settings.ajax.responseText);
} catch(e) {
//suppress
- };
+ }
data = {
xml: settings.ajax.responseXML,
global.Popcorn = Popcorn;
-})(window);
+})(window, document);
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 () {
};
});
- 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();
});