Socialmedia.js loads social media JavaScript SDKs and their functions into web pages and apps. Normally you'd dig the SDK snippet out of each platform's developer section, read the instructions, and paste the same block into every page of your site. With Socialmedia.js you initialise only the services you want, and the SDK code isn't duplicated across pages, which is where odd errors tend to come from.
I rewrote the library from scratch for version 1.4.1 and learned CoffeeScript while doing it. I enjoyed that a lot. The source is on GitHub, including the development files in both CoffeeScript and JavaScript. Report bugs in the repo's issues, and if you want to contribute, fork it and send a pull request.
The documentation covers the library and the methods for each service. Here's the Google+ Share function as an example.
Create a new instance of the Google+ class.
var gplus = new Socialmedia.GooglePlus();
Bind the Google+ Share action to a button’s click event.
// Initialize Google+ SDK
var gplus = new Socialmedia.GooglePlus();
// Get the target element in page
var gplusButton = document.querySelector('.google-plus-button');
// Attach an event handler function
gplusButton.addEventListener(
'click',
function (event) {
// Prevent default event actions
event.preventDefault();
// Use Share function from gplus instance of Socialmedia.GooglePlus class
gplus.Share({
link: 'http://example.com',
lang: 'ur',
});
},
false
);
link is the URL to share and lang sets the language of the Google+ interface. Leave them out and link defaults to the current page URL and lang to en (English). Clicking the button now opens a Google+ Share dialog with that data.
An example of Google+ Share dialog on action call
The sharing links at the end of this page use the library, so you can try it there.