function enableFormSubmitButton(){document.getElementById("submitButton").disabled=!1}function handlePopoverContentLoading(){$("[data-userprofilepopover]").popover({html:!0,trigger:"hover",delay:{show:1e3,hide:100},placement:"bottom",content:function(){var n="tmp-id-"+$.now(),t=$(this).data("username"),i="/api/user/about?username="+t;return userProfilePopupContents(i,n)}})}function removeCommentForm(){document.getElementById("commentForm").remove()}function setWaitingStatus(){$("#submit-comment-button").text("hold on tight...");$("#submit-comment-button").attr("disabled","disabled")}function toggleThingExpand(n){n.height<80?(n.style.height="auto",n.style.width="100%",n.style.maxWidth="100%",n.style.objectFit="contain"):(n.style.height="80px",n.style.width="80px",n.style.objectFit="cover")}function toggleMediaThingExpand(n){var t=n.getAttribute("data-media-source");n.height<80?(n.src=t,n.style.height="auto",n.style.width="100%",n.style.maxWidth="100%",n.style.objectFit="contain"):(n.style.height="80px",n.style.width="80px",n.style.objectFit="cover")}function toggleVideoExpand(n){var u=n.getAttribute("data-expanded"),f=n.getAttribute("data-videoId"),t,i,r;u=="false"?(t=document.createElement("div"),t.setAttribute("class","embed-responsive embed-responsive-16by9"),i=document.createElement("iframe"),i.setAttribute("src","https://www.youtube.com/embed/"+f),t.appendChild(i),n.appendChild(t),n.setAttribute("data-expanded",!0)):(r=n.childNodes[3],n.removeChild(r),n.setAttribute("data-expanded",!1))}function handleLikeToggle(n){var t=n.getAttribute("data-thingId");postAjax("/api/thinglikes/togglethinglike/",{ThingId:t},function(t){var r,i;console.log(t);r=JSON.parse(t);r?(i=parseInt(n.querySelector("span").textContent),n.querySelector("span").textContent=i-1):(i=parseInt(n.querySelector("span").textContent),n.querySelector("span").textContent=i+1)});n.firstElementChild.classList.toggle("thing-liked")}function handleCommentLikeToggle(n){var t=n.getAttribute("data-likeToggleCommentId");postAjax("/api/commentlikes/togglecommentlike/",{CommentId:t},function(t){var r=JSON.parse(t),i;r?(i=parseInt(n.querySelector("span").textContent),n.querySelector("span").textContent=i-1):(i=parseInt(n.querySelector("span").textContent),n.querySelector("span").textContent=i+1)});n.firstElementChild.classList.toggle("comment-liked")}function postAjax(n,t,i){var u=typeof t=="string"?t:Object.keys(t).map(function(n){return encodeURIComponent(n)+"="+encodeURIComponent(t[n])}).join("&"),r=new XMLHttpRequest;return r.open("POST",n),r.onreadystatechange=function(){r.readyState>3&&r.status==200&&i(r.responseText)},r.setRequestHeader("X-Requested-With","XMLHttpRequest"),r.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),r.send(u),r}function handleDeleteComment(n){var t=$("div").find(`[data-commentId='${n}']`);t.toggleClass("comment-container-selected-for-deletion");bootbox.confirm({message:"Are you sure you wish to delete this comment?",centerVertical:!0,swapButtonOrder:!0,backdrop:!0,closeButton:!1,buttons:{confirm:{label:"Yes, delete it",className:"btn btn-outline-primary btn-sm"},cancel:{label:"No, I changed my mind",className:"btn btn-outline-danger btn-sm"}},callback:function(i){i?(console.log("User confirmed, will delete the comment with Id: "+n),$.ajax({type:"DELETE",url:"/api/comment/deletecomment/",data:{Id:n},success:function(n){console.log(n);t.remove()},error:function(n){console.error("Error:",n);t.toggleClass("comment-container-selected-for-deletion")}})):(console.log("User aborted"),t.toggleClass("comment-container-selected-for-deletion"))}})}function userProfilePopupContents(n,t){return $.ajax({url:n,type:"GET",dataType:"json",cache:!0,success:function(n){var r=moment.utc(n.JoinedDate),i="Joined: "+r.fromNow();i+="<br>";i+="Written comments: "+n.CommentsWritten;i+="<br>";i+="Submitted posts: "+n.PostsSubmitted;i+="<br>";i+="Liked posts: "+n.PostsLiked;i+="<br>";i+="Liked comments: "+n.CommentsLiked;$("#"+t).html(i)}}),'<div id="'+t+'">loading...<\/div>'}function handleEditComment(n){var t=$("div").find(`[data-commentId='${n}']`);t.hide();editForm=$("div").find(`[data-editFormForCommentId='${n}']`);editForm.show()}function setCommentEditWaitingStatus(n){document.getElementById("submit-editedComment-button-"+n).disabled=!0;document.getElementById("submit-editedComment-button-"+n).innerHTML="hold on tight..."}function removeCommentEditForm(n){$.ajax({type:"GET",url:"/api/comment/",data:{Id:n},success:function(t){document.getElementById("comment-content-"+n).innerHTML=t.ContentFormatted},error:function(n){console.error("Error:",n)}});var t=$("div").find(`[data-commentId='${n}']`);t.show();editForm=$("div").find(`[data-editFormForCommentId='${n}']`);editForm.hide();document.getElementById("submit-editedComment-button-"+n).disabled=!1;document.getElementById("submit-editedComment-button-"+n).innerHTML="save"}function cancelCommentEditing(n){var t=$("div").find(`[data-commentId='${n}']`);t.show();editForm=$("div").find(`[data-editFormForCommentId='${n}']`);editForm.hide()}function handleLoginRequired(n){$(n).popover({html:!0,trigger:"focus",content:"We're sorry but you'll have to Log in in order to do that.",placement:"bottom"});window.navigator.vibrate(50);$(n).popover("show")}function handleLoadMoreReplies(n){var r=document.querySelector("[data-commentId='"+n+"']"),i,u,t,f;r&&(i=r.querySelector(".comment-container"),i&&(i.style.display="none"));u=document.getElementById("show-replies-for-comment-"+n);u.style.display="none";t=document.getElementById("comment-replies-container-forcomment-"+n);t.style="visible";f=Handlebars.compile(document.getElementById("comment-reply-template").innerHTML);$.ajax({type:"GET",url:"/api/commentReplies/",data:{Id:n},success:function(n){t.innerHTML=null;var i=f(n);t.innerHTML+=i;handlePopoverContentLoading();renderTimestamps()},error:function(n){console.error("Error:",n)}})}function handleAddCommentReply(n,t){var i=document.getElementById("add-comment-reply-form-container-for-comment-"+n),r,u,f;i&&(i.style="visible",r=Handlebars.compile(document.getElementById("comment-reply-form-template").innerHTML),u={Id:n,ThingId:t},i.innerHTML=null,f=r(u),i.innerHTML=f)}function cancelAddCommentReplyForComment(n){addCommentReplyForm=$("div").find(`[data-addCommentFormForCommentId='${n}']`);addCommentReplyForm.hide()}function setAddCommentReplyWaitingStatus(n){document.getElementById("submit-add-comment-reply-button-"+n).disabled=!0;document.getElementById("submit-add-comment-reply-button-"+n).innerHTML="hold on tight..."}function removeAddCommentReplyForm(n){addCommentReplyForm=$("div").find(`[data-addCommentFormForCommentId='${n}']`);addCommentReplyForm.hide()}function renderTimestamps(){$("[data-utcdate]").each(function(){var n=moment.utc($(this).attr("data-utcdate"));$(this).text(n.fromNow());$(this).attr("title",n.local().format("MMMM Do YYYY, h:mm:ss a"))})}function handleNotificationStatus(){var n=document.getElementById("notificationStatus"),t;n&&(t=n.getAttribute("data-username"),$.ajax({type:"GET",url:"/api/v1/notifications/status?username="+t,success:function(t){t.HasUnreadNotifications===!0&&(n.setAttribute("class","fas fa-bell unread-notifications"),n.setAttribute("title","You have "+t.UnreadNotificationsCount+" unread notifications."))},error:function(n){console.error("Error:",n)}}))}function handleDeleteCommentReplyNotification(n){$.ajax({type:"DELETE",url:"api/v1/notifications/commentreplynotification?id="+n,success:function(){var t=$("div").find(`[data-notificationid='${n}']`);t.remove();handleNotificationStatus()},error:function(n){console.error("Error:",n)}})}function handleDeleteThingReplyNotification(n){$.ajax({type:"DELETE",url:"api/v1/notifications/thingreplynotification?id="+n,success:function(){var t=$("div").find(`[data-notificationid='${n}']`);t.remove();handleNotificationStatus()},error:function(n){console.error("Error:",n)}})}$(window).click(function(n){$(".navbar-collapse").hasClass("show")&&($(".navbar-collapse").removeClass("show"),n.preventDefault())});$(".navbar-collapse").click(function(n){n.stopPropagation()});$(document).ready(function(){var n=document.getElementById("postContent"),t;n!=null&&(t=new SimpleMDE({element:document.getElementById("postContent"),autoDownloadFontAwesome:!1,spellChecker:!1,toolbar:["bold","italic","strikethrough","heading","quote","unordered-list","link","image","preview"]}));renderTimestamps();$(".popover-dismiss").popover({trigger:"focus"});$(function(){$('[data-toggle="popover"]').popover()});handlePopoverContentLoading();handleNotificationStatus();$('.nav-tabs a[href="#thing-replies"]').trigger("shown.bs.tab");document.location.hash&&setTimeout(function(){var n=document.location.hash.substr(1),t=document.getElementById(n),i=document.location.hash.replace("#comment-content-",""),r=$("div").find(`[data-commentId='${i}']`);r.toggleClass("highlight-comment");t.scrollIntoView(!0);window.scrollBy(0,-55)},10)});$('a[data-toggle="tab"]').on("shown.bs.tab",function(n){var t=n.target.getAttribute("data-notification-area");if(t==="thing-replies"){var i=document.getElementById("notificationStatus"),r=i.getAttribute("data-username"),u=document.getElementById("thing-replies");u.innerHTML=null;$.ajax({type:"GET",url:"/api/v1/notifications/thingreplies?username="+r,success:function(n){if(n){var t=Handlebars.compile(document.getElementById("thing-reply-notification-template").innerHTML),i=t(n);u.innerHTML+=i;renderTimestamps();handlePopoverContentLoading()}},error:function(n){console.error("Error:",n)}})}if(t==="comment-replies"){var i=document.getElementById("notificationStatus"),r=i.getAttribute("data-username"),f=document.getElementById("comment-replies");f.innerHTML=null;$.ajax({type:"GET",url:"/api/v1/notifications/commentreplies?username="+r,success:function(n){if(n){var t=Handlebars.compile(document.getElementById("comment-reply-notification-template").innerHTML),i=t(n);f.innerHTML+=i;renderTimestamps();handlePopoverContentLoading()}},error:function(n){console.error("Error:",n)}})}})