(function(){commentsModule=function(){this.VERSION="1.1";this.events={};this.params={comment_max_lines:5,items_per_page:20,sort_order:"Ascending",filter:"none",current_page:1,prefix:"",parent_uri:"",postFreq:0,textarea_height:"40px",character_count:0,limitingCharacters:false,critical_error_msg:"We're having some problems displaying the comments at the moment. Sorry. We're doing our best to fix it"};this.flags={ready:false,glow_ready:false,filter_tabs_events_added:false,submit_box_events_added:false,postOk:true,speedBumping:false,setupComplete:false};this.translations={you:"You",your:"Your",rated:"rated",already_rated:"Already rated",rate_this:"rate this",comments:"Comments",your_comments:"Your comments",add_your_comment:"Add your comment"};this.message_types=["error","message"];var A=this;this.container={};this.loadingElements={};this.tabElements={};this.initParams=function(C){for(var B in C){this.params[B]=C[B]}if(this.params.ajax_load_url&&this.params.bbc_id_env&&this.params.ajax_preview_url&&this.params.items_per_page&&this.params.sort_order&&this.params.site_name&&this.params.forum_id){A.flags.ready=true;A.init();A.enableForm()}};this.initGlow=function(B){A.glow=B;if(A.glow.isReady){A.flags.glow_ready=true}};this.initLogger=function(B){A.logger=B;A.flags.logger_ready=true};this.setRootNode=function(C){for(var D in C){var B=A.glow.dom.get(C[D]);if(B.length>0){this.container=B;this.rootSelector=C[D];break}}};this.findNode=function(C){var B=A.container.get(C);return(B.length>0)?B:A.glow.dom.get(C)};this.init=function(){if(this.flags.setupComplete){this.loadingElements=this.findNode(".loading");this.attachPaginatorEventsToLinks();this.attachModalIframeToPopupLinks();this.attachFormEvents()}else{this.setRootNode(["#comments",".comments_module"]);this.loadingElements=this.findNode(".loading");this.postingElements=this.findNode(".dna-tab-posting");this.tabElements=this.findNode("ul.tabs li");this.commentsList=this.findNode("div.dna-comment-list");this.messageElement=this.findNode(".comments-message");this.formElements=this.findNode(" form.postcomment input, form.postcomment textarea");this.formSubmitElements=this.findNode(" form.postcomment input");this.previewElement=this.findNode(".dna-comment-preview");this.attachPaginatorEventsToLinks();this.attachModalIframeToPopupLinks();this.attachFilterEventsToLinks();this.attachFormEvents();this.attachPostCommentLinkEvent();this.attachInitialViewCommentsLink();this.populateCommentCountAnchors();this.findNode("form.postcomment input.dna-commentbox-preview").css("display","inline");if(typeof (identity)=="object"){identity.status.enableJavaScript();identity.addSigninHandler(function(){A.setLoggedIn();A.loadLoggedInFragment()})}if(location.protocol=="https:"){this.params.ajax_load_url=this.params.ajax_load_url.replace("http:","https:")}this.flags.setupComplete=true}this.personaliseCommentFeed();this.updateCommentCounts(A.params.comment_count)};this.attachInitialViewCommentsLink=function(){};this.enhanceCommentFeed=function(){A.findNode(".dna-comments-comment-footer").css("visibility","hidden");A.findNode("ul.collections li.comment").each(function(){A.glow.events.addListener(this,"mouseover",function(){A.glow.dom.get(this).get(".dna-comments-comment-footer").css("visibility","visible")},this);A.glow.events.addListener(this,"mouseout",function(){A.glow.dom.get(this).get(".dna-comments-comment-footer").css("visibility","hidden")},this)})};this.personaliseCommentFeed=function(){if(A.params.logged_in&&typeof (A.params.user_id)=="number"){A.findNode("a.comment_username_"+A.params.user_id).each(function(){A.glow.dom.get(this).html(A.translations.you)});A.findNode("span.comment_moderated_username_"+A.params.user_id).each(function(){A.glow.dom.get(this).html(A.translations.your)});A.findNode("p.comment_complain_"+A.params.user_id).each(function(){A.glow.dom.get(this).css("display","none")});if(A.params.dml||A.params.del){A.findNode("div.dna-comment-list .dna-comments-comment-footer").each(function(){if(A.params.dml){var B=A.glow.dom.get(this).parent().attr("id").replace("comment_","");var C='<p class="flag"><a href="'+A.params.ml+B+'" class="popup" target="_blank">Moderation History</a></p>';C+=(A.glow.dom.get(this).children().hasClass("flag"))?"":"";A.glow.dom.get(this).prepend(C)}})}}};this.populateCommentCountAnchors=function(){var B=(typeof (A.params.comment_count)=="number"&&A.params.comment_count>0)?'<span class="dna-comment-count-number">('+A.params.comment_count+")</span>":'<span class="dna-comment-count-number"></span>';var C=A.findNode(".dna-comment-count-simple");var E=A.findNode(".dna-comment-count-personal");var D=A.findNode(".dna-comment-anchor");C.html('<a href="#dna-comments">'+A.translations.comments+" "+B+'<span class="gvl3-icon gvl3-icon-comment"></span></a> ');E.html('<a href="#dna-comments">'+A.translations.your_comments+" "+B+'<span class="gvl3-icon gvl3-icon-comment"></span></a> ');D.html('<a href="#dna-comments">'+A.translations.add_your_comment+"</a> ");A.glow.events.addListener(C,"click",A.scrollTop,this);A.glow.events.addListener(E,"click",A.scrollTop,this);A.glow.events.addListener(D,"click",A.scrollTop,this)};this.setLoggedIn=function(){this.findNode(".dna-commentbox-logged-in").show();this.findNode(".dna-commentbox-logged-out").hide();this.attachFormEvents();this.formatSubmitCommentForm();this.enableForm()};this.loadLoggedInFragment=function(){var B="?preset="+A.params.preset+"&ptrt="+escape(A.params.parent_uri)+"&idenv="+escape(A.params.bbc_id_env)+"&siteId="+A.params.site_name+"&loc="+A.params.loc;this.glow.net.loadScript(this.params.base_non_secure_url+"fragment/userfragment/"+B)};this.setEditorsPick=function(D){var B=A.findNode(".loading img");A.glow.dom.get(D.source).prepend('<img src="'+B.attr("src")+'" style="position: absolute; margin-left: -24px" /> ');var C=A.glow.net.get(D.source.href,{onLoad:function(E){A.glow.dom.get(D.source).get("img").remove();if(A.params.filter=="EditorPicks"){A.glow.dom.get(D.source.parentNode.parentNode.parentNode).remove()}alert(E.text())},onError:function(E){A.glow.dom.get(D.source).get("img").remove();alert(E.text())},useCache:false});return false};this.attachModalIframeToPopupLinks=function(){var B=this.commentsList.get("a.popup");B.each(function(){A.glow.events.addListener(this,"click",A.openJsPopupWindow,this)})};this.openModalIframe=function(B){A.overlay=new A.glow.widgets.Overlay(A.glow.dom.create('<div id="dna-comments-modal-overlay" class="dna-url-popup"><div class="dna-close-panel"><a href="#" onclick="comments.overlay.hide(); return false;">x</div><iframe id="modalpopup" src="'+B.source.href+'" width="100%" height="100%" frameborder="0"></iframe></div>'),{modal:true});A.overlay.show();return false};this.openJsPopupWindow=function(B){window.open(B.source.href,"dna_popup_window","height = 615, width = 694, scrollbars = 1");return false};this.openJsWindow=function(B){window.open(B.source.href,"dna_window");return false};this.attachPaginatorEventsToLinks=function(){var B=A.findNode("ul.comments_pagination_ul li a");B.each(function(){var C=this.innerHTML.toLowerCase().replace(/^\s*/,"").replace(/\s*$/,"");switch(C){case"first":case"start":A.glow.events.addListener(this,"click",function(){A.loadPage(1,this,function(){window.location="#"+A.params.prefix+"comments"});return false});break;case"last":case"end":A.glow.events.addListener(this,"click",function(){A.loadPage(A.params.page_count,this,function(){window.location="#"+A.params.prefix+"comments"});return false});break;case"newer":A.glow.events.addListener(this,"click",function(){A.loadPage(A.params.current_page-1,this,function(){window.location="#"+A.params.prefix+"comments"});return false});break;case"older":A.glow.events.addListener(this,"click",function(){A.loadPage(A.params.current_page+1,this,function(){window.location="#"+A.params.prefix+"comments"});return false});break;default:A.glow.events.addListener(this,"click",function(){A.loadPage(C,this,function(){window.location="#"+A.params.prefix+"comments"});return false});break}})};this.attachFilterEventsToLinks=function(){if(!this.params.filter_tabs_events_added){this.tabElements.get("a").each(function(){var B=this.href.match(/filter=([a-zA-Z]*)/);A.glow.events.addListener(this,"click",function(){A.params.filter=B[1];A.loadPage(1,this,function(){A.setTab(B[1])});return false})});this.params.filter_tabs_events_added=true}};this.attachFormEvents=function(){if(!this.flags.submit_box_events_added){var B=this.findNode("form.postcomment");this.glow.events.addListener(B,"submit",function(){A.postComment();return false});this.glow.events.addListener(this.findNode("textarea#dna-commentbox-text"),"focus",this.prepareSubmitBoxForSubmit);this.glow.events.addListener(this.findNode("textarea#dna-commentbox-text"),"blur",this.formatSubmitCommentForm);this.glow.events.addListener(this.findNode("input.dna-commentbox-preview"),"click",this.previewComment);this.glow.events.addListener(this.findNode("a.popup"),"click",this.openJsPopupWindow);this.glow.events.addListener(this.findNode("a.no-popup"),"click",this.openJsWindow);this.formatSubmitCommentForm();this.flags.submit_box_events_added=true}};this.checkUserAuthedToComment=function(){var B=A.glow.net.get("/users/authorized.bool?url="+A.params.policy_uri,{onLoad:function(C){if(parseInt(C.text())==0){A.showError('Sorry, you need to complete your registration details by <a href="https://'+A.params.bbc_id_env+"/users/dash/more?ptrt="+A.params.parent_uri+"&target_resource="+A.params.policy_uri+'">clicking here</a>.');A.disableForm()}else{A.enableForm()}}})};this.attachPostCommentLinkEvent=function(){var B=this.findNode(".dna-commentbox-add-comment-cta");if(B.length>0){this.glow.events.addListener(B,"click",function(){var C=A.glow.dom.get("textarea#dna-commentbox-text");A.scrollTextarea();C[0].focus();return false})}};this.formatSubmitCommentForm=function(){var B=A.findNode("form.postcomment textarea#dna-commentbox-text");if(B.length<1){return false}var C=parseInt(B.parent().css("width"))-((2*parseInt(B.css("padding-left")))+2);B.css("width",C);A.findNode("p.dna-comments-footer").css("width",parseInt(B.parent().css("width"))-((parseInt(B.css("padding-left")))+2));var D=B.val();if(D.toLowerCase()=="add your comment"||D.replace(/^\s*/,"").replace(/\s*$/,"")==""){var B=A.findNode("form.postcomment textarea#dna-commentbox-text");B.val("Add your comment");B.css("height",A.params.textarea_height);A.findNode("form.postcomment .dna-comments-footer").hide()}};this.prepareSubmitBoxForSubmit=function(){var B=A.findNode("form.postcomment textarea#dna-commentbox-text");var C=B.val();if(C.toLowerCase()=="add your comment"){B.val("");B.css("height","80px");A.findNode("p.dna-comments-footer").show()}else{A.formatSubmitCommentForm()}};this.loadPage=function(F,D,E,C,B){A.showLoader();var B=(typeof (B)=="boolean")?B:true;var G={siteId:this.params.site_name,forumId:this.params.forum_id,sortOrder:this.params.sort_order,limit:this.params.items_per_page,comments_page:F,filter:this.params.filter,preset:this.params.preset,parentUri:this.params.parent_uri,loc:this.params.loc,timezone:this.params.timezone,viaAjax:true};if(C){G.postId=C}var H=A.glow.data.encodeUrl(G);this.glow.net.loadScript(this.params.ajax_load_url+"?"+H);if(D){D.blur()}return false};this.postComment=function(){var B=A.findNode("#dna-commentbox-text").val().replace(/^\s*/,"").replace(/\s*$/,"");if(B.length==0){A.showError("You must enter some text in the comment box");return false}if(A.flags.postOk==false&&A.flags.speedBumping==true){A.showError("Sorry, you can only post a comment to this article once every "+A.params.postFreq+" seconds. You have <strong>"+A.getSpeedBumpCountdown()+"</strong> seconds left since the time of your last post.");return false}var E=A.findNode("form.postcomment");var C=E.val();C.sortOrder=A.params.sort_order;C.limit=A.params.items_per_page;C.filter=A.params.filter;C.preset=A.params.preset;C.viaAjax=true;A.disableForm();A.showPosting("posting your comment",true);var D=A.glow.data.encodeUrl(C);A.glow.net.loadScript(E.attr("action")+"?"+D);return false};this.previewComment=function(){var B=A.findNode("textarea#dna-commentbox-text").val().replace(/^\s*/,"").replace(/\s*$/,"");if(B.length==0){A.showError("You must enter some text in the comment box");return false}var C=(A.params.num_comments)?A.params.num_comments+1:1;var F=A.findNode("form.postcomment");var D=F.val();D.id=C;D.comment=B;D.preset=A.params.preset;D.viaAjax=true;A.showPosting("generating preview",true);var E=A.glow.data.encodeUrl(D);A.glow.net.loadScript(A.params.ajax_preview_url+"?"+E);return false};this.stripslashes=function(B){B=B.replace(/\\'/g,"'");B=B.replace(/\\"/g,'"');B=B.replace(/\\0/g,"\0");B=B.replace(/\\\\/g,"\\");return B};this.updateCsrf=function(B){A.findNode("input.dna-comments-csrf").val(B)};this.scrollToElement=function(C,B){var D=B||10;this.glow.dom.get(window).scrollTop(C.offset().top-D);return false};this.scrollTop=function(){this.scrollToElement(this.container);return false};this.scrollTopError=function(){this.scrollToElement(this.findNode(".comments-message"));return false};this.scrollTextarea=function(){this.scrollToElement(this.findNode("#dna-commentbox-text"));return false};this.showMessage=function(E,D){D=D||"message";for(var B in A.message_types){var C="comments-message-"+A.message_types[B];if(A.messageElement.hasClass(C)&&A.message_types[B]!=D){A.messageElement.removeClass(C)}}A.messageElement.addClass("comments-message-"+D);A.messageElement.show();A.messageElement.html(A.stripslashes(E));A.hideLoader();A.hidePosting();A.enableFormInputs();A.scrollTopError();A.findNode(".dna-comments-all-loaders").hide();return true};this.showError=function(B){if(typeof (B)!="string"){B=A.params.critical_error_msg}return this.showMessage(B,"error")};this.hideMessage=function(){if(!A.messageElement.hasClass("sticky")){A.messageElement.html();A.messageElement.hide();return true}return false};this.hideError=function(){A.hideMessage();return true};this.showLoader=function(){this.loadingElements.css("display","inline")};this.hideLoader=function(){this.loadingElements.css("display","none")};this.showPosting=function(C,B){this.postingElements.get("span").html(C);if(B==true){this.postingElements.get("img").css("display","inline")}else{this.postingElements.get("img").css("display","none")}this.postingElements.css("display","inline")};this.hidePosting=function(){this.postingElements.css("display","none")};this.disableFormInputs=function(){this.formSubmitElements.attr("disabled","true")};this.enableFormInputs=function(){this.formSubmitElements.removeAttr("disabled")};this.disableForm=function(){this.formElements.attr("disabled","true")};this.enableForm=function(){this.formElements.removeAttr("disabled")};this.setTab=function(B){};this.setSpeedBump=function(){A.params.speedBumpTimeLeft=A.params.postFreq;A.flags.postOk=false;A.flags.speedBumping=true;A.speedBumpTime=setInterval(function(){A.params.speedBumpTimeLeft--;var B=A.findNode("span.speed-bump-countdown");if(B){B.html(A.params.speedBumpTimeLeft)}if(A.params.speedBumpTimeLeft==0){clearInterval(A.speedBumpTime);A.flags.postOk=true;A.flags.speedBumping=false;A.hideError()}},1000)};this.updateCommentCounts=function(B){if(B>0){A.glow.dom.get("body .dna-comment-count-number").html("("+B+")")}};this.getSpeedBumpCountdown=function(){return'<span class="speed-bump-countdown">'+A.params.speedBumpTimeLeft+"</span>"};this.addNotificationPadding=function(){if(A.limitedFormInput&&A.limitedFormInput.parent()){A.limitedFormInput.parent().css("padding-bottom","28px")}};this.removeNotificationPadding=function(){if(A.limitedFormInput&&A.limitedFormInput.parent()){A.limitedFormInput.parent().css("padding-bottom","8px")}};this.removeLastScriptNode=function(){var B=comments.glow.dom.get("script");B[B.length-1].parentNode.removeChild(B[B.length-1])};this.destroyRecaptcha=function(){return true}}}());var comments;(function(){gloader.load(["glow","1","glow.events","glow.dom","glow.widgets"],{async:true,onLoad:function(A){A.ready(function(){window.comments=new commentsModule();window.comments.initGlow(A);try{require(["istats-1"],function(C){window.comments.initLogger(C)})}catch(B){}if(typeof (window.commentsParams)=="object"){window.comments.initParams(window.commentsParams);try{delete (window.commentsParams)}catch(B){}}})}})})();
