-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
410 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.