ips.templates.set('remotecommenting.wrapper',"  <h2 class='rcCommentCount rcHeader ipsAreaBackground ipsType_reset'><span data-role='commentCount'>0 Comments</span>   <ul class='ipsList_inline ipsPos_right ipsType_medium'>   {{#user}}    <li class='ipsType_unbold ipsFaded'>     {{#lang}}rcSignedInAs{{/lang}} {{user.name}}    </li>   {{/user}}   <li>    <a href='#' data-role='topicLink' class='ipsHide ipsType_blendLinks ipsFaded ipsFaded_withHover' data-ipsTooltip title='{{#lang}}rcGoToTopic{{/lang}}'><i class='fa fa-comment'></i></a>   </li>  </ul> </h2> {{#reply}}  <div class='ipsAreaBackground rcHeader ipsPad_half rcReplyForm rcMainReplyForm {{#user}}ipsPhotoPanel ipsPhotoPanel_tiny{{/user}}' data-role='mainReplyForm'>   {{{reply}}}  </div> {{/reply}} {{^reply}}  <div class='ipsAreaBackground rcHeader rcLogin' data-role='mainReplyForm'>   {{{login}}}  </div> {{/reply}} <div class='ipsPad'>  <div data-role='commentContainer'></div>  <hr class='ipsHr'>  <div class='ipsClearfix'>   {{#copy}}    <p class='ipsPos_right ipsType_reset ipsType_light ipsType_medium'>     <a href='http://www.invisionpower.com' class='ipsType_blendLinks'>Powered by IPS Community Suite</a>    </p>   {{/copy}}  </div> </div> <!--<a href='#' data-role='createCookie'>Developer create cookie</a>-->");ips.templates.set('remotecommenting.locked',"  <div class='ipsAreaBackground rcHeader ipsPad_half rcLocked'>  <p class='ipsType_reset'>This article is now closed to further comments. </div>");ips.templates.set('remotecommenting.login',"  {{^data.id}}  <p class='ipsType_reset ipsSpacer_bottom'><i class='fa fa-info-circle'></i> {{#lang}}rcRequiresLogin{{/lang}}</p>  {{#loginURL}}<a href='{{loginURL}}' data-action='login' class='ipsButton ipsButton_small ipsButton_primary'>Log In</a>{{/loginURL}} {{/data.id}}");ips.templates.set('remotecommenting.noComments',"  <div class='ipsPad ipsType_center ipsType_large ipsType_light' data-role='noComments'>  {{#lang}}rcNoComments{{/lang}} {{#open}}{{#lang}}rcBeTheFirst{{/lang}}{{/open}} </div>");ips.templates.set('remotecommenting.error',"  <div class='ipsAreaBackground_light ipsPad ipsType_medium ipsType_light ipsType_center'>  {{message}} </div>");ips.templates.set('remotecommenting.loadMore',"  <div class='ipsAreaBackground_light ipsPad ipsType_medium ipsType_light ipsType_center rcLoadMoreContainer' data-role='loadMoreContainer'>  <a href='#' class='ipsButton ipsButton_primary ipsButton_verySmall' data-role='loadMore'>{{#lang}}rcLoadOlder{{/lang}}</a> </div>");ips.templates.set('remotecommenting.replyForm',"  {{#user}}<span class='ipsUserPhoto ipsUserPhoto_tiny'><img src='{{user.photo}}' class='ipsUserPhoto_tiny'></span>{{/user}} <div data-role='commentFormContainer'>  <form method='post' action='{{formURL}}' data-role='commentForm'>   <input type='hidden' name='_contentReply' value='1'>   <input type='hidden' name='csrfKey' value='{{csrf}}'>   <input type='hidden' name='commentform_{{topicID}}_submitted' value='1'>   {{#replyingTo}}<p class='ipsType_reset ipsSpacer_bottom ipsSpacer_half'><i class='fa fa-mail-forward'></i> {{replyingToText}}</p>{{/replyingTo}}   <textarea rows='1' style='width: 100%' placeholder='{{placeholder}}' data-role='commentBox'></textarea>   <div data-role='commentFormControl' class='ipsSpacer_top ipsSpacer_half ipsClearfix ipsType_medium {{^replyingToComment}}ipsHide{{/replyingToComment}}'>    <ul class='ipsList_inline'>     <li><button type='submit' class='ipsPos_right ipsButton ipsButton_primary ipsButton_verySmall' data-action='submitComment'>{{#lang}}rcAddComment{{/lang}}</button></li>     {{#replyingToComment}}<li><a href='#' data-action='cancelComment' class='ipsType_light'>{{#lang}}rcCancel{{/lang}}</a></li>{{/replyingToComment}}    </ul>   </div>  </form> </div>");ips.templates.set('remotecommenting.quote'," <blockquote class='ipsQuote' data-cite='{{quoteData.username}}' data-ipsQuote data-ipsQuote-timestamp='{{quoteData.timestamp}}' data-ipsQuote-userid='{{quoteData.userid}}' data-ipsQuote-username='{{quoteData.username}}' data-ipsQuote-contenttype='{{quoteData.contenttype}}' data-ipsQuote-contentclass='{{quoteData.contentclass}}' data-ipsquote-contentid='{{quoteData.contentid}}' data-ipsquote-contentcommentid='{{quoteData.contentcommentid}}'>{{{quotedPost}}}</blockquote>\n\n");ips.templates.set('remotecommenting.comment',"  <div class='rcComment ipsSpacer_bottom' data-commentID='{{comment.id}}' data-quoteData='{{quoteData}}' {{#startHidden}}style='opacity: 0'{{/startHidden}}>  <div class='ipsAreaBackground_light ipsPad_half ipsClearfix'>   <div class='ipsPhotoPanel ipsPhotoPanel_tiny'>    {{#user.url}}<a href='{{user.url}}' class='ipsUserPhoto ipsUserPhoto_tiny'>{{/user.url}}    {{^user.url}}<span class='ipsUserPhoto ipsUserPhoto_tiny'>{{/user.url}}     <img src='{{user.photo}}' class='ipsUserPhoto_tiny'>    {{#user.url}}</a>{{/user.url}}    {{^user.url}}</span>{{/user.url}}    <div>     <h3 class='ipsType_large ipsType_reset ipsType_blendLinks rcUsername'>{{#user.url}}<a href='{{user.url}}'>{{/user.url}}{{user.username}}{{#user.url}}</a>{{/user.url}}</h3>     <span class='ipsType_light'><a href='{{commentURL}}' class='ipsType_blendLinks ipsType_medium'>{{date}}</a></span>     {{#hidden}}      <p class='ipsType_reset ipsType_negative ipsType_medium'><i class='fa fa-warning'></i> {{#lang}}rcAwaitingApproval{{/lang}}</p>     {{/hidden}}    </div>   </div>  </div>  <div class='ipsType_richText ipsType_break ipsType_normal ipsSpacer_top rcCommentBody'>{{{comment.content}}}</div>  {{#loggedIn}}   <ul class='ipsList_inline ipsType_medium rcCommentControls' data-role='commentControls'>    {{#likes}}     {{{likes}}}    {{/likes}}    {{^showReply}}     <li><a href='#' data-role='replyToComment'>{{#lang}}rcReply{{/lang}}</a></li>    {{/showReply}}   </ul>   {{^showReply}}    <div class='ipsHide ipsAreaBackground_light ipsPad_half rcReplyForm {{#user}}ipsPhotoPanel ipsPhotoPanel_tiny{{/user}}' data-role='commentReplyForm'>{{{form}}}</div>   {{/showReply}}  {{/loggedIn}}  {{^loggedIn}}   {{#likes}}    <ul class='ipsList_inline ipsType_medium rcCommentControls' data-role='commentControls'>     {{{likes}}}    </ul>   {{/likes}}  {{/loggedIn}} </div>");ips.templates.set('remotecommenting.likes',"  <li class='rcLikes {{^count}}rcLikes_zero{{/count}}' data-count='{{count}}' data-role='likesInfo'>  <i class='fa fa-heart'></i> {{text}} </li> {{#showLike}}  <li data-role='likesInfo'>   {{#hasLiked}}<a href='#' data-action='toggleLike' data-type='unlike'>{{#lang}}rcUnlike{{/lang}}</a>{{/hasLiked}}   {{^hasLiked}}<a href='#' data-action='toggleLike' data-type='like'>{{#lang}}rcLike{{/lang}}</a>{{/hasLiked}}  </li> {{/showLike}}");ips.templates.set('remotecommenting.styles',"  {{#linkColor}}  .rcCommentBody a, .rcCommentControls a, .rcDiscussMore a {   color: {{linkColor}} !important;  } {{/linkColor}} {{#header}}  .rcHeader.ipsAreaBackground {   background: {{header.background}} !important;   color: {{header.color}} !important;  } {{/header}}");;
;(function($,_,undefined){"use strict";ips.controller.register('core.front.remotecommenting.app',{_rcContainer:null,_member:false,_topicData:{},_textboxInterval:null,_parentURL:'',initialize:function(){this.on(window,'message',this.windowMessage);this.on(window,'resize',this.windowResize);this.on('focus',"[data-role='commentBox']",this.focusTextarea);this.on('blur',"[data-role='commentBox']",this.blurTextarea);this.on('click',"[data-role='createCookie']",this.developerCreateCookie);this.on('click',"[data-role='loadMore']",this.loadMoreComments);this.on('click',"[data-role='replyToComment']",this.replyToComment);this.on('click',"[data-action='submitComment']",this.submitComment);this.on('click',"[data-action='cancelComment']",this.cancelComment);this.on('click',"[data-role='forumLink']",this.forumLink);this.on('click',"[data-action='toggleLike']",this.toggleLike);this.on('click','a',this.interceptLinks);this.setup();},setup:function(){var url=ips.utils.url.getURIObject();var self=this;this._guid=url.queryKey['guid'];this._fetchUserData();this._loadTopicData().done(function(){self._buildWrapper();self._updateTopicStats();if(self._topicData.status!=='open'){self.scope.find("[data-role='mainReplyForm']").replaceWith(ips.templates.render('remotecommenting.locked'));}
if(self._topicData.pages===0){self._showNoComments();}else{self._loadComments(self._topicData.pages).done(function(response){if(_.isArray(response)&&response.length<15&&self._topicData.pages>1){self._loadComments(self._topicData.currentPage-1);}});}});},developerCreateCookie:function(e){e.preventDefault();ips.utils.cookie.set('rcsUser',JSON.stringify({id:1,photo:'http://127.0.0.1/ipsdev/ipssuite2/applications/core/dev/resources/global/default_photo.png',name:'testadmin',csrfKey:'ac6f0005f54bbea082de00822a902f10'}),1);},interceptLinks:function(e){var elem=$(e.currentTarget);var link=elem.attr('href');if(link.startsWith('#')){return;}
e.preventDefault();this._postMessage('goToLink',{link:link});},windowMessage:function(e){var allowedURLs=ips.getSetting('rcAllowedURLs');if(!allowedURLs||!_.isArray(allowedURLs)||!allowedURLs.length){return;}
if(allowedURLs.indexOf(e.originalEvent.origin)){utils.error("Invalid origin.");return;}
try{var pmData=JSON.parse(e.originalEvent.data);var method=pmData.method;}catch(err){utils.log("Invalid data.");return;}
if(method&&!_.isUndefined(this[method])){this[method].call(this,pmData);}},windowSize:function(){this._updateSize();},probedStyles:function(data){if(ips.getSetting('useParentStyles')){var contents=ips.templates.render('remotecommenting.styles',{linkColor:data.styles.a.color,header:{background:data.styles.header.background,color:data.styles.header.color}});$('head').append($('<style/>').attr('type','text/css').text(contents));}},parentURL:function(data){this._parentURL=data.url;var returnURL=ips.getSetting('rcLoginUrl');if(returnURL&&returnURL.indexOf('=')===(returnURL.length-1)){returnURL=returnURL+encodeURI(this._parentURL);if(this.scope.find('[data-action="login"]')){this.scope.find('[data-action="login"]').attr('href',returnURL);}}},focusTextarea:function(e){var textarea=$(e.currentTarget);var self=this;textarea.autoGrow();self._updateSize();this._textboxInterval=setInterval(_.bind(this._updateSize,this),75);textarea.siblings('[data-role="commentFormControl"]').show();},blurTextarea:function(e){clearInterval(this._textboxInterval);},loadMoreComments:function(e){e.preventDefault();var loadMoreContainer=this.scope.find('[data-role="loadMoreContainer"]');loadMoreContainer.css({height:loadMoreContainer.outerHeight()+'px'}).html('').addClass('ipsLoading ipsLoading_small');this._loadComments(this._topicData.currentPage-1);},replyToComment:function(e){e.preventDefault();var comment=$(e.currentTarget).closest("[data-commentid]");comment.find('[data-role="commentControls"]').hide().end().find('[data-role="commentReplyForm"]').show().find('textarea').autoGrow().focus();this._updateSize();},submitComment:function(e){e.preventDefault();var submit=$(e.currentTarget);var parent=submit.closest('[data-commentid]');var textarea=submit.closest("[data-role='commentFormContainer']").find('textarea');var post=textarea.val();var self=this;if($.trim(post)===''){ips.ui.alert.show({type:'alert',icon:'error',message:ips.getString('rcEmptyPost'),callbacks:{}});return;}
post="<p>"+post.replace(/\n/g,"<br>")+"</p>";if(parent.length){var quote=ips.templates.render("remotecommenting.quote",{quotedPost:parent.find('.rcCommentBody').html(),quoteData:JSON.parse(parent.attr('data-quoteData'))});post=quote+post;}
submit.html("<i class='icon-spinner2 ipsLoading_tinyIcon'></i> "+ips.getString('rcSubmitting')).prop('disabled',true);textarea.prop('disabled',true);var ajaxData={};ajaxData['commentform_'+this._topicData.topicId+'_submitted']=true;ajaxData['csrfKey']=this._member.csrfKey;ajaxData['_contentReply']=1;ajaxData['comment']=post;ips.getAjax()(ips.getSetting('baseURL')+'?app=rcs&module=comments&controller=post&guid='+this._guid,{dataType:'json',method:'post',data:ajaxData,xhrFields:{withCredentials:true}}).done(function(response){submit.text(ips.getString('rcAddComment')).prop('disabled',false);textarea.prop('disabled',false).val('');parent.find('[data-role="commentReplyForm"]').hide();parent.find('[data-role="commentControls"]').show();if(response.comment.hidden==="1"){ips.ui.flashMsg.show(ips.getString('rcReplyModerated'));}else{self._topicData.comments+=1;self._updateTopicStats();self._postMessage('updateCount',{count:self._topicData.comments});}
self._insertNewComment(response);}).fail(function(jqXHR,textStatus,errorThrown){Debug.log(textStatus);Debug.log(errorThrown);});},cancelComment:function(e){e.preventDefault();var comment=$(e.currentTarget).closest("[data-commentid]");comment.find('[data-role="commentReplyForm"]').find('textarea').blur().end().hide().end().find('[data-role="commentControls"]').show();this._updateSize();},toggleLike:function(e){e.preventDefault();var link=$(e.currentTarget);var type=link.attr('data-type');var currentComment=link.closest('[data-commentID]');var currentCount=parseInt(currentComment.find('[data-count]').attr('data-count'));var html='';if(type=='unlike'){html=this._renderLikes(currentCount-1,false);}else{html=this._renderLikes(currentCount+1,true);}
currentComment.find('[data-role="likesInfo"]').remove();currentComment.find('[data-role="commentControls"]').prepend(html);ips.getAjax()(ips.getSetting('baseURL')+'?app=rcs&module=comments&controller=post&do=like&guid='+this._guid,{dataType:'json',method:'post',data:{csrfKey:this._member.csrfKey,pid:currentComment.attr('data-commentID'),type:type},xhrFields:{withCredentials:true}}).done(function(response){});},forumLink:function(e){this._postMessage('scrollToFrame');setTimeout(function(){},320)},_showNoComments:function(){var self=this;this._rcContainer.prepend(ips.templates.render('remotecommenting.noComments',{open:(this._topicData.status=='open')}));this._postMessage('iframeReady');setTimeout(function(){self._updateSize();},50);},_insertNewComment:function(content){var newPost=this._getContentFromRawPost(content.comment.content);var quoteData=content.comment.quoteData;var self=this;var newComment=this._renderComment({comment:{id:quoteData.contentcommentid,date:content.comment.date,quoteData:quoteData,content:newPost.post,hidden:content.comment.hidden},user:{id:this._member.id,username:this._member.name,photo:this._member.photo,url:''},startHidden:true});this._postMessage('scrollToFrame');this.scope.find('[data-role="noComments"]').remove();this._rcContainer.prepend(newComment);$(document).trigger('contentChange',[this._rcContainer]);this._updateSize();setTimeout(function(){self._rcContainer.find('[data-commentid="'+quoteData.contentcommentid+'"]').animate({opacity:1},700);},320);},_getContentFromRawPost:function(rawContent){var contents=$("<div>"+rawContent+"</div>");var post=contents.html();return{post:post,quoteData:''};},_updateTopicStats:function(){this.scope.find('[data-role="commentCount"]').text(ips.pluralize(ips.getString('js_num_comments'),this._topicData.comments));this.scope.find('[data-role="topicLink"]').attr('href',this._topicData.topicUrl).show();},_loadTopicData:function(){var self=this;return ips.getAjax()(ips.getSetting('remoteCommentURL')+'/meta-'+this._guid+'.json',{cache:false,dataType:'json'}).done(function(response){self._topicData=response;}).fail(function(){self._showError("Sorry, we haven't been able to load comments.");});},_showError:function(message){$('body').html(ips.templates.render('remotecommenting.error',{message:message}));this._updateSize();},_fetchUserData:function(){if(ips.utils.cookie.get("rcsUser")){try{var data=JSON.parse(ips.utils.cookie.get('rcsUser'));}catch(err){return;}
this._member={id:data.id,photo:data.photo,name:data.name,csrfKey:data.csrfKey};}},_buildWrapper:function(){var returnURL=ips.getSetting('rcLoginUrl');var wrapperHTML=ips.templates.render('remotecommenting.wrapper',{login:ips.templates.render('remotecommenting.login',{data:this._member,loginURL:returnURL}),user:this._member,reply:(this._member)?ips.templates.render('remotecommenting.replyForm',{user:this._member,placeholder:ips.getString('rcPlaceholder'),replyingToComment:false,formURL:ips.getSetting('baseURL')+'?app=rcs&module=comments&controller=post&guid='+this._guid,csrf:this._member.csrfKey,topicID:this._topicData.topicId}):'',copy:(_.isUndefined(ips.getSetting('rcCopy')))});this.scope.find('#rcContainer').html(wrapperHTML);this._rcContainer=this.scope.find("[data-role='commentContainer']");},_loadComments:function(pageNo){var self=this;pageNo=pageNo||1;return ips.getAjax()(ips.getSetting('remoteCommentURL')+'/page-'+this._guid+'-'+pageNo+'.json',{cache:false,dataType:'json'}).done(function(response){response.reverse();self._topicData.currentPage=pageNo;self._renderComments(response);self._postMessage('iframeReady');}).fail(function(){self._topicData.currentPage=pageNo;self._renderComments([]);self._postMessage('iframeReady');});},_renderComments:function(commentData){var comments=[];var self=this;if(_.isArray(commentData)){for(var i=0;i<commentData.length;i++){comments.push(this._renderComment(commentData[i]));}
this.scope.find('[data-role="loadMoreContainer"]').remove();this._rcContainer.append(comments.join(''));if(self._topicData.currentPage>1){this._rcContainer.append(ips.templates.render('remotecommenting.loadMore'));}
$(document).trigger('contentChange',[this._rcContainer]);setTimeout(function(){self._updateSize();},50);}},_renderComment:function(commentData){var likesHTML='';if(ips.getSetting('rcLikes')){var hasLiked=false;if(_.isObject(commentData.comment.likes)&&_.size(commentData.comment.likes)&&!_.isUndefined(commentData.comment.likes[this._member.id])){hasLiked=true;}
likesHTML=this._renderLikes(_.size(commentData.comment.likes),hasLiked);}
return ips.templates.render('remotecommenting.comment',_.extend(commentData,{loggedIn:this._member.id,date:ips.utils.time.readable(commentData.comment.date),form:ips.templates.render('remotecommenting.replyForm',{user:this._member,replyingToComment:true,replyingTo:commentData.user.username,replyingToText:ips.getString('rcReplyingTo',{username:commentData.user.username}),formURL:ips.getSetting('baseURL')+'?app=rcs&module=comments&controller=post&guid='+this._guid,csrf:this._member.csrfKey,topicID:this._topicData.topicId}),likes:likesHTML,commentURL:this._topicData.topicUrl+'&do=findComment&comment='+commentData.comment.id,locked:!(this._topicData.status=='open'),hidden:commentData.comment.hidden==="1",showReply:(this._member&&this._topicData.status=='open'&&!commentData.comment.hidden==="1"),quoteData:JSON.stringify(commentData.comment.quoteData)}));},_renderLikes:function(likesCount,hasLiked){return ips.templates.render('remotecommenting.likes',{count:likesCount,text:(likesCount>0)?ips.pluralize(ips.getString('rcLikes'),likesCount):likesCount,hasLiked:hasLiked,showLike:this._member.id});},_updateSize:function(){var currentSize=$('body').outerHeight();this._postMessage('iframeSize',{size:currentSize});},_postMessage:function(method,obj){var allowedURLs=ips.getSetting('rcAllowedURLs');if(!allowedURLs||!_.isArray(allowedURLs)||!allowedURLs.length){return;}
var content=JSON.stringify(_.extend(obj||{},{method:method}));for(var i=0;i<allowedURLs.length;i++){try{window.top.postMessage(content,allowedURLs[i]);}catch(err){}}}});}(jQuery,_));;