]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#t479] initial wordriver commit, not tests yet
authorScottDowne <sdowne@learn.senecac.on.ca>
Mon, 16 May 2011 01:16:02 +0000 (21:16 -0400)
committerScottDowne <sdowne@learn.senecac.on.ca>
Mon, 16 May 2011 01:16:02 +0000 (21:16 -0400)
plugins/wordriver/popcorn.wordriver.html [new file with mode: 0644]
plugins/wordriver/popcorn.wordriver.js [new file with mode: 0644]

diff --git a/plugins/wordriver/popcorn.wordriver.html b/plugins/wordriver/popcorn.wordriver.html
new file mode 100644 (file)
index 0000000..a53fbce
--- /dev/null
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn Subtitle Plug-in Demo</title>
+  
+  <script src="../../popcorn.js"></script>
+
+  <script src="popcorn.wordriver.js"></script>
+  <script>
+    document.addEventListener('DOMContentLoaded', function () {
+      var p = Popcorn('#video')
+      .volume(0)
+      .play() 
+      .wordriver({
+                               start: 1, // seconds
+                               end: 3, // seconds
+                               text: "hello",
+                               target: "wordriverdiv",
+                               color: "red"
+      })
+      .wordriver({
+                               start: 3, // seconds
+                               end: 6, // seconds
+                               text: "world",
+                               target: "wordriverdiv",
+                               color: "blue"
+      })
+
+    }, false);
+
+  </script>
+</head>
+<body>
+  <h1 id="qunit-header">Popcorn Word River Plug-in Demo</h1>
+  <p> A "hello world" word river will appear from 1 to 6.</p>
+  <div>
+
+    <video id='video' 
+      controls height="480" width="854"
+      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>
+  <div id="wordriverdiv" style="height: 200px; width: 200px;"></div>
+
+</body>
+</html>
diff --git a/plugins/wordriver/popcorn.wordriver.js b/plugins/wordriver/popcorn.wordriver.js
new file mode 100644 (file)
index 0000000..dc601e6
--- /dev/null
@@ -0,0 +1,91 @@
+// PLUGIN: Wordriver
+
+(function (Popcorn) {
+
+  var container = {},
+      spanLocation = 0,
+      knownSpeaker = false,
+      knownIndex = 0,
+      unknownIndex = 0,
+      setupContainer = function( target ) {
+  
+        container[ target ] = document.createElement( "div" );
+        document.getElementById( target ).appendChild( container[ target ] );
+        
+        container[ target ].style.height = "100%";
+        container[ target ].style.position = "relative";
+        
+        return container[ target ];
+      };
+
+  Popcorn.plugin( "wordriver" , {
+    
+      manifest: {},
+
+      _setup: function( options ) {
+
+        options._duration = options.end - options.start;
+        options._container = container[ options.target ] || setupContainer( options.target );
+
+        options.word = document.createElement( "span" );
+        options.word.style.position = "absolute";
+
+        options.word.style.whiteSpace = "nowrap";
+        options.word.style.opacity = 0;
+
+        options.word.style.MozTransitionProperty = "opacity, -moz-transform";
+        options.word.style.webkitTransitionProperty = "opacity, -webkit-transform";
+        options.word.style.OTransitionProperty = "opacity, -o-transform";
+        options.word.style.transitionProperty = "opacity, transform";
+
+        options.word.style.MozTransitionDuration =
+          options.word.style.webkitTransitionDuration = 
+          options.word.style.OTransitionDuration = 
+          options.word.style.transitionDuration = 1 + "s, " + options._duration + "s";
+
+        options.word.style.MozTransitionTimingFunction =
+          options.word.style.webkitTransitionTimingFunction =
+          options.word.style.OTransitionTimingFunction =
+          options.word.style.transitionTimingFunction = "linear";
+
+        options.word.innerHTML = options.text;
+        options.word.style.color = options.color || "black";
+      },
+      start: function( event, options ){
+
+        options._container.appendChild( options.word );
+
+        // Resets the transform when changing to a new currentTime before the end event occurred.
+        options.word.style.MozTransform =
+          options.word.style.webkitTransform =
+          options.word.style.OTransform =
+          options.word.style.transform = "";
+
+        options.word.style.fontSize = ~~( 30 + 20 * Math.random() ) + "px";
+        spanLocation = spanLocation % ( options._container.offsetWidth - options.word.offsetWidth );
+        options.word.style.left = spanLocation + "px";
+        spanLocation += options.word.offsetWidth + 10;
+
+        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.opacity = 1;
+
+        // automatically clears the word based on time
+        setTimeout( function() {
+
+                     options.word.style.opacity = 0;
+        // ensures at least one second exists, because the fade animation is 1 second
+                   }, ( ( (options.end - options.start) - 1 ) || 1 ) * 1000 )
+
+      },
+      end: function( event, options ){
+
+        // manually clears the word based on user interaction
+        options.word.style.opacity = 0;
+      }
+  });
+
+})( Popcorn );