]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
demo and example plugin
authorrwldrn <waldron.rick@gmail.com>
Fri, 3 Dec 2010 21:54:50 +0000 (16:54 -0500)
committerrwldrn <waldron.rick@gmail.com>
Fri, 3 Dec 2010 21:54:50 +0000 (16:54 -0500)
popcorn-api-draft.js
test/demo.html [new file with mode: 0644]
test/demo.js [new file with mode: 0644]
test/popcorn-api-draft-unit.js

index d8496377b251da766f823b0379f2884b64f9da94..9876d387416ac7551c92ca034ee2f0fb9fa9647d 100644 (file)
@@ -88,7 +88,7 @@
   // A Few reusable utils, memoized onto Popcorn
   Popcorn.extend( Popcorn, {
     guid: function() {
-      return +new Date();
+      return +new Date() + Math.floor(Math.random()*11);
     }, 
     sizeOf: function ( obj ) {
       var size = 0;
         }
         
         //  setup for custom event system
-        this.data.events[type][ fn.toString() ] = fn;
+        this.data.events[type][ fn.toString() + Popcorn.guid() ] = fn;
         
         if ( Popcorn.events.all.indexOf( type ) > -1 ) {
           
-          
           this.video.addEventListener( type, function( event ) {
-          
+            
             Popcorn.forEach( self.data.events[type], function ( obj, key ) {
-
               obj.call(self, event);
-
             });            
           
           }, false);
     Popcorn.extend( Popcorn.p, plugin );
     
     
+    
+    
+    
+    
     //  within the context of a plugin, the `timeupdate` or any of the events can be listened to 
 
   };
diff --git a/test/demo.html b/test/demo.html
new file mode 100644 (file)
index 0000000..c96fe02
--- /dev/null
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn API DEMO</title>
+  
+  <script src="jquery.js"></script>
+  <script src="../popcorn-api-draft.js"></script>
+  <script src="demo.js"></script>
+</head>
+<body>
+  <h1 id="qunit-header">Popcorn API</h1>
+  
+  <style>
+    /* test positioning  */
+    
+    video {
+      position: fixed;
+      left: 100px;
+      top: 100px;
+    }
+  
+  </style>
+  
+  <div>
+    <video id='video' 
+      controls preload='none' 
+      poster="http://media.w3.org/2010/05/sintel/poster.png"> 
+
+      <source id='mp4'
+        src="http://media.w3.org/2010/05/sintel/trailer.mp4"
+        type='video/mp4; codecs="avc1, mp4a"'> 
+
+      <source id='ogv'
+        src="http://media.w3.org/2010/05/sintel/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/test/demo.js b/test/demo.js
new file mode 100644 (file)
index 0000000..69b5f51
--- /dev/null
@@ -0,0 +1,126 @@
+
+// EXAMPLE PLUGIN: SUBTITLER
+
+(function (Popcorn) {
+  
+  
+  
+  
+  Popcorn.plugin( "subtitler" , function ( options ) {
+    
+    var subtitles = [], 
+        context = this.video, 
+        div = document.getElementById("subtitle-container");
+        
+    
+    //  Check for existing frame
+    if ( !div ) {
+      // if no existing frame, create it.
+      div = document.createElement("div");
+      div.id  = "subtitle-container";
+      
+      Popcorn.extend(div.style, {
+        //border: "1px solid red",
+        width: context.clientWidth + "px", 
+        height: context.clientHeight + "px", 
+        top: context.offsetTop + "px", 
+        left: context.offsetLeft + "px",         
+        position: "absolute",
+        color:  "white",
+        textShadow: "black 2px 2px 6px",
+        fontSize: "18px",
+        fontWeight: "bold",
+        textAlign: "center"
+      });
+      
+      context.parentNode.appendChild(div);
+    }
+    
+    if ( typeof options === "object" && "join" in options ) {
+      subtitles = options;
+    } else {
+      subtitles.push(options);
+    }
+    
+    this.listen("timeupdate", function (event) {
+      
+      
+      Popcorn.forEach(subtitles, function ( subtitle ) {
+        
+        var temp  = div.querySelectorAll( subtitle.id );
+        
+        if ( this.currentTime() >= subtitle.start && !temp.length ) {
+          div.innerHTML = div.innerHTML + subtitle.html;
+        }
+
+        if ( this.currentTime() >= subtitle.end ) {
+          
+          if ( temp.length ) {
+            Popcorn.forEach(temp, function ( title ) {
+              title.style.display = "none";
+            });
+          }
+        }
+        
+      }, this);
+    });
+  });
+
+})(Popcorn);
+
+
+// END EXAMPLE
+
+
+$(function () {
+
+  
+  
+  var p = Popcorn('#video');
+  
+  
+  p.play();  
+  
+  
+  p.subtitler({
+    id: "#subtitle-a", 
+    start: 2, // seconds
+    end: 5, // seconds
+    html: '<p id="subtitle-a">Appear at 2 second mark, dissappear at 5 second mark</p>'
+  });
+  
+  
+  
+  // Butter would generate the data to populate this api function call's argument
+  
+  p.subtitler([
+    {
+      id: "#stays-forever", 
+      start: 5,
+      html: '<p id="stays-forever">Stays forever!</p>'
+    },
+    {
+      id: "#comes-and-goes-1", 
+      start: 10,
+      end: 12,
+      html: '<p id="comes-and-goes-1">Comes and goes</p>'
+    },
+    {
+      id: "#comes-and-goes-2", 
+      start: 12,
+      end: 14,
+      html: '<p id="comes-and-goes-2">BACK! For the second time...</p>'
+    },
+    {
+      id: "#comes-and-goes-3", 
+      start: 14,
+      end: 16,
+      html: '<p id="comes-and-goes-3">This is the last time. I promise.</p>'
+    }
+    
+  ]);
+
+  
+
+
+});
\ No newline at end of file
index 8adf688beb1e1aa7007b15b997077385d2e1592d..6d205fb8e718c0a75b852493b6fc047b4439a92e 100644 (file)
@@ -83,7 +83,7 @@ test("Popcorn Plugin", function () {
   Popcorn.plugin("subtitles", function ( ) {
   
     
-    //console.log(this);
+    console.log(this);