2016-09-15 14:46:14 +08:00
|
|
|
(function(){
|
|
|
|
|
|
|
|
function initializeComments(){
|
|
|
|
var steps = $(".step-comment");
|
|
|
|
$.each(steps, function(){
|
|
|
|
var that = $(this);
|
|
|
|
var link = that.attr("data-href");
|
|
|
|
|
2016-09-16 15:04:21 +08:00
|
|
|
$.ajax({ method: 'GET',
|
|
|
|
url: link,
|
|
|
|
beforeSend: animateSpinner(that, true) })
|
|
|
|
.done(function(data){
|
|
|
|
updateCommentHTML(that, data);
|
2016-09-15 14:46:14 +08:00
|
|
|
animateSpinner(that, false);
|
2016-09-16 15:04:21 +08:00
|
|
|
})
|
|
|
|
.always(animateSpinner(that, false));
|
2016-09-15 14:46:14 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshComments(child){
|
2016-09-15 17:45:51 +08:00
|
|
|
var parent = child.closest(".step-comment");
|
2016-09-15 14:46:14 +08:00
|
|
|
var link = parent.attr("data-href");
|
2016-09-16 15:04:21 +08:00
|
|
|
$.ajax({ method: 'GET',
|
|
|
|
url: link,
|
|
|
|
beforeSend: animateSpinner(parent, true) })
|
|
|
|
.done(function(data){
|
2016-09-15 17:45:51 +08:00
|
|
|
updateCommentHTML(parent, data);
|
2016-09-15 14:46:14 +08:00
|
|
|
animateSpinner(parent, false);
|
2016-09-16 15:04:21 +08:00
|
|
|
})
|
|
|
|
.always(animateSpinner(parent, false));
|
|
|
|
|
2016-09-15 14:46:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function commentFormOnSubmitAction(){
|
|
|
|
$(".comment-form")
|
|
|
|
.each(function() {
|
2016-09-16 17:55:10 +08:00
|
|
|
bindCommentAjax("#" + $(this).attr("id"));
|
2016-09-15 17:45:51 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function bindCommentAjax(form){
|
2016-09-16 15:04:21 +08:00
|
|
|
$(document)
|
|
|
|
.on('ajax:success', function () {
|
|
|
|
refreshComments($(form));
|
|
|
|
})
|
|
|
|
.on('ajax:error', function () {
|
|
|
|
refreshComments(form);
|
2016-09-15 14:46:14 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-15 17:45:51 +08:00
|
|
|
function updateCommentHTML(parent, data) {
|
|
|
|
$(parent.children()[0]).html(data.html);
|
2016-09-16 17:55:10 +08:00
|
|
|
var id = "#" + $(parent.find(".comment-form")).attr("id");
|
2016-09-16 15:04:21 +08:00
|
|
|
bindCommentAjax(id);
|
2016-09-15 17:45:51 +08:00
|
|
|
}
|
|
|
|
|
2016-09-15 14:46:14 +08:00
|
|
|
initializeComments();
|
|
|
|
})();
|