1(function () { 2 var STICKY_ADUNIT_NAME = 'sticky'; 3 var STICKY_CONTAINER_ID = 'sticky'; 4 var STICKY_Z_INDEX = 99998; 5 var DELAY_AFTER_CLOSE = 140000; 6 var FOOTER_SELECTOR = '.pharma-footer'; 7 var footerObserver = null; 8 var footerInViewport = false; 9 var currentSlot = null; 10 var rerenderTimeoutId = null; 11 var isRenderInProgress = false; 12 var renderAttemptId = 0; 13 14 function getContainer() { 15 var container = document.getElementById(STICKY_CONTAINER_ID); 16 17 if (container) { 18 return container; 19 } 20 21 if (!document.body) { 22 window.console.warn('[E1 desktop sticky] document.body is not available'); 23 24 return null; 25 } 26 27 container = document.createElement('div'); 28 container.id = STICKY_CONTAINER_ID; 29 document.body.appendChild(container); 30 31 return container; 32 } 33 34 function clearRerenderTimeout() { 35 if (rerenderTimeoutId) { 36 clearTimeout(rerenderTimeoutId); 37 rerenderTimeoutId = null; 38 } 39 } 40 41 function destroyDesktopSticky(creativeManager, slot) { 42 var container = document.getElementById(STICKY_CONTAINER_ID); 43 44 if (container && container.parentNode) { 45 container.parentNode.removeChild(container); 46 } 47 48 if ( 49 creativeManager 50 && slot 51 && typeof creativeManager.destroySlot === 'function' 52 ) { 53 creativeManager.destroySlot(slot); 54 } 55 56 if (slot && currentSlot === slot) { 57 currentSlot = null; 58 } 59 } 60 61 function renderDesktopSticky(creativeManager) { 62 var container; 63 var attemptId; 64 65 if (currentSlot || footerInViewport || isRenderInProgress) { 66 return; 67 } 68 69 if (!creativeManager || typeof creativeManager.createSlot !== 'function') { 70 window.console.warn('[E1 desktop sticky] createSlot is not available on creativeManager'); 71 72 return; 73 } 74 75 container = getContainer(); 76 77 if (!container) { 78 return; 79 } 80 81 isRenderInProgress = true; 82 renderAttemptId += 1; 83 attemptId = renderAttemptId; 84 85 creativeManager.ready.then(function () { 86 return creativeManager.createSlot({ 87 container: container, 88 adunit: STICKY_ADUNIT_NAME, 89 params: { 90 priority: 1, 91 type: 'floorAd', 92 platform: 'desktop', 93 slotRefreshManagerConfig: { 94 refreshAlgorithmType: 'INTERVAL', 95 }, 96 } 97 }); 98 }).then(function (slot) { 99 isRenderInProgress = false; 100 101 if (attemptId !== renderAttemptId || footerInViewport) { 102 if ( 103 slot 104 && typeof creativeManager.destroySlot === 'function' 105 ) { 106 creativeManager.destroySlot(slot); 107 } 108 109 return; 110 } 111 112 if (!slot) { 113 window.console.warn('[E1 desktop sticky] Failed to create slot'); 114 return; 115 } 116 117 currentSlot = slot; 118 119 if (typeof slot.on === 'function') { 120 slot.on('closed', function () { 121 destroyDesktopSticky(creativeManager, slot); 122 clearRerenderTimeout(); 123 rerenderTimeoutId = setTimeout(function () { 124 rerenderTimeoutId = null; 125 if (footerInViewport) { 126 return; 127 } 128 renderDesktopSticky(creativeManager); 129 }, DELAY_AFTER_CLOSE); 130 }); 131 } 132 133 return slot.refresh(); 134 }).catch(function (error) { 135 isRenderInProgress = false; 136 window.console.warn('[E1 desktop sticky] Failed to render', error); 137 }); 138 } 139 140 function observeFooterVisibility(creativeManager) { 141 var footer = document.querySelector(FOOTER_SELECTOR); 142 143 if (!footer || typeof IntersectionObserver !== 'function') { 144 return; 145 } 146 147 if (footerObserver) { 148 footerObserver.disconnect(); 149 } 150 151 footerObserver = new IntersectionObserver(function (entries) { 152 var entry = entries[0]; 153 154 if (!entry) { 155 return; 156 } 157 158 footerInViewport = entry.isIntersecting; 159 160 if (footerInViewport) { 161 renderAttemptId += 1; 162 isRenderInProgress = false;
163 clearRerenderTimeout(); 164 if (currentSlot) { 165 destroyDesktopSticky(creativeManager, currentSlot); 166 } 167 168 return; 169 } 170 171 if (!currentSlot) { 172 renderDesktopSticky(creativeManager); 173 } 174 }, { 175 threshold: 0 176 }); 177 178 footerObserver.observe(footer); 179 } 180 181 function initDesktopSticky() { 182 window.onHSMCreativeManagerReady.push(function (creativeManager) { 183 if (creativeManager.stickyRsya) { 184 creativeManager.stickyRsya.setzIndex(STICKY_Z_INDEX); 185 creativeManager.stickyRsya.setIsShrinkWrapper(true); 186 } 187 188 observeFooterVisibility(creativeManager); 189 renderDesktopSticky(creativeManager); 190 }); 191 } 192 193 if (!window.isMobile && window.screen.width > 1263) { 194 initDesktopSticky(); 195 } 196})();
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.