PageSourceSearch

https://townhall.com/_content/Rcl.Common/js/social-share-bar.js?v=kef5UVb09bkYTOmiLJS8qOlRUm9l_9BpssR3AkY4aTc

js townhall.com collected 2026-09-24 08:28:56 UTC 2,921 bytes, 96 lines download raw bytes

1/**
2 * Social Share Bar - fixed-size share popups
3
4 * @module social-share-bar
5 */
6
7const DEFAULT_POPUP_WIDTH = 600;
8const DEFAULT_POPUP_HEIGHT = 400;
9
10function getDatasetString(element, name) {
11    const value = element?.dataset?.[name];
12    if (!value) return '';
13    return String(value).trim();
14}
15
16function getDatasetInt(element, name, fallback) {
17    const raw = getDatasetString(element, name);
18    const value = Number.parseInt(raw, 10);
19    return Number.isFinite(value) ? value : fallback;
20}
21
22function getShareContext(root) {
23    const url = getDatasetString(root, 'url') || window.location.href;
24    const title = getDatasetString(root, 'title') || document.title || '';
25
26    return { url, title };
27}
28
29function buildShareUrl(platform, shareContext) {
30    const encodedUrl = encodeURIComponent(shareContext.url);
31    const encodedTitle = encodeURIComponent(shareContext.title);
32
33    switch (platform) {
34        case 'x':
35            return `https://x.com/intent/tweet?url=${encodedUrl}&text=${encodedTitle}`;
36        case 'truth':
37            return `https://truthsocial.com/share?url=${encodedUrl}&title=${encodedTitle}`;
38        case 'facebook':
39            return `https://www.facebook.com/sharer/sharer.php?u=${encodedUrl}`;
40        default:
41            return '';
42    }
43}
44
45function openPopup(url, width, height) {
46    if (!url) return;
47
48    const left = Math.max(0, Math.floor((window.screen.width - width) / 2));
49    const top = Math.max(0, Math.floor((window.screen.height - height) / 2));
50
51    const features = [
52        `width=${width}`,
53        `height=${height}`,
54        `left=${left}`,
55        `top=${top}`,
56        'scrollbars=yes',
57        'resizable=yes',
58        'noopener',
59        'noreferrer'
60    ].join(',');
61
62    window.open(url, '_blank', features);
63}
64
65function initializeSocialShareBar(root) {
66    if (root.dataset.initialized === 'true') return;
67    root.dataset.initialized = 'true';
68
69    const popupWidth = getDatasetInt(root, 'popupWidth', DEFAULT_POPUP_WIDTH);
70    const popupHeight = getDatasetInt(root, 'popupHeight', DEFAULT_POPUP_HEIGHT);
71
72    root.addEventListener('click', (event) => {
73        const link = event.target.closest('a[data-share-platform]');
74        if (!link || !root.contains(link)) return;
75
76        const platform = getDatasetString(link, 'sharePlatform');
77        if (!platform) return;
78
79        event.preventDefault();
80
81        const shareContext = getShareContext(root);
82        const shareUrl = buildShareUrl(platform, shareContext) || link.getAttribute('href') || '';
83
84        openPopup(shareUrl, popupWidth, popupHeight);
85    });
86}
87
88function initializeSocialShareBars() {
89    document.querySelectorAll('[data-social-share-bar]').forEach(initializeSocialShareBar);
90}
91
92// Initialize on module load (modules are deferred by default)
93initializeSocialShareBars();
94
95// Export for programmatic use
96export { initializeSocialShareBars, initializeSocialShareBar };

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.