From fdb3842ff9a38b40f369988cd791b6564dd2633d Mon Sep 17 00:00:00 2001 From: ScottDowne Date: Sun, 15 May 2011 21:16:02 -0400 Subject: [PATCH] [#t479] initial wordriver commit, not tests yet --- plugins/wordriver/popcorn.wordriver.html | 57 +++++++++++++++ plugins/wordriver/popcorn.wordriver.js | 91 ++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 plugins/wordriver/popcorn.wordriver.html create mode 100644 plugins/wordriver/popcorn.wordriver.js diff --git a/plugins/wordriver/popcorn.wordriver.html b/plugins/wordriver/popcorn.wordriver.html new file mode 100644 index 0000000..a53fbce --- /dev/null +++ b/plugins/wordriver/popcorn.wordriver.html @@ -0,0 +1,57 @@ + + + + Popcorn Subtitle Plug-in Demo + + + + + + + +

Popcorn Word River Plug-in Demo

+

A "hello world" word river will appear from 1 to 6.

+
+ + +
+
+ + + diff --git a/plugins/wordriver/popcorn.wordriver.js b/plugins/wordriver/popcorn.wordriver.js new file mode 100644 index 0000000..dc601e6 --- /dev/null +++ b/plugins/wordriver/popcorn.wordriver.js @@ -0,0 +1,91 @@ +// PLUGIN: Wordriver + +(function (Popcorn) { + + var container = {}, + spanLocation = 0, + knownSpeaker = false, + knownIndex = 0, + unknownIndex = 0, + setupContainer = function( target ) { + + container[ target ] = document.createElement( "div" ); + document.getElementById( target ).appendChild( container[ target ] ); + + container[ target ].style.height = "100%"; + container[ target ].style.position = "relative"; + + return container[ target ]; + }; + + Popcorn.plugin( "wordriver" , { + + manifest: {}, + + _setup: function( options ) { + + options._duration = options.end - options.start; + options._container = container[ options.target ] || setupContainer( options.target ); + + options.word = document.createElement( "span" ); + options.word.style.position = "absolute"; + + options.word.style.whiteSpace = "nowrap"; + options.word.style.opacity = 0; + + options.word.style.MozTransitionProperty = "opacity, -moz-transform"; + options.word.style.webkitTransitionProperty = "opacity, -webkit-transform"; + options.word.style.OTransitionProperty = "opacity, -o-transform"; + options.word.style.transitionProperty = "opacity, transform"; + + options.word.style.MozTransitionDuration = + options.word.style.webkitTransitionDuration = + options.word.style.OTransitionDuration = + options.word.style.transitionDuration = 1 + "s, " + options._duration + "s"; + + options.word.style.MozTransitionTimingFunction = + options.word.style.webkitTransitionTimingFunction = + options.word.style.OTransitionTimingFunction = + options.word.style.transitionTimingFunction = "linear"; + + options.word.innerHTML = options.text; + options.word.style.color = options.color || "black"; + }, + start: function( event, options ){ + + options._container.appendChild( options.word ); + + // Resets the transform when changing to a new currentTime before the end event occurred. + options.word.style.MozTransform = + options.word.style.webkitTransform = + options.word.style.OTransform = + options.word.style.transform = ""; + + options.word.style.fontSize = ~~( 30 + 20 * Math.random() ) + "px"; + spanLocation = spanLocation % ( options._container.offsetWidth - options.word.offsetWidth ); + options.word.style.left = spanLocation + "px"; + spanLocation += options.word.offsetWidth + 10; + + options.word.style.MozTransform = + options.word.style.webkitTransform = + options.word.style.OTransform = + options.word.style.transform = "translateY(" + ( document.getElementById( options.target ).offsetHeight - options.word.offsetHeight ) + "px)"; + + options.word.style.opacity = 1; + + // automatically clears the word based on time + setTimeout( function() { + + options.word.style.opacity = 0; + // ensures at least one second exists, because the fade animation is 1 second + }, ( ( (options.end - options.start) - 1 ) || 1 ) * 1000 ) + + }, + end: function( event, options ){ + + // manually clears the word based on user interaction + options.word.style.opacity = 0; + } + }); + +})( Popcorn ); -- 2.43.0