-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshare.js
82 lines (75 loc) · 2.91 KB
/
share.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var cal = {};
cal.base = function($, undefined) {
function getMetaContentByName(name) {
return (document.getElementsByName(name)[0] || 0).content;
}
function getDefaults(onlyUrl = false, s) {
var site = getMetaContentByName("twitter:site");
if (onlyUrl) {
newsUrl = s.parents("div.post-body").prevAll("h1")[0].firstElementChild.href;
title = $.trim(s.parents("div.post-body").prevAll("h1")[0].firstElementChild.text);
desc = s.parents("div.post-body").prevAll("p")[0].firstElementChild.text;
return { url: newsUrl, title: title, source: location.origin, origin: site, desc: desc }
} else {
var title = getMetaContentByName("title") || document.title;
var desc = getMetaContentByName("description") || "";
var defaults = {
url: location.href,
origin: site,
source: location.origin,
title: title,
desc: desc
}
return defaults
}
}
shareTools = {
templates: {
linkedin: "https://www.linkedin.com/shareArticle?mini=true&ro=true&title={{TITLE}}&url={{URL}}&source={{SOURCE}}&summary={{DESC}}&armin=armin",
facebook: "https://www.facebook.com/sharer/sharer.php?u={{URL}}&t={{TITLE}}",
twitter: "http://www.facebook.com/sharer/sharer.php?u={{URL}}",
google: "https://plus.google.com/share?url={{URL}}",
twitter: "https://twitter.com/intent/tweet?text={{TITLE}}&url={{URL}}&via={{ORIGIN}}"
},
makeUrl: function(name, data) {
return this.templates[name].replace(/\{\{(\w*)\}\}/g, function(fix, key) {
return encodeURIComponent(data[key.toLowerCase()]);
});
},
run: function(url) {
window.open(url, "_blank", 'toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=600, height=450,top=100,left=100');
}
}
function IsIndexList() {
loca = window.location.href;
if (loca.indexOf("index") == -1) {
return false;
}
return true;
}
function track_sharing_links() {
$("[data-shared]").on("click", function() {
var $this = $(this);
var shareLink = $this.data("shared");
if (shareLink === "") {
return;
}
isIndex = IsIndexList();
if (isIndex) {
data = getDefaults(true, $(this));
} else {
data = getDefaults();
}
realUrl = shareTools.makeUrl(shareLink, data);
shareTools.run(realUrl);
});
}
return {
init: function() {
$(document).ready(function() {
track_sharing_links();
});
}
}
}(jQuery);
cal.base.init();;