$(document).on("click", "#alert_close", function() { $(this).parent().alert('close'); }); $(document).ready(function () { $("#save_comment").click(function(e) { $("#message_comment").html(''); var new_c_count = parseInt($("#c_comments").html())+1; $.ajax({ url: '/inc/add_comment.php?act=normal', type: 'POST', headers : { 'X-Csrf-Token': $('meta[name="csrf-token"]').attr('content') }, data: { gallery_id: $("#gallery_id").val(), comment_text: $("#comment_text").val() }, success:function(response_main){ var response_split = response_main.split(","); var response = response_split[0]; if(response == 'not_logged') { $("#message_comment").html('
You have to be logged in for commenting to this gallery.
'); } else if(response == 'empty') { $("#message_comment").html('
Where is your comment?
'); } else if(response == 'too_less') { $("#message_comment").html('
Your comment must contain at least 6 characters.
'); } else if(response == 'too_much') { $("#message_comment").html('
Your comment must not contain more than 5000 characters.
'); } else if(response == 'duplicated') { $("#message_comment").html('
You are not allowed to enter duplicated comment.
'); } else if(response == 'common_error') { $("#message_comment").html('
There was a problem adding this gallery to favorites, please refresh page and try again.
'); } else if(response == 'success') { var coins = response_split[1]; $(".head a").hide(); $("#c_comments").html(new_c_count); $("#comment_text").hide(); $("#save_comment").hide(); $(".emoji").hide(); $("#message_comment").html('
Your comment has been posted successfully!
'); listComment(); var cleanCoins = $('.coin_text').text().replace(/,/g, ''); var reward = coins - cleanCoins; $(".reward").html('+'+new Intl.NumberFormat().format(reward)); if(reward > 0){ $(".reward").show(); $(".reward").effect( "bounce", "slow" ); $(".reward").fadeOut('fast',function(){ }); $(".coin_text").text(new Intl.NumberFormat().format(coins)); } } else { $("#message_comment").html('
There was a problem adding this gallery to favorites, please refresh page and try again.
'); } }, error: function(xhr, textStatus, error){ $("#message_comment").html('
There was a problem adding your comment, please refresh page and try again.
'); } }); return false; }); }); function postReply(commentID) { $(document).ready(function () { $("#comment_text").val(''); $("#comment_text").show(); $(".emoji").show(); $("#comment_text").focus(); var user_text = $("#user_text_"+commentID).text(); $("#comment_text").attr("placeholder", "Enter your reply for "+ user_text +" here..."); $("#save_comment").hide(); $("#save_reply").show(); $("#cancel_reply").show(); $("#save_reply").unbind( "click"); $("#save_reply").bind( "click"); $("#cancel_reply").bind( "click"); $("#cancel_reply").click(function(e) { $("#comment_text").attr("placeholder", "Enter your comment here..."); $("#save_reply").bind( "click"); $("#save_reply").unbind( "click"); $("#cancel_reply").unbind( "click"); $("#save_comment").show(); $("#save_reply").hide(); $("#cancel_reply").hide(); }); $("#save_reply").click(function(e) { e.preventDefault(); $("#message_comment").html(''); var new_c_count = parseInt($("#c_comments").html())+1; $.ajax({ url: '/inc/add_comment.php?act=reply', type: 'POST', headers : { 'X-Csrf-Token': $('meta[name="csrf-token"]').attr('content') }, data: { reply_to: commentID, gallery_id: $("#gallery_id").val(), comment_text: $("#comment_text").val() }, beforeSend:function(response_main) { }, success:function(response_main){ var response_split = response_main.split(","); var response = response_split[0]; if(response == 'not_logged') { $("#message_comment").html('
You have to be logged in for commenting to this gallery.
'); } else if(response == 'empty') { $("#message_comment").html('
Where is your comment?
'); } else if(response == 'too_less') { $("#message_comment").html('
Your comment must contain at least 6 characters.
'); } else if(response == 'too_much') { $("#message_comment").html('
Your comment must not contain more than 5000 characters.
'); } else if(response == 'duplicated') { $("#message_comment").html('
You are not allowed to enter duplicated comment.
'); } else if(response == 'common_error') { $("#message_comment").html('
There was a problem adding this gallery to favorites, please refresh page and try again.
'); } else if(response == 'success') { var coins = response_split[1]; $(".head a").hide(); $("#c_comments").html(new_c_count); $("#comment_text").hide(); $("#save_reply").hide(); $("#cancel_reply").hide(); $(".emoji").hide(); $("#message_comment").html('
Your comment has been posted successfully!
'); listComment(); var cleanCoins = $('.coin_text').text().replace(/,/g, ''); var reward = coins - cleanCoins; $(".reward").html('+'+new Intl.NumberFormat().format(reward)); if(reward > 0){ $(".reward").show(); $(".reward").effect( "bounce", "slow" ); $(".reward").fadeOut('fast',function(){ }); $(".coin_text").text(new Intl.NumberFormat().format(coins)); } } else { $("#message_comment").html('
There was a problem adding this gallery to favorites, please refresh page and try again.
'); } }, error: function(xhr, textStatus, error){ $("#message_comment").html('
There was a problem adding your comment, please refresh page and try again.
'); }, complete:function(response) { } }); return false; }); }); } listComment(); function listComment() { $(document).ready(function () { $.post("/inc/comments.php", function (data) { if(data == 'common_error') { console.log('There was a problem listing comments for this gallery, please refresh page and try again.'); } else if(data == 'empty') { console.log('Empty response.'); } else { var data = JSON.parse(data); var comments = ""; var replies = ""; var item = ""; var parent = -1; var results = new Array(); var list = $("