Skip to content

Commit 67e18b0

Browse files
committed
Refactoring
1 parent 28f4890 commit 67e18b0

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

dist/share-buttons.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/share-buttons.js

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
*/
1111
function ShareButtons() {
1212

13-
var FB_LINK_FORMAT = 'https://www.facebook.com/sharer/sharer.php?u=',
14-
VK_LINK_FORMAT = 'https://vk.com/share.php?url={0}&description={1}. {2}',
15-
TW_LINK_FORMAT = 'https://twitter.com/intent/tweet?url=',
16-
TG_LINK_FORMAT = 'https://telegram.me/share/url?url={0}&text={1}',
13+
var FB_LINK_FORMAT = 'https://www.facebook.com/sharer/sharer.php?u={0}',
14+
VK_LINK_FORMAT = 'https://vk.com/share.php?url={0}&title={1}',
15+
TW_LINK_FORMAT = 'https://twitter.com/intent/tweet?url={0}&text={1}',
16+
TG_LINK_FORMAT = 'https://t.me/share/url?url={0}&text={1}',
1717
MAIL_LINK_FORMAT = 'mailto:?Subject={0}{1}&body={2}{3}',
18+
FB_CLASS_NAME = 'fb',
19+
VK_CLASS_NAME = 'vk',
20+
TW_CLASS_NAME = 'tw',
21+
TG_CLASS_NAME = 'tg',
22+
MAIL_CLASS_NAME = 'mail',
1823

1924
// from https://wcoder.github.io/notes/string-format-for-string-formating-in-javascript
2025
stringFormat = function (str, args) {
@@ -116,26 +121,31 @@
116121
text = title || desc || '';
117122

118123
switch (id) {
119-
case 'fb':
120-
this.popupCenter(FB_LINK_FORMAT + url, titleDef);
124+
case FB_CLASS_NAME:
125+
this.popupCenter(
126+
stringFormat(FB_LINK_FORMAT, [url]),
127+
titleDef);
121128
break;
122129

123-
case 'vk':
124-
this.popupCenter(stringFormat(VK_LINK_FORMAT, [url, title, desc]), titleDef);
130+
case VK_CLASS_NAME:
131+
this.popupCenter(
132+
stringFormat(VK_LINK_FORMAT, [
133+
url,
134+
mergeForTitle([title, desc])
135+
]),
136+
titleDef);
125137
break;
126138

127-
case 'tw':
128-
if (title.length > 0 && desc.length > 0) {
129-
text = title + ' - ' + desc;
130-
}
131-
if (text.length > 0) {
132-
text = '&text=' + text;
133-
}
134-
135-
this.popupCenter(TW_LINK_FORMAT + url + text, titleDef);
139+
case TW_CLASS_NAME:
140+
this.popupCenter(
141+
stringFormat(TW_LINK_FORMAT, [
142+
url,
143+
mergeForTitle([title, desc])
144+
]),
145+
titleDef);
136146
break;
137147

138-
case 'tg':
148+
case TG_CLASS_NAME:
139149
this.popupCenter(
140150
stringFormat(TG_LINK_FORMAT, [
141151
url,
@@ -144,9 +154,9 @@
144154
titleDef);
145155
break;
146156

147-
case 'mail':
157+
case MAIL_CLASS_NAME:
148158
if (title.length > 0 && desc.length > 0) {
149-
text = title + ' - ' + desc;
159+
text = mergeForTitle([title, desc]);
150160
}
151161
if (text.length > 0) {
152162
text = text + ' / ';

0 commit comments

Comments
 (0)