readyBound = false,
readyFired = false,
+ // Non-public internal data object
+ internal = {
+ events: {
+ hash: {},
+ apis: {}
+ }
+ },
// Declare constructor
// Returns an instance object.
});
Popcorn.Events = {
- UIEvents: "blur focus focusin focusout load resize scroll unload ",
+ UIEvents: "blur focus focusin focusout load resize scroll unload",
MouseEvents: "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave click dblclick",
Events: "loadstart progress suspend emptied stalled play pause " +
"loadedmetadata loadeddata waiting playing canplay canplaythrough " +
Popcorn.Events.MouseEvents + " " +
Popcorn.Events.Events;
- Popcorn.events = {
+ internal.events.apiTypes = [ "UIEvents", "MouseEvents", "Events" ];
- isNative: function( type ) {
+ // Privately compile events table at load time
+ (function( events, data ) {
- var checks = Popcorn.Events.Natives.split( /\s+/g );
+ var apis = internal.events.apiTypes,
+ eventsList = events.Natives.split( /\s+/g ),
+ idx = 0, len = eventsList.length, prop;
- for ( var i = 0; i < checks.length; i++ ) {
- if ( checks[ i ] === type ) {
- return true;
- }
+ for( ; idx < len; idx++ ) {
+ data.hash[ eventsList[idx] ] = true;
+ }
+
+ apis.forEach(function( val, idx ) {
+
+ data.apis[ val ] = {};
+
+ var apiEvents = events[ val ].split( /\s+/g ),
+ len = apiEvents.length,
+ k = 0;
+
+ for ( ; k < len; k++ ) {
+ data.apis[ val ][ apiEvents[ k ] ] = true;
}
+ });
+ })( Popcorn.Events, internal.events );
+
+ Popcorn.events = {
- return false;
+ isNative: function( type ) {
+ return !!internal.events.hash[ type ];
},
getInterface: function( type ) {
return false;
}
- var natives = Popcorn.Events,
- proto;
-
- for ( var p in natives ) {
- if ( p !== "Natives" && natives[ p ].indexOf( type ) > -1 ) {
- proto = p;
+ var eventApi = internal.events,
+ apis = eventApi.apiTypes,
+ apihash = eventApi.apis,
+ idx = 0, len = apis.length, api, tmp;
+
+ for ( ; idx < len; idx++ ) {
+ tmp = apis[ idx ];
+
+ if ( apihash[ tmp ][ type ] ) {
+ api = tmp;
+ break;
}
}
-
- return proto;
+ return api;
},
// Compile all native events to single array
all: Popcorn.Events.Natives.split( /\s+/g ),
fn: {
trigger: function( type, data ) {
+ var eventInterface, evt;
// setup checks for custom event system
if ( this.data.events[ type ] && Popcorn.sizeOf( this.data.events[ type ] ) ) {
- var eventInterface = Popcorn.events.getInterface( type );
+ eventInterface = Popcorn.events.getInterface( type );
if ( eventInterface ) {
- var evt = document.createEvent( eventInterface );
- evt.initEvent( type, true, true, global, 1 );
+ evt = document.createEvent( eventInterface );
+ evt.initEvent( type, true, true, global, 1 );
this.media.dispatchEvent( evt );
module("Popcorn Events");
+test("Can Detect Native event types", function() {
+
+ var tests = [ "play", "pause", "rough loade", "data seek" ],
+ expects = [ true, true, false, false ];
+
+ expect( tests.length );
+
+ tests.forEach(function( type, idx ) {
+ equal( Popcorn.events.isNative( type ), expects[ idx ], type + ( expects[ idx ] ? " is " : " is not " ) + "a native valid event" );
+ });
+});
+
test("Stored By Type", function () {
QUnit.reset();
$pop.exec( 40, function() {
- console.log( "WOO!" );
// make sure toggler never happened
// look for: "toggler-test"