|
'use strict'; |
|
|
|
(function () { |
|
|
|
/** |
|
* Social share popups |
|
* |
|
*/ |
|
var url = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname; |
|
var title = document.getElementsByTagName("title")[0].innerHTML; |
|
var description = document.querySelector("meta[name=\'description\']").getAttribute('content'); |
|
|
|
// Need and attribute text |
|
var twitter = document.querySelector('button.share--twitter'); |
|
twitter.addEventListener('click', function (e) { |
|
e.preventDefault(); |
|
var text = this.getAttribute('data-message') + " " + title; |
|
window.open( "http://twitter.com/share?url=" + |
|
encodeURIComponent(url) + "&text=" + |
|
encodeURIComponent(text) + "&count=none/", |
|
"tweet", "height=300,width=550,resizable=1" |
|
); |
|
}); |
|
|
|
var facebook = document.querySelector('button.share--facebook'); |
|
facebook.addEventListener('click', function (e) { |
|
e.preventDefault(); |
|
window.open( "http://www.facebook.com/sharer.php?u=" + |
|
encodeURIComponent(url) + "&t=" + |
|
encodeURIComponent(title), |
|
"facebook", "height=300,width=550,resizable=1" |
|
); |
|
}); |
|
|
|
var googleplus = document.querySelector('button.share--googleplus'); |
|
googleplus.addEventListener('click', function (e) { |
|
e.preventDefault(); |
|
window.open( "https://plus.google.com/share?url=" + |
|
encodeURIComponent(url), |
|
"google +", "height=300,width=550,resizable=1" |
|
); |
|
}); |
|
|
|
var linkedIn = document.querySelector('button.share--linkedIn'); |
|
linkedIn.addEventListener('click', function (e) { |
|
e.preventDefault(); |
|
window.open( "https://www.linkedin.com/shareArticle?mini=true&url=" + |
|
encodeURIComponent(url) + '&title=' + |
|
encodeURIComponent(title) + '&summary=' + |
|
encodeURIComponent(description), |
|
"linkedIn", "height=300,width=550,resizable=1" |
|
); |
|
}); |
|
|
|
// Need and attibute data-image-url |
|
var pinterest = document.querySelector('button.share--pinterest'); |
|
pinterest.addEventListener('click', function (e) { |
|
e.preventDefault(); |
|
var imageUrl = this.getAttribute('data-image-url'); |
|
console.log(imageUrl); |
|
window.open( "https://pinterest.com/pin/create/button/?url=" + |
|
encodeURIComponent(url) + '&media=' + |
|
encodeURIComponent(imageUrl) + '&description=' + |
|
encodeURIComponent(description), |
|
"pinterest", "height=300,width=550,resizable=1" |
|
); |
|
}); |
|
|
|
var tumbler = document.querySelector('button.share--tumbler'); |
|
tumbler.addEventListener('click', function (e) { |
|
e.preventDefault(); |
|
console.log(imageUrl); |
|
window.open( "http://www.tumblr.com/share/link?url=" + |
|
encodeURIComponent(url) + '&name=' + |
|
encodeURIComponent(title) + '&description=' + |
|
encodeURIComponent(description), |
|
"tumbler", "height=300,width=550,resizable=1" |
|
); |
|
}); |
|
|
|
var reddit = document.querySelector('button.share--reddit'); |
|
reddit.addEventListener('click', function (e) { |
|
e.preventDefault(); |
|
var imageUrl = this.getAttribute('data-image-url'); |
|
console.log(imageUrl); |
|
window.open( "http://www.reddit.com/submit/?url=" + |
|
encodeURIComponent(url) + '&title=' + |
|
encodeURIComponent(title), |
|
"reddit", "height=300,width=550,resizable=1" |
|
); |
|
}); |
|
|
|
})(); |