-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
facebook.ts
67 lines (59 loc) · 1.97 KB
/
facebook.ts
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
import { updateStringAttribute } from '../helpers.js';
import type { ShareMenu, ShareTarget } from '../share-menu.js';
export class FacebookShareTarget extends HTMLElement implements ShareTarget {
public readonly displayName = 'Facebook';
public readonly color = '3b5998';
public readonly icon =
'M94 50v35H68v43h26v128h53V128h36l5-43h-41V55c0-4 6-10 12-10h29V0h-40C93 0 94 43 94 50z';
/**
* The Facebook App ID. If the Facebook JS SDK is not found and this parameter
* is specified, then the Facebook share dialog will be used instead of the sharer
* API to make it possible to also share the text and title together with the URL.
*
* @return {string | null}
*/
public get appId(): string | null {
return this.getAttribute('app-id');
}
public set appId(val: string | null | undefined) {
updateStringAttribute(this, 'app-id', val);
}
/**
* A URL to redirect to after the share has been completed.
*
* @return {string | null}
*/
public get redirectUri(): string | null {
return this.getAttribute('redirect-uri');
}
public set redirectUri(val: string | null | undefined) {
updateStringAttribute(this, 'redirect-uri', val);
}
public share(shareMenu: ShareMenu) {
if (window.FB) {
window.FB.ui({
method: 'share',
href: shareMenu.url,
quote: `${shareMenu.title}\n${shareMenu.text}`,
});
} else if (this.appId) {
shareMenu.openWindow('https://www.facebook.com/dialog/share', {
app_id: this.appId,
display: 'popup',
href: shareMenu.url,
quote: `${shareMenu.title}\n${shareMenu.text}`,
redirect_uri: this.redirectUri || undefined,
});
} else {
shareMenu.openWindow('https://www.facebook.com/sharer.php', {
u: shareMenu.url,
});
}
}
}
customElements.define('share-target-facebook', FacebookShareTarget);
declare global {
interface HTMLElementTagNameMap {
'share-target-facebook': FacebookShareTarget;
}
}