From: Dan Ventura Date: Thu, 14 Apr 2011 03:05:20 +0000 (-0400) Subject: facebook.js now uses getScript() and checks for null / incorrect options.type. Added... X-Git-Tag: v0.6~4^2~1^2~9 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=a4947d4a34c034c922ec705249fa7d396cbb719f;p=popcorn-js.git facebook.js now uses getScript() and checks for null / incorrect options.type. Added unit tests and added those tests to plugins/index.html --- diff --git a/plugins/facebook/popcorn.facebook.html b/plugins/facebook/popcorn.facebook.html index d14abfd..499be86 100644 --- a/plugins/facebook/popcorn.facebook.html +++ b/plugins/facebook/popcorn.facebook.html @@ -1,7 +1,7 @@ - Popcorn WebPage Plug-in Demo + Popcorn Facebook Plug-in Demo @@ -12,26 +12,25 @@ .play() .facebook({ type: "LIKE", - target: 'likediv' + target: "likediv" } ) .facebook({ href: "http://www.facebook.com/senecacollege", type: "LIKE-BOX", show_faces: "true", header: "false", - target: 'likeboxdiv' + target: "likeboxdiv" } ) .facebook({ href: "http://popcornjs.org/", type: "ACTIVITY", - target: 'activitydiv' + target: "activitydiv" } ) .facebook({ href: "http://www.facebook.com/senecacollege", type: "FACEPILE", - target: 'facepilediv' + target: "facepilediv" } ); - }, false); diff --git a/plugins/facebook/popcorn.facebook.js b/plugins/facebook/popcorn.facebook.js index 9155205..58f5b6a 100644 --- a/plugins/facebook/popcorn.facebook.js +++ b/plugins/facebook/popcorn.facebook.js @@ -6,7 +6,7 @@ * Places Facebook's "social plugins" inside a div ( http://developers.facebook.com/docs/plugins/ ) * Sets options according to user input or default values * Options parameter will need a target and a type - * Type is the name of the plugin in fbxml format. i.e: would have a type of like, respectively + * Type is the name of the plugin in fbxml format. Options: LIKE (default), LIKE-BOX, ACTIVITY, FACEPILE * Target is the id of the document element that the text needs to be * attached to, this target element must exist on the DOM * @@ -19,7 +19,7 @@ type: "LIKE-BOX", show_faces: "true", header: "false", - target: 'likeboxdiv' + target: "likeboxdiv" } ) This will show how many people "like" Seneca College's Facebook page, and show their profile pictures (show_faces) @@ -34,70 +34,85 @@ website: "dsventura.blogspot.com" }, options:{ - id : {elem:'input', type:'text', label:'Id'}, - type : {elem:"input", type:'text', label:"Type"}, - target : 'facebook-container' + id : {elem:"input", type:"text", label:"Id"}, + type : {elem:"input", type:"text", label:"Type"}, + target : "facebook-container" } }, _setup: function( options ) { // facebook script requires a div named fb-root - if( !document.getElementById('fb-root') ) { - var fbRoot = document.createElement( 'div' ); - fbRoot.setAttribute('id', "fb-root"); + if( !document.getElementById( "fb-root" ) ) { + var fbRoot = document.createElement( "div" ); + fbRoot.setAttribute( "id", "fb-root" ); document.body.appendChild( fbRoot ); - //initialize facebook JS SDK + + // initialize facebook JS SDK + Popcorn.getScript("http://connect.facebook.net/en_US/all.js"); window.fbAsyncInit = function() { FB.init({ - appId : 'YOUR APP ID', + appId : "YOUR APP ID", status : true, cookie : true, xfbml : true }); }; - //load facebook script asynchronously - (function() { - var e = document.createElement( 'script' ); - e.setAttribute( 'src', 'http://connect.facebook.net/en_US/all.js' ); - e.setAttribute( 'async', 'true' ); - document.getElementById( 'fb-root' ).appendChild( e ); - }()); } - options._container = document.createElement( 'fb:' + options.type.toLowerCase() ); + var validType = function( type ){ + var valid = false; + var existing = [ "like", "like-box", "activity", "facepile" ]; + + for(var i in existing){ + if ( type.toLowerCase() === existing[i] ) { + valid = true; + } + } + + return valid; + }; + + // default plugin is like button + if( typeof( options.type ) === "undefined"){ + options.type = "like"; + } else if ( !validType( options.type ) ){ + return; + } + + options._container = document.createElement( "fb:" + ( options.type.toLowerCase() || "like" ) ); - //setOptions property list doesn't accept dashes - if(options.type === "LIKE-BOX") { + // setOptions property list doesn't accept dashes + if( options.type === "LIKE-BOX" ) { options.type = "likebox"; } var setOptions = (function ( options ) { - options._container.setAttribute( 'href', ( options.href || document.URL ) ); + options._container.setAttribute( "href", ( options.href || document.URL ) ); return { like: function () { - options._container.setAttribute( 'width', ( options.width || "450" ) ); - options._container.setAttribute( 'show_faces', ( options.show_faces || "false" ) ); - options._container.setAttribute( 'layout', ( options.layout || "standard" ) ); - options._container.setAttribute( 'font', options.font ); + options._container.setAttribute( "width", ( options.width || "450" ) ); + options._container.setAttribute( "show_faces", ( options.show_faces || "false" ) ); + options._container.setAttribute( "layout", ( options.layout || "standard" ) ); + options._container.setAttribute( "font", options.font ); }, likebox: function () { - options._container.setAttribute( 'width', ( options.width || "292" ) ); - options._container.setAttribute( 'show_faces', ( options.show_faces || "false" ) ); - options._container.setAttribute( 'stream', ( options.stream || "false" ) ); - options._container.setAttribute( 'header', ( options.header || "true" ) ); + options._container.setAttribute( "width", ( options.width || "292" ) ); + options._container.setAttribute( "show_faces", ( options.show_faces || "false" ) ); + options._container.setAttribute( "stream", ( options.stream || "false" ) ); + options._container.setAttribute( "header", ( options.header || "true" ) ); }, facepile: function () { - options._container.setAttribute( 'width', ( options.width || "200" ) ); - options._container.setAttribute( 'max_rows', ( options.max_rows || "1" ) ); + options._container.setAttribute( "width", ( options.width || "200" ) ); + options._container.setAttribute( "max_rows", ( options.max_rows || "1" ) ); }, activity: function () { - options._container.setAttribute( 'width', ( options.width || "300" ) ); - options._container.setAttribute( 'height', ( options.height || "300" ) ); - options._container.setAttribute( 'header', ( options.header || "true" ) ); - options._container.setAttribute( 'border_color', ( options.border_color || "#000000" ) ); - options._container.setAttribute( 'recommendations', ( options.recommendations || "false" ) ); - options._container.setAttribute( 'font', options.font ); + options._container.setAttribute( "width", ( options.width || "300" ) ); + options._container.setAttribute( "height", ( options.height || "300" ) ); + options._container.setAttribute( "header", ( options.header || "true" ) ); + options._container.setAttribute( "border_color", ( options.border_color || "#000000" ) ); + options._container.setAttribute( "recommendations", ( options.recommendations || "false" ) ); + options._container.setAttribute( "font", options.font ); } }; })( options ); diff --git a/plugins/facebook/popcorn.facebook.unit.html b/plugins/facebook/popcorn.facebook.unit.html new file mode 100644 index 0000000..1cd24ec --- /dev/null +++ b/plugins/facebook/popcorn.facebook.unit.html @@ -0,0 +1,50 @@ + + + + Popcorn Facebook Plug-in Test + + + + + + + + + + +

Popcorn Facebook Plugin

+

+
+

+
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + diff --git a/plugins/facebook/popcorn.facebook.unit.js b/plugins/facebook/popcorn.facebook.unit.js new file mode 100644 index 0000000..9426f63 --- /dev/null +++ b/plugins/facebook/popcorn.facebook.unit.js @@ -0,0 +1,59 @@ +test("Popcorn Facebook Plugin", function () { + + var popped = Popcorn("#video"), + expects = 5, + count = 0, + interval, + interval2, + interval3, + interval4, + subtitlediv; + + expect(expects); + + function plus() { + if ( ++count===expects) { + start(); + } + } + + stop(); + + ok ('facebook' in popped, "facebook is a method of the popped instance"); + plus(); + + popped.facebook({ + type:"LIKE", + target: "likediv" + } ) + .facebook({ + href : "http://www.facebook.com/senecacollege", + type : "LIKE_BOX", + show_faces : "true", + header: "false", + target: "likeboxdiv" + } ) + .facebook({ + href : "http://popcornjs.org/", + type : "ACTIVITY", + target : "activitydiv" + } ) + .facebook({ + href : "http://www.facebook.com/senecacollege", + type : "FACEPILE", + target : "facepilediv" + } ) + .volume(0) + .play(); + + popped.exec( 5, function() { + ok ( document.getElementById( "likediv" ).innerHTML.length > 0, "No type specified. Like button added to div" ); + plus(); + ok ( document.getElementById( "likeboxdiv" ).innerHTML.length === 0, "Like box is not added to div" ); + plus(); + ok ( document.getElementById( "activitydiv" ).innerHTML.length > 0, "Activity feed is added to div" ); + plus(); + ok ( document.getElementById( "facepilediv" ).innerHTML.length > 0, "Facepile is added to div" ); + plus(); + }); +}); \ No newline at end of file diff --git a/plugins/index.html b/plugins/index.html index 7547606..c7a95f7 100644 --- a/plugins/index.html +++ b/plugins/index.html @@ -10,6 +10,7 @@