]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
#332 Corrected code style and fixed the problem of the plugin not loading in Firefox.
authorMohammed Buttu <mohammedbuttu@gmail.com>
Mon, 16 May 2011 16:09:48 +0000 (12:09 -0400)
committerMohammed Buttu <mohammedbuttu@gmail.com>
Mon, 16 May 2011 16:09:48 +0000 (12:09 -0400)
plugins/linkedin/popcorn.linkedin.html
plugins/linkedin/popcorn.linkedin.js
plugins/linkedin/popcorn.linkedin.unit.html
plugins/linkedin/popcorn.linkedin.unit.js

index 87608e6a950ba63c7b1e2fd1db7bfef2753e1553..e454e5ffd2d480d757fd3a0837ac03c3dca5de47 100644 (file)
@@ -10,7 +10,7 @@
     to be used on localhost (port 80). For other purposes, please obtain an API key
     from https://www.linkedin.com/secure/developer.
   -->
-  <script src="http://platform.linkedin.com/in.js" type="text/javascript"></script>
+
   <script src="../../popcorn.js"></script>
   <script src="popcorn.linkedin.js"></script>
   <script>
@@ -26,7 +26,7 @@
         apikey    : 'ZOLRI2rzQS_oaXELpPF0aksxwFFEvoxAFZRLfHjaAhcGPfOX0Ds4snkJpWwKs8gk',
         start     : 1,
         end       : 3
-      } )
+      })
       .linkedin({
         type      : 'recommendproduct',
         counter   : 'top',
@@ -36,7 +36,7 @@
         apikey    : 'ZOLRI2rzQS_oaXELpPF0aksxwFFEvoxAFZRLfHjaAhcGPfOX0Ds4snkJpWwKs8gk',
         start     : 4,
         end       : 7
-      } )
+      })
       .linkedin({
         type      : 'memberprofile',
         memberid  : '/in/jeffweiner08',
@@ -45,7 +45,7 @@
         apikey    : 'ZOLRI2rzQS_oaXELpPF0aksxwFFEvoxAFZRLfHjaAhcGPfOX0Ds4snkJpWwKs8gk',
         start     : 9,
         end       : 11
-      } )
+      })
       .linkedin({
         type      : 'companyinsider',
         companyid : '1441',
@@ -53,7 +53,7 @@
         apikey    : 'ZOLRI2rzQS_oaXELpPF0aksxwFFEvoxAFZRLfHjaAhcGPfOX0Ds4snkJpWwKs8gk',
         start     : 9,
         end       : 11
-      } )
+      })
       .linkedin({
         type      : 'companyprofile',
         companyid : '1441',
@@ -62,9 +62,8 @@
         apikey    : 'ZOLRI2rzQS_oaXELpPF0aksxwFFEvoxAFZRLfHjaAhcGPfOX0Ds4snkJpWwKs8gk',
         start     : 13,
         end       : 17
-      } )
-    }, false);
-
+      });
+    }, false );
   </script>
 </head>
 <body>
index 96fe8d50f6783f3788ebb0ddddd6adb8acff65d0..bf29770c8444049966ef62f333efbaa4cb29cfbb 100644 (file)
@@ -21,7 +21,7 @@
    *       url     : "http://www.google.ca",
    *       counter : "right",
    *       target  : 'sharediv'
-   *       api_key : 'ZOLRI2rzQS_oaXELpPF0aksxwFFEvoxAFZRLfHjaAhcGPfOX0Ds4snkJpWwKs8gk',
+   *       apikey : 'ZOLRI2rzQS_oaXELpPF0aksxwFFEvoxAFZRLfHjaAhcGPfOX0Ds4snkJpWwKs8gk',
    *       start   : 1,
    *       end     : 3
    *     } )
    * Will show number of people (counter) to the right of the share plugin.
    */
    
