Created
March 30, 2012 23:53
-
-
Save aforwark/2257974 to your computer and use it in GitHub Desktop.
SK Says Share
This file contains hidden or 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
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