Skip to content

Commit

Permalink
extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
dbushell committed Jun 9, 2012
1 parent d08c590 commit 1cd1139
Show file tree
Hide file tree
Showing 10 changed files with 410 additions and 69 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Copyright © 2012


### Changes from Version 1 ### Changes from Version 1


Please be aware that class names used by Socialite have changed since <a href="https://github.com/dbushell/Socialite/tags/">version 1</a>. All instances start with the class `socialite`, they gain the class `socialite-instance` once processed, and finally `socialite-loaded` once activated. Please be aware that class names used by Socialite have changed since <a href="https://github.com/dbushell/Socialite/tags/">version 1</a>. All instances start with the class `socialite`, they gain the class `socialite-instance` once processed, and finally `socialite-loaded` once activated. **Pinterest** and **Spotify** extensions are no longer in the default build of `socialite.js`. See end of this README for full change log.


## Using Socialite ## Using Socialite


Expand All @@ -30,6 +30,9 @@ Supported widgets are currently:
* Twitter: `twitter-share`, `twitter-follow`, `twitter-mention`, `twitter-hashtag` and `twitter-embed` (for individual tweets) * Twitter: `twitter-share`, `twitter-follow`, `twitter-mention`, `twitter-hashtag` and `twitter-embed` (for individual tweets)
* Google+: `googleplus-one`, `googleplus-share` * Google+: `googleplus-one`, `googleplus-share`
* LinkedIn: `linkedin-share`, `linkedin-recommend` * LinkedIn: `linkedin-share`, `linkedin-recommend`

Also available as extensions:

* Pinterest: `pinterest-pinit` * Pinterest: `pinterest-pinit`
* Spotify: `spotify-play` * Spotify: `spotify-play`


Expand Down Expand Up @@ -129,3 +132,10 @@ With these two functions you can add extended support. See the source code for e
Thanks, Thanks,


