Files
gallery3/modules/comment/js/comment.js
Tim Almdal 4c3b9e363a Refactor the comment module as part of ticket: #917 "Remove Rest Controller"
* Remove the methods create, update, delete, get_edit_form as there are not used
* Change the return when a comment is created to return the html for the new comment.
  This saves a second get request to down load the comment.
2009-11-25 08:12:50 -08:00

45 lines
1.2 KiB
JavaScript

$("document").ready(function() {
$("#g-admin-comment-button").click(function(event) {
event.preventDefault();
if (!$("#g-comment-form").length) {
$.get($(this).attr("href"),
{},
function(data) {
$("#g-comment-detail").append(data);
ajaxify_comment_form();
});
}
});
$("#g-no-comments").click(function(event) {
event.preventDefault();
if (!$("#g-comment-form").length) {
$.get($(this).attr("href"),
{},
function(data) {
$("#g-comment-detail").append(data);
ajaxify_comment_form();
});
$("#g-no-comments-yet").remove();
}
});
});
function ajaxify_comment_form() {
$("#g-comments form").ajaxForm({
dataType: "json",
success: function(data) {
if (data.result == "success") {
$("#g-comments #g-comment-detail ul").append(data.view);
$("#g-comments #g-comment-detail ul li:last").effect("highlight", {color: "#cfc"}, 8000);
$("#g-comment-form").hide(2000).remove();
$("#g-no-comments-yet").hide(2000);
} else {
if (data.form) {
$("#g-comments form").replaceWith(data.form);
ajaxify_comment_form();
}
}
}
});
}