From 96b904b9b01eb2b154e0088048c820ec92c7aa70 Mon Sep 17 00:00:00 2001 From: Matthew Schranz Date: Mon, 26 Sep 2011 10:47:06 -0400 Subject: [PATCH] [#734] Removed defaulting plugin type, removed tests and added one test. --- plugins/facebook/popcorn.facebook.js | 112 +++++++++------------- plugins/facebook/popcorn.facebook.unit.js | 66 +++++-------- 2 files changed, 69 insertions(+), 109 deletions(-) diff --git a/plugins/facebook/popcorn.facebook.js b/plugins/facebook/popcorn.facebook.js index 8087cb3..26310b8 100755 --- a/plugins/facebook/popcorn.facebook.js +++ b/plugins/facebook/popcorn.facebook.js @@ -47,25 +47,13 @@ */ var ranOnce = false; - - function toggle( container, display ) { - if ( container ) { - container.style.display = display; - - return; - } - - setTimeout(function() { - toggle( container, display ); - }, 10 ); - } - + Popcorn.plugin( "facebook" , { manifest: { about: { name: "Popcorn Facebook Plugin", version: "0.1", - author: "Dan Ventura", + author : "Dan Ventura, Matthew Schranz: @mjschranz", website: "dsventura.blogspot.com" }, options: { @@ -177,23 +165,7 @@ _setup: function( options ) { var target = document.getElementById( options.target ), - _type = options.type, - _font = options.font, - _xid = options.xid, - _href = options.href, - _site = options.site, - _height = options.height, - _width = options.width, - _action = options.action, - _stream = options.stream, - _header = options.header, - _layout = options.layout, - _maxRows = options.max_rows, - _borderColor = options.border_color, - _colorScheme = options.colorscheme, - _showFaces = options.show_faces, - _recom = options.recommendations, - _APTF = options.always_post_to_friends; + _type = options.type; // facebook script requires a div named fb-root if ( !document.getElementById( "fb-root" ) ) { @@ -216,24 +188,25 @@ }); }; } - + + // Lowercase to make value consistent no matter what user inputs + _type = _type.toLowerCase(); + var validType = function( type ) { - return ( [ "like", "like-box", "activity", "facepile", "comments", "live-stream", "send" ].indexOf( type ) > -1 ); + return ( ["like", "like-box", "activity", "facepile", "live-stream", "send"].indexOf( type ) > -1 ); }; - // default plugin is like button - _type = ( _type || "like" ).toLowerCase(); - - // default plugin is like button + // Checks if type is valid if ( !validType( _type ) ) { - _type = "like"; + throw new Error( "Facebook plugin type was invalid." ); } - + + options._container = document.createElement( "fb:" +_type ); var setOptions = (function( options ) { - options._container.style.display = "none"; + //options._container.style.display = "none"; // activity feed uses 'site' rather than 'href' var attr = _type === "activity" ? "site" : "href"; @@ -243,44 +216,44 @@ return { "like": function () { options._container.setAttribute( "send", ( options.send || false ) ); - options._container.setAttribute( "width", _width ); - options._container.setAttribute( "show_faces", _showFaces ); - options._container.setAttribute( "layout", _layout ); - options._container.setAttribute( "font", _font ); - options._container.setAttribute( "colorscheme", _colorScheme ); + options._container.setAttribute( "width", options.width ); + options._container.setAttribute( "show_faces", options.show_faces ); + options._container.setAttribute( "layout", options.layout ); + options._container.setAttribute( "font", options.font ); + options._container.setAttribute( "colorscheme", options.colorscheme ); }, "like-box": function () { - options._container.setAttribute( "height", ( _height || 250 ) ); - options._container.setAttribute( "width", _width ); - options._container.setAttribute( "show_faces", _showFaces ); - options._container.setAttribute( "stream", _stream ); - options._container.setAttribute( "header", _header ); - options._container.setAttribute( "colorscheme", _colorScheme ); + options._container.setAttribute( "height", ( options.height || 250 ) ); + options._container.setAttribute( "width", options.width ); + options._container.setAttribute( "show_faces", options.show_faces ); + options._container.setAttribute( "stream", options.stream ); + options._container.setAttribute( "header", options.header ); + options._container.setAttribute( "colorscheme", options.colorscheme ); }, "facepile": function () { - options._container.setAttribute( "height", _height ); - options._container.setAttribute( "width", _width ); - options._container.setAttribute( "max_rows", ( _maxRows || 1 ) ); + options._container.setAttribute( "height", options.height ); + options._container.setAttribute( "width", options.width ); + options._container.setAttribute( "max_rows", ( options.max_rows || 1 ) ); }, "activity": function () { - options._container.setAttribute( "width", _width ); - options._container.setAttribute( "height", _height ); - options._container.setAttribute( "header", _header ); - options._container.setAttribute( "border_color", _borderColor ); - options._container.setAttribute( "recommendations", _recom ); - options._container.setAttribute( "font", _font ); - options._container.setAttribute( "colorscheme", _colorScheme ); + options._container.setAttribute( "width", options.width ); + options._container.setAttribute( "height", options.height ); + options._container.setAttribute( "header", options.header ); + options._container.setAttribute( "border_color", options.border_color ); + options._container.setAttribute( "recommendations", options.recommendations ); + options._container.setAttribute( "font", options.font ); + options._container.setAttribute( "colorscheme", options.colorscheme ); }, "live-stream": function() { - options._container.setAttribute( "width", ( _width || 400 ) ); - options._container.setAttribute( "height", ( _height || 500 ) ); - options._container.setAttribute( "always_post_to_friends", ( _APTF || false ) ); + options._container.setAttribute( "width", ( options.width || 400 ) ); + options._container.setAttribute( "height", ( options.height || 500 ) ); + options._container.setAttribute( "always_post_to_friends", ( options.always_post_to_friends || false ) ); options._container.setAttribute( "event_app_id", options.event_app_id ); - options._container.setAttribute( "xid", _xid ); + options._container.setAttribute( "xid", options.xid ); }, "send": function() { - options._container.setAttribute( "font", _font ); - options._container.setAttribute( "colorscheme", _colorScheme ); + options._container.setAttribute( "font", options.font ); + options._container.setAttribute( "colorscheme", options.colorscheme ); } }; })( options ); @@ -299,7 +272,7 @@ * options variable */ start: function( event, options ){ - toggle( options._container, "inline" ); + options._container.style.display = "inline"; }, /** * @member facebook @@ -308,7 +281,8 @@ * options variable */ end: function( event, options ){ - toggle ( options._container, "none" ); + options._container.style.display = "none"; + options._container.innerHTML = ""; } }); diff --git a/plugins/facebook/popcorn.facebook.unit.js b/plugins/facebook/popcorn.facebook.unit.js index bde1855..58e2ac5 100755 --- a/plugins/facebook/popcorn.facebook.unit.js +++ b/plugins/facebook/popcorn.facebook.unit.js @@ -1,7 +1,7 @@ -test( "Popcorn Facebook Plugin", function() { - - var popped = Popcorn( "#video" ), - expects = 9, +test("Popcorn Facebook Plugin", function () { + + var popped = Popcorn("#video"), + expects = 5, count = 0, interval, interval2, @@ -23,23 +23,11 @@ test( "Popcorn Facebook Plugin", function() { plus(); popped.facebook({ - target: "likediv", - start: 1, - end: 6 - }) - .facebook({ - href: "http://www.facebook.com/senecacollege", - type: "LIKE_BOX", - target: "likeboxdiv", - start: 2, - end: 6 - }) - .facebook({ - site: "http://popcornjs.org/", - type: "ACTIVITY", - target: "activitydiv", - start: 3, - end: 6 + site : "http://popcornjs.org/", + type : "ACTIVITY", + target : "activitydiv", + start : 3, + end : 6 }) .facebook({ href: "http://www.facebook.com/senecacollege", @@ -52,28 +40,14 @@ test( "Popcorn Facebook Plugin", function() { .volume( 0 ) .play(); - ok( document.getElementById( "likediv" ), "likediv exists on the page" ); - plus(); - ok( document.getElementById( "likeboxdiv" ), "likeboxdiv exists on the page" ); - plus(); - ok( document.getElementById( "activitydiv" ), "activitydiv exists on the page" ); + + ok (document.getElementById('activitydiv'), "activitydiv exists on the page" ); plus(); ok( document.getElementById( "facepilediv" ), "facepilediv exists on the page" ); plus(); // I inspected the html genterated by facebook, and found that there are no uniquely identifying attributes between plug-in types // so right now, we just check ot make sure that facebook is returning a plugin and displaying it at the correct time. - - popped.exec( 2, function() { - ok( document.getElementById( "likediv" ).innerHTML, "likediv is not empty at 0:02 (expected)" ); - plus(); - }); - - popped.exec( 3, function() { - ok( document.getElementById( "likeboxdiv" ).innerHTML, "likeboxdiv is not empty at 0:03 (expected)" ); - plus(); - }); - popped.exec( 4, function() { ok( document.getElementById( "activitydiv" ).innerHTML, "Activitydiv is not empty at 0:04 (expected)" ); plus(); @@ -83,16 +57,16 @@ test( "Popcorn Facebook Plugin", function() { ok( document.getElementById( "facepilediv" ).innerHTML, "Facepilediv is not empty at 0:05 (expected)" ); plus(); }); - }); -test( "Test Empty Block", function () { + +test( "Test Initialized Facebook Blocks", function () { Popcorn.plugin.debug = true; var pop = Popcorn( "#video" ); - expect( 1 ); + expect( 2 ); // Tests for thrown Error on emtpy block try { @@ -101,4 +75,16 @@ test( "Test Empty Block", function () { ok( true, "Empty event was caught by debugger" ); } + // Tests for thrown Error on invalid plugin type + try { + pop.facebook({ + target: "likediv", + type: "asdasd", + start : 1, + end : 6 + } ); + } catch( e ) { + ok( true, "Facebook plugin type was invalid." ); + } }); + -- 2.43.0