]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
facebook.js now uses getScript() and checks for null / incorrect options.type. Added...
authorDan Ventura <distraction.attack@gmail.com>
Thu, 14 Apr 2011 03:05:20 +0000 (23:05 -0400)
committerDan Ventura <distraction.attack@gmail.com>
Thu, 14 Apr 2011 03:05:20 +0000 (23:05 -0400)
plugins/facebook/popcorn.facebook.html
plugins/facebook/popcorn.facebook.js
plugins/facebook/popcorn.facebook.unit.html [new file with mode: 0644]
plugins/facebook/popcorn.facebook.unit.js [new file with mode: 0644]
plugins/index.html

index d14abfd9add384de59e3d4eef5df5c62596619db..499be8613571e5457eb7ba8b87ac3e709da6c959 100644 (file)
@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html>
 <head>
-  <title>Popcorn WebPage Plug-in Demo</title>
+  <title>Popcorn Facebook Plug-in Demo</title>
   
   <script src="../../popcorn.js"></script>
   <script src="popcorn.facebook.js"></script>
       .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);
 
   </script>
index 915520543db126de3e57eb6fc1283f2fa7faf213..58f5b6aae42e513649c38564efc1c4729e32e088 100644 (file)
@@ -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: <fb:like> 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)
         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 (file)
index 0000000..1cd24ec
--- /dev/null
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn Facebook 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.facebook.js"></script>
+  <script src="popcorn.facebook.unit.js"></script>
+</head>
+<body>
+  <h1 id="qunit-header">Popcorn Facebook 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>
+    <div id="likediv"></div>
+    <div id="likeboxdiv"></div>
+  </div>
+  <div style="position:absolute;left:300px;top:150px">
+    <div id="facepilediv"></div>
+    <div id="activitydiv"></div>
+  </div>
+</body>
+</html>
diff --git a/plugins/facebook/popcorn.facebook.unit.js b/plugins/facebook/popcorn.facebook.unit.js
new file mode 100644 (file)
index 0000000..9426f63
--- /dev/null
@@ -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
index 7547606410100fb62cb5a372f783d6057685123f..c7a95f7739bdcafd7268d89b7363d63a2ad0e8de 100644 (file)
@@ -10,6 +10,7 @@
     <ul id="menuItems">
       <li><a onclick="clearEvents();" target="out" href="attribution/popcorn.attribution.unit.html">attribution</a></li>
       <li><a onclick="clearEvents();" target="out" href="code/popcorn.code.unit.html">code</a></li>
+      <li><a onclick="clearEvents();" target="out" href="facebook/popcorn.facebook.unit.html">facebook</a></li>
       <li><a onclick="clearEvents();" target="out" href="flickr/popcorn.flickr.unit.html">flickr</a></li>
       <li><a onclick="clearEvents();" target="out" href="footnote/popcorn.footnote.unit.html">footnote</a></li>
       <li><a onclick="clearEvents();" target="out" href="googlemap/popcorn.googlemap.unit.html">googlemap</a></li>
   <script>
   var eventList = [];
   function runAllTests(){
-    var testUrl = [ "attribution", "code", "flickr", "footnote", "googlemap", 
-                    "googlenews", "image", "lastfm", "lowerthird", "mustache", 
-                    "subtitle", "tagthisperson", "twitter", "webpage", "wikipedia" ];
+    var testUrl = [ "attribution", "code", "facebook", "flickr", "footnote", 
+                    "googlemap", "googlenews", "image", "lastfm", "lowerthird",
+                    "mustache", "subtitle", "tagthisperson", "twitter", "webpage", 
+                    "wikipedia" ];
     //googlenews and lowerthird tests do not exist, therefore their test time is set to 0
-    var testDur = [ 17000, 20000, 10000, 20000, 11000,
-                    0, 10000, 10000, 0, 15000,
-                    25000, 21000, 10000, 21000, 21000 ];
+    var testDur = [ 17000, 20000, 10000, 10000, 20000, 
+                    11000, 0, 10000, 10000, 0, 
+                    15000, 25000, 21000, 10000, 21000, 
+                    21000 ];
     
     var setTest = function( index ) {
       var url = function( str ) {