document.addEventListener('DOMContentLoaded', function () {
var p = Popcorn('#video')
.volume(0)
- .play()
+ .play()
.wordriver({
start: 1, // seconds
end: 3, // seconds
target: "wordriverdiv",
color: "blue"
})
+ .wordriver({
+ start: 1, // seconds
+ end: 4, // seconds
+ text: "hello",
+ target: "wordriverdiv2",
+ color: "red"
+ })
+ .wordriver({
+ start: 2, // seconds
+ end: 4, // seconds
+ text: "world",
+ target: "wordriverdiv2",
+ color: "blue"
+ });
}, false);
</video>
</div>
<div id="wordriverdiv" style="height: 200px; width: 200px;"></div>
+ <div id="wordriverdiv2" style="height: 200px; width: 200px;"></div>
</body>
</html>
var container = {},
spanLocation = 0,
- knownSpeaker = false,
- knownIndex = 0,
- unknownIndex = 0,
setupContainer = function( target ) {
container[ target ] = document.createElement( "div" );
- document.getElementById( target ).appendChild( container[ target ] );
+ document.getElementById( target ) && document.getElementById( target ).appendChild( container[ target ] );
container[ target ].style.height = "100%";
container[ target ].style.position = "relative";
options.word.style.MozTransform =
options.word.style.webkitTransform =
options.word.style.OTransform =
- options.word.style.transform = "translateY(" + ( document.getElementById( options.target ).offsetHeight - options.word.offsetHeight ) + "px)";
+ options.word.style.transform = "translateY(" +
+ ( document.getElementById( options.target ).offsetHeight - options.word.offsetHeight ) + "px)";
options.word.style.opacity = 1;
// manually clears the word based on user interaction
options.word.style.opacity = 0;
+ },
+ _teardown: function( options ) {
+
+ // removes word span from generated container
+ options._container.removeChild( options.word );
+
+ // if no more word spans exist in container, remove container
+ container[ options.target ] &&
+ !container[ options.target ].childElementCount &&
+ document.getElementById( options.target ).removeChild( container[ options.target ] ) &&
+ delete container[ options.target ];
}
});
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Popcorn Word River Plugin</title>
+ <link rel="stylesheet" href="../../test/qunit/qunit.css" type="text/css" media="screen">
+ <script src="../../test/qunit/qunit.js"></script>
+ <!--
+ do not move - this must be called immediately prior to
+ popcorn-api-draft.js
+ -->
+
+ <script src="../../popcorn.js"></script>
+ <script src="popcorn.wordriver.js"></script>
+
+ <script src="popcorn.wordriver.unit.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Popcorn Word River Plugin</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-fixture"> </div>
+
+ <video id='video'
+ controls preload='none'
+ width= '250px'
+ poster="../../test/poster.png">
+
+ <source id='mp4'
+ src="../../test/trailer.mp4"
+ type='video/mp4; codecs="avc1, mp4a"'>
+
+ <source id='ogv'
+ src="../../test/trailer.ogv"
+ type='video/ogg; codecs="theora, vorbis"'>
+
+ <p>Your user agent does not support the HTML5 Video element.</p>
+
+ </video>
+ <div id="wordriverdiv" style="height: 200px; width: 200px;"></div>
+</body>
+</html>
--- /dev/null
+test( "Popcorn wordriver Plugin", function () {
+
+ var popped = Popcorn( "#video" ),
+ expects = 16,
+ count = 0,
+ firstTrack,
+ secondTrack,
+ wordriverdiv = document.getElementById( "wordriverdiv" );
+
+ expect(expects);
+
+ function plus() {
+ if ( ++count === expects) {
+ start();
+ }
+ }
+
+ stop();
+
+ ok ( "wordriver" in popped, "wordriver is a method of the popped instance" );
+ plus();
+
+ equals ( wordriverdiv.childElementCount, 0, "initially, there is nothing inside the wordriverdiv" );
+ plus();
+
+
+ popped.wordriver({
+ start: 0, // seconds
+ end: 2, // seconds
+ text: "hello",
+ target: "wordriverdiv",
+ color: "red"
+ });
+
+ firstTrack = popped.getLastTrackEventId();
+
+ popped.wordriver({
+ start: 2, // seconds
+ end: 4, // seconds
+ text: "world",
+ target: "wordriverdiv",
+ color: "blue"
+ })
+ .volume(0);
+
+ secondTrack = popped.getLastTrackEventId();
+
+ popped.exec( 0, function() {
+ equals( wordriverdiv.children[0].childElementCount, 1, "wordriverdiv now has one inner element" );
+ plus();
+ equals( wordriverdiv.children[0].children[0].style.opacity, 1, "first word is visible on the page" );
+ plus();
+ equals( wordriverdiv.children[0].children[0].innerHTML, "hello", "first word content is correct" );
+ plus();
+ ok( !wordriverdiv.children[0].children[1], "second word does not exist yet" );
+ plus();
+ });
+
+ popped.exec( 2, function() {
+ equals( wordriverdiv.children[0].childElementCount, 2, "wordriverdiv now has two inner elements" );
+ plus();
+ equals( wordriverdiv.children[0].children[0].style.opacity, 0, "first word is not visible on the page" );
+ plus();
+ equals( wordriverdiv.children[0].children[0].innerHTML, "hello", "first word content is correct" );
+ plus();
+ equals( wordriverdiv.children[0].children[1].style.opacity, 1, "second word is visible on the page" );
+ plus();
+ equals( wordriverdiv.children[0].children[1].innerHTML, "world", "second word content is correct" );
+ plus();
+ });
+
+ popped.exec( 4, function() {
+ equals( wordriverdiv.children[0].children[0].style.opacity, 0, "first word is not visible on the page" );
+ plus();
+ equals( wordriverdiv.children[0].children[1].style.opacity, 0, "second word is not visible on the page" );
+ plus();
+
+ popped.pause().removeTrackEvent( firstTrack );
+ equals( wordriverdiv.children[0].childElementCount, 1, "wordriverdiv now has one inner element" );
+ plus();
+ equals( wordriverdiv.children[0].children[0].innerHTML, "world", "first word content is changed" );
+ plus();
+
+ popped.pause().removeTrackEvent( secondTrack );
+ equals( wordriverdiv.childElementCount, 0, "wordriverdiv now has no inner element" );
+ plus();
+ });
+
+ popped.play();
+
+});