Skip to content

Instantly share code, notes, and snippets.

@rpearce
Created September 22, 2012 17:24
Show Gist options
  • Save rpearce/3766937 to your computer and use it in GitHub Desktop.
Save rpearce/3766937 to your computer and use it in GitHub Desktop.
AddThis Static, Provided Solution
// ...
events: {
'click .facebook-share' : 'postToFeed',
},
postToFeed: function() {
FB.init({appId: fb_app_id, status: true, cookie: true});
// calling the API ...
var obj = {
method: 'feed',
link: 'http://www.google.com',
picture: 'http://athena.cornell.edu/images/rovers/rover_sundial.jpg',
name: 'My text about ' + this.model.get('something_interesting'),
caption: '',
description: 'Sweet! This is so great and about something interesting!',
redirect_uri: 'your redirect URI'
};
var self = this;
FB.ui(obj, function(response) {
self.callback(response);
});
},
callback: function(response) {
// callback where you do something with the response
}
// ...
var fb_app_id = 'your facebook application id';
// ...
// ...
render: function() {
this.setMetaTags();
// ...
},
setMetaTags: function() {
var self, title, url, tags;
self = this;
title = {'metaName': 'property', 'name': 'og:title', 'value': this.model.get('location_from') + ' to ' + this.model.get('location_to')}
url = {'metaName': 'property', 'name': 'og:url', 'value': app_uri + '/#posts/' + this.model.get('id')}
tags = [title, url];
_.each(tags, function(item) {
self.setOrCreateMetaTag(item.metaName, item.name, item.value);
});
},
setOrCreateMetaTag: function(metaName, name, value) {
var t = 'meta['+metaName+'="'+name+'"]';
var mt = $(t);
if (mt.length === 0) {
t = '<meta '+metaName+'="'+name+'" />';
mt = $(t).appendTo('head');
}
mt.attr('content', value);
return mt;
}
// ...
var GeneralMixins = {
preventHref: function(e) {
e.preventDefault();
}
};
// ...
// note: the view is titled ShareLinks
// ...
events: {
'click .facebook-share' : 'postToFeed',
'click a[href="#"]' : 'preventHref'
}
// ...
_.extend(ShareLinks.prototype, GeneralMixins);
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style addthis_32x32_style">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/300/addthis_widget.js#pubid=xa-505de6c2446fedb4"></script>
<!-- AddThis Button END -->
.facebook-share { float: left; }
.facebook-share:hover {
-khtml-opacity: 0.7;
-moz-opacity: 0.7;
opacity: 0.7;
filter: progid:DXImageTransform.Microsoft.Alpha(opacity=(70));
}
<div class="addthis_toolbox addthis_default_style addthis_32x32_style"
addthis:url="http://starvingdeveloper.wordpress.com"
addthis:title="My custom title!"
addthis:description="Sweet! This is my default text about <%= item.get('something_interesting') %>!">
<a class="addthis_button_facebook"></a>
<a class="addthis_button_twitter"
addthis:title="Sweet! This is my custom Twitter text about <%= item.get('something_interesting') %>!"></a>
<a class="addthis_button_linkedin"
addthis:description="Sweet! This is my custom LinkedIn text about <%= item.get('something_interesting') %>!"></a>
<a class="addthis_button_email"></a>
</div>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style"
addthis:url="http://starvingdeveloper.wordpress.com"
addthis:title="My custom title!"
addthis:description="Sweet! This is my default text about <%= item.get('something_interesting') %>!">
<div id='fb-root'></div>
<a class="facebook-share" href="javascript:void(0)">
<img src="http://starvingdeveloper.files.wordpress.com/2012/09/addthis-facebook.png" />
</a>
<a class="addthis_button_twitter"
addthis:title="Sweet! This is my custom Twitter text about <%= item.get('something_interesting') %>!"></a>
<a class="addthis_button_linkedin"
addthis:description="Sweet! This is my custom LinkedIn text about <%= item.get('something_interesting') %>!"></a>
<a class="addthis_button_email"></a>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment