// -------------------------EEWEBcomment plugin MORE-----------------------------------------// (function($) { $.fn.eeweb_comments = function() { var process = function(el){ var el = $(el); var parentContainer = el.closest('.level-1'); var parent_id = el.closest('.level-1').data('parent_id'); var comment_to = el.attr('id').split("-")[1]; clnTmp = $('.hidden_form').clone() ; clnTmp.find(".parent_id").val(parent_id); clnTmp.find(".comment_to").val(comment_to); is_exist = parentContainer.find(".append_form").length; clnTmp = clnTmp.removeClass('hidden_form'); if(is_exist) { $('.append_form').remove(); } parentContainer.append(clnTmp.addClass('append_form')); $('.animated').autosize(); var comment = parentContainer.find(".reply_comment"); var stp = parseInt(comment.offset().top) - (parseInt($('.top-bar').outerHeight() + 400)); comment.focus(); } return $(this).each(function(){ $(this).on('click', function(e) { e.preventDefault(); process(this); }) }); } }(jQuery)); // -------------------------END-----------------------------------------// $(function(){ // -------------------------LOAD MORE-----------------------------------------// //hide and show loadmore button toggleLoadMore(); //append more entries function getData() { var url = $(".navigation").find("a.next").attr("href"); if (url !== undefined) { $('
').load(url + ' .toggle_box', function() { $('.navigation').remove(); $(this).appendTo('.toggle_box') .find('.comment-reply').eeweb_comments(); $('.loader').hide(); toggleLoadMore(); }); } } // click event for the tag more $("#more").click(function(e) { e.preventDefault(); $(this).css("display","none"); $('.loader').show(); //$("html, body").animate({scrollTop: $("#more").offset().top}, 500); setTimeout(function() { getData(); }); }); //hide and show next button function toggleLoadMore() { if ($(".next").length == 0) { $('a#more').css("display","none"); } else { $('a#more').css("display","block"); } } // -------------------------END-----------------------------------------// // -------------------------Toggle Comments ALL COMMENTS-----------------------------------------// $('.toggle_view').click(function(e){ e.preventDefault(); var icon = $(this).find(".fa"); var toggle_switch = $(this); if($("#clickMe").length > 0) { $(".toggle_box").css("display","block"); } else { if($(".toggle_box").css("display") == "block") { icon.removeClass("fa-chevron-down").addClass("fa-chevron-right"); $(".toggle_box").css("display","none"); if ($(".next").length > 0) { $('a#more').css("display","none"); } } else { icon.removeClass("fa-chevron-right").addClass("fa-chevron-down"); $(".toggle_box").css("display","block"); if ($(".next").length > 0) { $('a#more').css("display","block"); } } } }); // -------------------------END-----------------------------------------// // -------------------------Toggle replies-----------------------------------------// $('.comments-cont').on('click','.display_replies',function(e){ e.preventDefault(); var el = $(this); var container = el.closest('.level-1'); var comments = container.find('.replies-c'); if(container.find('.level-2').length > 0) { if( el.find(".fa").hasClass('fa-angle-right') ) { el.find(".fa").removeClass('fa-angle-right').addClass('fa-angle-down'); } else { el.find(".fa").removeClass('fa-angle-down').addClass('fa-angle-right'); } comments.slideToggle("slow"); } return false; }); // -------------------------END-----------------------------------------// //insert comment using the current display form $('#comment_form').on('submit',function(e){ e.preventDefault(); var entry_id , URI ,site_id , comment , RET ; var el = $(this); entry_id = $(this).find("input[name='entry_id']").val(); URI = $(this).find("input[name='URI']").val(); site_id = $(this).find("input[name='site_id']").val(); comment = $(this).find(".reply_comment").val(); RET = $(this).find("input[name='RET']").val(); request_type = $(this).find("input[name='request_type']").val(); var textarea = $(this).find(".reply_comment"); textarea.attr("readonly",true); el.find(':button').attr("disabled",true); var data ={ entry_id:entry_id , URI:URI, site_id:site_id , comment:comment , csrf_token:'9b2d83b3e8c619b48f6d7ac98e197073ed2377a0' , RET:'' , request_type : request_type , notify_me : 'yes' }; $.ajax({ type: "POST", url: "http://www.eeweb.de/?ACT=63&c=comment&m=eeweb_comments", dataType:'json', data: data, success: function(data) { textarea.attr("readonly",false); el.find(':button').attr("disabled",false); if(data.hasError) { el.find('.error_message').remove(); var error = $("",{ class:'error_message error' }).html(data.error_message); console.log(el); el.prepend(error); el.find(".comment").focus(); } else { var b = $(data.response); b.find('.comment-reply').eeweb_comments(); $('.toggle_box').prepend(b); textarea.val(""); el.closest('.comments-cont').find('#cnt-id').html(data.total_count); } }, error: function(xhr, status, err) { console.log("xhr: ", xhr); console.log("status: ", status); console.log("err: ", err); }, complete: function() { } }); }); function disable_state(container) { container.find(":button").attr("disabled",true); container.find(".reply_comment").attr("readonly",true); } function endable_state(container) { container.find(":button").attr("disabled",false); container.find(".reply_comment").attr("readonly",false); } //insert comment using reply button $('.toggle_box').on('submit','.reply_form',function(e){ var entry_id , URI ,site_id , comment , RET , parent_id ,comment_to , request_type; var el = $(this); var levl1Container = el.closest('.level-1'); entry_id = $(this).find("input[name='entry_id']").val(); URI = $(this).find("input[name='URI']").val(); site_id = $(this).find("input[name='site_id']").val(); comment = $(this).find(".reply_comment").val(); RET = $(this).find("input[name='RET']").val(); parent_id = $(this).find("input[name='parent_id']").val(); comment_to = $(this).find("input[name='comment_to']").val(); request_type = $(this).find("input[name='request_type']").val(); disable_state(levl1Container); var data ={ entry_id:entry_id , URI:URI, site_id:site_id , comment:comment , csrf_token:'9b2d83b3e8c619b48f6d7ac98e197073ed2377a0' , RET:'' , parent_id:parent_id , comment_to : comment_to , request_type : request_type }; $.ajax({ type: "POST", url: "http://www.eeweb.de/?ACT=63&c=comment&m=eeweb_comments", dataType:'json', data: data, success: function(data) { if(data.hasError) { el.find('.error_message').remove(); var error = $("",{ class:'error_message error' }).html(data.error_message); el.prepend(error); el.find(".comment").focus(); } else { var b = $(data.response); b.find('.comment-reply').eeweb_comments(); el.closest('.append_form').removeClass('append_form'); el.closest('.level-1').find('.number_of_replies').html(data.commentReplies); el.closest('.comments-cont').find('#cnt-id').html(data.total_count); el.replaceWith(b); el.closest('.level-1').find('.more_replies').delay(1000).slideUp("slow"); } endable_state(levl1Container); }, error: function(xhr, status, err) { console.log("xhr: ", xhr); console.log("status: ", status); console.log("err: ", err); }, complete: function() { } }); return false; }); $('.comments-cont').on('focus','.reply_comment',function(){ $(this).closest('form').find('.error_message').remove(); }); //delete comments $('.comments-cont').on('click','.delete_com',function(){ var postdata = {}; var el = $(this); var levl1Container = el.closest('.level-1'); postdata['request_type'] = "DELETE"; postdata['comment_id'] = $(this).attr("id"); disable_state(levl1Container); $.ajax({ type: "POST", url: "http://www.eeweb.de/?ACT=63&c=comment&m=eeweb_comments", dataType:'json', data: postdata, success: function(data) { if(data.hasError) { var error = $("",{ class:'error_message error' }).html(data.error_message); el.closest('.reply-status').prepend(error); setInterval(function(){ el.closest('.reply-status').find('.error_message').remove(); },2000); } else { var data_id = el.closest('.level-1').data('parent_id'); el.closest('.level-1').find('.number_of_replies').html(data.commentReplies); el.closest('.comments-cont').find('#cnt-id').html(data.total_count); if(postdata['comment_id'] == data_id) { el.closest('.level-1').remove(); } else { el.closest('.more_replies').remove(); } } endable_state(levl1Container); }, error: function(xhr, status, err) { console.log("xhr: ", xhr); console.log("status: ", status); console.log("err: ", err); }, complete: function() { } }); return false; }); //edit comments $('.comments-cont').on('click','.edit_com',function(){ var postdata = {}; var el = $(this); var template ={} ; var button = {}; var texArea = {}; template['content'] = el.closest('.cm_wrapper').html(); template['wrapper'] = el.closest('.cm_wrapper'); button['id'] = template.wrapper.find('.edit_com').attr("id"); texArea['content'] = template.wrapper.find('div:eq(0)').text(); var cm_wrapper = el.closest('.cm_wrapper'); var pid = (cm_wrapper.find('.comment-reply').data('parent')) ? cm_wrapper.find('.comment-reply').data('parent') : 0; var form_template = "
"; el.closest('.cm_wrapper').html(form_template); return false; }); //save comments $('.comments-cont').on('click','.save_com',function(){ var postdata = {}; var el = $(this); var cm_wrapper = el.closest('.cm_wrapper'); var parent_id = $(this).data('hasparents'); postdata['request_type'] = "UPDATE"; postdata['comment_id'] = $(this).attr("id"); postdata['comment'] = cm_wrapper.find('.reply_comment').val(); postdata['parent_id'] = (parent_id == 0) ? 0 :parent_id; $.ajax({ type: "POST", url: "http://www.eeweb.de/?ACT=63&c=comment&m=eeweb_comments", dataType:'json', data: postdata, success: function(data) { if(data.hasError) { var error = $("",{ class:'error_message error' }).html(data.error_message); cm_wrapper.find("div:eq(0)").prepend(error); setInterval(function(){ el.closest('.reply-status').find('.error_message').remove(); },5000); } else { var tmpl = $(data.template); tmpl.find('.comment-reply').eeweb_comments(); cm_wrapper.html(tmpl); } }, error: function(xhr, status, err) { console.log("xhr: ", xhr); console.log("status: ", status); console.log("err: ", err); }, complete: function() { } }); return false }); });