1const LOADER_URL = 'https://d21-a.sdn.cz/d_21/sl/3/loader.js'; 2const LOAD_TIMEOUT = 20000; 3const CONSENT_MESSAGE = 'Pro zobrazenà diskuse povolte službu Seznam.cz v nastavenà souhlasu.'; 4const ERROR_MESSAGE = 'Diskusi se nepodaÅilo naÄÃst. Zkuste to prosÃm znovu.'; 5let sdkPromise; 6 7function loadSdk() { 8 if (!sdkPromise) { 9 sdkPromise = new Promise((resolve, reject) => { 10 const timeout = setTimeout(() => reject(new Error('Seznam discussion SDK timed out.')), LOAD_TIMEOUT); 11 loadLoader() 12 .then(() => window.SZN.DiscussionLoader.load(['embedded'])) 13 .then(resolve, reject) 14 .finally(() => clearTimeout(timeout)); 15 }).catch((error) => { 16 sdkPromise = undefined; 17 throw error; 18 }); 19 } 20 21 return sdkPromise; 22} 23 24function loadLoader() { 25 if (window.SZN?.DiscussionLoader) { 26 return Promise.resolve(); 27 } 28 29 return new Promise((resolve, reject) => { 30 const existing = document.querySelector(`script[src="${LOADER_URL}"]`); 31 const script = existing || document.createElement('script'); 32 const finish = (error) => { 33 clearTimeout(timeout); 34 script.removeEventListener('load', onLoad); 35 script.removeEventListener('error', onError); 36 if (error) { 37 script.remove(); 38 reject(error); 39 } else { 40 resolve(); 41 } 42 }; 43 const onError = () => finish(new Error('Seznam discussion loader is unavailable.')); 44 const onLoad = () => window.SZN?.DiscussionLoader ? finish() : onError(); 45 const timeout = setTimeout(onError, LOAD_TIMEOUT); 46 script.addEventListener('load', onLoad); 47 script.addEventListener('error', onError); 48 49 if (!existing) { 50 script.src = LOADER_URL; 51 script.async = true; 52 document.head.appendChild(script); 53 } 54 }); 55} 56 57export function initSeznamDiscussions(root = document) { 58 root.querySelectorAll('[data-js-module~="seznam-discussion"]:not([data-discussion-bound])').forEach((section) => { 59 section.dataset.discussionBound = 'true'; 60 const embed = section.querySelector('[data-discussion-embed]'); 61 const status = section.querySelector('[data-discussion-status]'); 62 const message = section.querySelector('[data-discussion-message]'); 63 const action = section.querySelector('[data-discussion-action]'); 64 let didomi; 65 let instance; 66 let loading = false; 67 let attempt = 0; 68 let loadedTimeout; 69 70 const hasConsent = () => didomi?.getUserConsentStatusForVendor('621') === true; 71 const showStatus = (text, buttonText) => { 72 status.hidden = false; 73 message.textContent = text; 74 action.textContent = buttonText || ''; 75 action.hidden = !buttonText; 76 }; 77 const unload = () => { 78 attempt += 1; 79 clearTimeout(loadedTimeout); 80 instance?.unload(); 81 instance = undefined; 82 loading = false; 83 embed.hidden = true; 84 }; 85 const fail = (error) => { 86 unload(); 87 showStatus(ERROR_MESSAGE, 'Zkusit znovu'); 88 console.error('Seznam discussion could not be loaded.', error); 89 }; 90 91 const updateConsent = async () => { 92 if (!hasConsent()) { 93 unload(); 94 showStatus(CONSENT_MESSAGE, 'Nastavenà souhlasu'); 95 return; 96 } 97 98 if (loading || instance) { 99 return; 100 } 101 102 loading = true; 103 const currentAttempt = ++attempt; 104 showStatus('NaÄÃtánà diskuseâ¦'); 105 try { 106 await loadSdk(); 107 if (currentAttempt !== attempt || !hasConsent()) { 108 return; 109 } 110 111 embed.hidden = false; 112 instance = window.SZN.Discussion.create(section.dataset.discussionService, embed, { 113 linksInNewTab: true, 114 allowScroll: true 115 }); 116 loadedTimeout = setTimeout(() => fail(new Error('Seznam discussion embed timed out.')), LOAD_TIMEOUT); 117 instance.listen('loaded', () => { 118 if (currentAttempt !== attempt) { 119 return; 120 } 121 122 clearTimeout(loadedTimeout); 123 loading = false; 124 status.hidden = true; 125 }); 126 instance.loadDiscussion(section.dataset.discussionThread, { 127 title: section.dataset.discussionTitle, 128 url: section.dataset.discussionUrl 129 }); 130 } catch (error) { 131 if (currentAttempt === attempt) { 132 fail(error); 133 } 134 } 135 }; 136 137 action.hidden = false;
138 action.addEventListener('click', () => { 139 if (hasConsent()) { 140 updateConsent(); 141 } else if (didomi) { 142 didomi.preferences.show(); 143 } else { 144 showStatus('Nastavenà souhlasu zatÃm nenà dostupné. Zkuste to znovu nebo obnovte stránku.', 'Nastavenà souhlasu'); 145 } 146 }); 147 148 window.didomiEventListeners = window.didomiEventListeners || []; 149 window.didomiEventListeners.push({event: 'consent.changed', listener: updateConsent}); 150 window.didomiOnReady = window.didomiOnReady || []; 151 window.didomiOnReady.push((sdk) => { 152 didomi = sdk; 153 updateConsent(); 154 }); 155 }); 156}
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.