(function(global, document) {
// Cache refs to speed up calls to native utils
-
+
var
-
+
AP = Array.prototype,
OP = Object.prototype,
-
+
forEach = AP.forEach,
slice = AP.slice,
hasOwn = OP.hasOwnProperty,
// Non-public internal data object
internal = {
- events: {
+ events: {
hash: {},
apis: {}
}
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.startIndex ]._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( tracksByEnd[ tracks.endIndex ]._natives.type ) === -1 ) {
tracksByEnd[ tracks.endIndex ]._running = true;
bounds[ p ] = Math.round( clientRect[ p ] );
}
- return Popcorn.extend({}, bounds, { top: top, left: left });
- },
+ 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 );
}
},
enable: function( instance, plugin ) {
- var disabled = instance.data.disabled,
+ var disabled = instance.data.disabled,
index = disabled.indexOf( plugin );
if ( index > -1 ) {
// Toggle a plugin's playback behaviour (on or off) per instance
toggle: function( plugin ) {
return Popcorn[ this.data.disabled.indexOf( plugin ) > -1 ? "enable" : "disable" ]( this, plugin );
- },
+ },
// Set default values for plugin options objects per instance
defaults: function( plugin, defaults ) {
// Privately compile events table at load time
(function( events, data ) {
- var apis = internal.events.apiTypes,
+ var apis = internal.events.apiTypes,
eventsList = events.Natives.split( /\s+/g ),
idx = 0, len = eventsList.length, prop;
data.apis[ val ] = {};
- var apiEvents = events[ val ].split( /\s+/g ),
- len = apiEvents.length,
+ var apiEvents = events[ val ].split( /\s+/g ),
+ len = apiEvents.length,
k = 0;
for ( ; k < len; k++ ) {
return false;
}
- var eventApi = internal.events,
+ var eventApi = internal.events,
apis = eventApi.apiTypes,
- apihash = eventApi.apis,
+ apihash = eventApi.apis,
idx = 0, len = apis.length, api, tmp;
for ( ; idx < len; idx++ ) {
tmp = apis[ idx ];
-
+
if ( apihash[ tmp ][ type ] ) {
api = tmp;
break;
listen: function( type, fn ) {
var self = this,
- hasEvents = true,
- eventHook = Popcorn.events.hooks[ type ],
- origType = type,
+ hasEvents = true,
+ eventHook = Popcorn.events.hooks[ type ],
+ origType = type,
tmp;
if ( !this.data.events[ type ] ) {
// Store this definition in an array sorted by times
var byStart = obj.data.trackEvents.byStart,
- byEnd = obj.data.trackEvents.byEnd,
+ byEnd = obj.data.trackEvents.byEnd,
idx;
for ( idx = byStart.length - 1; idx >= 0; idx-- ) {
var trackevents = [],
refs = obj.data.trackEvents.byStart,
length = refs.length,
- idx = 0,
+ idx = 0,
ref;
for ( ; idx < length; idx++ ) {
// apply safe, and empty default functions
methods.forEach(function( method ) {
- definition[ method ] = definition[ method ] || Popcorn.nop;
+ definition[ method ] = definition[ method ] || Popcorn.nop;
});
var pluginFn = function( setup, options ) {
// Storing the plugin natives
var natives = options._natives = {},
- compose = "",
+ compose = "",
defaults, originalOpts, manifestOpts, mergedSetupOpts;
Popcorn.extend( natives, setup );
options.dataType = options.dataType && options.dataType.toLowerCase() || null;
- if ( options.dataType &&
+ if ( options.dataType &&
( options.dataType === "jsonp" || options.dataType === "script" ) ) {
Popcorn.xhr.getJSONP(
test("Popcorn.* Static Methods", function () {
- var statics = [ "forEach", "extend", "error", "guid", "sizeOf", "nop",
- "addTrackEvent", "removeTrackEvent", "getTrackEvents", "getTrackEvent", "position", "disable", "enable" ],
+ var statics = [ "forEach", "extend", "error", "guid", "sizeOf", "nop",
+ "addTrackEvent", "removeTrackEvent", "getTrackEvents", "getTrackEvent", "position", "disable", "enable" ],
substatics = [ "addTrackEvent", "removeTrackEvent", "getTrackEvents", "getTrackEvent"];
expect(statics.length + substatics.length);
-
+
statics.forEach(function(val, idx) {
- equals( typeof Popcorn[val], "function" , "Popcorn."+val+"() is a provided static function");
+ equals( typeof Popcorn[val], "function" , "Popcorn."+val+"() is a provided static function");
});
substatics.forEach(function(val, idx) {
- equals( typeof Popcorn[val].ref, "function" , "Popcorn."+val+".ref() is a private use static function");
+ equals( typeof Popcorn[val].ref, "function" , "Popcorn."+val+".ref() is a private use static function");
});
});
expect(3);
- var count = 0,
- nodelist = document.querySelectorAll("div[id^='qunit-']"),
- array = [ 1, 2 ],
+ var count = 0,
+ nodelist = document.querySelectorAll("div[id^='qunit-']"),
+ array = [ 1, 2 ],
object = { a: "1", b: "2" };
Popcorn.forEach( nodelist, function() {
expect(18);
- var empty = [],
- fastSmall = [1],
+ var empty = [],
+ fastSmall = [1],
slow = [],
- slowSmall = [],
+ slowSmall = [],
all = null;
slowSmall[999999] = 0;
all = [ [], [1], new Array, Array(0),'abc'.match(/(a)/g), slow, slowSmall ];
- all.forEach(function( a ) {
- ok( Popcorn.isArray(a), "Popcorn.isArray("+JSON.stringify(a)+")" );
+ all.forEach(function( a ) {
+ ok( Popcorn.isArray(a), "Popcorn.isArray("+JSON.stringify(a)+")" );
});
equal( Popcorn.isArray.length, 1, "Popcorn.isArray.length, 1" );
-
+
ok( !Popcorn.isArray(), "!Popcorn.isArray(), false");
ok( !Popcorn.isArray({}), "!Popcorn.isArray({}), false");
ok( !Popcorn.isArray(null), "!Popcorn.isArray(null), false");
} catch( e ) {
ok( true, e.message + " and cannot be used as a plugin name" );
}
-
+
try {
Popcorn.removePlugin( name );
} catch( e ) {
test("Popcorn.[addTrackEvent | removeTrackEvent].ref()", function() {
expect(2);
-
+
var popped = Popcorn("#video");
// Calling exec() will create tracks and added them to the
});
test( "Popcorn.extend", function () {
-
+
QUnit.reset();
-
+
expect( 12 );
-
+
var dest = {},
obj1 = {
"key11" : "value",
"key23" : function() { return false; }
},
prop;
-
+
Popcorn.extend( dest, obj1 );
-
+
for ( prop in obj1 ) {
equal( dest.hasOwnProperty( prop ), true, "{dest} has property: " + prop );
}
-
+
equal( typeof dest[ "key13" ], "function", "dest[key13] is a function" );
-
+
dest = {};
-
+
Popcorn.extend( dest, obj1, obj2 );
-
+
for ( prop in obj1 ) {
equal( dest.hasOwnProperty( prop ), true, "{dest} has property: " + prop + ", when extending 2 objects" );
}
for ( prop in obj2 ) {
equal( dest.hasOwnProperty( prop ), true, "{dest} has property: " + prop + ", when extending 2 objects" );
}
-
+
equal( typeof dest[ "key13" ], "function","dest[key13] is a function" );
-
+
equal( typeof dest[ "key23" ], "function","dest[key23] is a function" );
-
+
});
test( "Popcorn.events", function() {
QUnit.reset()
expect( 43 );
-
- var eventTypes = [ "UIEvents", "MouseEvents", "Events" ],
- natives = "",
- events,
+
+ var eventTypes = [ "UIEvents", "MouseEvents", "Events" ],
+ natives = "",
+ events,
eventsReturned,
idx = 0,
len,
test("Popcorn.events.hooks", function() {
expect(1);
-
+
ok( Popcorn.events.hooks, "Popcorn.events.hooks exists" );
});
//qunit-fixture
var expects = 1,
- count = 0,
+ count = 0,
fired = 0;
expect(expects);
- function plus(){
+ function plus(){
if ( ++count == expects ) {
start();
}
var video = document.createElement("video"),
sources = {
- mp4: document.createElement("source"),
- ogv: document.createElement("source"),
+ mp4: document.createElement("source"),
+ ogv: document.createElement("source"),
webm: document.createElement("source")
},
url = "http://videos.mozilla.org/serv/webmademovies/popcornplug.";
});
/*
-<video height="180" width="300" id="video" controls>
+<video height="180" width="300" id="video" controls>
<source src="http://videos.mozilla.org/serv/webmademovies/popcornplug.mp4"></source>
<source src="http://videos.mozilla.org/serv/webmademovies/popcornplug.ogv"></source>
<source src="http://videos.mozilla.org/serv/webmademovies/popcornplug.webm"></source>
test("position", function () {
expect(25);
-
- var $absolute = $(".absolute"),
- $relative = $(".relative"),
+
+ var $absolute = $(".absolute"),
+ $relative = $(".relative"),
$fixed = $(".fixed"),
- $static = $(".static"),
+ $static = $(".static"),
tests;
$("#position-tests").show();
{ id: "absolute-1-1-1", top: 2, left: 2 },
{ id: "absolute-2", top: 19, left: 19 }
];
-
+
Popcorn.forEach( tests, function( test ) {
equals( Popcorn( "#vid-" + test.id ).position().top, test.top, "Popcorn('#vid-" + test.id + "').position().top" );
equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" );
Popcorn.forEach( tests, function( test ) {
equals( Popcorn( "#vid-" + test.id ).position().top, test.top, "Popcorn('#vid-" + test.id + "').position().top" );
equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" );
- });
+ });
tests = [
{ id: "fixed-1", top: 0, left: 0 },
Popcorn.forEach( tests, function( test ) {
equals( Popcorn( "#vid-" + test.id ).position().top, test.top, "Popcorn('#vid-" + test.id + "').position().top" );
equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" );
- });
+ });
tests = [
{ id: "static-1", top: 200, left: 0 },
{ id: "static-1-1-1", top: 0, left: 0 },
{ id: "static-2", top: 300, left: 0 }
];
-
+
Popcorn.forEach( tests, function( test ) {
equals( Popcorn( "#vid-" + test.id ).position().top, test.top, "Popcorn('#vid-" + test.id + "').position().top" );
equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" );
expect( expects );
- function plus(){
+ function plus(){
if ( ++count == expects ) {
start();
Popcorn.removePlugin("positionPlugin");
});
test("Configurable Defaults", function () {
-
+
var expects = 13,
count = 0;
}
stop();
-
+
Popcorn.plugin( "configurable", function () {
return {
_setup: function( options ) {
plus();
// target: "foo"
// text: "bar"
- // type: "thinger"
+ // type: "thinger"
equal( options.target, "foo", 'options.target, "foo" in configurable start');
plus();
equal( options.text, "bar", 'options.text, "bar" in configurable start');
_setup: function( options ) {
equal( options.text, "hello!", 'options.text, overriden with "hello!" in overridden _setup');
plus();
-
+
equal( options.target, "custom", 'options.target, overriden with "custom" in overridden _setup');
plus();
},
start: function( event, options ) {
equal( options.text, "hello!", 'options.text, overriden with "hello!" in overridden start');
plus();
-
+
equal( options.target, "custom", 'options.target, overriden with "custom" in overridden start');
plus();
},
// set a default element target id
target: "foo"
-
- }).defaults([
- {
- multiconfig: {
- target: "quux"
- }
+
+ }).defaults([
+ {
+ multiconfig: {
+ target: "quux"
+ }
},
- {
- configurable: {
+ {
+ configurable: {
text: "bar",
type: "thinger"
- }
- }
+ }
+ }
]).configurable({
// all calls will have:
// target: "quux"
start: 4,
end: 5
-
+
}).overridden({
// has a default set
var popped = Popcorn("#video"),
methods = "load play pause currentTime mute volume roundTime exec removePlugin",
expects = 34, // 15*2+2+2. executor/complicator each do 15
- count = 0;
+ count = 0;
function plus() {
if ( ++count == expects ) {
plus();
popped.complicator({
- start: 4,
+ start: 4,
end: 5
});
setup: 0,
running: 0
}
- };
+ };
function plus() {
if ( ++count == expects ) {
});
test("Defaulting Empty End Values", function() {
-
+
expect (2);
-
+
Popcorn.plugin("testdefault", {
_setup: function( options ) {
equals( options.end, Number.MAX_VALUE, "The end value defaulted to maximum number value");
}
});
-
+
var popped = Popcorn( document.createElement( "audio" ) )
- .play()
+ .play()
.testdefault({
start: 0, // seconds
apikey: "CHAyhB5IisvLqqzGYNYbmA",
trackIds.push( popped.getLastTrackEventId() );
-
+
popped.rw({
start: 5,
end: 7
var trackEvent = popped.getTrackEvent( id );
equals( id, trackEvent._id, "returned the correct TrackEvent");
});
-
+
oldId = trackIds[trackIds.length - 1];
-
+
popped.removeTrackEvent( oldId );
equals( popped.getTrackEvent( oldId ), undefined, "returned undefined when id is not found" );
plus();
// Test per-instance toggle on
- $pop.toggle( "toggler" );
+ $pop.toggle( "toggler" );
ok( $pop.data.disabled.indexOf("toggler") === -1, "toggle() plugin: toggler is re-enabled" );
plus();
});
$pop.toggler({
- start: 40,
+ start: 40,
end: 50
});
// Test per-instance function call
$pop.disable( "toggler" );
-
+
ok( $pop.data.disabled.indexOf("toggler") > -1, "disable() plugin: toggler is disabled" );
plus();
// Test per-instance function call
- $pop.enable( "toggler" );
-
+ $pop.enable( "toggler" );
+
ok( $pop.data.disabled.indexOf("toggler") === -1, "enable() plugin: toggler is enabled" );
plus();
// Test per-instance toggle off
- $pop.toggle( "toggler" );
-
+ $pop.toggle( "toggler" );
+
ok( $pop.data.disabled.indexOf("toggler") > -1, "toggle() plugin: toggler is disabled" );
plus();
$("iframe[data-src]").attr( "src", function() {
return $(this).data("src");
});
-
+
})( jQuery );
});