|
10 | 10 | */
|
11 | 11 | function ShareButtons() {
|
12 | 12 |
|
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}', |
17 | 17 | 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', |
18 | 23 |
|
19 | 24 | // from https://wcoder.github.io/notes/string-format-for-string-formating-in-javascript
|
20 | 25 | stringFormat = function (str, args) {
|
|
116 | 121 | text = title || desc || '';
|
117 | 122 |
|
118 | 123 | 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); |
121 | 128 | break;
|
122 | 129 |
|
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); |
125 | 137 | break;
|
126 | 138 |
|
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); |
136 | 146 | break;
|
137 | 147 |
|
138 |
| - case 'tg': |
| 148 | + case TG_CLASS_NAME: |
139 | 149 | this.popupCenter(
|
140 | 150 | stringFormat(TG_LINK_FORMAT, [
|
141 | 151 | url,
|
|
144 | 154 | titleDef);
|
145 | 155 | break;
|
146 | 156 |
|
147 |
| - case 'mail': |
| 157 | + case MAIL_CLASS_NAME: |
148 | 158 | if (title.length > 0 && desc.length > 0) {
|
149 |
| - text = title + ' - ' + desc; |
| 159 | + text = mergeForTitle([title, desc]); |
150 | 160 | }
|
151 | 161 | if (text.length > 0) {
|
152 | 162 | text = text + ' / ';
|
|
0 commit comments