Skip to content

Instantly share code, notes, and snippets.

@aforwark
Created March 30, 2012 23:53
Show Gist options
  • Save aforwark/2257974 to your computer and use it in GitHub Desktop.
Save aforwark/2257974 to your computer and use it in GitHub Desktop.
SK Says Share
YUI().use('node', 'event', function(Y) {
Y.on('domready', function() {
function shareStuff(response) {
if (response && response.items) {
var uids = response.items.join(','),
message;
if (hash > "") {
message = {
title: 'What’s your breakfast buzz?',
description: 'I shared my buzz about breakfast and entered a free giveaway!',
message: 'I shared my buzz about breakfast and entered a free giveaway!',
link: 'http://www.sheknows.com/food-and-recipes/quizzes/sk-says',
target: uids
};
}
else {
message = {
title: 'What’s your breakfast buzz?',
description: 'I shared my buzz about breakfast and entered a free giveaway!',
message: 'I shared my buzz about breakfast and entered a free giveaway!',
link: 'http://www.sheknows.com/food-and-recipes/quizzes/sk-says',
target: uids
}
}
Connect.prototype.api('/me/feed', 'POST', message,
function(response) {
if (response && response.status == 'success') {
// celebrate perfection!
}
else {
// go cry some more
}
});
}
};
function handleShare(evt) {
var el = evt.target,
hash = el.getAttribute('data-hash');
Connect.prototype.login(
{provider: 'facebook'},
function(user) {
if(user && user.id) {
Connect.prototype.ui({method: 'friends'}, function(response) {
shareStuff(response, hash);
});
}
}
);
// stop the event so the # doesn't show in the URL
evt.preventDefault();
return false;
};
Y.all('#invite, #share').on('click', handleShare);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment