]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
added linked plugin. go to http://matrix.senecac.on.ca/~dsventura/popcorn-js/plugins...
authorDan Ventura <distraction.attack@gmail.com>
Tue, 12 Apr 2011 02:16:51 +0000 (22:16 -0400)
committerDan Ventura <distraction.attack@gmail.com>
Tue, 12 Apr 2011 02:16:51 +0000 (22:16 -0400)
plugins/linkedin/popcorn.linkedin.html [new file with mode: 0644]
plugins/linkedin/popcorn.linkedin.js [new file with mode: 0644]

diff --git a/plugins/linkedin/popcorn.linkedin.html b/plugins/linkedin/popcorn.linkedin.html
new file mode 100644 (file)
index 0000000..9eef967
--- /dev/null
@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn LinkedIn Plug-in Demo</title>
+  <script src="../../popcorn.js"></script>
+  <script>
+    var api_key = 'ND1uSIEUBH8MkI8E7g41kgGlWUexzvFL9uB2ihJbIrFuqunFq8aVmUrxyfAqxCBX';
+  </script>
+  <script src="popcorn.linkedin.js"></script>
+  <script>
+    document.addEventListener('DOMContentLoaded', function () {
+      var p = Popcorn('#video')
+      .volume(0)
+      .play()
+      .linkedin({
+        type      : 'share',
+        counter   : 'right',
+        url       : "http://www.google.ca",
+        target    : "sharediv"
+      } )
+      .linkedin({
+        type      : 'recommendproduct',
+        counter   : 'top',
+        target    : "recommenddiv",
+        companyid : 'LinkedIn',
+        productid : '201714'
+      } )
+      .linkedin({
+        type      : 'memberprofile',
+        memberid  : '/in/jeffweiner08',
+        format    : 'inline',
+        target    : "memberprofilediv"
+      } )
+      .linkedin({
+        type      : 'companyinsider',
+        companyid : '1441',
+        target    : "bottomdiv"
+      } )
+      .linkedin({
+        type      : 'companyprofile',
+        companyid : '1441',
+        format    : 'inline',
+        target    : "bottomdiv"
+      } )
+    }, false);
+
+  </script>
+</head>
+<body>
+<h1 id="qunit-header">Popcorn Facebook Plug-in Demo</h1>
+  <p>Right of video: share button, recommend button, member profile. <br />
+     Below video: company insider, company profile.<br />
+     For a description of each plugin's purpose, go to: <a href="http://developer.linkedin.com/community/plugins">LinkedIn Plugins</a></p>
+  
+  <div>
+    <video id='video' 
+      controls preload='none' 
+      width= '350px'
+      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="sharediv" style="position:absolute;top:150px;left:400px;"></div>
+  <div id="recommenddiv" style="position:absolute;top:175px;left:400px;"></div>
+  <div id="memberprofilediv" style="position:absolute;top:150px;left:500px;"></div>
+  <div id="bottomdiv">
+    <br />
+  </div>
+</body>
+</html>
\ No newline at end of file
diff --git a/plugins/linkedin/popcorn.linkedin.js b/plugins/linkedin/popcorn.linkedin.js
new file mode 100644 (file)
index 0000000..35ca14c
--- /dev/null
@@ -0,0 +1,138 @@
+//PLUGIN: linkedin
+(function (Popcorn){
+/**
+   * LinkedIn Popcorn plug-in 
+   * An api_key must be specified before the linkedin.js script
+   * Places a  LinkedIn plugin 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. Either share, memberprofile, companyinsider, companyprofile, or recommendproduct
+   * Target is the id of the document element that the plugin needs to be 
+   * attached to, this target element must exist on the DOM
+   * 
+   * @param {Object} options
+   * 
+   * Example:
+   * // This api_key is valid for the matrix.senecac.on.ca domain
+   * <script>
+   *   var api_key = 'ND1uSIEUBH8MkI8E7g41kgGlWUexzvFL9uB2ihJbIrFuqunFq8aVmUrxyfAqxCBX';
+   * </script>
+   * <script src="popcorn.linkedin.js"></script>
+   * ...
+   * var p = Popcorn('#video')
+   *     .linkedin({
+   *       type    : 'share',
+   *       url     : "http://www.google.ca",
+   *       counter : "right",
+   *       target  : 'sharediv'
+   *     } )
+   *
+   * This will show how many people have "shared" Google (default url is current page, if non specified) via LinkedIn.
+   * Will show number of people (counter) to the right of the share plugin.
+   */
+   
+  Popcorn.plugin( "linkedin" , {  
+    manifest:{
+      about:{
+        name   : "Popcorn LinkedIn Plugin",
+        version: "0.1",
+        author : "Dan Ventura",
+        website: "dsventura.blogspot.com"
+      },
+      options:{
+        type   : {elem:"input", type:'text', label:"Type"},
+        target : 'linkedin-container'
+      }
+    },  
+    
+    _setup: function( options ) {
+      // similar to facebook script load idea
+      if ( !document.getElementById("linkedin-root") ) {
+        var r = document.createElement( 'div' );
+        r.setAttribute( 'div', "linkedin-root" );
+        document.body.appendChild( r );
+        
+        (function() {
+          var s = document.createElement( 'script' );
+          s.setAttribute( 'src', "http://platform.linkedin.com/in.js" );
+          s.setAttribute( 'type', "text/javascript" );
+          s.setAttribute( 'async', 'true' );
+          if ( typeof( api_key ) !== "undefined" ) {
+            s.innerHTML = 'api_key: ' + api_key;
+          }
+          r.appendChild( s );
+        }());
+      }
+      
+      options._container = document.createElement( 'script' );
+      options.type = options.type.toLowerCase();
+      
+      // Replace the LinkedIn plugin's error message to something more helpful
+      var errorMsg = function () {
+        options._container = document.createElement( 'p' );
+        options._container.innerHTML = "Plugin requires a valid <a href=\"https://www.linkedin.com/secure/developer\">api_key</a>";
+        document.getElementById( options.target ).appendChild( options._container );
+      }
+      
+      var setOptions = (function ( options ) {
+        return {
+          share: function () {
+            options._container.setAttribute( 'type', "IN/Share" );
+            if ( options.counter ) {
+              options._container.setAttribute( 'data-counter', options.counter );
+            }
+            if ( options.url ) {
+              options._container.setAttribute( 'data-url', options.url);
+            }
+          },
+          memberprofile: function () {
+            options._container.setAttribute('type', "IN/MemberProfile");
+            options._container.setAttribute( 'data-id', ( options.memberid ) );
+            options._container.setAttribute( 'data-format', ( options.format || "inline" ) );
+            if ( options.text && options.format.toLowerCase() !== "inline" ) {
+              options._container.setAttribute( 'data-text', options.text );
+            }
+          },
+          companyinsider: function () {
+            options._container.setAttribute( 'type', "IN/CompanyInsider" );
+            options._container.setAttribute( 'data-id', options.companyid );
+            if( options.modules ) {
+              options._container.setAttribute( 'data-modules', options.modules );
+            }
+          },
+          companyprofile: function () {
+            options._container.setAttribute( 'type', "IN/CompanyProfile" );
+            options._container.setAttribute( 'data-id', ( options.companyid ) );
+            options._container.setAttribute( 'data-format', ( options.format || "inline" ) );
+            if ( options.text && options.format.toLowerCase() !== "inline" ) {
+              options._container.setAttribute( 'data-text', options.text );
+            }
+            if ( options.related !== undefined ) {
+              options._container.setAttribute( 'data-related', options.related );
+            }
+          },
+          recommendproduct: function () {
+            options._container.setAttribute( 'type', "IN/RecommendProduct" );
+            options._container.setAttribute( 'data-company', ( options.companyid || "LinkedIn" ) );
+            options._container.setAttribute( 'data-product', ( options.productid || "201714" ) );
+            if ( options.counter ) {
+              options._container.setAttribute( 'data-counter', options.counter );
+            }
+          }
+        };
+      })( options );
+      
+      if ( typeof( api_key ) === "undefined" ) {
+        errorMsg();
+      }
+      else {
+        setOptions[ options.type ] && setOptions[ options.type ]();
+      }
+      
+      if ( document.getElementById( options.target ) ) {
+        document.getElementById( options.target ).appendChild( options._container );
+      }
+    }
+  });
+
+})( Popcorn );
\ No newline at end of file