]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Added app_id capability. Added more plugins: live-stream, send, and comments(plugin...
authorDan Ventura <distraction.attack@gmail.com>
Tue, 17 May 2011 18:00:46 +0000 (14:00 -0400)
committerDan Ventura <distraction.attack@gmail.com>
Tue, 17 May 2011 18:00:46 +0000 (14:00 -0400)
plugins/facebook/popcorn.facebook.html
plugins/facebook/popcorn.facebook.js

index 3e12cd8390b1a4b5ce1b12a2db0658b830972f2e..c154af8f77ce54a4de52ca95425d14ef80b38ffa 100644 (file)
@@ -9,36 +9,58 @@
     document.addEventListener('DOMContentLoaded', function () {
       var p = Popcorn('#video')
       .volume(0)
-      .play() 
+      .play()
+      .facebook({
+        num_posts  : 2,
+        type       : "COMMENTS",
+        target     : "likediv",
+        start      : 15,
+        end        : 30,
+        colorscheme:'dark'
+      } )
+      .facebook({
+        type        : "live-stream",
+        target      : "activitydiv",
+        start       : 1,
+        end         : 10,
+        event_app_id: 174243249296725 // id is from example http://developers.facebook.com/docs/reference/plugins/live-stream/
+      } )
       .facebook({
         type  : "LIKE",
         target: "likediv",
+        layout: "box_count",
         start : 5,
         end   : 10
       } )
+      .facebook({
+        type   : "send",
+        target : "likediv",
+        start  : 1,
+        end    : 5
+      } )
       .facebook({
         href  : "http://www.facebook.com/senecacollege",
         type  : "LIKE-BOX",
         show_faces : "true",
         header: "false",
         target: "likeboxdiv",
-        start : 3,
-        end   : 8
+        start : 6,
+        end   : 10
       } )
       .facebook({
         site  : "http://popcornjs.org/",
         type  : "ACTIVITY",
         target: "activitydiv",
         header: true,
-        start : 9,
-        end   : 13
+        start : 11,
+        end   : 15
       } )
       .facebook({
         href  : "http://www.facebook.com/senecacollege",
         type  : "FACEPILE",
         target: "facepilediv",
         width : 300,
-        start : 5,
+        start : 10,
         end   : 15
       } );
     }, false);
index 9d850bc7675918d247aafcbc3105632c12c66c27..5c88d94ce90d0bcca67f1e60402777a93be0cf7a 100644 (file)
@@ -2,46 +2,53 @@
 
 (function (Popcorn){
 /**
-   * Facebook Popcorn plug-in 
-   * 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, type, start and end time
-   * 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
-   * 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
-   * 
-   * @param {Object} options
-   * 
-   * Example:
-     var p = Popcorn('#video')
-        .facebook({
-          type  : "LIKE-BOX",
-          target: "likeboxdiv",
-          start : 3,
-          end   : 10,
-          href  : "http://www.facebook.com/senecacollege",
-          show_faces: "true",
-          header: "false"
-        } )
-   * This will show how many people "like" Seneca College's Facebook page, and show their profile pictures (show_faces)
-   *
-   Other than the mandatory four parameters, there are several optional parameters (Some options are only applicable to certain plugins)
-   * Font - the font of the text contained in the plugin. Options: arial / segoe ui / tahoma / trebuchet ms / verdana / lucida grande
-   * Action - like button will either "Like" or "Recommend". Options: recommend / like(default)
-   * Recommendations - shows recommendations, if any, in the bottom half of activity feed. Options: true / false(default)
-   * Border_color - border color of the activity feed. Names (i.e: "white") and html color codes are valid
-   * Max_rows - number of rows to disperse pictures in facepile. Default is 1
-   * Stream - displays a the latest posts from the specified page's wall. Options: true / false(default)
-   * Header - displays the title of like-box or activity feed. Options: true / false(default)
-   * Colorscheme - changes the color of almost all plugins. Options: light(default) / dark
-   * Layout - changes the format of the 'like' count (written in english or a number in a callout).
-     Options: box_count / button_count / standard(default)
-   * Show_faces - show pictures beside like button and like-box. Options: true / false(default)
-   * Href - url to apply to the plugin. Default is current page
-   * Site - href for activity feed. No idea why it must be "site". Default is current page
-   * Type - determines which plugin to create
-   */
+  * Facebook Popcorn plug-in 
+  * 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, type, start and end time
+  * 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
+  * 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
+  *
+  * Other than the mandatory four parameters, there are several optional parameters (Some options are only applicable to certain plugins)
+  * Action - like button will either "Like" or "Recommend". Options: recommend / like(default)
+  * Always_post_to_friends - live-stream posts will be always be posted on your facebook wall if true. Options: true / false(default)
+  * Border_color - border color of the activity feed. Names (i.e: "white") and html color codes are valid
+  * Colorscheme - changes the color of almost all plugins. Options: light(default) / dark
+  * Event_app_id - an app_id is required for the live-stream plugin
+  * Font - the font of the text contained in the plugin. Options: arial / segoe ui / tahoma / trebuchet ms / verdana / lucida grande
+  * Header - displays the title of like-box or activity feed. Options: true / false(default)
+  * Href - url to apply to the plugin. Default is current page
+  * Layout - changes the format of the 'like' count (written in english or a number in a callout).
+  *          Options: box_count / button_count / standard(default)
+  * Max_rows - number of rows to disperse pictures in facepile. Default is 1
+  * Num_posts - number of posts to display with comments plugin. Default is 10
+  * Recommendations - shows recommendations, if any, in the bottom half of activity feed. Options: true / false(default)
+  * Show_faces - show pictures beside like button and like-box. Options: true / false(default)
+  * Site - href for activity feed. No idea why it must be "site". Default is current page
+  * Stream - displays a the latest posts from the specified page's wall. Options: true / false(default)
+  * Type - determines which plugin to create. Case insensitive
+  * Xid - unique identifier if more than one live-streams are on one page
+  *
+  * @param {Object} options
+  * 
+  * Example:
+    var p = Popcorn('#video')
+      .facebook({
+        type  : "LIKE-BOX",
+        target: "likeboxdiv",
+        start : 3,
+        end   : 10,
+        href  : "http://www.facebook.com/senecacollege",
+        show_faces: "true",
+        header: "false"
+      } )
+  * This will show how many people "like" Seneca College's Facebook page, and show their profile pictures
+  */
+  
+  var ranOnce = false;
+  
   Popcorn.plugin( "facebook" , {  
     manifest:{
       about:{
         website: "dsventura.blogspot.com"
       },
       options:{
-        type   : {elem:"select", options:["LIKE", "LIKE-BOX", "ACTIVITY", "FACEPILE"], label:"Type"},
+        type   : {elem:"select", options:["LIKE", "LIKE-BOX", "ACTIVITY", "FACEPILE", "LIVE-STREAM", "SEND"], label:"Type"},
         target : "facebook-container",
         start  : {elem:'input', type:'number', label:'In'},
         end    : {elem:'input', type:'number', label:'Out'},
         // optional parameters:
-        font   : {elem:"input", type:"text", label:"font"},
+        font   : {elem:"input", type:"text", label:"font"},        
+        xid    : {elem:"input", type:"text", label:"Xid"},
+        href   : {elem:"input", type:"text", label:"Href"},
+        site   : {elem:"input", type:"text", label:"Site"},
+        height : {elem:"input", type:"text", label:"Height"},
+        width  : {elem:"input", type:"text", label:"Width"},
         action : {elem:"select", options:["like", "recommend"], label:"Action"},
-        recommendations : {elem:"select", options:["false", "true"], label:"Recommendations"},
-        border_color    : {elem:"input",  type:"text", label:"Border_color"},
-        height          : {elem:"input",  type:"text", label:"Height"},
-        width           : {elem:"input",  type:"text", label:"Width"},
-        max_rows        : {elem:"input",  type:"text", label:"Max_rows"},
-        stream          : {elem:"select", options:["false", "true"], label:"Stream"},
-        header          : {elem:"select", options:["false", "true"], label:"Header"},
-        colorscheme     : {elem:"select", options:["light", "dark"], label:"Colorscheme"},
-        layout          : {elem:"select", options:["standard", "button_count", "box_count"], label:"Layout"},
-        show_faces      : {elem:"select", options:["false", "true"], label:"Showfaces"},
-        href            : {elem:"input",  type:"text", label:"Href"},
-        site            : {elem:"input",  type:"text", label:"Site"}
+        stream : {elem:"select", options:["false", "true"], label:"Stream"},
+        header : {elem:"select", options:["false", "true"], label:"Header"},
+        layout : {elem:"select", options:["standard", "button_count", "box_count"], label:"Layout"},
+        max_rows     : {elem:"input", type:"text", label:"Max_rows"},
+        num_posts    : {elem:"input", type:"text", label:"Num_Posts"},
+        border_color : {elem:"input", type:"text", label:"Border_color"},
+        event_app_id : {elem:"input", type:"text", label:"Event_app_id"},
+        colorscheme  : {elem:"select", options:["light", "dark"], label:"Colorscheme"},
+        show_faces   : {elem:"select", options:["false", "true"], label:"Showfaces"},
+        recommendations        : {elem:"select", options:["false", "true"], label:"Recommendations"},
+        always_post_to_friends : {elem:"input",  options:["false", "true"], label:"Always_post_to_friends"}
       }
     },
     
     _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" );
         document.body.appendChild( fbRoot );
-        
+      }
+      
+      if(!ranOnce || options.event_app_id){
+        ranOnce = true;
         // initialize facebook JS SDK
         Popcorn.getScript("http://connect.facebook.net/en_US/all.js");
+      
         window.fbAsyncInit = function() {
           FB.init({
-            appId  : "YOUR APP ID",
+            appId  : ( options.event_app_id || "" ),
             status : true,
             cookie : true,
             xfbml  : true
       
       var validType = function( type ){
         var valid = false;
-        var existing = [ "like", "like-box", "activity", "facepile" ];
+        var existing = [ "like", "like-box", "activity", "facepile", "comments", "live-stream", "send" ];
         
         for(var i in existing){
           if ( type.toLowerCase() === existing[i] ) {
       // default plugin is like button
       if( typeof( options.type ) === "undefined"){
         options.type = "like";
-      } else if ( !validType( options.type ) ){
+      } else if ( !validType( options.type ) ) {
         return;
       }
       
-      options.type = options.type.toLowerCase();
-      options._container = document.createElement( "fb:" + options.type );
+      var type = options.type.toLowerCase();
+      options._container = document.createElement( "fb:" + type );
       
       // setOptions property list doesn't accept dashes
-      if( options.type === "like-box" ) {
-        options.type = "likebox";
+      if ( type === "like-box" ) {
+        type = "likebox";
+      }
+      else if ( type === "live-stream" ) {
+        type = "livestream";
       }
       
       var setOptions = (function ( options ) {
         options._container.style.display = "none";
         // activity feed uses 'site' rather than 'href'
-        if ( options.type === "activity" ) {
+        if ( type === "activity" ) {
           options._container.setAttribute( "site", ( options.site || document.URL));
         } else {
           options._container.setAttribute( "href", ( options.href || document.URL ) );
 
         return {
           like: function () {
+            options._container.setAttribute( "send", ( options.send || false ) );
             options._container.setAttribute( "width", options.width );
             options._container.setAttribute( "show_faces", options.show_faces );
             options._container.setAttribute( "layout", options.layout );
             options._container.setAttribute( "recommendations", options.recommendations );
             options._container.setAttribute( "font", options.font );
             options._container.setAttribute( "colorscheme", options.colorscheme );
+          },
+          comments: function() {
+            options._container.setAttribute( "num_posts", ( options.num_posts || 10 ) );
+            options._container.setAttribute( "width", ( options.width || 450 ) );
+            options._container.setAttribute( "colorscheme", options.colorscheme );
+          },
+          livestream: function() {
+            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", options.xid );
+          },
+          send: function() {
+            options._container.setAttribute( "font", options.font );
+            options._container.setAttribute( "colorscheme", options.colorscheme );
           }
         };
       })( options );
 
-      setOptions[ options.type ]();
+      setOptions[ type ]();
       
       if ( document.getElementById( options.target ) ) {
         document.getElementById( options.target ).appendChild( options._container );
     * options variable
     */
     start: function( event, options ){
-      options._container.style.display = "inline";
+      if ( !!options._container ) {
+        options._container.style.display = "inline";
+      }
     },
     /**
     * @member facebook
     * options variable
     */
     end: function( event, options ){
-      options._container.style.display = "none";
+      if ( !!options._container ) {
+        options._container.style.display = "none";
+      }
     }
   });