]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#170] lower third plugin
authorScottDowne <sdowne@learn.senecac.on.ca>
Fri, 7 Jan 2011 20:16:26 +0000 (15:16 -0500)
committerScottDowne <sdowne@learn.senecac.on.ca>
Fri, 7 Jan 2011 20:16:26 +0000 (15:16 -0500)
plugins/lowerThird/popcorn.lowerThird.html [new file with mode: 0644]
plugins/lowerThird/popcorn.lowerThird.js [new file with mode: 0644]

diff --git a/plugins/lowerThird/popcorn.lowerThird.html b/plugins/lowerThird/popcorn.lowerThird.html
new file mode 100644 (file)
index 0000000..0543fd5
--- /dev/null
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn Lower Third Plug-in Demo</title>
+  
+  <script src="../../popcorn.js"></script>
+
+  <script src="popcorn.lowerThird.js"></script>
+  <script>
+    document.addEventListener('DOMContentLoaded', function () {
+      var p = Popcorn('#video')
+      .play()
+      .lowerThird({
+        start: 5, // seconds
+        end: 15, // seconds
+        salutation: 'Mr',
+        name: 'Hyde',
+        role: 'Monster'
+      } )
+      .lowerThird({
+        start: 20, // seconds
+        end: 45, // seconds
+        salutation: 'Dr',
+        name: 'Jekyll',
+        role: 'Person'
+      } )
+
+    }, false);
+
+  </script>
+</head>
+<body>
+  <h1 id="qunit-header">Popcorn Lower Third Plug-in Demo</h1>
+  <p> At 5 seconds info will appear in the lower third of the video and disappear at 15 seconds.</p>
+  <p> At 20 seconds info will appear in the lower third of the video and disappear at 45 seconds.</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>
+
+</body>
+</html>
diff --git a/plugins/lowerThird/popcorn.lowerThird.js b/plugins/lowerThird/popcorn.lowerThird.js
new file mode 100644 (file)
index 0000000..7bcc6b4
--- /dev/null
@@ -0,0 +1,95 @@
+// PLUGIN: LowerThird
+
+(function (Popcorn) {
+  
+  /**
+  */
+
+  // just a little tool function
+  // calculates the top and left position of an element
+  var offset = function(elem) {
+    if(!elem) elem = this;
+
+    var x = elem.offsetLeft;
+    var y = elem.offsetTop;
+
+    while (elem = elem.offsetParent) {
+      x += elem.offsetLeft;
+      y += elem.offsetTop;
+    }
+
+    return { left: x, top: y };
+  }
+
+  Popcorn.plugin( "lowerThird" , {
+    
+      manifest: {
+        about:{
+          name: "Popcorn LowerThird Plugin",
+          version: "0.1",
+          author: "Scott Downe",
+          website: "http://scottdowne.wordpress.com/"
+        },
+        options:{
+          start : {elem:'input', type:'text', label:'In'},
+          end : {elem:'input', type:'text', label:'Out'},
+          target : 'LowerThird-container',
+          salutation : {elem:'input', type:'text', label:'Text'},
+          name : {elem:'input', type:'text', label:'Text'},
+          role : {elem:'input', type:'text', label:'Text'}
+        }
+      },
+
+      _setup: function( options ) {
+
+        // Creates a div for all LowerThirds to use
+        if ( !this.container ) {
+          this.container = document.createElement('div');
+
+          this.container.style.position = "absolute";
+          this.container.style.color = "white";
+          this.container.style.textShadow = "black 2px 2px 6px";
+          this.container.style.fontSize = "24px";
+          this.container.style.fontWeight = "bold";
+          this.container.style.paddingLeft = "40px";
+
+          // the video element must have height and width defined
+          this.container.style.width = this.video.offsetWidth + "px";
+          this.container.style.left = offset( this.video ).left + "px";
+
+          this.video.parentNode.appendChild( this.container );
+        }
+
+        // if a target is specified, use that
+        if ( options.target && options.target !== 'LowerThird-container' ) {
+          options.container = document.getElementById( options.target );
+        } else { // use shared default container
+          options.container = this.container;
+        }
+
+
+
+      },
+      /**
+       * @member lowerThird
+       * The start function will be executed when the currentTime
+       * of the video reaches the start time provided by the
+       * options variable
+       */
+      start: function(event, options){
+        options.container.innerHTML = ( options.salutation ? options.salutation + " " : "" ) + options.name + ( options.role ? "<br />" + options.role : "" );
+        this.container.style.top = offset( this.video ).top + this.video.offsetHeight - ( 40 + this.container.offsetHeight ) + "px";
+      },
+      /**
+       * @member lowerThird
+       * The end function will be executed when the currentTime
+       * of the video reaches the end time provided by the
+       * options variable
+       */
+      end: function(event, options){
+        options.container.innerHTML = "";
+      }
+   
+  } );
+
+})( Popcorn );