2016-09-15 14:46:14 +08:00
|
|
|
(function(){
|
2016-09-16 21:22:24 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// // Initialize comment form.
|
|
|
|
// function initStepCommentForm(ev, $el) {
|
|
|
|
// var $form = $el.find("ul form");
|
|
|
|
//
|
|
|
|
// var $commentInput = $form.find("#comment_message");
|
|
|
|
//
|
|
|
|
// $(".help-block", $form).addClass("hide");
|
|
|
|
//
|
|
|
|
// $form
|
|
|
|
// .on("ajax:send", function (data) {
|
|
|
|
// $("#comment_message", $form).attr("readonly", true);
|
|
|
|
// })
|
|
|
|
// .on("ajax:success", function (e, data) {
|
|
|
|
// if (data.html) {
|
|
|
|
// var list = $form.parents("ul");
|
|
|
|
//
|
|
|
|
// // Remove potential "no comments" element
|
|
|
|
// list.parent().find(".content-comments")
|
|
|
|
// .find("li.no-comments").remove();
|
|
|
|
//
|
|
|
|
// list.parent().find(".content-comments")
|
|
|
|
// .prepend("<li class='comment'>" + data.html + "</li>")
|
|
|
|
// .scrollTop(0);
|
|
|
|
// list.parents("ul").find("> li.comment:gt(8)").remove();
|
|
|
|
// $("#comment_message", $form).val("");
|
|
|
|
// $(".form-group", $form)
|
|
|
|
// .removeClass("has-error");
|
|
|
|
// $(".help-block", $form)
|
|
|
|
// .html("")
|
|
|
|
// .addClass("hide");
|
|
|
|
// scrollCommentOptions(
|
|
|
|
// list.parent().find(".content-comments .dropdown-comment")
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
// .on("ajax:error", function (ev, xhr) {
|
|
|
|
// if (xhr.status === 400) {
|
|
|
|
// var messageError = xhr.responseJSON.errors.message;
|
|
|
|
//
|
|
|
|
// if (messageError) {
|
|
|
|
// $(".form-group", $form)
|
|
|
|
// .addClass("has-error");
|
|
|
|
// $(".help-block", $form)
|
|
|
|
// .html(messageError[0])
|
|
|
|
// .removeClass("hide");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
// .on("ajax:complete", function () {
|
|
|
|
// $("#comment_message", $form)
|
|
|
|
// .attr("readonly", false)
|
|
|
|
// .focus();
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // Initialize show more comments link.
|
|
|
|
// function initStepCommentsLink($el) {
|
|
|
|
// $el.find(".btn-more-comments")
|
|
|
|
// .on("ajax:success", function (e, data) {
|
|
|
|
// if (data.html) {
|
|
|
|
// var list = $(this).parents("ul");
|
|
|
|
// var moreBtn = list.find(".btn-more-comments");
|
|
|
|
// var listItem = moreBtn.parents('li');
|
|
|
|
// $(data.html).insertBefore(listItem);
|
|
|
|
// if (data.results_number < data.per_page) {
|
|
|
|
// moreBtn.remove();
|
|
|
|
// } else {
|
|
|
|
// moreBtn.attr("href", data.more_url);
|
|
|
|
// moreBtn.trigger("blur");
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // Reposition dropdown comment options
|
|
|
|
// scrollCommentOptions(listItem.closest(".content-comments")
|
|
|
|
// .find(".dropdown-comment"));
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// function initStepCommentTabAjax() {
|
|
|
|
// $(".comment-tab-link")
|
|
|
|
// .on("ajax:before", function (e) {
|
|
|
|
// var $this = $(this);
|
|
|
|
// var parentNode = $this.parents("li");
|
|
|
|
// var targetId = $this.attr("aria-controls");
|
|
|
|
//
|
|
|
|
// if (parentNode.hasClass("active")) {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
// .on("ajax:success", function (e, data) {
|
|
|
|
// if (data.html) {
|
|
|
|
// var $this = $(this);
|
|
|
|
// var targetId = $this.attr("aria-controls");
|
|
|
|
// var target = $("#" + targetId);
|
|
|
|
// var parentNode = $this.parents("ul").parent();
|
|
|
|
//
|
|
|
|
// target.html(data.html);
|
|
|
|
// initStepCommentForm(e, parentNode);
|
|
|
|
// initStepCommentsLink(parentNode);
|
|
|
|
//
|
|
|
|
// parentNode.find(".active").removeClass("active");
|
|
|
|
// $this.parents("li").addClass("active");
|
|
|
|
// target.addClass("active");
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
// .on("ajax:error", function(e, xhr, status, error) {
|
|
|
|
// // TODO
|
|
|
|
// });
|
|
|
|
// }
|
2016-09-15 14:46:14 +08:00
|
|
|
|
|
|
|
function initializeComments(){
|
|
|
|
var steps = $(".step-comment");
|
|
|
|
$.each(steps, function(){
|
|
|
|
var that = $(this);
|
|
|
|
var link = that.attr("data-href");
|
2016-09-16 21:22:24 +08:00
|
|
|
var parentNode = that.parents("ul").parent();
|
|
|
|
debugger;
|
2016-09-16 15:04:21 +08:00
|
|
|
$.ajax({ method: 'GET',
|
|
|
|
url: link,
|
|
|
|
beforeSend: animateSpinner(that, true) })
|
|
|
|
.done(function(data){
|
2016-09-16 21:22:24 +08:00
|
|
|
debugger;
|
2016-09-16 15:04:21 +08:00
|
|
|
updateCommentHTML(that, data);
|
2016-09-15 14:46:14 +08:00
|
|
|
animateSpinner(that, false);
|
2016-09-16 15:04:21 +08:00
|
|
|
})
|
2016-09-16 21:22:24 +08:00
|
|
|
.always(function(data){
|
|
|
|
debugger;
|
|
|
|
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-16 21:22:24 +08:00
|
|
|
debugger;
|
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 21:22:24 +08:00
|
|
|
debigger;
|
2016-09-16 17:55:10 +08:00
|
|
|
bindCommentAjax("#" + $(this).attr("id"));
|
2016-09-15 17:45:51 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-16 21:22:24 +08:00
|
|
|
// function bindMoreCommentButton(){
|
|
|
|
// $(".btn-more-comments")
|
|
|
|
// .each(function(){
|
|
|
|
// bindCommentAjax($(this));
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
2016-09-15 17:45:51 +08:00
|
|
|
function bindCommentAjax(form){
|
2016-09-16 15:04:21 +08:00
|
|
|
$(document)
|
|
|
|
.on('ajax:success', function () {
|
2016-09-16 21:22:24 +08:00
|
|
|
debugger;
|
|
|
|
refreshComments($(form));
|
2016-09-16 15:04:21 +08:00
|
|
|
})
|
|
|
|
.on('ajax:error', function () {
|
2016-09-16 21:22:24 +08:00
|
|
|
refreshComments(form);
|
2016-09-15 14:46:14 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-09-15 17:45:51 +08:00
|
|
|
function updateCommentHTML(parent, data) {
|
2016-09-16 17:55:10 +08:00
|
|
|
var id = "#" + $(parent.find(".comment-form")).attr("id");
|
2016-09-16 21:22:24 +08:00
|
|
|
debugger;
|
|
|
|
$(parent.children()[0]).html(data.html);
|
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();
|
|
|
|
})();
|