From: Mohammed Buttu Date: Mon, 16 May 2011 16:09:48 +0000 (-0400) Subject: #332 Corrected code style and fixed the problem of the plugin not loading in Firefox. X-Git-Tag: v0.6~23 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=f3873d418ed7b77e087f9dffb485fdd369f5b985;p=popcorn-js.git #332 Corrected code style and fixed the problem of the plugin not loading in Firefox. --- diff --git a/plugins/linkedin/popcorn.linkedin.html b/plugins/linkedin/popcorn.linkedin.html index 87608e6..e454e5f 100644 --- a/plugins/linkedin/popcorn.linkedin.html +++ b/plugins/linkedin/popcorn.linkedin.html @@ -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. --> - + diff --git a/plugins/linkedin/popcorn.linkedin.js b/plugins/linkedin/popcorn.linkedin.js index 96fe8d5..bf29770 100644 --- a/plugins/linkedin/popcorn.linkedin.js +++ b/plugins/linkedin/popcorn.linkedin.js @@ -21,7 +21,7 @@ * url : "http://www.google.ca", * counter : "right", * target : 'sharediv' - * api_key : 'ZOLRI2rzQS_oaXELpPF0aksxwFFEvoxAFZRLfHjaAhcGPfOX0Ds4snkJpWwKs8gk', + * apikey : 'ZOLRI2rzQS_oaXELpPF0aksxwFFEvoxAFZRLfHjaAhcGPfOX0Ds4snkJpWwKs8gk', * start : 1, * end : 3 * } ) @@ -30,43 +30,64 @@ * 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 api_key"; + var errorMsg = function() { + + options._container = document.createElement( "p" ); + options._container.innerHTML = "Plugin requires a valid apikey"; 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" ) { @@ -84,6 +106,7 @@ } }, companyinsider: function () { + options._container.setAttribute( 'type', "IN/CompanyInsider" ); options._container.setAttribute( 'data-id', options.companyid ); if( options.modules ) { @@ -91,6 +114,7 @@ } }, companyprofile: function () { + options._container.setAttribute( 'type', "IN/CompanyProfile" ); options._container.setAttribute( 'data-id', ( options.companyid ) ); options._container.setAttribute( 'data-format', ( options.format || "inline" ) ); @@ -102,6 +126,7 @@ } }, recommendproduct: function () { + options._container.setAttribute( 'type', "IN/RecommendProduct" ); options._container.setAttribute( 'data-company', ( options.companyid || "LinkedIn" ) ); options._container.setAttribute( 'data-product', ( options.productid || "201714" ) ); @@ -112,17 +137,19 @@ }; })( 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"; }, /** @@ -132,7 +159,8 @@ * options variable */ start: function( event, options ) { - options._container.parentNode.style.display = 'block'; + + options._container.parentNode.style.display = "block"; }, /** @@ -142,7 +170,8 @@ * options variable */ end: function( event, options ) { - options._container.parentNode.style.display = 'none'; + + options._container.parentNode.style.display = "none"; } }); diff --git a/plugins/linkedin/popcorn.linkedin.unit.html b/plugins/linkedin/popcorn.linkedin.unit.html index b126802..e474a95 100644 --- a/plugins/linkedin/popcorn.linkedin.unit.html +++ b/plugins/linkedin/popcorn.linkedin.unit.html @@ -9,7 +9,6 @@ popcorn-api-draft.js --> - diff --git a/plugins/linkedin/popcorn.linkedin.unit.js b/plugins/linkedin/popcorn.linkedin.unit.js index 3f6a448..fb34528 100644 --- a/plugins/linkedin/popcorn.linkedin.unit.js +++ b/plugins/linkedin/popcorn.linkedin.unit.js @@ -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(); });