1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| $(function() {
$("#cancel-comment-reply-link").hide();
$(".reply_button").live('click', function(event) {
event.preventDefault();
var id = $(this).attr("id");
if ($("#li_comment_" + id).find('ul').size() > 0) {
$("#li_comment_" + id + " ul:first").prepend($("#comment_form_wrapper"));
} else {
$("#li_comment_" + id).append($("#comment_form_wrapper"));
}
var depth_level = $('#li_comment_' + id).data('depth-level');
$("#reply_id").attr("value", id);
$("#depth_level").attr("value", depth_level);
$("#cancel-comment-reply-link").show();
});
$("#cancel-comment-reply-link").bind("click", function(event) {
event.preventDefault();
$("#reply_id").attr("value", "");
$("#comment_wrapper").prepend($("#comment_form_wrapper"));
$(this).hide();
});
$("#comment_form").bind("submit", function(event) {
event.preventDefault();
if ($("#comment_name").val() == "")
{
alert("Please enter your name");
return false;
}
if ($("#comment_email").val() == "")
{
alert("Please enter your email");
return false;
}
var regex_email = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if (regex_email.test($("#comment_email").val()) == false) {
alert('Invalid Email Address');
return false;
}
var regex_web = /^((ftp|https?):\/\/)?(www\.)?[a-z0-9\-\.]{3,}\.[a-z]{2,3}$/;
if ($("#comment_web").val() != "" && regex_web.test($("#comment_web").val()) == false) {
alert('Invalid Website Address');
return false;
}
if ($("#comment_text").val() == "")
{
alert("Please enter your comment");
return false;
}
$.ajax({
type: "POST",
//async: false,
url: "add_comment.php",
data: $('#comment_form').serialize(),
dataType: "html",
cache: false,
beforeSend: function() {
$('#comment_wrapper').block({
message: 'Please wait....',
css: {
border: 'none',
padding: '15px',
backgroundColor: '#ccc',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px'
},
overlayCSS: {
backgroundColor: '#ffe'
}
});
},
success: function(comment) {
var reply_id = $("#reply_id").val();
if (reply_id == "") {
$("#comment_wrapper ul:first").prepend(comment);
}
else {
if ($("#li_comment_" + reply_id).find('ul').size() > 0) {
$("#li_comment_" + reply_id + " ul:first").prepend(comment);
}
else {
$("#li_comment_" + reply_id).append('<ul class="comment">' + comment + '</ul>');
}
}
$("#comment_name").attr("value", "");
$("#comment_email").attr("value", "");
$("#comment_web").attr("value", "");
$("#comment_text").attr("value", "");
$("#reply_id").attr("value", "");
$("#cancel-comment-reply-link").hide();
$("#comment_wrapper").prepend($("#comment_form_wrapper"));
$('#comment_wrapper').unblock();
},
error: function(jqXHR, textStatus, errorThrown) {
//console.log(textStatus, errorThrown);
alert(textStatus + " " + errorThrown);
}
});
});
}); |
Partager