-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
131 lines (121 loc) · 4.39 KB
/
index.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* share-url v1.2.0
* @link https://github.com/noeldelgado/share-url
* @license MIT
*/
(function(root, factory) {
if (typeof exports === 'object') module.exports = factory(root);
else root.ShareUrl = factory(root);
}(this, function factory(root) {
var ENDPOINTS = {
facebook : 'https://www.facebook.com/sharer/sharer.php?',
twitter : 'https://twitter.com/share?',
pinterest : 'https://pinterest.com/pin/create/button/?',
reddit : 'http://www.reddit.com/submit?',
linkedin : 'https://linkedin.com/sharing/share-offsite/?',
whatsapp : 'https://api.whatsapp.com/send?',
telegram : 'https://t.me/share/url?',
};
return {
VERSION : '1.2.0',
facebook : facebook,
twitter : twitter,
pinterest : pinterest,
reddit : reddit,
linkedin : linkedin,
whatsapp : whatsapp,
telegram : telegram,
email : email,
};
function _generateUrlParams(data) {
return Object.keys(data || {}).map(function(propertyName) {
return propertyName + '=' + encodeURIComponent(data[propertyName]);
}).join('&');
}
/* Compose the share on facebook url string.
* @argument data [Object] <required>
* @argument data.u [String] <required>
* @return url
*/
function facebook(data) {
return ENDPOINTS.facebook + _generateUrlParams(data);
}
/* Compose the share on whatsapp url string
* @argument data [Object] <required>
* @argument data.text [String] <required>
* @return url
*/
function whatsapp(data) {
return ENDPOINTS.whatsapp + _generateUrlParams(data);
}
/* Compose the share on telegram url string
* @argument data [Object] <required>
* @argument data.url [String] <required>
* @argument data.text [String] <optional>
* @return url
*/
function telegram(data) {
return ENDPOINTS.telegram + _generateUrlParams(data);
}
/* Compose the share on twitter url string.
* @argument data [Object] <required>
* @argument data.text [String] <optional> Pre-populated text highlighted in the Tweet composer.
* @argument data.in_reply_to [String] <optional> Status ID string of a parent Tweet such as a Tweet from your account (if applicable).
* @argument data.url [String] <optional> URL included with the Tweet.
* @argument data.hashtags [String] <optional> A comma-separated list of hashtags to be appended to default Tweet text.
* @argument data.via [String] <optional> Attribute the source of a Tweet to a Twitter username.
* @argument data.related [String] <optional> A comma-separated list of accounts related to the content of the shared URI.
* @info https://dev.twitter.com/web/tweet-button/parameters
* @return url
*/
function twitter(data) {
return ENDPOINTS.twitter + _generateUrlParams(data);
}
/* Compose the share on pinterest url string.
* @argument data [Object] <required>
* @argument data.url <required>
* @argument data.media <required>
* @argument data.description <required>
* @info https://developers.pinterest.com/pin_it/
* @return url
*/
function pinterest(data) {
return ENDPOINTS.pinterest + _generateUrlParams(data);
}
/* Compose the submit to reddit url string.
* @argument data [Object] <required>
* @argument data.url <required>
* @argument data.title <optional>
* @argument data.text <optional>
* @info http://www.reddit.com/buttons/
* @return url
*/
function reddit(data) {
return ENDPOINTS.reddit + _generateUrlParams(data);
}
/* Compose the share article on linkedin url string.
* @argument data [Object] <required>
* @argument data.url [String, 1024] <required> The url-encoded URL of the page that you wish to share.
* @info https://developer.linkedin.com/docs/share-on-linkedin
* @return url
*/
function linkedin(data) {
return ENDPOINTS.linkedin + _generateUrlParams(data);
}
/* Compose the send email url string.
* @argument data [Object] <required>
* @argument to [String] <required>
* @argument subject [String] <optional>
* @argument cc [String] <optional>
* @argument bcc [String] <optional>
* @argument body [String] <optional>
* @info https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Email_links
* @return url
*/
function email(data) {
var to = data.to;
delete data.to;
var params = _generateUrlParams(data);
return 'mailto:' + (params.length ? (to + '?' + params) : to);
}
}));