if (self.CavalryLogger) { CavalryLogger.start_js(["VdNG1"]); } __d('ViewportTrackingHooks',['Base64'],(function a(b,c,d,e,f,g){if(c.__markCompiled)c.__markCompiled();var h={},i=[],j={registerFeedObject:function k(l,m){h[l]=c('Base64').encode(m);},updateVisibleViewportObjects:function k(l){var m=[],n=false;for(var o=0;o0){aa[aa.length-1].appendChild(z[0]);}else y.appendChild(z[0]);y.insertBefore(z[1],y.firstChild);}var ba=this.totalVPVDuration[x],ca=Math.floor(ba/1000)+'.'+Math.floor(ba%1000/100);c('DOM').setContent(z[0],ca);c('DOM').setContent(z[1],ca);};u.prototype.updateVPVDTimers=function(){for(var x in this.activeStories)if(this.activeStories.hasOwnProperty(x))this.updateVPVDTimer(x);};u.prototype.logVpvdAnalysis=function(x,y,z,aa,ba,ca){var da=new (c('BanzaiScuba'))('vpv_duration');da.addDenorm('qid',this.getQueryID(this.activeStories[x].story));da.addDenorm('uid',c('CurrentUser').getID());da.addDenorm('vsid',x);da.addInteger('time',Math.round(Date.now()/1000));da.addInteger('duration',aa);da.addInteger('total_duration',ba);da.addNormal('story_state',this.activeStories[x].state);da.addNormal('is_active_state',z);da.addNormal('num_visible_stories',this.numVisibleStories);da.addInteger('story_height',this.activeStories[x].story_height);da.addInteger('story_visible_height',this.activeStories[x].height);da.addInteger('state_visible_height',ca);da.addInteger('total_visible_height',this.totalVisibleHeight);da.addInteger('total_height',this.totalHeight);da.addNormal('user_focus',this.latestUserFocus);da.addNormal('next_user_focus',this.userFocus);da.addInteger('vpvd',y);da.addInteger('accumulated_vpvd',this.activeStories[x].vpvd);da.addNormal('user_activity',this.latestUserActivity);da.addNormal('next_user_activity',this.userActivity);da.addInteger('story_position_y',this.activeStories[x].y);da.addInteger('feed_insertion_position',this.getFBFeedInsertionPosition(this.activeStories[x].story));da.addNormal('visible_position',this.activeStories[x].visible_position);da.addNormal('is_focused_story',this.activeStories[x].is_focused);da.post();};u.prototype.shouldDiscardStory=function(x){var y=this.activeStories[x].height||0;return y!=this.activeStories[x].story_height&&ythis.discardVPVDIntervalThreshold)return;var z=(y={},y[o]=0,y[n]=0,y[m]=0,y),aa=x-this.latestTimeTrackingTimestamp>=this.focused_state_duration;this.totalVisibleHeight=0;for(var ba in this.activeStories)if(this.activeStories.hasOwnProperty(ba))if(!(this.latestUserFocus===q&&aa&&this.shouldDiscardStory(ba))){var ca=this.activeStories[ba].state||null,da=this.activeStories[ba].height||0;if(ca!==null&&z.hasOwnProperty(ca))z[ca]+=da;this.totalVisibleHeight+=da;}var ea=0,fa=x-this.latestTimeTrackingTimestamp;if(this.latestUserFocus===q){fa=z[m]>0?this.focused_state_duration:this.active_state_duration;fa=Math.min(fa,x-this.latestTimeTrackingTimestamp);ea=x-this.latestTimeTrackingTimestamp-fa;}var ga=0,ha=m;for(var ia=m;ia>=o;ia--)if(z[ia]>0){ga=z[ia];ha=ia;break;}var ja=z[m]+z[n]+z[o],ka=0;for(ba in this.activeStories)if(this.activeStories.hasOwnProperty(ba)){if(this.latestUserFocus===q&&aa&&this.shouldDiscardStory(ba))continue;var la=this.activeStories[ba].state||p;if(ga>0&&la>=ha){var ma=this.activeStories[ba].height||0;ka=fa*(ma/ga);if(this.vpvdAnalysis&&fa>0)this.logVpvdAnalysis(ba,ka,true,fa,fa+ea,ga);this.activeStories[ba].vpvd+=ka;this.totalVPVDuration[ba]+=ka;}if(ja>0){var na=this.activeStories[ba].height||0;ka=ea*(na/ja);if(this.vpvdAnalysis&&ea>0)this.logVpvdAnalysis(ba,ka,false,ea,fa+ea,ja);this.activeStories[ba].vpvd+=ka;this.totalVPVDuration[ba]+=ka;}}};u.prototype.updateActiveStory=function(x,y,z,aa){this.activeStories[x].state=y;this.activeStories[x].ts=z;this.activeStories[x].height_snapshot=aa[x].height;this.activeStories[x].is_focused=this.focusedStory===aa[x].story;this.activeStories[x].story_height=aa[x].story_height;if(this.vpvdAnalysis){this.activeStories[x].visible_position=aa[x].visible_position;this.activeStories[x].y=aa[x].y;}};u.prototype.updateActiveStories=function(x,y){for(var z in x)if(x.hasOwnProperty(z))if(z in this.activeStories){var aa=x[z].height||0;this.activeStories[z].height=aa;var ba=aa-(this.activeStories[z].height_snapshot||0);if(this.focusedStory===x[z].story){this.updateActiveStory(z,m,y,x);}else if(ba<=-this.height_diff_to_change_state){this.updateActiveStory(z,this.shouldDiscardStory(z)?p:o,y,x);}else if(ba>=this.height_diff_to_change_state||this.activeStories[z].is_focused||this.activeStories[z].height===this.activeStories[z].story_height)this.updateActiveStory(z,n,y,x);}else{this.activeStories[z]={evp_ts:y,story:x[z].story,height:x[z].height,vpvd:0};if(!this.totalVPVDuration[z])this.totalVPVDuration[z]=0;this.updateActiveStory(z,n,y,x);}};u.prototype.recordVPVDurations=function(x,y){for(var z in this.activeStories)if(this.activeStories.hasOwnProperty(z))if(y||!(z in x)){var aa=this.activeStories[z].vpvd||0;if(aa>this.focused_state_duration||aa===this.totalVPVDuration[z])this.recordTimeStoryWasInView(this.activeStories[z]);delete this.activeStories[z];}};u.prototype.updateTimeTrackingData=function(x,y){this.userActivity=y;if(!this.activeStories)this.activeStories={};var z=Date.now();if(!this.latestTimeTrackingTimestamp)this.latestTimeTrackingTimestamp=z;var aa=this.getVisibleStoriesFromCache();this.calculateTotalHeight();this.updateVPVDurations(z);this.updateActiveStories(aa,z);if(this.vpvdDebug)this.updateVPVDTimers();this.recordVPVDurations(aa,x);if(x){this.latestTimeTrackingTimestamp=0;}else this.latestTimeTrackingTimestamp=z;this.latestUserActivity=this.userActivity;this.latestUserFocus=this.userFocus;if(this.focusedStory)this.latestActiveStory=this.focusedStory;this.latestFocusedStory=this.focusedStory;this.focusedStory=null;};u.prototype.needsToUpdateTimeTrackingData=function(){return !(this.latestUserFocus===this.userFocus&&(this.userFocus===r||this.userFocus===q&&!this.latestFocusedStory&&!this.focusedStory));};u.prototype.getfocusedStory=function(x){var y=this.getVisibleStoriesFromCache();for(var z in y)if(y.hasOwnProperty(z)){var aa=y[z].story;if(aa&&c('ViewportTrackingHelper').isDescendantOf(x,aa))return aa;}return null;};u.prototype.handleLayers=function(){if(this.userFocus===s||this.userFocus===t){this.focusedStory=this.latestActiveStory;this.updateTimeTrackingData(false,'media_layer');return true;}return false;};u.prototype.didInteractWithStream=function(x){if(!this.behavior.getStream)return false;var y=this.behavior.getStream();return c('ViewportTrackingHelper').isDescendantOf(x,y)||c('ViewportTrackingHelper').isDescendantOf(y,x);};u.prototype.handleScroll=function(event){if(this.handleLayers())return;var x=Date.now();!this.behavior.getStream?i(0):void 0;var y=c('getElementPosition')(this.behavior.getStream()).y;if(y!=this.lastStreamY||x-this.latestStreamYChangedTimeStamp<2.5*this.scrollThrottlingInterval||this.didInteractWithStream(event.target)){this.latestStreamYChangedTimeStamp=x;this.userFocus=q;}else this.userFocus=r;this.lastStreamY=y;if(this.userFocus===q||this.needsToUpdateTimeTrackingData())this.updateTimeTrackingData(false,'scroll');};u.prototype.handleKeyboard=function(event){if(this.handleLayers())return;if(this.didInteractWithStream(event.target)){this.userFocus=q;this.focusedStory=this.getfocusedStory(event.target);}else if(c('CSS').hasClass(event.target,'shareInput')){this.userFocus=q;this.focusedStory=this.latestActiveStory;}else this.userFocus=r;if(this.userFocus===q||this.needsToUpdateTimeTrackingData())this.updateTimeTrackingData(false,'keyboard');};u.prototype.handleMouse=function(event){if(this.handleLayers())return;if(event.type!='click'&&event.clientX===this.lastMouseX&&event.clientY===this.lastMouseY)return;if(event.type==='click')this.invalidateVisibleStoriesCache();if(this.didInteractWithStream(event.target)){this.userFocus=q;this.focusedStory=this.getfocusedStory(event.target);}else this.userFocus=r;this.lastMouseX=event.clientX;this.lastMouseY=event.clientY;if(this.needsToUpdateTimeTrackingData())this.updateTimeTrackingData(false,event.type);};u.prototype.getStoriesInView=function(){var x=this.behavior.getAllStories(),y=[],z=false;for(var aa=0;aaba/2){aa=ba-1;ba=-1;ca=-ca;}for(var ea=aa;ea!=ba;ea+=ca){var fa=x[ea],ga=c('ViewportTrackingHelper').getHeightIfVisible(fa,Math.min(this.minSizeToBeVisible,this.minFractionToBeVisibleForTimetracking*c('DOMDimensions').getElementDimensions(fa).height));if(ga>0||fa===this.focusedStory){if(fa.getAttribute('data-insertion-position')===null)fa.setAttribute('data-insertion-position',(ea-this._headLoadStoryCount).toString());var ha=this.behavior.getStoryID(fa);if(ha){y[ha]={story:fa,height:ga,story_height:c('DOMDimensions').getElementDimensions(fa).height};z=true;if(this.vpvdAnalysis){y[ha].y=c('getElementPosition')(fa).y;y[ha].visible_position=ea;da=Math.min(da,ea);}}}else if(z){this._indexOfLastVisibleStoryOnPreviousPass=ea-ca;break;}}if(this.vpvdAnalysis){this.numVisibleStories=0;for(ha in y)if(y.hasOwnProperty(ha)){y[ha].visible_position-=da;this.numVisibleStories++;}}return y;};u.prototype.getTimetrackingDataToLog=function(x){var y={evt:j,vpvd_start_timestamp:x.evp_ts||null,vpvd_time_delta:Math.round(x.vpvd||0),story_height:c('DOMDimensions').getElementDimensions(x.story).height,viewport_height:this.cachedViewportHeight};return {ft:y};};u.prototype.recordTimeStoryWasInView=function(x){if(!this.isTimetrackingEnabled)return;if(!x.vpvd||!x.story)return;if(x.vpvd>0){var y=this.getTimetrackingDataToLog(x),z=c('collectDataAttributes')(x.story,['ft']);Object.assign(y.ft,z.ft);var aa=!!z.ft.ei&&y.ft.vpvd_time_delta>this.minTimeToReportImmediately;if(y.ei)delete y.ei;!x.story?i(0):void 0;this.sendDataToLog(x.story,y,aa);}};u.prototype.hasBeenVisible=function(x){return x in this.readStoryIDs;};u.prototype.sendDataToLog=function(x,y,z){if(this.useBanzai){var aa={};if(z)aa.delay=3000;var ba=this.getSessionID();if(ba)y.ft.session_id=ba;c('Banzai').post('feed_tracking',y,aa);}else c('clickRefAction')(l,x,null,'FORCE',y);};u.prototype.markStoryRead=function(x){var y=this.behavior.getStoryID(x);if(!y||this.hasBeenVisible(y))return;this.readStoryIDs[y]=true;this.annotatedStoryIDs[y]=true;var z=this._getDataToLogImpl(x),aa=c('collectDataAttributes')(x,['ft']);Object.assign(z.ft,aa.ft);delete z.ei;this.sendDataToLog(x,z,false);c('CSS').addClass(x,"_x72");if(this.vpvDebug)c('CSS').addClass(x,"_5m7s");};u.prototype.logAnnotatedVPV=function(x){var y=this.behavior.getStoryID(x);if(!y||y in this.annotatedStoryIDs)return;this.annotatedStoryIDs[y]=true;var z=this._getDataToLogImpl(x),aa=c('collectDataAttributes')(x,['ft']);Object.assign(z.ft,aa.ft);delete z.ei;z.ft.vpv_ft_only=1;this.sendDataToLog(x,z,false);};u.prototype._getDataToLogImpl=function(x){var y=this.behavior.getDataToLog(x);if(!y.ft)y.ft={};return y;};u.clearSingleton=function(){};var v={getAllStories:function x(){return [];},getStoryID:function x(y){return null;},getDataToLog:function x(y){return {};}},w=c('viewportTrackingBuilder')(function(x){return new u(v);});u.factory=w.factory.bind(w);u.singleton=w.singleton.bind(w);u.clearSingleton=w.clearSingleton.bind(w);u.getBehavior=function(){return v;};f.exports=u;}),null); __d('collectSubtreeData',[],(function a(b,c,d,e,f,g){if(c.__markCompiled)c.__markCompiled();function h(j,k,l,m,n){if(j.offsetWidth===0&&j.offsetHeight===0)return n;var o={};if(j.getAttribute)for(s=0;s0)n[u][r].push(m[r]);n[u][r].push('('+q[r]);}}}for(var s=0;s0&&w.charAt(0)=='('){n[u][v][n[u][v].length-1]=w.substr(1);}else n[u][v].push(')');}return n;}function i(j,k){var l={};for(var m=0;mm){k=l*m;}else if(n