Skip to content

Commit a58f4f1

Browse files
author
Jonas Gossens
committed
✨ Normalize sharing buttons for all devices/browsers
1 parent 42c7601 commit a58f4f1

File tree

2 files changed

+27
-59
lines changed

2 files changed

+27
-59
lines changed

src/react-chayns-sharingbar/component/sharingActions.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
function shareWithUrl(provider, link) {
22
const openLink = provider.url.replace('{url}', link);
3-
chayns.openUrlInBrowser(openLink);
3+
if (openLink.startsWith('mailto')) {
4+
window.open(openLink);
5+
} else {
6+
chayns.openUrlInBrowser(openLink);
7+
}
48
}
59

610
function shareWithApp(provider, link) {
@@ -14,9 +18,16 @@ function shareWithApp(provider, link) {
1418

1519
function copyToClipboard(provider, link) {
1620
const aux = document.createElement('input');
21+
const range = document.createRange();
1722
aux.setAttribute('value', link);
23+
aux.setAttribute('contenteditable', 'true');
1824
document.body.appendChild(aux);
1925
aux.select();
26+
range.selectNodeContents(aux);
27+
const s = window.getSelection();
28+
s.removeAllRanges();
29+
s.addRange(range);
30+
aux.setSelectionRange(0, 999999);
2031
document.execCommand('copy');
2132
document.body.removeChild(aux);
2233
}

src/react-chayns-sharingbar/component/sharingProvider.js

Lines changed: 15 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,40 @@
11
import { faFacebookF } from '@fortawesome/free-brands-svg-icons/faFacebookF';
22
import { faWhatsapp } from '@fortawesome/free-brands-svg-icons/faWhatsapp';
33
import { faTwitter } from '@fortawesome/free-brands-svg-icons/faTwitter';
4-
import { faTumblr } from '@fortawesome/free-brands-svg-icons/faTumblr';
5-
import { faTelegram } from '@fortawesome/free-brands-svg-icons/faTelegram';
6-
import { faSkype } from '@fortawesome/free-brands-svg-icons/faSkype';
74
import { faEnvelope } from '@fortawesome/free-regular-svg-icons/faEnvelope';
8-
import { faLink } from '@fortawesome/free-solid-svg-icons/faLink';
5+
import { faCopy } from '@fortawesome/free-regular-svg-icons/faCopy';
96
import { faShareAlt } from '@fortawesome/free-solid-svg-icons/faShareAlt';
107

118
export const shareProvider = [
9+
{
10+
id: 2,
11+
providerId: 1,
12+
name: 'WhatsApp',
13+
androidIdentifier: 'com.whatsapp',
14+
icon: faWhatsapp,
15+
action: 1,
16+
url: 'https://api.whatsapp.com/send?text={url}',
17+
available: true,
18+
},
1219
{
1320
id: 0,
1421
providerId: -1,
1522
name: 'Zwischenablage',
1623
androidIdentifier: null,
17-
icon: faLink,
24+
icon: faCopy,
1825
action: 0,
1926
url: null,
20-
available: false,
27+
available: true,
2128
},
2229
{
2330
id: 1,
2431
providerId: 0,
2532
name: 'Mail',
2633
androidIdentifier: null,
2734
icon: faEnvelope,
28-
action: 2,
29-
url: null,
30-
available: false,
31-
},
32-
{
33-
id: 2,
34-
providerId: 1,
35-
name: 'WhatsApp',
36-
androidIdentifier: 'com.whatsapp',
37-
icon: faWhatsapp,
3835
action: 1,
39-
url: null,
40-
available: false,
36+
url: 'mailto:?body={url}',
37+
available: true,
4138
},
4239
{
4340
id: 3,
@@ -59,46 +56,6 @@ export const shareProvider = [
5956
url: 'http://twitter.com/intent/tweet?text=&url={url}&hashtags=chayns',
6057
available: true,
6158
},
62-
{
63-
id: 6,
64-
providerId: -1,
65-
name: 'Tumblr',
66-
androidIdentifier: 'com.tumblr',
67-
icon: faTumblr,
68-
action: 1,
69-
url: '//tumblr.com/widgets/share/tool?canonicalUrl={url}',
70-
available: false,
71-
},
72-
{
73-
id: 7,
74-
providerId: -1,
75-
name: 'Telegram',
76-
androidIdentifier: 'org.telegram.messenger',
77-
icon: faTelegram,
78-
action: 1,
79-
url: null,
80-
available: false,
81-
},
82-
/* {
83-
'id': 8,
84-
'providerId': -1,
85-
'name': 'Snapchat',
86-
'androidIdentifier': 'com.snapchat.android',
87-
'icon': 'fa-snapchat-ghost',
88-
'action': 2,
89-
'url': null,
90-
'available': false,
91-
}, */
92-
{
93-
id: 9,
94-
providerId: -1,
95-
name: 'Skype',
96-
androidIdentifier: 'com.skype.raider',
97-
icon: faSkype,
98-
action: 2,
99-
url: null,
100-
available: false,
101-
},
10259
{
10360
id: 10,
10461
providerId: -1,

0 commit comments

Comments
 (0)