EBG.declareNamespace("RichModules");EBG.RichModules.IntersectionObserverVisibilityProvider=function (resourceObjId,adConfig,options){EBG.callSuperConstructor(EBG.RichModules.IntersectionObserverVisibilityProvider,this,[resourceObjId,adConfig,options]);this._initObserver();};EBG.RichModules.IntersectionObserverVisibilityProvider.prototype={name:"InteractionObserver",_precision:0.05,_observer:null,_lastPercentage:null,_lastViewport:null,_initObserver:function (){if(window.IntersectionObserver){var options={threshold:[0,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95,1]};this._observer=new IntersectionObserver(this._handleChanges.bind(this),options);}if(this.adConfig.ffs["CFF_AMPIntersection"]&&this.adConfig.actualServingMode==EBG.Adaptors.ServingMode.IFRAME&&window.context&&context.observeIntersection&&EBG.isFunc(context.observeIntersection)){context.observeIntersection(this._handleAMPChanges.bind(this));}},_handleChanges:function (changes){var entry=changes[changes.length-1];this._lastPercentage=Math.round(entry.intersectionRatio*100);if(entry.rootBounds){this._lastViewport=entry.rootBounds;}this._triggerVisibilityCheck();},_handleAMPChanges:function (changes){var entry=changes[changes.length-1];if(!this._observer){this._lastPercentage=Math.round(entry.intersectionRatio*100);}this._lastViewport=entry.rootBounds;this._triggerVisibilityCheck();},_calculateVisibilityPercentage:function (){try{return EBG.adaptor.isPageVisible()?this._lastPercentage:0;}catch(e){return 0;}},updateResourceObjId:function (resourceObjId){this._observer.unobserve(this._res);EBG.callSuperFunction(EBG.RichModules.IntersectionObserverVisibilityProvider,this,"updateResourceObjId",[resourceObjId]);this._observer.observe(this._res);},_getViewPortRect:function (){return this._lastViewport;},_getViewPortMetrics:function (){var rect=this._getViewPortRect();if(rect){return {Height:rect.height,Width:rect.width};}return null;},_isVisible:function (){return !!this._calculateVisibilityPercentage();},_checkVisibility:function (){var res=this._calculateVisibilityResult();if(this._lastPercentage!=res.percentage||(!this._lastViewport||this._lastViewport.Height!=res.viewPort.Height||this._lastViewport.Width!=res.viewPort.Width)){this._dispatchCheckVisibility(res);this._lastPercentage=res.percentage;this._lastViewport=res.viewPort;}},start:function (){this._lastPercentage=0;EBG.callSuperFunction(EBG.RichModules.IntersectionObserverVisibilityProvider,this,"start");this._observer.observe(this._res);}};EBG.declareClass(EBG.RichModules.IntersectionObserverVisibilityProvider,EBG.RichModules.BasicVisibilityProvider);