[@dbushell](http://twitter.com/dbushell/) [@dbushell](http://twitter.com/dbushell/)

## Change Log

### 2.0.1 - 9th June 2012

* created an `extensions` folder in the repository
* **Pinterest** and **Spotify** removed from the default `socialite.js` and `socialite.min.js` builds.
72 changes: 72 additions & 0 deletions extensions/socialite.extension-template.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,72 @@
/*!
* Socialite v2.0 - Extension template
* http://socialitejs.com
* Copyright (c) 2011 David Bushell
* Dual-licensed under the BSD or MIT licenses: http://socialitejs.com/license.txt
*/
(function(window, document, Socialite, undefined)
{
// External documentation URLs

// add required default settings
Socialite.setup({
'network_name': {
lang: 'en'
}
});

/**
* One network can cater for multiple widgets
* Check the extensions repository to make sure it doesn't already exist
* The script object is optional for extentions that require simple images or iframes
*/
Socialite.network('network_name', {
script: {
src : '//network_name.js',
charset : 'utf-8'
},
/**
* (optional) Called before `Socialite.load()` appends the network script via `Socialite.appendNetwork()`
*/
append: function(network)
{
// return false to cancel the append and activate all instances immedicately
},
/**
* (optional) called after an appended network script has loaded
*/
onload: function(network)
{
// return false to cancel automatically activation of all instances
}
});

/**
* Add a unique widget to the network
* Socialite will activate elements with a class name of `network_name-widget_name`, e.g. `twitter-share`
*/
Socialite.widget('network_name', 'widget_name', {
/**
* (optional) Called after a new instance has been created but before it is initialised
*/
process: function(instance)
{
// return false or replace function with `null` to cancel the default processing of `Socialite.processInstance()`
},
/**
* Called when an instance is loaded
*/
init: function(instance)
{
// After this function that instance should resemble the suggested implementation by the social network
},
/**
* (optional) Called by `Socialite.activateInstance()` when the network has loaded and the final widget is ready to display
*/
activate: function(instance)
{
//
}
});

})(window, window.document, window.Socialite);
59 changes: 59 additions & 0 deletions extensions/socialite.facebook.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,59 @@
/*!
* Socialite v2.0 - Facebook extension
* http://socialitejs.com
* Copyright (c) 2011 David Bushell
* Dual-licensed under the BSD or MIT licenses: http://socialitejs.com/license.txt
*/
(function(window, document, Socialite, undefined)
{
// http://developers.facebook.com/docs/reference/plugins/like/
// http://developers.facebook.com/docs/reference/javascript/FB.init/

Socialite.setup({
facebook: {
lang: 'en_GB',
appId: null
}
});

Socialite.network('facebook', {
script: {
src : '//connect.facebook.net/{{language}}/all.js',
id : 'facebook-jssdk'
},
append: function(network)
{
var fb = document.createElement('div'),
settings = Socialite.settings.facebook,
events = { onlike: 'edge.create', onunlike: 'edge.remove', onsend: 'message.send' };
fb.id = 'fb-root';
document.body.appendChild(fb);
network.script.src = network.script.src.replace('{{language}}', settings.lang);
window.fbAsyncInit = function() {
window.FB.init({
appId: settings.appId,
xfbml: true
});
for (var e in events) {
if (typeof settings[e] === 'function') {
window.FB.Event.subscribe(events[e], settings[e]);
}
}
};
}
});

Socialite.widget('facebook', 'like', {
init: function(instance)
{
var el = document.createElement('div');
el.className = 'fb-like';
Socialite.copyDataAttributes(instance.el, el);
instance.el.appendChild(el);
if (window.FB && window.FB.XFBML) {
window.FB.XFBML.parse(instance.el);
}
}
});

})(window, window.document, window.Socialite);
65 changes: 65 additions & 0 deletions extensions/socialite.googleplus.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,65 @@
/*!
* Socialite v2.0 - GooglePlus extension
* http://socialitejs.com
* Copyright (c) 2011 David Bushell
* Dual-licensed under the BSD or MIT licenses: http://socialitejs.com/license.txt
*/
(function(window, document, Socialite, undefined)
{
// https://developers.google.com/+/plugins/+1button/
// Google does not support IE7

Socialite.setup({
googleplus: {
lang: 'en-GB'
}
});

Socialite.network('googleplus', {
script: {
src: '//apis.google.com/js/plusone.js'
},
append: function(network)
{
if (window.gapi) {
return false;
}
window.___gcfg = {
lang: Socialite.settings.googleplus.lang,
parsetags: 'explicit'
};
}
});

var googleplusInit = function(instance)
{
var el = document.createElement('div');
el.className = 'g-' + instance.widget.gtype;
Socialite.copyDataAttributes(instance.el, el);
instance.el.appendChild(el);
};

var googleplusEvent = function(instance, callback) {
return (typeof callback !== 'function') ? null : function(data) {
callback(instance.el, data);
};
};

var googleplusActivate = function(instance)
{
var type = instance.widget.gtype;
if (window.gapi && window.gapi[type]) {
var settings = Socialite.settings.googleplus,
params = Socialite.getDataAttributes(instance.el, true, true),
events = ['onstartinteraction', 'onendinteraction', 'callback'];
for (var i = 0; i < events.length; i++) {
params[events[i]] = googleplusEvent(instance, settings[events[i]]);
}
window.gapi[type].render(instance.el, params);
}
};

Socialite.widget('googleplus', 'one', { init: googleplusInit, activate: googleplusActivate, gtype: 'plusone' });
Socialite.widget('googleplus', 'share', { init: googleplusInit, activate: googleplusActivate, gtype: 'plus' });

})(window, window.document, window.Socialite);
32 changes: 32 additions & 0 deletions extensions/socialite.linkedin.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,32 @@
/*!
* Socialite v2.0 - LinkedIn extension
* http://socialitejs.com
* Copyright (c) 2011 David Bushell
* Dual-licensed under the BSD or MIT licenses: http://socialitejs.com/license.txt
*/
(function(window, document, Socialite, undefined)
{
// http://developer.linkedin.com/plugins/share-button/

Socialite.network('linkedin', {
script: {
src: '//platform.linkedin.com/in.js'
}
});

var linkedinInit = function(instance)
{
var el = document.createElement('script');
el.type = 'IN/' + instance.widget.intype;
Socialite.copyDataAttributes(instance.el, el);
instance.el.appendChild(el);
if (typeof window.IN === 'object' && typeof window.IN.parse === 'function') {
window.IN.parse(instance.el);
Socialite.activateInstance(instance);
}
};

Socialite.widget('linkedin', 'share', { init: linkedinInit, intype: 'Share' });
Socialite.widget('linkedin', 'recommend', { init: linkedinInit, intype: 'RecommendProduct' });

})(window, window.document, window.Socialite);
47 changes: 47 additions & 0 deletions extensions/socialite.pinterest.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,47 @@
/*!
* Socialite v2.0 - Pinterest extension
* http://socialitejs.com
* Copyright (c) 2011 David Bushell
* Dual-licensed under the BSD or MIT licenses: http://socialitejs.com/license.txt
*/
(function(window, document, Socialite, undefined)
{
// http://pinterest.com/about/goodies/

Socialite.network('pinterest', {
script: {
src: '//assets.pinterest.com/js/pinit.js'
}
});

Socialite.widget('pinterest', 'pinit', {
process: function(instance)
{
// Pinterest activates all <a> elements with a href containing share URL
// so we have to jump through hoops to protect each instance
if (instance.el.nodeName.toLowerCase() !== 'a') {
return true;
}
var id = 'socialite-instance-' + instance.uid,
href = instance.el.getAttribute('href');
instance.el.id = id;
instance.el.href = '#' + id;
instance.el.setAttribute('data-default-href', href);
instance.el.setAttribute('onclick', '(function(){window.open("' + href + '")})();');
},
init: function(instance)
{
Socialite.processInstance(instance);
var el = document.createElement('a');
el.className = 'pin-it-button';
Socialite.copyDataAttributes(instance.el, el);
el.setAttribute('href', instance.el.getAttribute('data-default-href'));
el.setAttribute('count-layout', instance.el.getAttribute('data-count-layout') || 'horizontal');
instance.el.appendChild(el);
if (Socialite.networkReady('pinterest')) {
Socialite.reloadNetwork('pinterest');
}
}
});

})(window, window.document, window.Socialite);
34 changes: 34 additions & 0 deletions extensions/socialite.spotify.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,34 @@
/*!
* Socialite v2.0 - Spotify extension
* http://socialitejs.com
* Copyright (c) 2011 David Bushell
* Dual-licensed under the BSD or MIT licenses: http://socialitejs.com/license.txt
*/
(function(window, document, Socialite, undefined)
{
// https://developer.spotify.com/technologies/spotify-play-button/

Socialite.network('spotify');

Socialite.widget('spotify', 'play', {
process: null,
init: function(instance)
{
Socialite.processInstance(instance);
var src = 'https://embed.spotify.com/?',
width = parseInt(instance.el.getAttribute('data-width'), 10),
height = parseInt(instance.el.getAttribute('data-height'), 10);
src += 'uri=' + (instance.el.getAttribute('data-default-href') || instance.el.getAttribute('data-href')) + '&';
instance.el.setAttribute('data-href', '');
instance.el.setAttribute('data-default-href', '');
instance.el.setAttribute('data-socialite', '');
src += Socialite.getDataAttributes(instance.el, true);
var iframe = Socialite.createIframe(src, instance);
iframe.style.width = (isNaN(width) ? 300 : width) + 'px';
iframe.style.height = (isNaN(height) ? 380 : height) + 'px';
instance.el.appendChild(iframe);
Socialite.activateInstance(instance);
}
});

})(window, window.document, window.Socialite);
Loading

0 comments on commit 1cd1139

Please sign in to comment.