this.BX=this.BX||{};(function(e,t,n,i){"use strict";var a=function(){function e(){babelHelpers.classCallCheck(this,e);this.panelInitialized=false;this.postsInitialized=false;this.handlePostClick=this.handlePostClick.bind(this);this.init()}babelHelpers.createClass(e,[{key:"resetFlags",value:function e(){this.panelInitialized=false;this.postsInitialized=false}},{key:"init",value:function e(){var t=this;this.initPanel();this.initPosts();this.initEvents();n.EventEmitter.subscribe("onFrameDataProcessed",function(){t.initPanel();t.initPosts()})}},{key:"initPanel",value:function e(){if(this.panelInitialized){return}var a=this.getPanelNode();if(!a){return}this.panelInitialized=true;t.Event.bind(a,"click",function(e){var a=e.target.classList.contains("feed-inform-ilike")||e.target.closest(".feed-inform-ilike")!==null;var s=e.target.classList.contains("feed-inform-follow")||e.target.closest(".feed-inform-follow")!==null;var o=e.target.classList.contains("feed-post-more-link")||e.target.closest(".feed-post-more-link")!==null||e.target.classList.contains("feed-post-right-top-menu");var r=e.target.classList.contains("feed-inform-contentview")||e.target.closest(".feed-inform-contentview")!==null;var l=e.target.classList.contains("feed-post-pin")||e.target.closest(".feed-post-pin")!==null;var d=e.target.classList.contains("feed-post-pinned-link-collapse");var c=e.target.classList.contains("feed-inform-comments-pinned")||e.target.closest(".feed-inform-comments-pinned")!==null;var u=null;if(e.target.classList.contains("feed-post-block")){u=e.target}else{u=e.target.closest(".feed-post-block")}if(!u){return}if(u.classList.contains("feed-post-block-pinned")){if(!a&&!s&&!o&&!r&&!l){u.classList.remove("feed-post-block-pinned");var f=u.getAttribute("data-menu-id");if(f){i.MenuManager.destroy(f)}var v=new n.BaseEvent({compatData:[{rootNode:u}],data:{rootNode:u}});n.EventEmitter.emit("BX.Livefeed:recalculateComments",v)}if(c){var p=u.querySelector(".feed-comments-block a[name=comments]");if(p){var m=t.Dom.getPosition(p);window.scrollTo(0,m.top-200)}}e.stopPropagation();e.preventDefault()}else if(d){u.classList.add("feed-post-block-pinned");e.stopPropagation();e.preventDefault()}})}},{key:"initPosts",value:function e(){var n=this;if(this.postsInitialized){return}var i=document.querySelectorAll("[data-livefeed-post-pinned]");if(i.length>0){this.postsInitialized=true}Array.from(i).forEach(function(e){t.Event.unbind(e,"click",n.handlePostClick);t.Event.bind(e,"click",n.handlePostClick)})}},{key:"handlePostClick",value:function e(t){if(!t.target.classList.contains("feed-post-pin")){return}var n=t.target.closest("[data-livefeed-id]");if(!n){return}var i=n.getAttribute("data-livefeed-post-pinned")==="Y"?"N":"Y";var a=parseInt(n.getAttribute("data-livefeed-id"));if(a<=0){return}this.changePinned({logId:a,newState:i,event:t})}},{key:"initEvents",value:function e(){var i=this;n.EventEmitter.subscribe("OnUCCommentWasRead",function(e){var n=e.getData(),a=babelHelpers.slicedToArray(n,3),s=a[0],o=a[1],r=a[2];var l=i.getCommentsData(s),d=l.oldValue,c=l.newValue;if(!!r.new){i.setCommentsData(s,{newValue:t.Type.isInteger(c)?c-1:0,oldValue:t.Type.isInteger(d)?d+1:1})}});n.EventEmitter.subscribe("OnUCCommentWasPulled",function(e){var n=e.getData(),a=babelHelpers.slicedToArray(n,3),s=a[0],o=a[1],r=a[2];var l=babelHelpers.slicedToArray(s,2),d=l[0],c=l[1];var u=i.getCommentsData(d),f=u.newValue,v=u.oldValue,p=u.follow;if(parseInt(r.AUTHOR.ID)!==parseInt(BX.message("USER_ID"))&&p){i.setCommentsData(d,{newValue:t.Type.isInteger(f)?f+1:1})}else{i.setCommentsData(d,{oldValue:t.Type.isInteger(v)?v+1:1})}});n.EventEmitter.subscribe("OnUCommentWasDeleted",function(e){var n=e.getData(),a=babelHelpers.slicedToArray(n,3),s=a[0],o=a[1],r=a[2];var l=i.getCommentsData(s),d=l.oldValue;i.setCommentsData(s,{oldValue:t.Type.isInteger(d)?d-1:0})})}},{key:"changePinned",value:function e(n){var i=this;var a=n.logId?parseInt(n.logId):0;var s=n.node?n.node:null;var o=n.event?n.event:null;var r=n.newState?n.newState:null;if(!a||!r){return}this.setPostState({node:s?s:o.target,state:r});t.ajax.runAction("socialnetwork.api.livefeed.logentry."+(r==="Y"?"pin":"unpin"),{data:{params:{logId:a}},analyticsLabel:{b24statAction:r==="Y"?"pinLivefeedEntry":"unpinLivefeedEntry"}}).then(function(e){if(!e.data.success){i.setPostState({node:s?s:o.target,state:r==="Y"?"N":"Y"})}else{i.movePost({node:s?s:o.target,state:r})}},function(e){i.setPostState({node:s?s:o.target,state:r==="Y"?"N":"Y"})})}},{key:"setPostState",value:function e(t){var n=t.state?t.state:null;var i=t.node?t.node:null;if(!i||!["Y","N"].includes(n)){return}var a=i.closest("[data-livefeed-post-pinned]");if(!a){return}a.setAttribute("data-livefeed-post-pinned",n);a.classList.remove("feed-post-block-pin-active");a.classList.remove("feed-post-block-pin-inactive");if(n==="Y"){a.classList.add("feed-post-block-pin-active",n)}else{a.classList.add("feed-post-block-pin-inactive",n)}}},{key:"getPanelNode",value:function e(){return document.querySelector("[data-livefeed-pinned-panel]")}},{key:"getPinnedData",value:function e(n){var i=n.logId?parseInt(n.logId):0;if(i<=0){return Promise.reject()}return new Promise(function(e,n){t.ajax.runAction("socialnetwork.api.livefeed.logentry.getPinData",{data:{params:{logId:i}}}).then(function(t){e(t.data)},function(e){n()})})}},{key:"movePost",value:function e(n){var i=n.state?n.state:null;var a=n.node?n.node:null;if(!a||!["Y","N"].includes(i)){return}var s=a.closest("[data-livefeed-post-pinned]");if(!s){return}var o=parseInt(s.getAttribute("data-livefeed-id"));if(!o){return}var r=this.getPanelNode();if(!r){return}var l=s.parentNode.classList.contains("feed-item-wrap")?s.parentNode:s;if(i==="Y"){this.getPinnedData({logId:o}).then(function(e){var n=s.querySelector(".feed-post-pinned-title");var i=s.querySelector(".feed-post-pinned-desc");var a=s.querySelector(".feed-post-pin");if(n){n.innerHTML=e.TITLE}if(i){i.innerHTML=e.DESCRIPTION}if(a){a.title=t.Loc.getMessage("SONET_EXT_LIVEFEED_PIN_TITLE_Y")}s.classList.add("feed-post-block-pinned");r.insertBefore(l,r.firstChild)})}else{s.classList.remove("feed-post-block-pinned");r.parentNode.insertBefore(l,r.nextSibling)}}},{key:"getCommentsNodes",value:function e(n){var i={follow:true,newNode:null,oldNode:null};if(!t.Type.isStringFilled(n)){return i}var a=document.querySelector('.feed-comments-block[data-bx-comments-entity-xml-id="'.concat(n,'"]'));if(!a){return i}var s=a.closest(".feed-post-block-pin-active");if(!s){return i}var o=s.querySelector(".feed-inform-comments-pinned-new");var r=s.querySelector(".feed-inform-comments-pinned-old");if(!o||!r){return i}i.newNode=o;i.oldNode=r;i.follow=a.getAttribute("data-bx-follow")!=="N";return i}},{key:"getCommentsData",value:function e(n){var i={newValue:null,oldValue:null};if(!t.Type.isStringFilled(n)){return i}var a=this.getCommentsNodes(n),s=a.newNode,o=a.oldNode,r=a.follow;i.follow=r;if(!t.Type.isDomNode(s)||!t.Type.isDomNode(o)){return i}var l=0;var d=0;var c=s.innerHTML.match(/\+(\d+)/);if(c){l=parseInt(c[1])}c=o.innerHTML.match(/(\d+)/);if(c){d=parseInt(c[1])}i.oldValue=d;i.newValue=l;return i}},{key:"setCommentsData",value:function e(n,i){if(!t.Type.isStringFilled(n)){return}var a=this.getCommentsNodes(n),s=a.newNode,o=a.oldNode;if(!t.Type.isDomNode(s)||!t.Type.isDomNode(o)){return}if(t.Type.isInteger(i.newValue)){s.innerHTML="+".concat(i.newValue);if(i.newValue>0&&!s.classList.contains("feed-inform-comments-pinned-new-active")){s.classList.add("feed-inform-comments-pinned-new-active")}else if(i.newValue<=0&&s.classList.contains("feed-inform-comments-pinned-new-active")){s.classList.remove("feed-inform-comments-pinned-new-active")}}if(t.Type.isInteger(i.oldValue)){o.innerHTML=i.oldValue}}}]);return e}();var s=function(){function e(){babelHelpers.classCallCheck(this,e);this.init();this.entryData={}}babelHelpers.createClass(e,[{key:"init",value:function e(){}},{key:"changeFavorites",value:function e(n){var i=this;var a=n.logId?parseInt(n.logId):0;var s=n.event?n.event:null;var o=n.node?n.node:null;var r=n.newState?n.newState:null;if(t.Type.isStringFilled(o)){o=document.getElementById(o)}if(!a){return}var l=null;if(s){l=s.target;if(!l.classList.contains("menu-popup-item-text")){l=l.querySelector(".menu-popup-item-text")}}var d=null;if(t.Type.isDomNode(o)){d=o.classList.contains("feed-post-important-switch")?o:o.querySelector(".feed-post-important-switch")}if(typeof this.entryData[a]=="undefined"){this.entryData[a]={}}if(typeof this.entryData[a].favorites!="undefined"){r=this.entryData[a].favorites?"N":"Y";this.entryData[a].favorites=!this.entryData[a].favorites}else if(d){r=d.classList.contains("feed-post-important-switch-active")?"N":"Y";this.entryData[a].favorites=r=="Y"}if(!r){return}this.adjustFavoritesControlItem(d,r);this.adjustFavoritesMenuItem(l,r);t.ajax.runAction("socialnetwork.api.livefeed.changeFavorites",{data:{logId:a,value:r},analyticsLabel:{b24statAction:r=="Y"?"addFavorites":"removeFavorites"}}).then(function(e){if(t.Type.isStringFilled(e.data.newValue)&&["Y","N"].includes(e.data.newValue)){i.entryData[a].favorites=e.data.newValue=="Y"}i.adjustFavoritesControlItem(d,e.data.newValue);i.adjustFavoritesMenuItem(l,e.data.newValue)},function(e){i.entryData[a].favorites=!i.entryData[a].favorites})}},{key:"adjustFavoritesMenuItem",value:function e(n,i){if(!t.Type.isDomNode(n)||!["Y","N"].includes(i)){return}n.innerHTML=this.getMenuTitle(i==="Y")}},{key:"adjustFavoritesControlItem",value:function e(n,i){if(!t.Type.isDomNode(n)||!["Y","N"].includes(i)){return}n.title=this.getMenuTitle(i==="Y");if(i=="Y"){n.classList.add("feed-post-important-switch-active")}else{n.classList.remove("feed-post-important-switch-active")}}},{key:"getMenuTitle",value:function e(n){return t.Loc.getMessage("SONET_EXT_LIVEFEED_MENU_TITLE_FAVORITES_".concat(n?"Y":"N"))}}]);return e}();e.FeedInstance=null;e.PinnedPanelInstance=null;t.Event.ready(function(){e.FeedInstance=new s;e.PinnedPanelInstance=new a})})(this.BX.Livefeed=this.BX.Livefeed||{},BX,BX.Event,BX.Main);
//# sourceMappingURL=livefeed.bundle.map.js