nop: function () {}
});
- // Simple Factory pattern to implement native
- // getters/setters and controllers
- // as methods of the returned Popcorn instance
- // The immediately invoked function creates
- // and returns an object of methods
+ // Simple Factory pattern to implement getters, setters and controllers
+ // as methods of the returned Popcorn instance. The immediately invoked function
+ // creates and returns an object of methods
Popcorn.extend(Popcorn.p, (function () {
// todo: play, pause, mute should toggle
}
-
if ( arg !== false && arg !== null && typeof arg !== "undefined" ) {
this.video[ name ] = arg;
}
});
-
- var nativeEvents = "loadstart progress suspend emptied stalled play pause " +
- "loadedmetadata loadeddata waiting playing canplay canplaythrough " +
- "seeking seeked timeupdate ended ratechange durationchange volumechange";
+
+ Popcorn.Events = {
+ 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 " +
+ "seeking seeked timeupdate ended ratechange durationchange volumechange"
+ };
+
+ Popcorn.Events.Natives = Popcorn.Events.UIEvents + " " +
+ Popcorn.Events.MouseEvents + " " +
+ Popcorn.Events.Events,
Popcorn.events = {
- //todo, fix types to be custom, natives will be native only
- types: nativeEvents.split(/\s+/g),
- natives: nativeEvents.split(/\s+/g),
- custom: [ "frame" ],
- all: [ "frame" ].concat( nativeEvents.split(/\s+/g) ),
+
+
+ isNative: function( type ) {
+
+ var checks = Popcorn.Events.Natives.split(/\s+/g);
+
+ for ( var i = 0; i < checks.length; i++ ) {
+ if ( checks[i] === type ) {
+ return true;
+ }
+ }
+
+ return false;
+ },
+ getInterface: function( type ) {
+
+ if ( !Popcorn.events.isNative( type ) ) {
+ return false;
+ }
+
+ var natives = Popcorn.Events, proto;
+
+ for ( var p in natives ) {
+ if ( p !== "Natives" && natives[p].indexOf(type) > -1 ) {
+ proto = p;
+ }
+ }
+
+ return proto;
+
+ },
+
+
+ all: Popcorn.Events.Natives.split(/\s+/g),
+
fn: {
trigger: function ( type, data ) {
// setup checks for custom event system
if ( this.data.events[type] && Popcorn.sizeOf(this.data.events[type]) ) {
- var evt = document.createEvent("Events");
- evt.initEvent(type, true, true, window, 1);
+ var interface = Popcorn.events.getInterface(type);
- this.video.dispatchEvent(evt);
-
- /*
+ if ( interface ) {
+
+ var evt = document.createEvent( interface );
+ evt.initEvent(type, true, true, window, 1);
- TODO: implement some form of custom event system
+ this.video.dispatchEvent(evt);
+
+ return this;
+ }
+
+ // Custom events
Popcorn.forEach(this.data.events[type], function ( obj, key ) {
- //obj.call(_target, _data);
+ obj.call( this, evt, data );
- // update to dispatch an event
-
- });
- */
+ }, this);
+
}
+
+ return this;
},
listen: function ( type, fn ) {
this.data.events[type][ fn.toString() + Popcorn.guid() ] = fn;
// only attach one event of any type
- if (!hasEvents && Popcorn.events.all.indexOf( type ) > -1 ) {
+ if ( !hasEvents && Popcorn.events.all.indexOf( type ) > -1 ) {
this.video.addEventListener( type, function( event ) {
// Provides some sugar, but ultimately extends
// the definition into Popcorn.p
- var natives = nativeEvents.split(/\s+/g),
+ var natives = Popcorn.events.all,
reserved = [ "start", "end", "timeupdate" ],
plugin = {},
setup;
});
-
// Future support for plugin event definitions
// for all of the native events
Popcorn.forEach( setup, function ( callback, type ) {
methods = "load play pause currentTime mute volume";
-
- console.log(popped);
-
popped.play();
methods.split(/\s+/g).forEach(function (k,v) {
completed = [];
- var expects = 11,
+ var expects = 10,
count = 0;
- //expect(expects);
- // not in full use
+
function plus(){
if ( ++count == expects ) start();
}
Setup.events.forEach(function ( name ) {
+
p.listen( name, function (event) {
-
+
if ( completed.indexOf(name) === -1 ) {
ok(true, name + " fired");
plus();
+});
+
+test("Custom", function () {
+
+ var expects = 1,
+ count = 0;
+
+ expect(expects);
+
+ function plus(){ if ( ++count == expects ) start(); }
+
+ stop();
+
+ var p = Popcorn("#video");
+
+
+ p.listen("eventz0rz", function ( event ) {
+
+ ok( true, "Custom event fired" );
+ plus();
+
+ });
+
+ p.trigger("eventz0rz");
+
+
+
+});
+
+
+test("UI/Mouse", function () {
+
+ var expects = 1,
+ count = 0;
+
+ expect(expects);
+
+ function plus(){ if ( ++count == expects ) start(); }
+
+ stop();
+
+ var p = Popcorn("#video");
+
+
+ p.listen("click", function ( event ) {
+
+ ok( true, "click event fired" );
+ plus();
+
+ });
+
+ p.trigger("click");
+
+
+
});
module("Popcorn Plugin")
});
+
/*
module("Popcorn Video Object")
test("wait()", function () {