* 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 );
}
},
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";
}
});
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();
}
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",
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" );
});
popped.exec( 4, function() {
+
ok( /none/.test( linkedin.style.display ), "Div contents are hidden again" );
plus();
});
- popped.volume(0).play();
-
+
+ popped.volume(0).play();
});