(function(){"use strict";function b(){return new URLSearchParams(window.location.search).has("debug")}function i(...t){b()&&console.debug(`[${window.name||"root"}]`,...t)}const p=[{landing:"stream_uuid",backlink:"stream_uuid"},{landing:"googleIdTh",backlink:"lna-surfer-uuid"},{landing:"googleIdTh",backlink:"surfer_uuid"},{landing:"thank_you_page",backlink:"thank_you_page"},{landing:"lf_utm_source",backlink:"utm_source"},{landing:"lf_utm_medium",backlink:"utm_medium"},{landing:"lf_utm_campaign",backlink:"utm_campaign"},{landing:"lf_utm_content",backlink:"utm_content"},{landing:"lf_utm_term",backlink:"utm_term"},{landing:"lf_subid1",backlink:"subid1"},{landing:"lf_subid2",backlink:"subid2"},{landing:"lf_subid3",backlink:"subid3"},{landing:"lf_subid4",backlink:"subid4"},{landing:"lf_subid5",backlink:"subid5"},{landing:"kit",backlink:"kit"},{landing:"debug",backlink:"debug"},{landing:"tup",backlink:"tup"}],w="eqp_";function _(t,e){const n=new URL(t),a=n.searchParams,r=new URL(window.location.href);e&&(r.search=e);const m=r.searchParams;return m.has("googleIdTh")?(i("set no-trek"),a.set("no-trek","1")):(i("set trek"),a.set("trek","1")),p.forEach(function(u){const c=m.get(u.landing);c&&a.set(u.backlink,c)}),m.forEach((u,c)=>{c.startsWith(w)&&a.set(c,u)}),n.search=a.toString(),n.toString()}function y(){const t=new URL(window.location.href);return t.searchParams.set("from_backlink","1"),t.toString()}function E(){window.history.replaceState(window.history.state,"",y())}const s="newsFrame";function I(){return!!window.top.frames[s]}const l={frame:document.createElement("iframe"),recreateFrame(){this.frame.remove(),this.frame=document.createElement("iframe"),this.frame.src=""},hideRootPageContent(){i("Hide root page content"),document.body.style.overflow="hidden",document.querySelectorAll(`body > *:not(#${s})`).forEach(function(t){t.setAttribute("style","display:none;")})},initBacklinkFrame(){this.recreateFrame(),i(`Init frame named '${s}'`),this.frame.id=s,this.frame.name=s,this.frame.style.width="100%",this.frame.style.height="100vh",this.frame.style.position="fixed",this.frame.style.top="0",this.frame.style.left="0",this.frame.style.border="none",this.frame.style.zIndex="-1",this.frame.style.display="block",this.frame.style.opacity="0",this.frame.style.backgroundColor="#fff",this.frame.src="",document.body.append(this.frame),this.frame.onload=()=>l.setVisibility("show")},setVisibility(t){const e=t==="hide"?"0":"1",n=t==="hide"?"-1":"999997";this.frame.style.opacity=e,this.frame.style.zIndex=n},setFrameUrl(t){this.frame.src=t}};var d=(t=>(t[t.UPDATE_BACKLINK_OPTIONS=0]="UPDATE_BACKLINK_OPTIONS",t))(d||{});function T(t){return JSON.stringify(t)}function S(t){try{const e=JSON.parse(t);if(typeof e!="object"||!Object.keys(e).includes("operation")||!Object.keys(d).includes(e.operation.toString()))throw new Error;return e}catch{return null}}function P(t){window.parent.postMessage(T(t),"*")}function O(t,e){function n(a){const r=S(a.data);r&&t(r)}return e.addEventListener("message",n),()=>e.removeEventListener("message",n)}function v(t){t.sendInitMessages&&P({operation:d.UPDATE_BACKLINK_OPTIONS,payload:t})}const A="NOVOSTI24",k=1,U={_timeout:null,forward(){this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout(()=>window.history.forward())}};function B(){try{i(`Add to history ${k.toString()} items`);const t={eventStateName:A,origin:window.location.href};for(let e=0;e{i(`Trigger = ${t}`),L()};switch(t){case"timeout":setTimeout(e,1500);break;case"init":e();break;default:window.addEventListener(t,e,{once:!0})}}function h(t){t.preventDefault(),i("On first popstate"),window.onpopstate=f,l.hideRootPageContent(),f(t)}function N(t){t.preventDefault(),i("Stub popstate handler"),o.registerBacklink&&E(),window.onpopstate=f}function F(t){if(!o.mapQueryParams)return t;const e=_(t);return i(`Mapped url = ${e}`),e}function f(t){t.preventDefault(),window.onpopstate=N;const e=F(o.url||window.location.href);i(`History length is ${window.history.length.toString()}`),i(`Back to ${e}`),l.initBacklinkFrame(),l.setFrameUrl(e),U.forward()}function R(t){g(t),window.onpopstate=h,O(({operation:e,payload:n})=>{switch(e){case d.UPDATE_BACKLINK_OPTIONS:g(n);break}},window)}function K(t,e=!0,n=!1){const a=I();a||(R({url:t,mapQueryParams:e,registerBacklink:n}),i("Init master backlink"),["init","timeout","click","touchstart","scroll"].forEach(M)),v({url:t,sendInitMessages:a,registerBacklink:n,mapQueryParams:e}),i("Init slave backlink")}function H(t){return K(t,!1,!1)}window.initBacklink=H})();