window.__tnt||(window.__tnt={});__tnt.comment||(__tnt.comment={}); __tnt.comment.post={clear:function(a){a.find("button,textarea").removeAttr("disabled");a.find("button[type=submit]").button("reset");a.find(".form-body").find("#comment-reply-preview").remove();a.find("input[name=parent_uuid]").remove();a.find("textarea[name=comment]").val("");a.find(".alert").text("").hide()},prepare:function(a,b){if(""!=b){var c=$("#comment-"+b).clone();c.attr("id","comment-reply-preview");c.find(".comment-options").remove();c.find(".comment-footer").remove();c.find(".replies").remove(); c.append("
");a.find(".modal-body").prepend(c);a.append('')}},data:function(a){var b=a.find("input[name=app]").val(),c=a.find("input[name=id]").val(),d="",e="";""!=a.find("textarea[name=comment]").val()&&(e=a.find("textarea[name=comment]").val());a.find("input[name=parent_uuid]").length&&(d=a.find("input[name=parent_uuid]").val());this.obj=Object({id:c,app:b,comment:e,parent_uuid:d});null==__tnt.user.authToken&&(a.find("input[name=alias]")&& (this.obj.alias=a.find("input[name=alias]").val()),a.find("input[name=tncms_captcha_id]")&&(this.obj.tncms_captcha_id=a.find("input[name=tncms_captcha_id]").val(),this.obj.tncms_captcha_response=a.find("input[name=tncms_captcha_response]").val()),a.find("textarea.g-recaptcha-response")&&(this.obj["g-recaptcha-response"]=a.find("textarea.g-recaptcha-response").val()));return this.obj}}; __tnt.comment.abuse={prepare:function(a,b){a.find(".modal-body").html("");var c=$("#comment-"+b).clone();c.attr("id","comment-report-preview");c.find(".comment-options").remove();c.find(".comment-footer").remove();c.find(".replies").remove();a.find(".modal-body").prepend(c);a.find("input[name=comment_id]").val(b)}}; __tnt.comment.subscribe={prepare:function(a){try{window.localStorage&&localStorage.getItem("comment-subscribed-"+$("#asset-content").attr("data-asset-uuid"))&&__tnt.comment.subscribe.toggle()}catch(b){}},toggle:function(){var a=$("#commentSubscribe");if(a.length){var b=["/subscribe/","/unsubscribe/"];0>a.attr("action").search(/\/subscribe\//)&&b.reverse();a.attr("action",$("#commentSubscribe").attr("action").replace(b[0],b[1]));$("#commentSubscribeModal").find(".subscribe, .unsubscribe").toggle(); $("#comments").find(".watch span").toggle()}},set:function(){var a=$("#asset-content").attr("data-asset-uuid");try{window.localStorage&&localStorage.setItem("comment-subscribed-"+a,1)}catch(b){}},unset:function(){var a=$("#asset-content").attr("data-asset-uuid");try{window.localStorage&&localStorage.removeItem("comment-subscribed-"+a)}catch(b){}}}; __tnt.comment.preview={append:function(a,b){a.length&&$.each(a,function(){__tnt.comment.preview.create(this.data,$("#commentPostModal").find(".template.success"),b)})},create:function(a,b,c){var d=c.hasClass("desc"),e=__tnt.comment.preview.sanitize(a.comment);""!=a.parent_uuid&&(c=$("#comment-"+a.parent_uuid),c.find(".replies").length||c.append('
'),c=c.find(".replies").first());e=[{element:"img.avatar",attr:[{attr:"src",value:__tnt.user.avatar}]},{element:".comment-text", html:"

"+e+"

"}];null!=__tnt.user.authToken?e.push({element:".username",html:__tnt.user.screenName}):""!=a.alias&&e.push({element:".username",html:a.alias});__tnt.template(b,c,d,e,function(a){null!=__tnt.user.avatar?$(a).find("div.avatar").remove():($(a).find("img.avatar").remove(),null==__tnt.user.authToken&&$(a).find("div.avatar").find("i").removeClass("fa-user").addClass("fa-user-secret"))});__tnt.emoticon.handle($(".comment.preview .comment-text"))},sanitize:function(a){"string"==typeof a&& (a=a.replace(//g,""));return a},store:function(a,b){var c=!1;try{if(window.sessionStorage){var d=[],e=new Date,f="",g=0;null!=sessionStorage.getItem("comment-previews")&&(d=JSON.parse(sessionStorage.getItem("comment-previews")));f=e.getTime("u");g=b.find('.comment[data-user="'+__tnt.user.screenName+'"]').length+b.find(".comment.preview").length;storedJSON={c:g,t:f,data:{comment:a.comment,parent_uuid:a.parent_uuid}};d.push(storedJSON);var h=$("#asset-content").attr("data-asset-uuid"); try{sessionStorage.setItem("comment-previews-"+h,JSON.stringify(d)),c=!0}catch(k){}}}catch(l){}return c},fetch:function(){var a="comment-previews-"+$("#asset-content").attr("data-asset-uuid"),b=[],c="";try{window.sessionStorage&&(c=sessionStorage.getItem(a),null!=c&&(b=JSON.parse(c)))}catch(d){}return b},filter:function(a,b,c){var d=$("#asset-content").attr("data-asset-uuid"),e=b.find('.comment[data-user="'+__tnt.user.screenName+'"]').length,f=new Date,g=[];"undefined"!=typeof a&&(a=__tnt.comment.preview.fetch()); "undefined"==typeof c&&(c=!1);a&&$.each(a,function(){var a=!1;this.cChanges pending'); a.siblings(".contribute-tools").find("button.edit, button.approve, button.deny").prop("disabled",!0)},filter:function(a,b,c){var d=b.find(".comment").length;b=b.data("asset-uuid");var e=new Date,f=[];"undefined"!=typeof a&&(a=__tnt.comment.pending.fetch());"undefined"==typeof c&&(c=!1);$.each(a,function(){var a=!1;this.c/g,"\n"));$('#commentEditModal form input[name="commentid"]').val(a.data("comment-uuid"));$("#commentEditModal").modal({backdrop:"static", keyboard:!0,show:!0,remove:!1})});$("#commentEdit").on("submit",function(a){a.preventDefault();a=$("#commentEdit").serialize();$("#commentEditModal").find("button,textarea").prop("disabled",!0);$("#commentEditModal").find("button[type=submit]").button("loading");""!=a.content&&$.ajax({type:"POST",url:$("#commentEdit").attr("action"),data:a,success:function(a,c,d){$("#commentEditModal").modal("hide");$("#commentEditModal").find("button,textarea").prop("disabled",!1);a=$("#commentEdit").find('input[name="commentid"]').val(); __tnt.comment.pending.store({comment_uuid:a},$("#comment-index"));__tnt.comment.pending.mark($("#comment-"+a))}})});$("#comment-index .contribute-tools .approve").click(function(a){var b=$(this).parents(".contribute-tools").siblings(".comment").data("comment-uuid");a=$("#comment-index").data("asset-uuid");$.ajax({type:"POST",url:location.href,data:{submit:"approve",commentid:b,assetid:a},success:function(a){__tnt.comment.pending.store({comment_uuid:b},$("#comment-index"));__tnt.comment.pending.mark($("#comment-"+ b))}})});$("#comment-index .contribute-tools a.deny").click(function(a){var b=$(this),c=b.parents(".contribute-tools").siblings(".comment").data("comment-uuid");a=$("#comment-index").data("asset-uuid");b=b.data("reason");$.ajax({type:"POST",url:location.href,data:{submit:"deny",commentid:c,assetid:a,reason:b},success:function(a){__tnt.comment.pending.store({comment_uuid:c},$("#comment-index"));__tnt.comment.pending.mark($("#comment-"+c))}})})});