From: ScottDowne Date: Mon, 20 Dec 2010 16:18:03 +0000 (-0500) Subject: [#166] initial flickr plugin without unit tests X-Git-Tag: v0.2~36 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=3072f46a2cc310abf4d629a1d0b6e4686c08e8f5;p=popcorn-js.git [#166] initial flickr plugin without unit tests --- diff --git a/plugins/flickr/popcorn.flickr.html b/plugins/flickr/popcorn.flickr.html new file mode 100644 index 0000000..b1a17fa --- /dev/null +++ b/plugins/flickr/popcorn.flickr.html @@ -0,0 +1,54 @@ + + + + Popcorn Flickr Plug-in Demo + + + + + + + +

Popcorn Flickr Plug-in Demo

+

Flickr images will appear at 5 seconds and disappear at 15 seconds.

+

More Flickr images will appear at 20 seconds and disappear at 45 seconds.

+
+ +
+
+ + diff --git a/plugins/flickr/popcorn.flickr.js b/plugins/flickr/popcorn.flickr.js new file mode 100644 index 0000000..98fd020 --- /dev/null +++ b/plugins/flickr/popcorn.flickr.js @@ -0,0 +1,83 @@ +// PLUGIN: FLICKR + +(function (Popcorn) { + + /** + * Flickr popcorn plug-in + * Appends a users Flickr images to an element on the page. + * Options parameter will need a start, end, target and userid. + * 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 + * Userid is the id of who's Flickr images you wish to show + * Target is the id of the document element that the images are + * appended to, this target element must exist on the DOM + * + * @param {Object} options + * + * Example: + var p = Popcorn('#video') + .footnote({ + start: 5, // seconds, mandatory + end: 15, // seconds, mandatory + userid: '35034346917@N01', // mandatory + numberofimages: '8', // optional + height: '50px', // optional + width: '50px', // optional + padding: '5px', // optional + border: '0px', // optional + target: 'flickrdiv' // mandatory + } ) + * + */ + Popcorn.plugin( "flickr" , { + _setup: function( options ) { + options.container = document.createElement( 'div' ); + options.container.style.display = "none"; + document.getElementById( options.target ).appendChild( options.container ); + var height = options.height || "50px", + width = options.width || "50px", + count = options.numberofimages || 4, + padding = options.padding || "5px", + border = options.border || "0px"; + + $.getJSON( "http://api.flickr.com/services/feeds/photos_public.gne?id=" + options.userid + "&lang=en-us&format=json&jsoncallback=?", function( data ){ + options.container.innerHTML = "

" + data.title + "

"; + $.each( data.items, function( i, item ) { + if ( i < count ) { + var link = document.createElement('a'); + link.setAttribute( 'href', item.link ); + link.setAttribute( "target", "_blank" ); + var image = document.createElement( 'img' ); + image.setAttribute( 'src', item.media.m ); + image.setAttribute( 'height', height ); + image.setAttribute( 'width', width ); + image.setAttribute( 'style', 'border:' + border + ';padding:' + padding ); + link.appendChild( image ); + options.container.appendChild( link ); + } else { + return false; + } + }); + }); + }, + /** + * @member Flickr + * 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.style.display = "inline"; + }, + /** + * @member Flickr + * 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.style.display = "none"; + } + }); + +})( Popcorn ); diff --git a/plugins/flickr/popcorn.flickr.unit.html b/plugins/flickr/popcorn.flickr.unit.html new file mode 100644 index 0000000..aa40c53 --- /dev/null +++ b/plugins/flickr/popcorn.flickr.unit.html @@ -0,0 +1,45 @@ + + + + Popcorn API + + + + + + + + + + + + +

Popcorn Flickr Plugin

+

+
+

+
    +
    + + +
    + + diff --git a/plugins/flickr/popcorn.flickr.unit.js b/plugins/flickr/popcorn.flickr.unit.js new file mode 100644 index 0000000..97ec034 --- /dev/null +++ b/plugins/flickr/popcorn.flickr.unit.js @@ -0,0 +1,68 @@ +test("Popcorn Flickr Plugin", function () { + + var popped = Popcorn("#video"), + expects = 6, + count = 0, + interval, + interval2, + interval3, + flickrdiv = document.getElementById('flickrdiv'); + + var images = document.getElementsByTagName('img'); + + expect(expects); + + function plus() { + if ( ++count===expects) { + start(); + } + } + + stop(); + + ok('flickr' in popped, "flickr is a method of the popped instance"); + plus(); + + equals ( flickrdiv.innerHTML, "", "initially, there is nothing inside the flickrdiv" ); + plus(); + + popped.flickr({ + start: 5, // seconds + end: 15, // seconds + userid: '35034346917@N01', + numberofimages: '1', + target: 'flickrdiv' + } ); + + console.log(images); + + /*interval = setInterval( function() { + if( popped.currentTime() > 5 && popped.currentTime() <= 15 ) { + console.log(images[0].style); + ok( images[0].style.display === "inline" && images[1].style.display === "none", "first image is displayed, second is not" ); + plus(); + clearInterval( interval ); + } + }, 5000); + + interval2 = setInterval( function() { + if( popped.currentTime() > 15 && popped.currentTime() < 35 ) { + console.log(images); + ok( images[0].style.display === "none" && images[1].style.display === "none", "neither image is displayed" ); + plus(); + clearInterval( interval2 ); + } + }, 5000); + + interval3 = setInterval( function() { + if( popped.currentTime() > 35 && popped.currentTime() < 45 ) { + console.log(images); + ok( images[0].style.display === "none" && images[1].style.display === "inline", "second image is displayed, first is not" ); + plus(); + clearInterval( interval3 ); + } + }, 5000);*/ + + popped.play(); + +});