From: ScottDowne Date: Sun, 9 Jan 2011 22:04:43 +0000 (-0500) Subject: [#246] second conversion of 0.1 semantic demo X-Git-Tag: v0.2~14 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=144942a3860d5045b2f4b2d9799fca260e561eee;p=popcorn-js.git [#246] second conversion of 0.1 semantic demo --- diff --git a/demos/semantic_video/index.html b/demos/semantic_video/index.html index 80c9484..c6f70e0 100644 --- a/demos/semantic_video/index.html +++ b/demos/semantic_video/index.html @@ -13,6 +13,14 @@ + + + + + + + + diff --git a/demos/semantic_video/style.css b/demos/semantic_video/style.css index 9f3eea4..34133b1 100644 --- a/demos/semantic_video/style.css +++ b/demos/semantic_video/style.css @@ -8,7 +8,7 @@ dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td { margin: 0; - padding: 0; + padding: 0;video-div border: 0; outline: 0; font-size: 100%; @@ -304,7 +304,7 @@ background: url(images/arro.png) no-repeat right -21px; } .video-div{ -position:relative; + border: 2px solid #cc433c; margin-bottom: 15px; -webkit-box-shadow: -1px 1px 1px #d9d9d9; @@ -748,4 +748,4 @@ top:-22px; width:23px; cursor: pointer; z-index: 999999; -} \ No newline at end of file +} diff --git a/demos/semantic_video/xml/webMadeMovies.xml b/demos/semantic_video/xml/webMadeMovies.xml index cf6837a..55be40f 100644 --- a/demos/semantic_video/xml/webMadeMovies.xml +++ b/demos/semantic_video/xml/webMadeMovies.xml @@ -86,104 +86,104 @@ Look around the page as info is updated! - + + - + - - - Grassroots Mapping, Tungsten Monkey + + + - Keyboard Cat - - KeyBoard Cat, Charlie Schmidt - + + + + - Jeffrey Warren - Grassroots Mapping, Tungsten Monkey - Village Telco Guy + + + - - + + - Jeffrey Warren + - - - - + + + + Learn more about Grass Roots mapping at www.grassrootsmapping.org - + - - - Michael Adeyeye + + + - Charlie Schmidt - - - Keyboard Cat - Charlie Schmidt + + + + + - Jonathan Zittrain - - - - - - + + + + + + + - + - - - + + + - + - - + + - - + + - + - NCSA guy - Computer Chronicles guy #1 - Computer Chronicles guy #2 - Computer Chronicles guy #3 + + + + - Jonathan Zittrain - + + Read Zittrain's book 'The Future of the Internet — And How to Stop It' - Mona Kasra - Noah Workman - - Wilken Sanches - - Keechang Kim - - Celine Celines + + + + + + + + - + - + @@ -314,7 +314,7 @@ producing and sharing music using Creative Commons - --> + diff --git a/plugins/subtitle/popcorn.subtitle.js b/plugins/subtitle/popcorn.subtitle.js index 9a07e7b..27ad26b 100644 --- a/plugins/subtitle/popcorn.subtitle.js +++ b/plugins/subtitle/popcorn.subtitle.js @@ -7,19 +7,43 @@ // just a little tool function // calculates the top and left position of an element - var offset = function(elem) { - if(!elem) elem = this; + var offset = function(obj) { + var left, top; + left = top = 0; + if (obj.offsetParent) { + do { + left += obj.offsetLeft; + top += obj.offsetTop; + } while (obj = obj.offsetParent); + } + return { + left : left, + top : top + }; + }; - var x = elem.offsetLeft; - var y = elem.offsetTop; + // translates whatever is in options.container into selected language + var translate = function( options, text ) { - while (elem = elem.offsetParent) { - x += elem.offsetLeft; - y += elem.offsetTop; - } + options.selectedLanguage = options.languageSrc.options[ options.languageSrc.selectedIndex ].value; + + google.language.translate( text, '', options.selectedLanguage, function( result ) { + + options.container.innerHTML = result.translation; - return { left: x, top: y }; - } + } ); + }; + + +/* + // Find element offset + if (element.offsetParent) { + do { + offsetX += element.offsetLeft; + offsetY += element.offsetTop; + } while ((element = element.offsetParent)); + } +*/ Popcorn.plugin( "subtitle" , { @@ -53,7 +77,7 @@ // the video element must have height and width defined this.container.style.width = this.video.offsetWidth + "px"; - //this.container.style.top = offset( this.video ).top + "px"; + this.container.style.top = offset( this.video ).top + this.video.offsetHeight - 65 + "px"; this.container.style.left = offset( this.video ).left + "px"; this.video.parentNode.appendChild( this.container ); @@ -66,60 +90,66 @@ options.container = this.container; } - options.translatedText = options.text; - var selectedLanguage = ( options.language || "" ), - // declared as a function, it can be called, but does nothing if not needed - toggleSubtitles = function() {}, - accessibility = document.getElementById( options.accessibilitysrc ), + var accessibility = document.getElementById( options.accessibilitysrc ), that = this; - if ( options.languagesrc ) { - var languageSrc = document.getElementById( options.languagesrc ); - - var updateLanguage = function() { + options.showSubtitle = function() { + options.container.innerHTML = options.text; + }; + options.toggleSubtitles = function() {}; + options.that = this; + - selectedLanguage = document.getElementById( options.languagesrc ).options[ languageSrc.selectedIndex ].value; + if ( options.languagesrc ) { + options.showSubtitle = translate; + options.languageSrc = document.getElementById( options.languagesrc ); + options.selectedLanguage = options.languageSrc.options[ options.languageSrc.selectedIndex ].value; - google.language.translate( options.text, '', selectedLanguage, function( result ) { + if ( !this.languageSources ) { + this.languageSources = {}; + } - options.translatedText = result.translation; + - } ); + if ( !this.languageSources[ options.languagesrc ] ) { + this.languageSources[ options.languagesrc ] = {}; + + } - google.language.translate( options.container.innerHTML, '', selectedLanguage, function( result ) { + if ( !this.languageSources[ options.languagesrc ][ options.target ] ) { + this.languageSources[ options.languagesrc ][ options.target ] = true; - options.container.innerHTML = result.translation; - toggleSubtitles(); // update visuals if accessibility is used + options.languageSrc.addEventListener( "change", function() { - } ); - that.container.style.top = offset( that.video ).top + that.video.offsetHeight - ( 40 + that.container.offsetHeight ) + "px"; + options.toggleSubtitles(); + options.showSubtitle( options, options.container.innerHTML ); - }; + }, false ); - languageSrc.addEventListener( "change", updateLanguage, false ); + } - // initiate it once to set starting state - updateLanguage(); } if ( accessibility ) { - - toggleSubtitles = function() { - - if ( accessibility.checked || selectedLanguage !== ( options.language || "") ) { - options.container.style.display = "inline"; - } else if ( selectedLanguage === ( options.language || "") ) { - options.container.style.display = "none"; + options.accessibility = accessibility; + + options.toggleSubtitles = function() { + options.selectedLanguage = options.languageSrc.options[ options.languageSrc.selectedIndex ].value; + if ( options.accessibility.checked || options.selectedLanguage !== ( options.language || "") ) { + options.display = "inline"; + options.container.style.display = options.display; + } else if ( options.selectedLanguage === ( options.language || "") ) { + options.display = "none"; + options.container.style.display = options.display; } - that.container.style.top = offset( that.video ).top + that.video.offsetHeight - ( 40 + that.container.offsetHeight ) + "px"; }; - accessibility.addEventListener( "change", toggleSubtitles, false ); + options.accessibility.addEventListener( "change", options.toggleSubtitles, false ); // initiate it once to set starting state - toggleSubtitles(); + options.toggleSubtitles(); } }, @@ -130,8 +160,8 @@ * options variable */ start: function(event, options){ - options.container.innerHTML = options.translatedText; - this.container.style.top = offset( this.video ).top + this.video.offsetHeight - ( 40 + this.container.offsetHeight ) + "px"; + options.container.style.display = options.display; + options.showSubtitle( options, options.text ); }, /** * @member subtitle @@ -140,6 +170,7 @@ * options variable */ end: function(event, options){ + options.container.style.display = options.display; options.container.innerHTML = ""; }