},
removeEventListener: function( evtName, fn ) {
return this.evtHolder.removeEventListener( evtName, fn );
+ },
+ dispatchEvent: function( evtName ) {
+ return this.evtHolder.dispatchEvent( evtName );
}
});
})( Popcorn );
\ No newline at end of file
// adding padding to the front and end of the arrays
// this is so we do not fall off either end
- var duration = typeof that.video.duration === "function" ? that.video.duration() : that.video.duration;
+ var duration = that.video.duration;
+
+ if( typeof that.video.duration === "function") {
+ duration = that.video.duration();
+ }
+
// Check for no duration info (NaN)
var videoDurationPlus = duration != duration ? Number.MAX_VALUE : duration + 1;
// todo: play, pause, mute should toggle
var methods = "load play pause currentTime playbackRate mute volume duration",
+ noArgMethods = /load|play|pause|mute/,
ret = {};
var isFunc = typeof this.video[name] === "function";
- if ( /load|play|pause|mute/.test( name ) || ( arg !== false && arg !== null && typeof arg !== "undefined" ) ) {
+ if ( noArgMethods.test( name ) || ( arg !== false && arg !== null && typeof arg !== "undefined" ) ) {
if ( isFunc ) {
this.video[ name ]( arg );
});
+test("Passed an object", function () {
+
+ QUnit.reset();
+
+ var evtMethods = "addEventListener dispatchEvent".split(/\s+/),
+ methods = "load play pause currentTime playbackRate mute volume duration".split(/\s+/),
+ attributes = "readyState autoplay".split(/\s+/),
+ obj = {},
+ p,
+ playEvent,
+ count = 0,
+ wants;
+
+ function plus(){
+
+ if ( ++count === wants ) {
+ start();
+ }
+ }
+
+ Popcorn.forEach( methods, function( method ) {
+ obj[method] = (function() {
+ var calledWithArgs = 0,
+ calledWithoutArgs = 0;
+
+ return function( arg ) {
+ if ( arg && !calledWithArgs ) {
+ calledWithArgs = 1;
+ ok(true, method+" called with argument");
+ plus();
+ } else if ( !arg && !calledWithoutArgs ) {
+ calledWithoutArgs = 1;
+ ok(true, method+" called without argument");
+ plus();
+ }
+ }
+ })();
+ });
+
+ Popcorn.forEach( evtMethods, function( method ) {
+ obj[method] = (function() {
+ var hasCalled = 0;
+
+ return function() {
+ if ( hasCalled ) {
+ return;
+ }
+
+ hasCalled = 1;
+ ok(true, method+" called");
+ plus();
+ };
+ })()
+ });
+
+ Popcorn.forEach( attributes, function( attr ) {
+ obj[attr] = 3;
+ });
+
+ p = Popcorn( obj );
+ wants = methods.length*2 + evtMethods.length;
+
+ expect( wants );
+ stop( 10000 );
+
+ p.listen( "play", Popcorn.nop );
+
+ Popcorn.forEach( methods, function( method ) {
+ p[method]();
+ p[method]( 1 );
+ });
+
+ p.trigger( "play" );
+});
+
+
test("Simulated", function () {
QUnit.reset();