]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#734] Removed defaulting plugin type, removed tests and added one test.
authorMatthew Schranz <schranz.m@gmail.com>
Mon, 26 Sep 2011 14:47:06 +0000 (10:47 -0400)
committerMatthew Schranz <schranz.m@gmail.com>
Tue, 27 Sep 2011 16:13:57 +0000 (12:13 -0400)
plugins/facebook/popcorn.facebook.js
plugins/facebook/popcorn.facebook.unit.js

index 8087cb387e2902502c11d43968dd887f0c4cdbed..26310b8b0acd43fd45c33d9e2719b649ed2a14ad 100755 (executable)
   */
 
   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: {
     _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" ) ) {
           });
         };
       }
-
+      
+      // 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";
         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 );
     * options variable
     */
     start: function( event, options ){
-      toggle( options._container, "inline" );
+      options._container.style.display = "inline";
     },
     /**
     * @member facebook
     * options variable
     */
     end: function( event, options ){
-      toggle ( options._container, "none" );
+      options._container.style.display = "none";
+      options._container.innerHTML = "";
     }
   });
 
index bde1855ea9aba0fe81b8da93b203a9d19148ef6b..58e2ac554911775d4d7a56b4a8d075d0cc4b559d 100755 (executable)
@@ -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." );  
+  }  
 });
+