-  Popcorn.plugin( "linkedin" , {  
-    manifest:{
-      about:{
+  Popcorn.plugin( "linkedin", {
+
+    manifest: {
+
+      about: {
+
         name   : "Popcorn LinkedIn Plugin",
         version: "0.1",
         author : "Dan Ventura",
         website: "dsventura.blogspot.com"
       },
-      options:{
+      options: {
+
         type   : {elem:"input", type:'text', label:"Type"},
         target : 'linkedin-container'
       }
     },
     
     _setup: function( options ) {
-      var api_key = options.apikey,
-                    target = document.getElementById( options.target );
-   
+
+      var apikey = options.apikey,
+          target  = document.getElementById( options.target );
+
+      if ( !document.getElementById("linkedin-root") ) {
+        var root = document.createElement( 'div' );
+        root.setAttribute( 'div', "linkedin-root" );
+        document.body.appendChild( root );
+        
+        (function() {
+          var linkedinAPIScript = document.createElement( 'script' );
+          linkedinAPIScript.setAttribute( 'src', "http://platform.linkedin.com/in.js" );
+          linkedinAPIScript.setAttribute( 'type', "text/javascript" );
+          root.appendChild( linkedinAPIScript );
+        }());
+      }
+      
       options._container = document.createElement( 'script' );
       
-      options._container.setAttribute( 'async', 'true' );
-      if ( typeof( api_key ) !== "undefined" ) {
-        options._container.innerHTML = 'api_key: ' + api_key;
+      if ( apikey ) {
+        options._container.innerHTML = 'api_key: ' + apikey;
       }
       
       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>";
+      var errorMsg = function() {
+
+        options._container = document.createElement( "p" );
+        options._container.innerHTML = "Plugin requires a valid <a href='https://www.linkedin.com/secure/developer'>apikey</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 );
@@ -76,7 +97,8 @@
             }
           },
           memberprofile: function () {
-            options._container.setAttribute('type', "IN/MemberProfile");
+
+            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" ) {
             }
           },
           companyinsider: function () {
+
             options._container.setAttribute( 'type', "IN/CompanyInsider" );
             options._container.setAttribute( 'data-id', options.companyid );
             if( 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" ) );
             }
           },
           recommendproduct: function () {
+
             options._container.setAttribute( 'type', "IN/RecommendProduct" );
             options._container.setAttribute( 'data-company', ( options.companyid || "LinkedIn" ) );
             options._container.setAttribute( 'data-product', ( options.productid || "201714" ) );
         };
       })( options );
       
-      if ( typeof( api_key ) === "undefined" ) {
+      if ( !apikey ) {
+
         errorMsg();
-      }
-      else {
+      } else {
+
         setOptions[ options.type ] && setOptions[ options.type ]();
       }
       
       if ( document.getElementById( options.target ) ) {
         document.getElementById( options.target ).appendChild( options._container );
       }
-      target.style.display = 'none';
+
+      target.style.display = "none";
     },
     
     /**
      * options variable
      */
     start: function( event, options ) {
-      options._container.parentNode.style.display = 'block';
+      
+      options._container.parentNode.style.display = "block";
     },
     
     /**
      * options variable
      */    
     end: function( event, options ) {
-      options._container.parentNode.style.display = 'none';
+      
+      options._container.parentNode.style.display = "none";
     }
   });
 
index b1268026eb055b5333d33d6be1356c182332ef21..e474a95b90f32e2567240e64a4e08431ea3e40aa 100644 (file)
@@ -9,7 +9,6 @@
     popcorn-api-draft.js
   -->
   
-  <script src="http://platform.linkedin.com/in.js" type="text/javascript"></script>
   <script src="../../popcorn.js"></script>
   <script src="popcorn.linkedin.js"></script>  
   <script src="popcorn.linkedin.unit.js"></script>
index 3f6a4486a1f0e9cbf64906a04f0cf80ed037af3b..fb34528e28b41c2a1980f3633eb2bcd1709a993c 100644 (file)
@@ -1,13 +1,14 @@
 test("Popcorn LinkedIn Plugin", function () {
   
-  var popped = Popcorn("#video"),
-      expects = 5,
-      count = 0,
+  var popped   = Popcorn("#video"),
+      expects  = 5,
+      count    = 0,
       linkedin = document.getElementById('linkedindiv');
   
   expect( expects );
   
   function plus() {
+
     if ( ++count === expects ) {
       start();
     }
@@ -15,14 +16,14 @@ test("Popcorn LinkedIn Plugin", function () {
 
   stop();
  
-  ok('linkedin' in popped, "linkedin is a method of the popped instance");
+  ok( 'linkedin' in popped, "linkedin is a method of the popped instance" );
   plus();
 
-  equals ( linkedin.innerHTML, "", "initially, there is nothing inside the linkedin div" );
+  equals( linkedin.innerHTML, "", "initially, there is nothing inside the linkedin div" );
   plus();
   
-  
   popped.linkedin({
+
     type      : 'share',
     counter   : 'right',
     url       : "http://www.google.ca",
@@ -30,9 +31,10 @@ test("Popcorn LinkedIn Plugin", function () {
     apikey    : 'ZOLRI2rzQS_oaXELpPF0aksxwFFEvoxAFZRLfHjaAhcGPfOX0Ds4snkJpWwKs8gk',
     start     : 1,
     end       : 3
-  } );
+  });
 
   popped.exec( 2, function() {
+
       ok( /block/.test( linkedin.style.display ), "Div contents are displayed" );
       plus();
       ok( /script/.test( linkedin.innerHTML ), "LinkedIn plugin exists" );
@@ -40,9 +42,10 @@ test("Popcorn LinkedIn Plugin", function () {
   });
   
   popped.exec( 4, function() {
+
       ok( /none/.test( linkedin.style.display ), "Div contents are hidden again" );
       plus();
   });
-  popped.volume(0).play();  
-  
+
+  popped.volume(0).play();
 });