зеркало из https://github.com/mozilla/popcorn-js.git
Merge pull request #31 from rwldrn/1015
[#1015] Implement ranges: [ {}, … ] property (plugin feature)
This commit is contained in:
Коммит
031f4836f5
22
popcorn.js
22
popcorn.js
|
@ -1330,6 +1330,28 @@
|
|||
return this;
|
||||
}
|
||||
|
||||
// When the "ranges" property is set and its value is an array, short-circuit
|
||||
// the pluginFn definition to recall itself with an options object generated from
|
||||
// each range object in the ranges array. (eg. { start: 15, end: 16 } )
|
||||
if ( options.ranges && Popcorn.isArray(options.ranges) ) {
|
||||
Popcorn.forEach( options.ranges, function( range ) {
|
||||
// Create a fresh object, extend with current options
|
||||
// and start/end range object's properties
|
||||
// Works with in/out as well.
|
||||
var opts = Popcorn.extend( {}, options, range );
|
||||
|
||||
// Remove the ranges property to prevent infinitely
|
||||
// entering this condition
|
||||
delete opts.ranges;
|
||||
|
||||
// Call the plugin with the newly created opts object
|
||||
this[ name ]( opts );
|
||||
}, this);
|
||||
|
||||
// Return the Popcorn instance to avoid creating an empty track event
|
||||
return this;
|
||||
}
|
||||
|
||||
// Storing the plugin natives
|
||||
var natives = options._natives = {},
|
||||
compose = "",
|
||||
|
|
|
@ -2277,6 +2277,33 @@ test( "Special track event listeners: trackstart, trackend", function() {
|
|||
}).play();
|
||||
});
|
||||
|
||||
test( "Range of track events #1015", function() {
|
||||
|
||||
var $pop = Popcorn( "#video" );
|
||||
|
||||
expect( 2 );
|
||||
|
||||
Popcorn.plugin( "ranger", {
|
||||
start: function() {},
|
||||
end: function() {}
|
||||
});
|
||||
|
||||
$pop.ranger({
|
||||
text: "I will appear at 3 different times",
|
||||
ranges: [
|
||||
{ start: 15, end: 16 },
|
||||
{ start: 18, end: 19 },
|
||||
{ start: 21, end: 22 }
|
||||
]
|
||||
});
|
||||
|
||||
equal( $pop.data.trackEvents.byStart.length, 5, "There are 5 start track events (2 padding events, 3 custom event)" );
|
||||
equal( $pop.data.trackEvents.byEnd.length, 5, "There are 5 end track events (2 padding events, 3 custom event)" );
|
||||
|
||||
Popcorn.removePlugin( "ranger" );
|
||||
$pop.destroy();
|
||||
});
|
||||
|
||||
test( "frame function (frameAnimation)", function() {
|
||||
|
||||
var $pop = Popcorn( "#video", {
|
||||
|
|
Загрузка…
Ссылка в новой задаче