-
Notifications
You must be signed in to change notification settings - Fork 0
/
share_social.js
52 lines (37 loc) · 1.77 KB
/
share_social.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(function(){
var popupcenter = function(url, title, width, height){
var popupWidth = width || 640;
var popupHeight = height || 320;
var window_top = window.screenTop || window.screenY;
var window_left = window.screenLeft || window.screenX;
var window_width = window.innerWidth || document.documentElement.clientWidth;
var window_height = window.innerHeight || document.documentElement.clientHeight;
var popupLeft = window_left + window_width / 2 - popupWidth / 2;
var popupTop = window_top + window_height / 2 - popupHeight / 2;
var popup = window.open(url, title, "scrollbars=yes, width=" + popupWidth + ", height="
+ popupHeight + ", top=" + popupTop + ", left=" + popupLeft + "");
popup.focus();
return true;
};
if (document.querySelector('.share_twitter') === null)
return false;
else{
document.querySelector('.share_twitter').addEventListener('click', function (e) {
e.preventDefault();
var url = this.getAttribute('data-url');
var shareUrl = "https://twitter.com/intent/tweet?text=" + encodeURIComponent(document.title) +
"&via=NinaRistorcelli" + "&url=" + encodeURIComponent(url);
popupcenter(shareUrl, "Partager sur Twitter");
});
}
if (document.querySelector('.share_facebook') === null)
return false;
else{
document.querySelector('.share_facebook').addEventListener('click', function (e) {
e.preventDefault();
var url = this.getAttribute('data-url');
var shareUrl = "https://facebook.com/sharer/sharer.php?u=" + encodeURIComponent(url);
popupcenter(shareUrl, "Partager sur Facebook");
});
}
})();