!function(){var e=window.hasOwnProperty("LB")?window.LB.api_host:"",t=document.referrer,n=window.hasOwnProperty("LB")?window.LB.blog._id:"";e+="api/analytics/hit";var r=function(e,t,n){var r="",i=new Date;n&&(i.setTime(i.getTime()+24*n*60*60*1e3),r="; expires="+i.toUTCString()),document.cookie=e+"="+t+r+"; path=/"},i=function(e){for(var t=e+"=",n=document.cookie.split(";"),r=0;r<n.length;r++){for(var i=n[r];" "==i.charAt(0);)i=i.substring(1,i.length);if(0==i.indexOf(t))return i.substring(t.length,i.length)}return null},o=function(){var i=new XMLHttpRequest,o=JSON.stringify({context_url:t,blog_id:n});i.open("POST",e),i.setRequestHeader("Content-Type","application/json"),i.onload=function(){200==i.status&&r("hit",o,2)},i.send(o)};i("hit")||o()}(),function(e){"use strict";e.module("liveblog-embed",["ngResource","angular-cache"]).constant("config",window.LB).run(["ConsentManager",function(e){e.start()}])}(angular),function(e){"use strict";function t(t){return function(n){var r="";return e.forEach(n,function(e,n){"original"!==n&&(r+=", "+t(e.href)+" "+e.width+"w")}),r.substring(2)}}function n(t){return function(n){if(n&&n.thumbnail)return t(n.thumbnail.href);var r,i="",o=!1;return e.forEach(n,function(e){r=parseInt(e["with"],10)*parseInt(e.height,10),(r<o||o===!1)&&(i=t(e.href),o=r)}),i}}function r(e,t,n){return function(r){return r.descriptionHtml=n.trustAsHtml(r.description),r.picture_url&&r.picture&&(r.picture_srcset=t(r.picture.renditions),r.picture_url=e(r.picture_url)),r}}function i(t,n,r){return t(n.api_host+'api/client_blogs/:blogId?embedded={"picture":1}',{blogId:n.blog._id},{get:{method:"GET",transformResponse:function(t){return t=e.fromJson(t),r(t)}}})}function o(t,n,r,i){return t(n.api_host+"api/client_users/:userId",{userId:"@id"},{get:{method:"GET",transformResponse:function(t){if(t=e.fromJson(t),t&&t.picture_url){var n=i(t.avatar_renditions);t.picture_url=n?n:t.picture_url,t.picture_srcset=r(t.avatar_renditions)}return t}}})}function s(e,t){return e.original_creator=t._items?t._items[0]:t,!e.original_creator.byline&&e.byline&&(e.original_creator.byline=e.byline),!e.original_creator.sign_off&&e.sign_off&&(e.original_creator.sign_off=e.sign_off),e.original_creator}function a(t,n,r,i,o,a,c){function u(t){var n,a;if(r.get("usersCache"))n=r.get("usersCache"),a=r.get("refreshCache");else{var c=e.copy(f);c.onExpire=function(r,c){i.$apply(function(){o.get({userId:r}).$promise.then(function(i){var o=s(t,i),c=n.get(r);e.extend(c,o),n.put(r,c),a.put(r,{})})})},n=r.createCache("usersCache",{storageMode:"memory"}),a=r.createCache("refreshCache",c)}if(t.commenter)t.original_creator={display_name:t.commenter,sign_off:t.commenter,byline:t.commenter};else if(t.syndicated_creator)t.original_creator=t.syndicated_creator;else if(""!==t.original_creator&&"None"!==t.original_creator){var u=t.original_creator;if("string"!=typeof u)return t;n.get(u)?"function"==typeof n.get(u).then?n.get(u).then(function(e){n.put(u,s(t,e))}):s(t,n.get(u)):n.put(u,o.get({userId:t.original_creator}).$promise.then(function(e){return n.put(u,s(t,e)),a.put(u,{}),e}))}return t}return t(n.api_host+"api/client_blogs/:blogId/"+(window.LB.output?window.LB.output._id+"/":"")+"posts",{blogId:n.blog._id},{get:{transformResponse:function(t){return t=e.fromJson(t),t._items.forEach(function(t){t.mainItem=u(t.groups[1].refs[0].item),t.hasComments=_.reduce(t.groups[1].refs,function(e,t){return e||!_.isUndefined(t.item.commenter)},!1),t.fullDetails=t.hasComments,t.content_updated_date||(t.content_updated_date=t._updated),t.showUpdate=t.content_updated_date!==t.published_date&&!t.hasComments&&"comment"!==t.mainItem.item_type,e.isDefined(t.groups[1])&&(t.items=t.groups[1].refs.map(function(e){var n=e.item;return"image"==n.item_type&&n.meta&&n.meta.media&&(n.picture_url=c(n.meta.media.renditions.thumbnail.href),n.picture_srcset=a(n.meta.media.renditions)),t.fullDetails?(u(n),n.displayDate=n.meta&&n.meta._created||n._created):n.displayDate=t.published_date,n})),t=u(t),t.fullDetails?t.displayDate=t.mainItem.meta&&t.mainItem.meta._created||t.mainItem._created:t.displayDate=t.published_date}),t}}})}function c(e,t){return e(t.api_host+"api/client_comments/")}function u(e,t){return e(t.api_host+"api/client_items/")}function l(e,t){return e(t.api_host+'api/client_advertisement_outputs/:id?embedded={"collection":1}',{id:"@id"})}function d(t,n){return t(n.api_host+"api/client_advertisements/:advertisementId",{advertisementId:"@id"},{get:{method:"GET",transformResponse:function(t){t=e.fromJson(t),t.item_type=t.type,t.group_type="freetype";var n={_id:t._id,mainItem:t,items:[t]};return n}}})}var f={deleteOnExpire:"aggressive",recycleFreq:12e4,maxAge:24e4,storageMode:"memory"};t.$inject=["fixProtocol"],n.$inject=["fixProtocol"],r.$inject=["fixProtocol","srcSet","$sce"],i.$inject=["$resource","config","transformBlog"],o.$inject=["$resource","config","srcSet","thumbnailRendition"],a.$inject=["$resource","config","CacheFactory","$rootScope","users","srcSet","fixProtocol"],c.$inject=["$resource","config"],u.$inject=["$resource","config"],l.$inject=["$resource","config"],d.$inject=["$resource","config"],e.module("liveblog-embed").service("users",o).service("posts",a).service("blogs",i).service("comments",c).service("items",u).service("outputs",l).service("advertisements",d).factory("transformBlog",r).factory("srcSet",t).factory("thumbnailRendition",n)}(angular),function(e){"use strict";function t(e){return e.replace(/(<([^>]+)>)/gi,"")}function n(e,t,n,r){function i(i,o){this.send=function(i){var o=n.defer();return i.client_blog=r.blog._id,i.item_type="comment",t.save(i).$promise.then(function(t){if("ERR"===t._status)return void o.reject("Try again later!");var n={post_status:"comment",client_blog:r.blog._id,groups:[{id:"root",refs:[{idRef:"main"}],role:"grpRole:NEP"},{id:"main",refs:[{residRef:t._id}],role:"grpRole:Main"}]};e.save(n).$promise.then(function(e){return"ERR"===e._status?void o.reject("Try again later!"):void o.resolve(e)})},function(e){o.reject("Try again later!")}),o.promise}}return i}function r(n,r,i){var o=n,s=new i;e.extend(o,{modal:!0,notify:!1,form:!0,reset:function(){o.form||(o.commenter=void 0,o.content=void 0)},toggle:function(e){o.notify?(o.notify=!1,o.form=!1,o.modal=!1,o.reset()):(o.modal=!o.modal,o.form=!o.form,o.reset())},send:function(){return!o.commenter||o.commenter.length<3||o.commenter.length>30||!o.content||o.content.length<3||o.content.length>300?(o.commenter=void 0===o.commenter?"":o.commenter,o.content=void 0===o.content?"":o.content,!1):(o.notify="sended",o.form=!1,void s.send({commenter:t(o.commenter),text:t(o.content)}).then(function(){o.reset(),r(function(){o.notify&&(o.notify=!1,o.form=!0,o.comment=!1)},5e3)}))}})}n.$inject=["comments","items","$q","config"],r.$inject=["$scope","$timeout","CommentsManager"],e.module("liveblog-embed").factory("CommentsManager",n).directive("lbComments",["$timeout","asset",function(e,t){return{scope:{comment:"="},templateUrl:t.templateUrl("views/comments.html"),controller:r,link:function(e,t,n){e.comment=!1,e.$watch("comment",e.toggle)}}}])}(angular),function(e){"use strict";function t(t,n,r,i,o){function s(s,a,c){function u(){L.pagesLoaded=0,L.newUpdatesApplied=0,L.uncountedPosts=[],L.countedPosts=[]}function l(e){return{posts:e||[],addPost:function(e){this.posts.push(e)}}}function d(e,n){n=n||{},n.tags=n.tags||o.tags;var r=L.highlight?{filtered:{filter:{and:[{term:{sticky:c}},{term:{post_status:"open"}},{term:{lb_highlight:!0}},{not:{term:{deleted:!0}}}]}}}:{filtered:{filter:{and:[{term:{sticky:c}},{term:{post_status:"open"}},{not:{term:{deleted:!0}}}]}}},i={source:{query:r,sort:[O[L.sort]],post_filter:{}},page:e,max_results:n.max_results||L.maxResults};if(!LB.output||n.tags&&0!==n.tags.length)n.tags&&0!==n.tags.length&&(i.source.post_filter.terms={tags:n.tags});else{const s=LB.output.tags||[];s.length>0&&(i.source.post_filter.terms={tags:s})}return t.get(i).$promise.then(function(e){return L.meta=e._meta,e})}function f(e){return L.highlight=e,L.pages=[],u(),h()}function p(e){return L.pages=[],u(),h({tags:e})}function m(e){return L.sort=e,L.pages=[],u(),h()}function g(e){return e?void(L.sort=e):L.sort}function h(e){var t=n.when();return 0===L.pages.length&&(u(),t=L.retrieveUpdate().then(function(e){E(e._items)})),t.then(function(){var t=v();return L.pagesLoaded=L.pagesLoaded+1+t,P(L.pagesLoaded,e)})}function v(){var e,t;return e="oldest_first"===L.sort?L.newUpdatesApplied:L.newUpdatesApplied+L.uncountedPosts.length,L.countedPosts=L.countedPosts.concat(L.uncountedPosts),L.uncountedPosts=[],L.newUpdatesApplied=0,t=Math.floor(e/L.maxResults)}function w(r){var i=L.latestUpdatedDate?L.latestUpdatedDate.utc().format():void 0,o={page:1,source:{sort:[{_updated:{order:"desc"}}],query:{filtered:{filter:{and:[{range:{_updated:{gt:i}}}]}}},post_filter:{}}};if(LB.output){var s=LB.output.tags||[];s.length>0&&(o.source.post_filter.terms={tags:s})}return t.get(o).$promise.then(function(r){var s=r._meta;if(s.total<=s.max_results*s.page||!e.isDefined(i))return r;for(var a=[],c=s.page+1;c<=Math.floor(s.total/s.max_results)+1;c++)o.page=c,a.push(t.get(o).$promise);return n.all(a).then(function(t){return e.extend({},t[0],{_items:[].concat.apply([],t.map(function(e){return e._items})),_meta:e.extend(s,{max_results:s.max_results*t.length})})})}).then(function(e){return e})}function b(e,t){t=t===!0;var n=$(e._items,t);return 0!==L.pages.length&&y(e._items),n}function y(t){t.forEach(function(t){var n=T(t);e.isDefined(n)||t.deleted||"open"!==t.post_status||t.sticky!==c||L.uncountedPosts.push(t)})}function $(t,n){var r=[];return t.forEach(function(t){var i=T(t);e.isDefined(i)?t.deleted?(R(t),L.newUpdatesApplied--):"open"!==t.post_status||t.sticky!==c||L.highlight&&!t.lb_highlight?(R(t),L.newUpdatesApplied--):(L.pages[i[0]].posts[i[1]]=t,x(L.allPosts(),!0)):t.deleted||"open"!==t.post_status||t.sticky!==c||(n?(U(t),L.countedPosts.indexOf(t)===-1&&"oldest_first"!==L.sort&&L.newUpdatesApplied++):r.push(t))}),n&&(L.countedPosts=[]),E(t),r}function E(t){var n;t.forEach(function(t){n=moment(t._updated),e.isDefined(L.latestUpdatedDate)?L.latestUpdatedDate.diff(n)<0&&(L.latestUpdatedDate=n):L.latestUpdatedDate=n})}function C(){window.instgrm&&instgrm.Embeds.process(),window.twttr&&twttr.widgets.load(),window.FB&&window.FB.XFBML.parse()}function x(t,n){t=t||L.allPosts(),n&&(L.pages=[]);var r=Object.keys(O[L.sort])[0],o=O[L.sort][r].order;t=_.orderBy(t,r,o);var s;t.forEach(function(e,t){t%L.maxResults===0&&(s=new l),s.addPost(e),s.posts.length===L.maxResults&&(D(s),s=void 0)}),e.isDefined(s)&&D(s),i(C,1e3)}function P(t,n){t=t||L.pages.length;var r=[];return d(t,n).then(function(t){return _.forEach(t._items,function(t){var n=T(t);e.isDefined(n)||r.push(t)}),x(r,!1),t})}function T(e){for(var t,n=0;n<L.pages.length;n++){t=L.pages[n];for(var r=0;r<t.posts.length;r++)if(t.posts[r]._id===e._id)return[n,r]}}function U(t){var n=L.allPosts();e.isArray(t)||(t=[t]),t.forEach(function(t){e.isDefined(T(t))||n.push(t)}),x(n,!0),E(n)}function R(t){var n=T(t);if(e.isDefined(t)){var r=n[0],i=n[1];L.pages[r].posts.splice(i,1),x(L.allPosts(),!0)}}function D(e){L.pages.push(e)}var O={editorial:{order:{order:"desc",missing:"_last",unmapped_type:"long"}},newest_first:{published_date:{order:"desc",missing:"_last",unmapped_type:"long"}},oldest_first:{published_date:{order:"asc",missing:"_last",unmapped_type:"long"}}},L=this;L.newUpdatesApplied=0,L.pagesLoaded=0,L.uncountedPosts=[],L.countedPosts=[],e.extend(L,{pages:[],meta:{},sort:a||r.settings.postOrder,changeHighlight:f,changeOrder:m,filterPosts:p,order:g,maxResults:s||r.settings.postsPerPage,latestUpdatedDate:void 0,fetchNewPage:h,retrieveUpdate:w,processUpdates:b,applyUpdates:$,updateLatestDates:E,allPosts:function(){var e=L.pages.map(function(e){return e.posts.map(function(e){return e})}),t=[];return t.concat.apply(t,e)}})}return s}t.$inject=["posts","$q","config","$timeout","$rootScope"],e.module("liveblog-embed").factory("PagesManager",t)}(angular),function(e){"use strict";e.module("liveblog-embed").factory("Permalink",["$q","$timeout","config",function(t,n,r){return function(r,i){function o(e){return e.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1")}var s,a="liveblog._id",c=i;if(document.parent)try{s=document.location.href}catch(u){s=document.referrer}else s=document.location.href;var l,d=new RegExp(o(a)+"=([^&#]*)"),l=s.match(d);if(l){var f=decodeURIComponent(l[1]).split("->");this._id=f[0],r.order(f[1])}this.get=function(e){var t=!1,n=a+"="+e+"->"+r.order();if(s.indexOf(c)===-1)t=s+c+n;else if(s.indexOf(a+"=")!==-1){var i=new RegExp(o(a)+"=[^&#]*");t=s.replace(i,n)}else t=s+"&"+n;return t},this.loadPost=function(){var i=t.defer(),o=this,s=!1;return o._id?(e.forEach(r.allPosts(),function(e){e._id===o._id&&(s=!0)}),s?n(function(){i.resolve(o._id)}):r.fetchNewPage().then(function(){o.loadPost()})):i.reject(),i.promise}}}])}(angular);var CONSENT_KEY="__lb_consent_key__",CONSENT_LIFE_DAYS=365;!function(e){"use strict";e.module("liveblog-embed").factory("fixProtocol",["config",function(e){return function(t){var n=RegExp(/http(s)?:\/\//gi);return e.api_host.replace(n,"//"),t.replace(n,"//"),t.replace(n,"//")}}]).provider("asset",["$injector",function(e){this.templateUrl=function(t){var n=e.get("config"),r=e.has("assets_simplified_path")&&e.get("assets_simplified_path"),i=t;return n.debug&&n.templates&&n.templates[t]?n.templates[t]:!n.debug&&r?i:(/^(https?:\/\/|\/\/)/.test(t)||(i=n.assets_root+"/"+i),i=i.replace(/[^\/]+\/+\.\.\//g,"/").replace(/\.\//g,"").replace(/(\w)\/\/(\w)/g,"$1/$2"))},this.imageUrl=this.templateUrl,this.$get=function(){return this}}]).service("ConsentManager",["$rootScope","Storage",function(e,t){this.start=function(){window.addEventListener("message",this.handleEnhancerMessage,!1),window.parent.postMessage({type:"init_consent"},"*")},this.handleEnhancerMessage=function(n){var r=n.data.type;switch(r&&console.log("Received msg in iframe",n.data),r){case"sync-consent-given":t.write(CONSENT_KEY,n.data.data,CONSENT_LIFE_DAYS),e.$apply()}},this.isConsentGiven=function(){return"Y"===t.read(CONSENT_KEY)},this.acceptConsent=function(){t.write(CONSENT_KEY,"Y",CONSENT_LIFE_DAYS),window.parent.postMessage({type:"accept_consent"},"*")}}]).service("Storage",function(){this.read=function(e){var t=localStorage.getItem(e);if(!t)return null;var n=JSON.parse(t),r=new Date;return r.getTime()>n.expiry?(localStorage.removeItem(e),null):n.value},this.write=function(e,t,n){var r=new Date;r.setTime(r.getTime()+24*n*60*60*1e3);var i={value:t,expiry:r.getTime()};localStorage.setItem(e,JSON.stringify(i))}})}(angular);var CONSENT_ACCEPT_SELECTOR=".lb_consent--accept",domainRequiresConsent=function(e,t){var n=LB.settings.gdprConsentDomains,r=!1;if(n.length>0)if(n=n.split(","),n=n.map(function(e){return e.trim().toLowerCase()}),e){var i=new URL(e).hostname;i=i.replace("www.",""),r=n.indexOf(i)!==-1}else(t.indexOf("iframe")>-1||t.indexOf("script")>-1)&&n.forEach(function(e){var n=e.replace("www.","");t.indexOf(n)>-1&&(r=!0)});return r};!function(e){"use strict";e.module("liveblog-embed").directive("lbBindHtml",[function(){return{restrict:"A",link:function(e,t,n){n.$observe("htmlContent",function(){n.htmlLocation?t.find("["+n.htmlLocation+"]").html(n.htmlContent):t.html(n.htmlContent)})}}}]).directive("lbFluidIframe",["$timeout","$window",function(t,n){return{restrict:"EA",link:function(r,i,o){function s(){var e=i.innerWidth();e<a.attr("width")&&a.width(e).height(e*a.data("aspectRatio"))}var a;t(function(){a=i.find("iframe"),a.data("aspectRatio",a.attr("height")/a.attr("width")),s()},1e3),e.element(n).bind("resize",_.debounce(s,1e3))}}}]).directive("lbGdprEmbedConsent",["config","asset","$timeout","ConsentManager",function(t,n,r,i){return{template:'<ng-include src="getTemplateUrl()" />',scope:{item:"=",timeline:"="},restrict:"E",link:function(t,n,o){r(function(){var t=e.element(n).find(CONSENT_ACCEPT_SELECTOR);t.on("click",function(e){e.preventDefault(),i.acceptConsent()})},50)},controller:["$scope",function(e){e.getTemplateUrl=function(){var r,o=e.item;if(t.settings.enableGdprConsent){var s=o.meta.provider_url;if("YoutubeUpload"===o.meta.provider_name&&(s="https://www.youtube.com"),!i.isConsentGiven()&&domainRequiresConsent(s,o.meta.html))return n.templateUrl("views/embeds/consent-placeholder.html")}switch(o.meta.provider_name){case"Twitter":case"Facebook":case"Instagram":r="views/embeds/"+o.meta.provider_name.toLowerCase()+".html";break;default:r="views/embeds/generic.html"}return n.templateUrl(r)}}]}}]).directive("lbTwitterCard",[function(){return{restrict:"E",link:function(e,t,n){t.html(n.lbTwitterContent)}}}]).directive("lbGenericEmbed",["$timeout","$window","asset",function(e,t,n){return{scope:{item:"="},templateUrl:n.templateUrl("views/generic-embed.html")}}]).directive("lbDropdown",["$rootScope","asset",function(e,t){return{restrict:"E",templateUrl:t.templateUrl("views/dropdown.html"),scope:{placeholder:"@",list:"=",selected:"&",order:"&",tags:"&",type:"@"},link:function(t){t.listVisible=!1,t.isPlaceholder=!0,t.selectedTags=[],t.select=function(e){t.isPlaceholder=!1,t.order({order:e.order}),t.listVisible=!1},t.check=function(n){const r=t.selectedTags.indexOf(n.name);r===-1?t.selectedTags.push(n.name):t.selectedTags.splice(r,1),t.tags({tags:t.selectedTags}),e.tags=t.selectedTags,t.listVisible=!0},t.isSelected=function(e){return e.order===t.selected()},t.isChecked=function(e){return t.selectedTags.indexOf(e.name)!==-1},t.show=function(){t.listVisible=!0},e.$on("documentClicked",function(e,n){(0==$(n[0]).parents(".dropdown-container").length||$(n[0]).parents(".dropdown-display.clicked").length>0)&&t.$apply(function(){t.listVisible=!1})}),t.$watch("selected()",function(e){_.each(t.list,function(e){e.order===t.selected()&&(t.display=e.name,t.isPlaceholder=!1)})})}}}])}(angular),function(e){"use strict";e.module("liveblog-embed").filter("varname",["config",function(e){return function(e){return e&&e.toLowerCase().replace(" ","_")}}]).filter("prettifyIsoDate",["config",function(e){return function(t){return moment(t).format(e.settings.datetimeFormat)}}]).filter("outboundAnchors",function(){return function(e){return e?e.replace(/<a([^>]*)>/g,function(e,t){return t.indexOf("target")===-1?"<a"+t+' target="_blank">':e}):""}}).filter("convertLinksWithRelativeProtocol",["fixProtocol",function(e){return e}]).filter("fixEmbed",["config",function(e){return function(t){return e.settings.livestream&&e.settings.livestreamAutoplay&&(t=t.replace(/src\w*=\w*("|')?([^\"\']+)("|')/,function(e,t,n){var r="?";return n.indexOf("?")!==-1&&(r="&"),'src="'+n+r+'rel=0&autoplay=1"'})),t.indexOf("youtube")!==-1&&(t='<div class="responsive-video">'+t+"</div>"),t.replace(/<blockquote class="instagram-media"[^>]*/g,function(e){return e.replace(/ max-width:[^;]*;/,"").replace(/ width:[^;]*;/," width: 96%;")})}}]).filter("fixMarkup",function(){var e=[/<\/?span>/g,/<(\/?)div([^>]+)>/g,/<([^>]+)><br><\/([^>]+)>/g,/<([^>]+)><\/([^>]+)>/g,/(<p>)+/,/&nbsp;/g],t=["","<$1p$2>",function(e,t,n){return"<"+t+"></"+n+">"},function(e,t,n){return t===n?"":e},"<p>"," "];return function(n){return n?(e.forEach(function(e,r){n=n.replace(e,t[r])}),n):""}})}(angular);