DISQUS.addBlocks("theme")(function(c){c.blocks.relatedThreadHref=function(i,b){var a=new c.Builder,e=DISQUS.extend({},i,b);with(e)return a.put("    "),variant=="midway-6x2-swapless-redirect"?(a.put('        href="'),a.put((a.esc||function(a){return a})(thread.redirectUrl))):(a.put('        href="'),a.put((a.esc||function(a){return a})(thread.link)),a.put('"        data-redirect="'),a.put((a.esc||function(a){return a})(thread.redirectUrl))),a.put('"    '),a.compile()};c.blocks.discoveryBoxHelp=function(i,
b){var a=new c.Builder,e=DISQUS.extend({},i,b);with(e)return a.put('    <div class="alert">        <a class="close" data-action="discovery-help-close"/>\u00d7</a>        '),a.put(c.interpolate(trans("Disqus helps you find new and interesting content, discussions and products. Some sponsors and ecommerce sites may pay us for these recommendations and links. %(learnMore)s or %(feedback)s."),{learnMore:c.renderBlock("learnMore"),feedback:c.renderBlock("feedback")})),a.put("    </div>"),a.compile()};
c.blocks.feedback=function(i,b){var a=new c.Builder,e=DISQUS.extend({},i,b);with(e)return a.put('<a href="https://www.surveymonkey.com/s/GHK872T" target="_blank">    '),a.put(trans("give us feedback")),a.put("</a>"),a.compile()};c.blocks.relatedThread=function(i,b){var a=new c.Builder,e=DISQUS.extend({},i,b);with(e){a.put('    <li class="discovery-unit">        <div class="main publisher-anchor-color">            <h3 title="');a.put((a.esc||function(a){return a})(thread.title));a.put('">                <a class="title"                ');
(function(){var d={};c.extend(d,b);c.extend(d,{variant:variant});a.put(c.renderBlock("relatedThreadHref",d))})();a.put("                ");external&&a.put('target="_blank"');a.put(">");a.put(thread.title);a.put("</a>            </h3>            ");external&&thread.forum&&thread.forum.name&&(a.put('            <span class="extra eo">'),a.put((a.esc||function(a){return a})(thread.forum.name)),a.put("</span>            "));a.put('            <span class="extra">            ');thread.posts?(a.put("                "),
thread.posts===1?(a.put("                    "),a.put(trans("1 comment"))):(a.put("                    "),a.put(c.interpolate(trans("%(numPosts)s comments"),{numPosts:thread.posts}))),a.put("                ")):(a.put("                "),a.put((a.esc||function(a){return a})(thread.brand)));a.put("            ");a.put("            </span>        </div>        ");if(variant=="midway"||variant=="midway-top")a.put('            <a class="content-preview" href="'),a.put((a.esc||function(a){return a})(thread.link)),
a.put('#disqus_thread"            data-redirect="'),a.put((a.esc||function(a){return a})(thread.redirectUrl)),a.put('"            data-role="discovery-top-comment"            '),external&&a.put('target="_blank"'),a.put(">                "),thread.brand||(a.put('                <img src="'),a.put((a.esc||function(a){return a})(urls.avatar.generic)),a.put('" alt="'),a.put(trans("Default user")),a.put('" data-role="discovery-avatar">                ')),a.put("                <p>"),thread.brand||(a.put('<span class="user" data-role="discovery-top-comment-author">'),
a.put("</span> &#8212;")),a.put('                <span data-role="discovery-top-comment-snippet">'),a.put("</span></p>            </a>        ");a.put("    </li>");return a.compile()}};c.blocks.learnMore=function(i,b){var a=new c.Builder,e=DISQUS.extend({},i,b);with(e)return a.put('<a href="http://help.disqus.com/customer/portal/articles/666278-introducing-promoted-discovery-and-f-a-q-"   target="_blank">'),a.put(trans("Learn more")),a.put("</a>"),a.compile()};c.blocks.relatedThreads=function(i,b){var a=
new c.Builder,e=DISQUS.extend({},i,b);with(e)return a.put('<div id="discovery-main" class="extra-links">    <div id="discovery-note" style="display:none;">        '),function(){var d={};c.extend(d,b);c.extend(d,{});a.put(c.renderBlock("discoveryBoxHelp",d))}(),a.put('    </div>    <div id="discovery-content-wrap">        <section id="discovery-external">            <header>                <div id="discovery-options">                    <span class="publisher-anchor-color"><a href="#" id="discovery-help" data-action="discovery-help">'),
a.put(trans("What's this?")),a.put("</a></span>                    "),a.put("                </div>                <h2>"),a.put(trans("Recommended For You")),a.put("</h2>            </header>            <ul>                "),a.put('            </ul>        </section>        <section id="discovery-internal">            <header>                <h2>'),a.put(c.interpolate(trans("Also on %(forumName)s"),{forumName:c.renderBlock("forumName",forum)})),a.put("</h2>            </header>            <ul>                "),
a.put("            </ul>        </section>    </div></div>"),a.compile()};c.blocks.forumName=function(i,b){var a=new c.Builder,e=DISQUS.extend({},i,b);with(e)return a.put("<strong>"),a.put((a.esc||function(a){return a})(name)),a.put("</strong>"),a.compile()}});
(function(c){var i=c.document,b=c.DISQUS;b.registerActions=function(){b.define("discovery.views",function(){var a=!1;return{load:function(e){var d=b.discovery.views;if(a)return d;d.RelatedThreadView=Backbone.View.extend({events:{"click [data-redirect]":"swapLink"},dtplBlock:"relatedThread",initialize:function(a){this.snippetLimit=a.snippetLimit;this.model.on("change:topComment",this.renderTopComment,this)},swapLink:function(a){a=a.target||a.srcElement;a.tagName.toUpperCase()=="A"&&a.getAttribute("data-redirect")||
(a=$(a).closest("a[data-redirect]")[0]);var b=a;b.setAttribute("data-href",b.getAttribute("href"));b.setAttribute("href",b.getAttribute("data-redirect"));_.delay(function(){b.setAttribute("href",b.getAttribute("data-href"))},100)},renderAvatar:function(a){var b=this.$el.find("[data-role=discovery-avatar]");b.attr("src",a.avatar.cache);b.attr("alt",this.authorName(a));return this},authorName:function(a){return a.name||a.username},renderCommentSnippet:function(a){var b=this.$el.find("[data-role=discovery-top-comment]");
if(a.author){var f=this.authorName(a.author);b.find("[data-role=discovery-top-comment-author]").text(f)}a=_.strip(a.message);a=_.truncate(a,this.snippetLimit,"\u2026");f=b.find("[data-role=discovery-top-comment-snippet]");f.text(a);b.css({display:"block"});e.lineTruncate(f,{lines:3,ellipsis:!0});return this},renderTopComment:function(a,b){if(b)return this.renderAvatar(b.author),this.renderCommentSnippet(b),this.trigger("resize"),this},render:function(a){var a=a||{},d=a.parent,f=this.model.toJSON();
if(!_.isObject(f.forum)&&_.isString(f.forum))f.forum={name:f.forum};this.setElement(b.renderBlock(this.dtplBlock,{thread:f,external:!!a.external,variant:this.model.collection.variant.name}));d.append(this.$el);e.lineTruncate(this.$el.find("h3 a.title"),{lines:2,ellipsis:!0});this.$el.find("h3, .extra").css({display:"inline"});return this}});d.RelatedThreadCollectionView=Backbone.View.extend({initialize:function(a){this.snippetLimit=a.snippetLimit},resize:_.debounce(function(){this.trigger("resize")},
500),render:function(a){var a=a||{},b=a.limit,f=_.isNumber(b),p=a.start,g=_.isNumber(p);this.collection.each(function(a,h){f&&h>=b||g&&h<p||((new d.RelatedThreadView({model:a,snippetLimit:this.snippetLimit})).on("resize",this.resize,this).render({parent:this.$el.find("ul"),external:!!this.collection.external}),a.trigger("change:topComment",a.get("topComment")))},this);return this}});d.AdvertisementCollectionView=Backbone.View.extend({initialize:function(a){this.snippetLimit=a.snippetLimit},render:function(a){var a=
a||{},b=a.limit,f=_.isNumber(b);this.collection.each(function(a,g){if(!(f&&g>=b)){var h=new d.RelatedThreadView({model:a,snippetLimit:this.snippetLimit});h.render({parent:this.$el.find("ul"),external:!0});h.renderCommentSnippet({message:a.get("text")})}},this);return this}});d.MainView=Backbone.View.extend({dtplBlock:"relatedThreads",events:{"click [data-action=discovery-close]":"close","click [data-action=discovery-help]":"showHelp","click [data-action=discovery-help-close]":"closeHelp"},close:function(a){a.preventDefault();
this.remove();this.trigger("resize",0)},showHelp:function(a){a.preventDefault();$(a.currentTarget).hide();this.$el.find("#discovery-note").show();this.trigger("resize")},closeHelp:function(a){a&&a.preventDefault();this.$el.find("#discovery-note").hide();this.trigger("resize")},renderHelp:function(a){this.closeHelp();this.$el.find("[data-action=discovery-help]").show();this.$el.find("#discovery-note").html(b.renderBlock("discoveryBoxHelp",{session:a.toJSON()}))},render:function(){this.$el.css({position:"static",
visibility:"visible"});return this}});a=!0;return d}}});b.define("discovery.collections",function(){var a=!1;return{load:function(e,d){var h=b.discovery.collections;if(a)return h;var c=Backbone.Collection.extend({initialize:function(a,b){this.mainThread=b.thread;this.limit=b.limit;this.variant=b.variant||{};this.external=b.external},fetch:function(a){var b={};b.data={thread:this.mainThread.get("id")};b.parse=!1;_.extend(b,a);Backbone.Collection.prototype.fetch.call(this,b)},addBandit:function(a){if((a=
a.response)&&a.bandit)this.bandit=a.bandit},getBanditJSON:_.memoize(function(){return b.JSON.stringify(this.bandit)}),makeRedirect:function(a,d,g){var c=a?"http://redirect.disqus.com/url":d.link+"#redirect",a={url:a,imp:b.juggler.impId,zone:g.external?"external_discovery":"internal_discovery",forum:this.mainThread.get("forum").id,source_thread_id:this.mainThread.id};this.variant.isExperiment&&_.extend(a,{variant:this.variant.name});d.advertisement_id?_(a).extend({zone:"promoted_discovery",advertisement_id:d.advertisement_id,
body_id:d.body_id}):_(a).extend({thread:d.id});this.bandit&&_.extend(a,{bandit:this.getBanditJSON()});return b.serialize(c,a)}});h.RelatedThreadCollection=c.extend({model:e.RelatedThread,url:b.api.getURL("discovery/listRelated.json"),parse:function(a){this.addBandit(a);var b=[],g=a.response||[];if(g.results)g=g.results;var c=d.log,h=this.mainThread.get("forum");c(this.url,"results (",g.length,"):",g,"ids:",_.pluck(g,"id"));for(var e=0,i=g.length;e<i&&b.length<this.limit;e++)if(a=g[e].thread||g[e],
a.id==this.mainThread.id)c("Thread",a.id,"is same as source thread.");else if(a.posts===0)c("Thread",a.id,"does not have any comments.");else if(a.title.indexOf("http://")===0)c("Thread",a.id,"has a title that starts with http.");else{a.score={score:g[e].score,k:g[e].k};if(a.signedUrl)a.redirectUrl=this.makeRedirect(a.signedUrl,a,{external:a.forum.id!=h.id});b.push(a)}c("Total results after pruning:",b.length);return b},getTopComment:function(a){var c=this;b.api.call("discovery/listTopPost.json",
{method:"GET",data:{thread:a},success:function(b){b=b.response;d.log("discovery/listTopPost.json","with thread ids",a,"posts (",b.length,"):",b,"post.thread:",_.pluck(b,"thread"));_.each(b,function(a){c.get(a.thread).set("topComment",a)})}});return c}});h.AdvertisementCollection=c.extend({model:e.Advertisement,url:b.api.getURL("discovery/listPromoted.json"),external:!0,parse:function(a){this.addBandit(a);var b=[],c=a.response||[];if(c.results)c=c.results;d.log(this.url,"results (",c.length,"):",c,
"ad_ids:",_.pluck(c,"advertisement_id"));for(var e=0,h=c.length;e<h&&b.length<this.limit;e++)a=c[e],a.redirectUrl=this.makeRedirect(a.signedUrl,a,{external:!0}),b.push(a);return b}});a=!0;return h}}});b.define("discovery.models",function(){var a=!1;return{load:function(){var c=b.discovery.models;if(a)return c;var d=c.Thread=Backbone.Model.extend({defaults:{author:null,category:null,createdAt:null,forum:null,identifiers:[],ipAddress:null,isClosed:!1,isDeleted:!1,link:null,message:null,slug:null,title:null,
userSubscription:!1,posts:0,reactions:0,likes:0,dislikes:0,userScore:0},url:b.api.getURL("threads/details"),parse:function(a){return a.response}});c.RelatedThread=d.extend({defaults:_.defaults({redirectUrl:null,topComment:null},d.prototype.defaults)});c.Advertisement=Backbone.Model.extend({idAttribute:"body_id",defaults:{brand:"",headline:"",text:"",url:"",advertisement_id:null,body_id:null,redirectUrl:null},get:function(a){if(a==="title")return this.get("headline");return Backbone.Model.prototype.get.call(this,
a)},toJSON:function(){var a=this.attributes;return{title:a.headline,brand:a.brand,redirectUrl:a.redirectUrl,link:a.url}}});a=!0;return c}}});b.define("discovery.helpers",function(a,c){var d=null,h=!1,l=!1,f=function(){};a.console&&(f=function(){l&&(a.console.log.apply?a.console.log.apply(a.console,arguments):a.console.log(_.toArray(arguments).join(" ")))});var p=function(a){if(a===c)return l;l=!!a},g=function(a){if(a===c)return h;h=!!a},t=function(a,b,c){if(d)if(d.length)d.enabled(a)&&b();else{var e=
function(){d.enabled(a)&&b();c&&d.off("reset",e)};return void d.on("reset",e)}};return{config:function(a){d=a;t("discovery_next:logging",function(){p(!0)});t("discovery_next:truncate",function(){g(!0)})},allowLog:p,ifSwitch:t,log:f,allowLineTruncate:g,lineTruncate:function(c,d){function e(){return l.scrollHeight-l.offsetHeight>0.2*m}function g(){n.lastChild&&!_.contains(["...","\u2026"],n.lastChild.nodeValue)&&(o=n.appendChild(a.document.createTextNode(" "+k)),e()&&(n.removeChild(o),n.removeChild(n.lastChild),
g()))}if(h){var f=b.logError;if(!c.closest("body").length)return void f("lineTruncate called on el not on DOM");if(c.text().length<1)return void f("lineTruncated called on empty el");if(_.any(c.children(),function(a){return a.nodeType!==3}))return void f("lineTruncate called on non-flat el");var n=c[0],l=n;if(c.css("display")!=="block")for(;l.parentNode;)if(l=l.parentNode,$(l).css("display")==="block")break;var m=parseFloat(c.css("font-size"),10);if(e()){var d=d||{},f=d.lines||1,k=d.ellipsis,o,j=
c.text();if(j.length){var p=c.width()/m,f=parseInt(p*f,10),j=j.split(/\s/),p=0;c.empty();for(var q=0,y=j.length;q<y;q++){p+=j[q].length+1;if(p>=f)break;n.appendChild(i.createTextNode(" "+j[q]))}if(e()){do o=n.removeChild(n.lastChild);while(e())}else{do o=n.appendChild(i.createTextNode(" "+j[q++]));while(!e()&&q<y);n.removeChild(o)}k&&(_.isString(k)||(k="\u2026"),g())}}}}}});b.define("discovery",function(){return this.overwrites({init:function(a,c){function d(a,b,c,d,e){if(_.isNumber(d)&&a.length<
d)return void h();a=new z({el:b,collection:a,snippetLimit:t});a.on("resize",function(){c.trigger("resize")});a.render(e||{});c.trigger("subViewRendered")}function h(c){c=c||{};if(!q&&(q=!0,b.juggler)){var c={major_version:"midway",internal_organic:m.length,external_organic:k.length,promoted:o.length,promoted_ids:b.JSON.stringify(o.pluck("advertisement_id")),display:!!c.display},d;if(x.bandit||o.bandit)d=_.extend({},x.bandit,o.bandit);d&&_.extend(c,{bandit:b.JSON.stringify(d)});a.isExperiment&&_.extend(c,
{variant:i});f("Juggler init_discovery",c);b.juggler.emit("init_discovery",c)}}var l=b.discovery.helpers,f=l.log,i=a.variant,g=a.session;l.config(a.switches);var t=100,r=4,s=i.match(/(\d)x\d/);s&&(r=parseInt(s[1],10));var u=b.discovery.models.load(),w=b.discovery.collections.load(u,l),l=b.discovery.views.load(l),s=w.RelatedThreadCollection,z=l.RelatedThreadCollectionView,w=w.AdvertisementCollection,n=l.AdvertisementCollectionView,v=new u.Thread(_.extend(a.thread,{forum:a.forum})),r={thread:v,limit:r,
variant:{isExperiment:!!a.isExperiment,name:i}},m=new s(null,r),k=new s(null,_.defaults({external:!0},r)),o=new w(null,_.defaults({external:!0},r)),u=[m,k,o];_.invoke(u,"on","error",h);var j=new l.MainView({el:a.mainEl});j.$el.css({position:"absolute",visibility:"hidden",display:"block",width:j.$el.width()});j.$el.append(b.renderBlock(j.dtplBlock,{forum:v.get("forum"),variant:i,session:g.toJSON()}));g.on("change:canModerate",_.bind(j.renderHelp,j,g));_.invoke(u,"on","reset",function(){var a=0,b=0,
d=!1;return function(f){d||(f.external?b+=f.length:a+=f.length,a<2||b<2||(d=!0,c(j)))}}());j.on("subViewRendered",_.after(2,function(){j.trigger("allSubviewsRendered");h({display:!0})}));var x=new s(null,_.defaults({limit:m.limit+k.limit},r));x.fetch({data:{thread:v.id,external:1,limit:x.limit},success:function(a){if(a.length<2)return void h();i!="midway-6x2"&&a.getTopComment(a.pluck("id"));var b=v.get("forum"),c;c=a.filter(function(a){return a.get("forum").id!=b.id});a=_.difference(a.models,c);m.reset(a.slice(0,
m.limit)).each(function(a){a.collection=m});a=j.$el.find("#discovery-internal")[0];d(m,a,j,2,{start:0,limit:c.length});f("Internal organic",m.pluck("id"));k.reset(c.slice(0,k.limit)).each(function(a){a.collection=k});k.fetched=!0;f("External organic",k.pluck("id"))},error:h});o.fetch({data:{thread:v.id,limit:o.limit-1},success:function(a){f("Promoted:",a.pluck("advertisement_id"));var b=j.$el.find("#discovery-external")[0],c=new n({el:b,collection:a,snippetLimit:175}),e=function(){k.off("reset",e);
if(m.length<2)return void h();var f=Math.min(m.length,a.limit),g=Math.min(m.limit,k.length+a.length);g>k.length&&d(m,j.$el.find("#discovery-internal")[0],j,2,{start:k.length,limit:g});k.length>0?(c.render({limit:f-1}),d(k,b,j,2-a.length,{limit:Math.max(f-a.length,1)})):c.render({limit:f});a.length>=2&&j.trigger("subViewRendered")};if(k.fetched)e();else k.on("reset",e)},error:h});var q=!1}})})};b.runThemeScript=b.registerActions})(this);