+++ /dev/null
-<!DOCTYPE html>
-<html>
-<head>
- <title>Popcorn google Map Plug-in Demo</title>
-
- <script src="../../popcorn.js"></script>
-
- <script src="popcorn.googlenews.js"></script>
- <script>
- document.addEventListener('DOMContentLoaded', function () {
- var p = Popcorn('#video')
- .volume(0)
- .play()
- .googlenews({
- start: 0, // seconds
- end: 20, // seconds
- topic: 'Oil Spill',
- target: 'newsdiv'
- } )
- .googlenews({
- start: 25, // seconds
- end: 30, // seconds
- topic: 'Village Telco',
- target: 'newsdiv'
- } );
- }, false);
- </script>
-</head>
-<body>
- <h1 id="qunit-header">Popcorn google News Plug-in Demo</h1>
- <p> Google News topic will appear at 0 seconds and disappear at 20 seconds.</p>
- <p> Google News topic will appear at 25 seconds and disappear at 30 seconds.</p>
- <div>
- <video id='video'
- controls
- width= '250px'
- poster="../../test/poster.png">
-
- <source id='mp4'
- src="../../test/trailer.mp4"
- type='video/mp4; codecs="avc1, mp4a"'>
-
- <source id='ogv'
- src="../../test/trailer.ogv"
- type='video/ogg; codecs="theora, vorbis"'>
-
- <p>Your user agent does not support the HTML5 Video element.</p>
-
- </video>
- </div>
- <div id="newsdiv"></div>
-</body>
-</html>
+++ /dev/null
-// PLUGIN: Google News
-
-(function (Popcorn) {
-
- var scriptLoaded = false,
- scriptLoading = false,
- callBack = function( data ) {
-
- if ( typeof google !== 'undefined' && google.load ) {
-
- google.load("elements", "1", {packages : ["newsshow"], callback: function() {scriptLoaded = true;}});
- } else {
-
- setTimeout( function() {
-
- callBack( data );
- }, 1);
- }
- };
-
- /**
- * Google News popcorn plug-in
- * Displays Google News information on a topic in a targeted div.
- * Options parameter will need a start, end and target.
- * Optional parameters are topic. topic defaults to "top stories"
- * Start is the time that you want this plug-in to execute
- * End is the time that you want this plug-in to stop executing
- * Target is the id of the document element that the content is
- * appended to, this target element must exist on the DOM
- * Topic is the topic of news articles you want to display.
- *
- * @param {Object} options
- *
- * Example:
- var p = Popcorn('#video')
- .googlenews({
- start: 5, // seconds, mandatory
- end: 15, // seconds, mandatory
- topic: 'oil spill', // optional
- target: 'newsdiv' // mandatory
- } )
- *
- */
- Popcorn.plugin( "googlenews" , {
-
- manifest: {
- about:{
- name: "Popcorn Google News Plugin",
- version: "0.1",
- author: "Scott Downe",
- website: "http://scottdowne.wordpress.com/"
- },
- options:{
- start : {elem:'input', type:'text', label:'In'},
- end : {elem:'input', type:'text', label:'Out'},
- target : 'news-container',
- topic : {elem:'select', type:'text', label:'Type'}
- }
- },
- _setup : function( options ) {
-
- if ( !scriptLoading ) {
-
- scriptLoading = true;
- Popcorn.getScript( "http://www.google.com/jsapi", callBack );
- }
-
- options.container = document.createElement( 'div' );
- var container = document.createElement( 'div' );
- if ( document.getElementById( options.target ) ) {
- document.getElementById( options.target ).appendChild( options.container );
- options.container.appendChild( container );
- }
-
- var readyCheck = setInterval(function() {
- if ( !scriptLoaded ) {
- return;
- }
- clearInterval( readyCheck );
-
- options.newsShow = new google.elements.NewsShow( container, {
- format : "300x250",
- queryList : [
- { q: options.topic || "Top Stories" }
- ]
- } );
-
- }, 5);
-
- options.container.style.display = "none";
-
- },
- /**
- * @member googlenews
- * The start function will be executed when the currentTime
- * of the video reaches the start time provided by the
- * options variable
- */
- start: function( event, options ){
- options.container.setAttribute( 'style', 'display:inline' );
- },
- /**
- * @member googlenews
- * The end function will be executed when the currentTime
- * of the video reaches the end time provided by the
- * options variable
- */
- end: function( event, options ){
- options.container.setAttribute( 'style', 'display:none' );
- },
- _teardown: function( options ) {
- // google news does not like this, throws an error "a is null"
- // doesn't hurt popcorn, and only happens once
- document.getElementById( options.target ) && document.getElementById( options.target ).removeChild( options.container );
- options.newsShow = null;
- }
- });
-
-})( Popcorn );
+++ /dev/null
-<!DOCTYPE html>
-<html>
-<head>
- <title>Popcorn Google News Plug-in Test</title>
- <link rel="stylesheet" href="../../test/qunit/qunit.css" type="text/css" media="screen">
- <script src="../../test/qunit/qunit.js"></script>
- <!--
- do not move - this must be called immediately prior to
- popcorn-api-draft.js
- -->
-
- <script src="../../popcorn.js"></script>
-
- <script src="popcorn.googlenews.js"></script>
- <script src="popcorn.googlenews.unit.js"></script>
-</head>
-<body>
- <h1 id="qunit-header">Popcorn Google News Plugin</h1>
- <h2 id="qunit-banner"></h2>
- <div id="qunit-testrunner-toolbar"></div>
- <h2 id="qunit-userAgent"></h2>
- <ol id="qunit-tests"></ol>
- <div id="qunit-fixture"> </div>
-
- <video id='video'
- controls preload='none'
- width= '250px'
- poster="../../test/poster.png">
-
- <source id='mp4'
- src="../../test/trailer.mp4"
- type='video/mp4; codecs="avc1, mp4a"'>
-
- <source id='ogv'
- src="../../test/trailer.ogv"
- type='video/ogg; codecs="theora, vorbis"'>
-
- <p>Your user agent does not support the HTML5 Video element.</p>
-
- </video>
- <div id="googlenewsdiv"></div>
-</body>
-</html>
+++ /dev/null
-test( "Popcorn google news Plugin", function () {
-
- var popped = Popcorn( "#video" ),
- expects = 8,
- count = 0,
- setupId,
- googlenewsdiv = document.getElementById( "googlenewsdiv" );
-
- expect(expects);
-
- function plus() {
- if ( ++count===expects ) {
- start();
- }
- }
-
- stop();
-
- ok ( "googlenews" in popped, "googlenews is a method of the popped instance" );
- plus();
-
- equals ( googlenewsdiv.innerHTML, "", "initially, there is nothing inside the googlenewsdiv" );
- plus();
-
- popped.googlenews({
- start: 0, // seconds
- end: 2, // seconds
- topic: "Oil Spill",
- target: "googlenewsdiv"
- })
- .googlenews({
- start: 2, // seconds
- end: 4, // seconds
- topic: "Village Telco",
- target: "googlenewsdiv"
- })
- .volume( 0 );
-
- setupId = popped.getLastTrackEventId();
-
- popped.exec( 0, function() {
- equals( googlenewsdiv.childElementCount, 2, "googlenewsdiv now has two inner elements" );
- plus();
- equals( googlenewsdiv.children[0].style.display , "inline", "first googlenews is visible on the page" );
- plus();
- });
-
- popped.exec( 3, function() {
- equals( googlenewsdiv.children[1].style.display , "inline", "second googlenews is visible on the page" );
- plus();
- });
-
- popped.exec( 4, function() {
- equals( googlenewsdiv.children[1].style.display , "none", "second googlenews is no longer visible on the page" );
- plus();
- equals( googlenewsdiv.children[0].style.display , "none", "first googlenews is no longer visible on the page" );
- plus();
-
- popped.pause().removeTrackEvent( setupId );
- ok( !googlenewsdiv.children[1], "removed google news was properly destroyed" );
- plus();
- });
-
- popped.play();
-
-});
start: 5, // seconds
end: 15, // seconds
text: 'this is the first subtitle of 2011',
- language: "en",
- languagesrc: "language",
- accessibilitysrc: "accessibility"
} )
.subtitle({
start: 20, // seconds
end: 45, // seconds
text: 'this is the second subtitle of 2011',
- language: "en",
- languagesrc: "language",
- accessibilitysrc: "accessibility"
} )
}, false);
</video>
</div>
- <h2>Choose your language</h2>
- <select id="language">
- <option value="zh" selected="selected">Chinese</option>
- <option value="en">English</option>
- <option value="fr">French</option>
- <option value="de">German</option>
- <option value="it">Italian</option>
- <option value="ja">Japanese</option>
- <option value="ko">Korean</option>
- <option value="fa">Persian</option>
- <option value="pl">Polish</option>
- <option value="pt">Portuguese</option>
- <option value="es">Spanish</option>
- </select>
- <div>
- with help from <a href="http://google.com/translate">Google Translate</a><br />
- <input type="checkbox" id="accessibility" checked="checked" />All subtitles (accessibility)
- </div>
</body>
</html>
(function ( Popcorn ) {
- var scriptLoaded = false,
- i = 0,
- callBack = function( data ) {
-
- if ( window.google && google.load ) {
-
- google.load( "language", "1", {
- callback: function() {
- scriptLoaded = true;
- }
- });
- } else {
-
- setTimeout( function() {
-
- callBack( data );
- }, 1);
- }
- },
+ var i = 0,
createDefaultContainer = function( context ) {
var ctxContainer = context.container = document.createElement( "div" ),
context.media.parentNode.appendChild( ctxContainer );
};
- Popcorn.getScript( "http://www.google.com/jsapi", callBack );
-
/**
* Subtitle popcorn plug-in
* Displays a subtitle over the video, or in the target div
* appended to, this target element must exist on the DOM
* Text is the text of the subtitle you want to display.
*
- * Language is the expected language the subtitle text is in
- * Languagesrc is the target id of the element that contains
- * the language value ("en", "fr", etc.) to translate the text into
- * example:
- * <select id="language">
- * <option value="zh" selected="selected">Chinese</option>
- * <option value="en">English</option>
- * <option value="fr">French</option>
- * <option value="de">German</option>
- * <option value="it">Italian</option>
- * <option value="ja">Japanese</option>
- * <option value="ko">Korean</option>
- * <option value="fa">Persian</option>
- * <option value="pl">Polish</option>
- * <option value="pt">Portuguese</option>
- * <option value="es">Spanish</option>
- * </select>
- * Accessibilitysrc is the target id of a checkbox element
- * checked means show all subtitles regardless of language and languagesrc
- * not checked means only translate if language and languagesrc are different
- * if no accessibilitysrc exists, default is to display all subtitles regardless
- *
* @param {Object} options
*
* Example:
end: 15, // seconds, mandatory
text: 'Hellow world', // optional
target: 'subtitlediv', // optional
- language: 'en', // optional
- languagesrc: 'language', // optional
- accessibilitysrc: 'accessibility' // optional
} )
*
*/
- // translates whatever is in options.container into selected language
- var translate = function( options, text ) {
-
- options.selectedLanguage = options.languageSrc.options[ options.languageSrc.selectedIndex ].value;
- google.language.translate( text, "", options.selectedLanguage, function( result ) {
-
- for( var k = 0, children = options.container.children, len = children.length; k < len; k++ ) {
- if ( children[ k ].style.display === "inline" ) {
- children[ k ].innerHTML = result.translation;
- }
- }
-
- });
- };
-
Popcorn.plugin( "subtitle" , {
manifest: {
},
_setup: function( options ) {
- var newdiv = document.createElement( "div" ),
- accessibility = document.getElementById( options.accessibilitysrc );
+ var newdiv = document.createElement( "div" );
- newdiv.id = "subtitle-" + i;
+ newdiv.id = "subtitle-" + i++;
newdiv.style.display = "none";
- i++;
// Creates a div for all subtitles to use
( !this.container && ( !options.target || options.target === "subtitle-container" ) ) &&
options.showSubtitle = function() {
options.innerContainer.innerHTML = options.text;
};
- options.toggleSubtitles = function() {};
-
- var readyCheck = setInterval(function() {
- if ( !scriptLoaded ) {
- return;
- }
- clearInterval( readyCheck );
-
- if ( options.languagesrc ) {
- options.showSubtitle = translate;
- options.languageSrc = document.getElementById( options.languagesrc );
- options.selectedLanguage = options.languageSrc.options[ options.languageSrc.selectedIndex ].value;
-
- if ( !this.languageSources ) {
- this.languageSources = {};
- }
-
- if ( !this.languageSources[ options.languagesrc ] ) {
- this.languageSources[ options.languagesrc ] = {};
- }
-
- if ( !this.languageSources[ options.languagesrc ][ options.target ] ) {
- this.languageSources[ options.languagesrc ][ options.target ] = true;
-
- options.languageSrc.addEventListener( "change", function() {
-
- options.toggleSubtitles();
-
- for( var k = 0, children = options.container.children, len = children.length; k < len; k++ ) {
- if ( children[ k ].style.display === "inline" ) {
- options.showSubtitle( options, children[ k ].innerHTML );
- }
- }
-
- }, false );
-
- }
-
- }
- if ( accessibility ) {
- 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;
- }
- };
-
- options.accessibility.addEventListener( "change", options.toggleSubtitles, false );
-
- // initiate it once to set starting state
- options.toggleSubtitles();
- }
- }, 5);
-
},
/**
* @member subtitle
<p>Your user agent does not support the HTML5 Video element.</p>
</video>
- <h2>Choose your language</h2>
- <select id="language">
- <option value="en" selected="selected">English</option>
- </select>
- <div>
- with help from <a href="http://google.com/translate">Google Translate</a><br />
- <input type="checkbox" id="accessibility" checked="checked" />All subtitles (accessibility)
- </div>
</body>
</html>
var popped = Popcorn( "#video" ),
popped2 = Popcorn( "#video2" ),
- expects = 16,
+ expects = 12,
count = 0,
subTop = 9001,
subLeft = 9001,
start: 0,
end: 2,
text: 'this is the first subtitle of 2011',
- language: "en",
- languagesrc: "language",
- accessibilitysrc: "accessibility"
} )
.subtitle({
start: 2,
end: 4,
text: 'this is the second subtitle of 2011',
- language: "en",
- languagesrc: "language",
- accessibilitysrc: "accessibility"
} )
.subtitle({
start: 5,
end: 7,
text: 'this is the third subtitle of 2011',
- language: "en",
- languagesrc: "language",
- accessibilitysrc: "accessibility"
} )
.volume(0)
.play();
popped.media.play();
});
-
- popped.exec( 6, function() {
-
- popped.media.play();
-
- equals (subtitlediv.style.display, "inline", "subtitles being displayed with accessiblity on" );
- plus();
-
- // turn accessibility off
- document.getElementById( "accessibility" ).click();
-
- equals (subtitlediv.style.display, "none", "subtitles not being displayed with accessiblity off" );
- plus();
-
- // turn accessibility back on
- document.getElementById( "accessibility" ).click();
-
- equals (subtitlediv.style.display, "inline", "subtitles being displayed with accessiblity back on" );
- plus();
-
- equals (subtitlediv.children[ 2 ].innerHTML, "this is the third subtitle of 2011", "subtitle displaying correct information" );
- plus();
- popped.media.play();
-
- });
popped.exec( 8, function() {
popped.pause();