(function(global, document) {
// Cache refs to speed up calls to native utils
+
var
- forEach = Array.prototype.forEach,
- hasOwn = Object.prototype.hasOwnProperty,
- slice = Array.prototype.slice,
- toString = Object.prototype.toString,
+
+ AP = Array.prototype,
+ OP = Object.prototype,
+
+ forEach = AP.forEach,
+ slice = AP.slice,
+ hasOwn = OP.hasOwnProperty,
+ toString = OP.toString,
// ID string matching
rIdExp = /^(#([\w\-\_\.]+))$/,
// Register new instance
Popcorn.addInstance( this );
- this.options = options || { };
+ this.options = options || {};
+
this.data = {
- history: [],
+
+ // Allows disabling a plugin per instance
+ disabled: [],
+
+ // Stores DOM event queues by type
events: {},
+
+ // Store track event history data
+ history: [],
+
+ // Playback track event queues
trackEvents: {
byStart: [{
start: -1,
while ( tracksByStart[ tracks.startIndex ] && tracksByStart[ tracks.startIndex ].start <= currentTime ) {
// If plugin does not exist on this instance, remove it
if ( !tracksByStart[ tracks.startIndex ]._natives || !!that[ tracksByStart[ tracks.startIndex ]._natives.type ] ) {
- if ( tracksByStart[ tracks.startIndex ].end > currentTime && tracksByStart[ tracks.startIndex ]._running === false ) {
+ if ( tracksByStart[ tracks.startIndex ].end > currentTime &&
+ tracksByStart[ tracks.startIndex ]._running === false &&
+ that.data.disabled.indexOf( tracksByStart[ tracks.endIndex ]._natives.type ) === -1 ) {
+
tracksByStart[ tracks.startIndex ]._running = true;
tracksByStart[ tracks.startIndex ]._natives.start.call( that, event, tracksByStart[ tracks.startIndex ] );
}
while ( tracksByEnd[ tracks.endIndex ] && tracksByEnd[ tracks.endIndex ].end > currentTime ) {
// if plugin does not exist on this instance, remove it
if ( !tracksByEnd[ tracks.endIndex ]._natives || !!that[ tracksByEnd[ tracks.endIndex ]._natives.type ] ) {
- if ( tracksByEnd[ tracks.endIndex ].start <= currentTime && tracksByEnd[ tracks.endIndex ]._running === false ) {
+ if ( tracksByEnd[ tracks.endIndex ].start <= currentTime &&
+ tracksByEnd[ tracks.endIndex ]._running === false &&
+ that.data.disabled.indexOf( tracksByStart[ tracks.endIndex ]._natives.type ) === -1 ) {
+
tracksByEnd[ tracks.endIndex ]._running = true;
tracksByEnd[ tracks.endIndex ]._natives.start.call( that, event, tracksByEnd[tracks.endIndex] );
}
}
return Popcorn.extend({}, bounds, { top: top, left: left });
+ },
+
+ disable: function( instance, plugin ) {
+
+ var disabled = instance.data.disabled;
+
+ if ( disabled.indexOf( plugin ) === -1 ) {
+ disabled.push( plugin );
+ }
+ return instance;
+ },
+ enable: function( instance, plugin ) {
+
+ var disabled = instance.data.disabled,
+ index = disabled.indexOf( plugin );
+
+ if ( index > -1 ) {
+ disabled.splice( index, 1 );
+ }
+ return instance;
}
});
}
});
+ Popcorn.forEach( "enable disable".split(" "), function( method ) {
+ Popcorn.p[ method ] = function( plugin ) {
+ return Popcorn[ method ]( this, plugin );
+ };
+ });
+
Popcorn.Events = {
UIEvents: "blur focus focusin focusout load resize scroll unload ",
MouseEvents: "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave click dblclick",
test("Utility", function () {
- expect(8);
+ expect(10);
// TODO: comprehensive tests for these utilities
- equals( typeof Popcorn.forEach, "function" , "Popcorn.forEach is a provided utility function");
- equals( typeof Popcorn.extend, "function" , "Popcorn.extend is a provided utility function");
- equals( typeof Popcorn.error, "function" , "Popcorn.error is a provided utility function");
- equals( typeof Popcorn.guid, "function" , "Popcorn.guid is a provided utility function");
- equals( typeof Popcorn.sizeOf, "function" , "Popcorn.sizeOf is a provided utility function");
- equals( typeof Popcorn.nop, "function" , "Popcorn.nop is a provided utility function");
- equals( typeof Popcorn.addTrackEvent, "function" , "Popcorn.addTrackEvent is a provided utility function");
- equals( typeof Popcorn.position, "function" , "Popcorn.position is a provided utility function");
+ equals( typeof Popcorn.forEach, "function" , "Popcorn.forEach is a provided static function");
+ equals( typeof Popcorn.extend, "function" , "Popcorn.extend is a provided static function");
+ equals( typeof Popcorn.error, "function" , "Popcorn.error is a provided static function");
+ equals( typeof Popcorn.guid, "function" , "Popcorn.guid is a provided static function");
+ equals( typeof Popcorn.sizeOf, "function" , "Popcorn.sizeOf is a provided static function");
+ equals( typeof Popcorn.nop, "function" , "Popcorn.nop is a provided static function");
+ equals( typeof Popcorn.addTrackEvent, "function" , "Popcorn.addTrackEvent is a provided static function");
+ equals( typeof Popcorn.position, "function" , "Popcorn.position is a provided static function");
+ equals( typeof Popcorn.disable, "function" , "Popcorn.disable is a provided static function");
+ equals( typeof Popcorn.enable, "function" , "Popcorn.enable is a provided static function");
});
test("Standard Time Strings" , function () {
Popcorn("#video");
- ok( typeof Popcorn.addInstance === "function" , "Popcorn.addInstance is a provided utility function");
+ ok( typeof Popcorn.addInstance === "function" , "Popcorn.addInstance is a provided static function");
plus();
- ok( typeof Popcorn.removeInstance === "function" , "Popcorn.removeInstance is a provided utility function");
+ ok( typeof Popcorn.removeInstance === "function" , "Popcorn.removeInstance is a provided static function");
plus();
- ok( typeof Popcorn.getInstanceById === "function" , "Popcorn.getInstanceById is a provided utility function");
+ ok( typeof Popcorn.getInstanceById === "function" , "Popcorn.getInstanceById is a provided static function");
plus();
- ok( typeof Popcorn.removeInstanceById === "function" , "Popcorn.removeInstanceById is a provided utility function");
+ ok( typeof Popcorn.removeInstanceById === "function" , "Popcorn.removeInstanceById is a provided static function");
plus();
ok( typeof Popcorn.instanceIds === "object" , "Popcorn.instanceIds is a provided cache object");
});
+test("Popcorn.disable/enable", function() {
+
+
+ var $pop = Popcorn.getInstanceById( "video" ),
+ count = 0,
+ expects = 4;
+
+ expect( expects );
+
+ function plus() {
+ if ( ++count === expects ) {
+ start();
+ }
+ }
+
+ stop( 10000 );
+ // rw/ff
+ // Test static function call
+ Popcorn.disable( $pop, "rw" );
+ ok( $pop.data.disabled.indexOf("rw") > -1, "Plugin: rw is disabled" );
+ plus();
+ // Test per-instance function call
+ $pop.disable( "ff" );
+
+ ok( $pop.data.disabled.indexOf("ff") > -1, "Plugin: ff is disabled" );
+ plus();
+ // Test static function call
+ Popcorn.enable( $pop, "rw" );
+
+ ok( $pop.data.disabled.indexOf("rw") === -1, "Plugin: rw is enabled" );
+ plus();
+
+ // Test per-instance function call
+ $pop.enable( "ff" );
+
+ ok( $pop.data.disabled.indexOf("ff") === -1, "Plugin: ff is enabled" );
+ plus();
+
+ //console.log( Popcorn.instances[ Popcorn.instanceIds.video ], );
+});
module("Popcorn XHR");
test("Basic", function () {
expect(2);
- equals( typeof Popcorn.xhr, "function" , "Popcorn.xhr is a provided utility function");
- equals( typeof Popcorn.xhr.httpData, "function" , "Popcorn.xhr.httpData is a provided utility function");
+ equals( typeof Popcorn.xhr, "function" , "Popcorn.xhr is a provided static function");
+ equals( typeof Popcorn.xhr.httpData, "function" , "Popcorn.xhr.httpData is a provided static function");
});