From 8f48584b6fcf907d54e52db978bdf9de1fde7174 Mon Sep 17 00:00:00 2001 From: ScottDowne Date: Thu, 12 May 2011 19:06:14 -0400 Subject: [PATCH] [#t381] subtile position changes with the video's position --- plugins/subtitle/popcorn.subtitle.js | 52 ++++++++------ plugins/subtitle/popcorn.subtitle.unit.js | 85 +++++++++++++---------- 2 files changed, 77 insertions(+), 60 deletions(-) diff --git a/plugins/subtitle/popcorn.subtitle.js b/plugins/subtitle/popcorn.subtitle.js index 93dfc86..f56d986 100644 --- a/plugins/subtitle/popcorn.subtitle.js +++ b/plugins/subtitle/popcorn.subtitle.js @@ -15,6 +15,34 @@ 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 ); @@ -100,23 +128,8 @@ _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' ) { @@ -189,11 +202,6 @@ } }, 5); - - - - - }, /** * @member subtitle diff --git a/plugins/subtitle/popcorn.subtitle.unit.js b/plugins/subtitle/popcorn.subtitle.unit.js index 9e7c58b..14e80d3 100644 --- a/plugins/subtitle/popcorn.subtitle.unit.js +++ b/plugins/subtitle/popcorn.subtitle.unit.js @@ -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 +}); -- 2.43.0