Skip to content

Instantly share code, notes, and snippets.

@janbaykara
Last active August 29, 2015 14:20
Show Gist options
  • Save janbaykara/60ec0819fdaef02abfb0 to your computer and use it in GitHub Desktop.
Save janbaykara/60ec0819fdaef02abfb0 to your computer and use it in GitHub Desktop.
Facebook/twitter sharing popup functions
/* // USAGE
tweetIntent({
url: window.location.href,
text: "Some message"
related: "OptionalAdvertisedTwitterUser"
})
facebookShare({
url: window.location.href,
text: "Some message"
})
*/
function tweetIntent(data) {
var url = "https://twitter.com/intent/tweet/?"
, options = {
url: data.url,
text: encodeURIComponent(data.text),
related: data.related
}
popupGET(options,url);
}
function facebookShare(data) {
var url = "https://www.facebook.com/sharer/sharer.php?"
, options = {
u: data.url,
t: encodeURIComponent(data.text)
}
popupGET(options,url);
}
function popupGET(options,url) {
for(var key in options){
if (options.hasOwnProperty(key))
url += "&"+key+"="+options[key]
}
var w = popupWindow("","_blank",400,400)
w.location.href = url;
}
function popupWindow(url, title, w, h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width='+w+', height='+h+', top='+top+', left='+left);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment