]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#t381] subtile position changes with the video's position
authorScottDowne <sdowne@learn.senecac.on.ca>
Thu, 12 May 2011 23:06:14 +0000 (19:06 -0400)
committerScottDowne <sdowne@learn.senecac.on.ca>
Thu, 12 May 2011 23:06:14 +0000 (19:06 -0400)
plugins/subtitle/popcorn.subtitle.js
plugins/subtitle/popcorn.subtitle.unit.js

index 93dfc86a5fd959ebefbb88e964fdf4175ca3e297..f56d98671a59f3b07f48361a5cbd3945752e3f47 100644 (file)
             callBack( data );
           }, 1);
         }
+      },
+      createDefaultContainer = function( context ) {
+
+        // clear this function from future calls; we are done
+        createDefaultContainer = Popcorn.nop;
+
+        var updatePosition = function() {
+
+          // the video element must have height and width defined
+          context.container.style.fontSize   = "18px";
+          context.container.style.width      = context.media.offsetWidth + "px";
+          context.container.style.top        = context.position().top  + context.media.offsetHeight - context.container.offsetHeight - 40 + "px";
+          context.container.style.left       = context.position().left + "px";
+
+          setTimeout( updatePosition, 10 );
+        };
+
+        context.container = document.createElement('div');
+        context.container.id               = "subtitlediv";
+        context.container.style.position   = "absolute";
+        context.container.style.color      = "white";
+        context.container.style.textShadow = "black 2px 2px 6px";
+        context.container.style.fontWeight = "bold";
+        context.container.style.textAlign  = "center";
+
+        updatePosition();
+
+        document.body.appendChild( context.container );
       };
 
   Popcorn.getScript( "http://www.google.com/jsapi", callBack );
       _setup: function( options ) {
 
         // Creates a div for all subtitles to use
-        if ( !this.container ) {
-          this.container = document.createElement('div');
-          this.container.id = "subtitlediv";
-          this.container.style.position   = "absolute";
-          this.container.style.color      = "white";
-          this.container.style.textShadow = "black 2px 2px 6px";
-          this.container.style.fontSize   = "18px";
-          this.container.style.fontWeight = "bold";
-          this.container.style.textAlign  = "center";
-
-          // the video element must have height and width defined
-          this.container.style.width      = this.media.offsetWidth + "px";
-          this.container.style.top        = this.position().top + this.media.offsetHeight - 65 + "px";
-          this.container.style.left       = this.position().left + "px";
-
-          document.body.appendChild( this.container );
-        }
+        ( !this.container && !options.target || options.target === 'Subtitle-container' ) && 
+          createDefaultContainer( this );
 
         // if a target is specified, use that
         if ( options.target && options.target !== 'Subtitle-container' ) {
           }
         }, 5);
 
-
-
-
-
-
       },
       /**
        * @member subtitle 
index 9e7c58bf6f5a0b81fe14ec9a7714a2277823a778..14e80d33c54b8013084d39c30054b173a9abd345 100644 (file)
@@ -1,7 +1,7 @@
 test("Popcorn Subtitle Plugin", function () {
   
   var popped = Popcorn("#video"),
-      expects = 5,
+      expects = 9,
       count = 0,
       interval,
       interval2,
@@ -23,22 +23,24 @@ test("Popcorn Subtitle Plugin", function () {
   plus();
 
   popped.subtitle({
-      start: 3,
+      start: 0,
+      end: 1,
       text: 'this is the first subtitle of 2011',
       language: "en",
       languagesrc: "language",
       accessibilitysrc: "accessibility"
     } )
   .subtitle({
-      start: 10,
-      end: 15,
+      start: 1,
+      end: 2,
       text: 'this is the second subtitle of 2011',
       language: "en",
       languagesrc: "language",
       accessibilitysrc: "accessibility"
     } )
        .subtitle({
-      start: 20,
+      start: 3,
+      end: 4,
       text: 'this is the third subtitle of 2011',
       language: "en",
       languagesrc: "language",
@@ -46,38 +48,45 @@ test("Popcorn Subtitle Plugin", function () {
     } )
     .volume(0)
     .play();
-  
-  interval = setInterval( function() {
-    if( popped.currentTime() >= 3 && popped.currentTime() < 10 ) {
-      subtitlediv = document.getElementById('subtitlediv'); // this div has only now been created
-      equals (subtitlediv.innerHTML, "this is the first subtitle of 2011", "subtitle displaying correct information" );
-      plus();
-      clearInterval( interval );
-    }
-  }, 500);
-  
-  interval2 = setInterval( function() {
-    if( popped.currentTime() >= 10 && popped.currentTime() < 15  ) {
-      equals (subtitlediv.innerHTML, "this is the second subtitle of 2011", "subtitle displaying correct information" );
-      plus();
-      clearInterval( interval2 );
-    }
-  }, 500);
 
-  interval3 = setInterval( function() {
-    if( popped.currentTime() >= 15 && popped.currentTime() < 20 ) {
-      equals (subtitlediv.innerHTML, "" );
-      plus();
-      clearInterval( interval3 );
-    }
-  }, 500);
-  
-  interval4 = setInterval( function() {
-    if( popped.currentTime() > 20) {
-      equals (subtitlediv.innerHTML, "this is the third subtitle of 2011", "subtitle displaying correct information" );
-      plus();
-      clearInterval( interval4 );
-    }
-  }, 500);
+  subtitlediv = document.getElementById('subtitlediv');
+
+  popped.exec( 0.5, function() {
+
+console.log(subtitlediv.style.top);
+    equals ( subtitlediv.style.left, "400px", "subtitle left position moved" );
+    plus();
+    equals ( subtitlediv.style.top, "657px", "subtitle top position moved" );
+    plus();
+    equals (subtitlediv.innerHTML, "this is the first subtitle of 2011", "subtitle displaying correct information" );
+    plus();
+  });
+
+  popped.exec( 1.5, function() {
+
+    equals (subtitlediv.innerHTML, "this is the second subtitle of 2011", "subtitle displaying correct information" );
+    plus();
+  });
+
+  popped.exec( 2.5, function() {
+
+    equals (subtitlediv.innerHTML, "", "subtitle is clear" );
+    plus();
+  });
+
+  popped.exec( 3.5, function() {
+
+    equals (subtitlediv.innerHTML, "this is the third subtitle of 2011", "subtitle displaying correct information" );
+    plus();
+  });
+
+  equals ( "8px", subtitlediv.style.left, "subtitle left position default" );
+  plus();
+  equals ( "247px", subtitlediv.style.top, "subtitle top position default" );
+  plus();
+
+  popped.media.style.position = "absolute";
+  popped.media.style.left = "400px";
+  popped.media.style.top = "600px";
 
-});
\ No newline at end of file
+});