From 30a49a56611a2f7997c341fda63797c428a30666 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 21 Sep 2011 12:02:12 -0400 Subject: [PATCH] [#729] Adds play(n)/pause(n) shorthands to currentTime(n).play()/pause() Includes tests --- popcorn.js | 9 +++++++++ test/popcorn.unit.js | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/popcorn.js b/popcorn.js index e2c7320..b0e9e0a 100644 --- a/popcorn.js +++ b/popcorn.js @@ -418,6 +418,15 @@ ret[ name ] = function( arg ) { if ( typeof this.media[ name ] === "function" ) { + + // Support for shorthanded play(n)/pause(n) jump to currentTime + // If arg is not null or undefined and called by one of the + // allowed shorthandable methods, then set the currentTime + // Supports time as seconds or SMPTE + if ( arg != null && /play|pause/.test( name ) ) { + this.media.currentTime = Popcorn.util.toSeconds( arg ); + } + this.media[ name ](); return this; diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 6dfff8f..61b9a86 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -601,6 +601,46 @@ test("mute", function() { }); +test("play(n) as shorthand to currentTime(n).play()", function() { + + var $pop = Popcorn( "#video" ), + expects = 2, + count = 0, + fired = 0; + + expect( expects ); + + function plus() { + if ( ++count == expects ) { + start(); + } + } + + stop( 1000 ); + + function poll() { + + if ( $pop.media.readyState >= 2 ) { + // this should trigger immediately + + $pop.play( 10 ).pause(); + + equal( Math.round($pop.currentTime()), 10, "play(n) sets currentTime to 10" ); + plus(); + + $pop.pause( 5 ); + + equal( Math.round($pop.currentTime()), 5, "pause(n) sets currentTime to 5" ); + plus(); + + } else { + setTimeout( poll, 10 ); + } + } + + poll(); +}); + module("Popcorn Static Methods"); -- 2.43.0