studs.js refactoring.
- Replacing "" by '' - Use chaining when possible - Correct the scrolling on comment correctly set.
This commit is contained in:
parent
974148550b
commit
5552cc4d9d
@ -18,18 +18,19 @@
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
$("#poll_form").submit(function (event) {
|
||||
var name = $("#name").val();
|
||||
name = name.trim();
|
||||
$('#poll_form').submit(function (event) {
|
||||
var name = $('#name').val().trim();
|
||||
|
||||
if (name.length == 0) {
|
||||
event.preventDefault();
|
||||
var newMessage = $("#nameErrorMessage").clone();
|
||||
$("#message-container").empty();
|
||||
$("#message-container").append(newMessage);
|
||||
newMessage.removeClass("hidden");
|
||||
var newMessage = $('#nameErrorMessage').clone();
|
||||
var messageContainer = $('#message-container');
|
||||
messageContainer
|
||||
.empty()
|
||||
.append(newMessage);
|
||||
newMessage.removeClass('hidden');
|
||||
$('html, body').animate({
|
||||
scrollTop: $("#message-container").offset().top
|
||||
scrollTop: messageContainer.offset().top
|
||||
}, 750);
|
||||
}
|
||||
});
|
||||
@ -45,30 +46,40 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
var form = $('#comment_form');
|
||||
|
||||
form.submit(function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
type: 'POST',
|
||||
url: form.attr('action'),
|
||||
data: form.serialize(),
|
||||
dataType: 'json',
|
||||
success: function(data)
|
||||
{
|
||||
$('#comment').val("");
|
||||
$('#comment').val('');
|
||||
|
||||
if (data.result) {
|
||||
$("#comments_list").replaceWith(data.comments);
|
||||
var lastComment = $("#comments_list").find("div.comment").last();
|
||||
$('#comments_list')
|
||||
.replaceWith(data.comments);
|
||||
var lastComment = $('#comments_list')
|
||||
.find('div.comment')
|
||||
.last();
|
||||
lastComment.effect('highlight', {color: 'green'}, 401);
|
||||
$('html, body').animate({
|
||||
scrollTop: $("#comments_alerts").offset().top
|
||||
scrollTop: lastComment.offset().top
|
||||
}, 750);
|
||||
} else {
|
||||
var newMessage = $("#genericErrorTemplate").clone();
|
||||
newMessage.find(".contents").text(data.message.message);
|
||||
$("#comments_alerts").empty().append(newMessage);
|
||||
var newMessage = $('#genericErrorTemplate').clone();
|
||||
newMessage
|
||||
.find('.contents')
|
||||
.text(data.message.message);
|
||||
var commentsAlert = $('#comments_alerts');
|
||||
commentsAlert
|
||||
.empty()
|
||||
.append(newMessage);
|
||||
$('html, body').animate({
|
||||
scrollTop: commentsAlert.offset().top
|
||||
}, 750);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user