Sugar for comment sending.
- Do not send if comment empty - Disable submit button while submit is in progress
This commit is contained in:
parent
f6f04c69e0
commit
1ec9ea2dd5
@ -49,40 +49,45 @@ $(document).ready(function () {
|
|||||||
form.submit(function(event) {
|
form.submit(function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
$.ajax({
|
if ($('#comment').val()) {
|
||||||
type: 'POST',
|
$('#add_comment').attr("disabled", "disabled");
|
||||||
url: form.attr('action'),
|
$.ajax({
|
||||||
data: form.serialize(),
|
type: 'POST',
|
||||||
dataType: 'json',
|
url: form.attr('action'),
|
||||||
success: function(data)
|
data: form.serialize(),
|
||||||
{
|
dataType: 'json',
|
||||||
$('#comment').val('');
|
success: function(data)
|
||||||
|
{
|
||||||
if (data.result) {
|
$('#comment').val('');
|
||||||
$('#comments_list')
|
if (data.result) {
|
||||||
.replaceWith(data.comments);
|
$('#comments_list')
|
||||||
var lastComment = $('#comments_list')
|
.replaceWith(data.comments);
|
||||||
.find('div.comment')
|
var lastComment = $('#comments_list')
|
||||||
.last();
|
.find('div.comment')
|
||||||
lastComment.effect('highlight', {color: 'green'}, 401);
|
.last();
|
||||||
$('html, body').animate({
|
lastComment.effect('highlight', {color: 'green'}, 401);
|
||||||
scrollTop: lastComment.offset().top
|
$('html, body').animate({
|
||||||
}, 750);
|
scrollTop: lastComment.offset().top
|
||||||
} else {
|
}, 750);
|
||||||
var newMessage = $('#genericErrorTemplate').clone();
|
} else {
|
||||||
newMessage
|
var newMessage = $('#genericErrorTemplate').clone();
|
||||||
.find('.contents')
|
newMessage
|
||||||
.text(data.message.message);
|
.find('.contents')
|
||||||
var commentsAlert = $('#comments_alerts');
|
.text(data.message.message);
|
||||||
commentsAlert
|
var commentsAlert = $('#comments_alerts');
|
||||||
.empty()
|
commentsAlert
|
||||||
.append(newMessage);
|
.empty()
|
||||||
$('html, body').animate({
|
.append(newMessage);
|
||||||
scrollTop: commentsAlert.offset().top
|
$('html, body').animate({
|
||||||
}, 750);
|
scrollTop: commentsAlert.offset().top
|
||||||
|
}, 750);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
$('#add_comment').removeAttr("disabled");
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user