$(document).ready(function () { $.ajax({ url: "/blog/getComments", data: { url: window.location.pathname }, beforeSend: function () { $("#comment-list").html("

Loading Comments

"); }, success: function (data) { $("#comment-list").html(data); }, error: function () { $("#comment-list").html(""); } }); $('.blog .info-box').each((el) => { }); }); $('#commentForm').submit(function (event) { event.preventDefault(); addComment(); }); var addComment = function () { if ($('#commentField').val() !== '') { var comment = $('#commentField').val(); comment.replace("\n", "
"); var item; $.ajax({ url: "/blog/comment", method: 'POST', data: { url: window.location.pathname, comment: comment }, beforeSend: function () { item = $(`
  • Du

    jetzt gerade

    ${comment}

  • `); $('#comment-list').prepend(item); $('#commentField').attr('disabled', ''); $('#addComment').attr('disabled', ''); }, success: function (data) { console.log(data); if (data.success) { $('#commentField').val(''); addSnackbar('success', 'Dein Kommentar wurde erfolgreich veröffentlicht!'); item .find('.item-avatar').attr('src', data.content.profilePicture).attr('alt', data.content.username) .find('.item-user a').attr('href', data.content.profileUrl).text(data.content.displayname); item.find('.item-avatar-container .loadingSpinner').fadeOut(); setTimeout(() => { item.find('.item-avatar-container .loadingSpinner').remove(); item.find('.item-avatar-container') .addClass('text-center') .append('') .find('.fa').fadeIn(); }, 500); setTimeout(() => { item.find('.item-avatar-container .fa').fadeOut(); }, 1500); setTimeout(() => { item.find('.item-avatar-container') .empty() .removeClass('text-center') .append(``) .find('img').fadeIn(); }, 2000); // $('.loading-container', item).css('background-color', '#28b62c'); // $('.loading-container i', item) // .removeClass('fa-cog').removeClass('fa-spin') // .addClass('fa-check').css('color', '#fff'); // $('.content h3 small', item).hide() // .html(`von ${data.content.displayname} / ${data.content.date}`).fadeIn(); // $('.loading-container', item).delay(2000).fadeOut(2000); // $('.comment-well', item).prepend(``); // $('.comment-well img', item).fadeIn(2000); // $('.image-placeholder', item).remove(); // wait(8000); // $('.content', item).removeClass('small'); // $('.comment-count').text(parseInt($('.comment-count').text()) + 1); } else { addSnackbar('danger', data.message); } }, error: function (data) { console.log(data); $('#notice-container').html(''); $('div.loading-container', item).css('background-color', '#ff4136'); $('div.loading-container i', item).removeClass('fa-cog').removeClass('fa-spin').addClass('fa-exclamation').css("color", '#fff'); $(item).delay(3000).fadeOut(2000); }, complete: function () { $('#commentField').removeAttr('disabled'); $('#addComment').html('Kommentar senden').removeAttr('disabled'); } }); } }; function wait(ms) { var start = new Date().getTime(); var end = start; while (end < start + ms) { end = new Date().getTime(); } } function likeDislike(postID) { $.ajax({ type: "POST", url: "/blog/like", data: { postID: postID }, success: function (data) { if (data == "no-user") { $('#loginModal').modal('show'); } else { data = data.split(":"); $('.like-toggle-icon').toggleClass('-checked'); $('.like-count').text(data[1]); } } }); }