Merge pull request #3997 from rockandror/remove_ajax_complete
Do not run all javascript after every ajax call
This commit is contained in:
@@ -173,5 +173,4 @@ $(function() {
|
|||||||
|
|
||||||
$(document).ready(initialize_modules);
|
$(document).ready(initialize_modules);
|
||||||
$(document).on("page:load", initialize_modules);
|
$(document).on("page:load", initialize_modules);
|
||||||
$(document).on("ajax:complete", initialize_modules);
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -43,23 +43,18 @@
|
|||||||
$("span#" + id + "_arrow").toggleClass("fa-minus-square").toggleClass("fa-plus-square");
|
$("span#" + id + "_arrow").toggleClass("fa-minus-square").toggleClass("fa-plus-square");
|
||||||
},
|
},
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
$("body .js-add-comment-link").each(function() {
|
$("body").on("click", ".js-add-comment-link", function() {
|
||||||
if ($(this).data("initialized") !== "yes") {
|
App.Comments.toggle_form($(this).data().id);
|
||||||
$(this).on("click", function() {
|
return false;
|
||||||
App.Comments.toggle_form($(this).data().id);
|
|
||||||
return false;
|
|
||||||
}).data("initialized", "yes");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
$("body .js-toggle-children").each(function() {
|
|
||||||
$(this).on("click", function() {
|
$("body").on("click", ".js-toggle-children", function() {
|
||||||
var children_container_id;
|
var children_container_id;
|
||||||
children_container_id = ($(this).data().id) + "_children";
|
children_container_id = ($(this).data().id) + "_children";
|
||||||
$("#" + children_container_id).toggle("slow");
|
$("#" + children_container_id).toggle("slow");
|
||||||
App.Comments.toggle_arrow(children_container_id);
|
App.Comments.toggle_arrow(children_container_id);
|
||||||
$(this).children(".js-child-toggle").toggle();
|
$(this).children(".js-child-toggle").toggle();
|
||||||
return false;
|
return false;
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,6 +31,13 @@
|
|||||||
return $(this).contents();
|
return $(this).contents();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
loadAnnotationComments: function(annotation_url, annotation_id) {
|
||||||
|
$.ajax({
|
||||||
|
method: "GET",
|
||||||
|
url: annotation_url + "/annotations/" + annotation_id + "/comments",
|
||||||
|
dataType: "script"
|
||||||
|
});
|
||||||
|
},
|
||||||
renderAnnotationComments: function(event) {
|
renderAnnotationComments: function(event) {
|
||||||
if (event.offset) {
|
if (event.offset) {
|
||||||
$("#comments-box").css({
|
$("#comments-box").css({
|
||||||
@@ -40,11 +47,7 @@
|
|||||||
if (App.LegislationAnnotatable.isMobile()) {
|
if (App.LegislationAnnotatable.isMobile()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$.ajax({
|
App.LegislationAnnotatable.loadAnnotationComments(event.annotation_url, event.annotation_id);
|
||||||
method: "GET",
|
|
||||||
url: event.annotation_url + "/annotations/" + event.annotation_id + "/comments",
|
|
||||||
dataType: "script"
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
onClick: function(event) {
|
onClick: function(event) {
|
||||||
var annotation_id, annotation_url, parents, parents_ids, target;
|
var annotation_id, annotation_url, parents, parents_ids, target;
|
||||||
@@ -108,15 +111,11 @@
|
|||||||
App.LegislationAnnotatable.highlight("#7fff9a");
|
App.LegislationAnnotatable.highlight("#7fff9a");
|
||||||
$("#comments-box textarea").focus();
|
$("#comments-box textarea").focus();
|
||||||
$("#new_legislation_annotation").on("ajax:complete", function(e, data) {
|
$("#new_legislation_annotation").on("ajax:complete", function(e, data) {
|
||||||
App.LegislationAnnotatable.app.destroy();
|
|
||||||
if (data.status === 200) {
|
if (data.status === 200) {
|
||||||
App.LegislationAnnotatable.remove_highlight();
|
App.LegislationAnnotatable.remove_highlight();
|
||||||
|
App.LegislationAnnotatable.app.annotations.runHook("annotationCreated", [data.responseJSON]);
|
||||||
$("#comments-box").html("").hide();
|
$("#comments-box").html("").hide();
|
||||||
$.ajax({
|
App.LegislationAnnotatable.loadAnnotationComments(annotation_url, data.responseJSON.id);
|
||||||
method: "GET",
|
|
||||||
url: annotation_url + "/annotations/" + data.responseJSON.id + "/comments",
|
|
||||||
dataType: "script"
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
$(e.target).find("label").addClass("error");
|
$(e.target).find("label").addClass("error");
|
||||||
$("<small class='error'>" + data.responseJSON[0] + "</small>").insertAfter($(e.target).find("textarea"));
|
$("<small class='error'>" + data.responseJSON[0] + "</small>").insertAfter($(e.target).find("textarea"));
|
||||||
|
|||||||
@@ -84,6 +84,26 @@ describe "Commenting debates" do
|
|||||||
expect(page).not_to have_content grandchild_comment.body
|
expect(page).not_to have_content grandchild_comment.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "can collapse comments after adding a reply", :js do
|
||||||
|
parent_comment = create(:comment, body: "Main comment", commentable: debate)
|
||||||
|
create(:comment, body: "First subcomment", commentable: debate, parent: parent_comment)
|
||||||
|
|
||||||
|
login_as(user)
|
||||||
|
visit debate_path(debate)
|
||||||
|
|
||||||
|
within ".comment", text: "Main comment" do
|
||||||
|
first(:link, "Reply").click
|
||||||
|
fill_in "Leave your comment", with: "It will be done next week."
|
||||||
|
click_button "Publish reply"
|
||||||
|
|
||||||
|
expect(page).to have_content("It will be done next week.")
|
||||||
|
|
||||||
|
find(".fa-minus-square").click
|
||||||
|
|
||||||
|
expect(page).not_to have_content("It will be done next week.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
scenario "Comment order" do
|
scenario "Comment order" do
|
||||||
c1 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 100,
|
c1 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 100,
|
||||||
cached_votes_total: 120, created_at: Time.current - 2)
|
cached_votes_total: 120, created_at: Time.current - 2)
|
||||||
@@ -230,6 +250,31 @@ describe "Commenting debates" do
|
|||||||
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
|
expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Reply to reply", :js do
|
||||||
|
create(:comment, commentable: debate, body: "Any estimates?")
|
||||||
|
|
||||||
|
login_as(create(:user))
|
||||||
|
visit debate_path(debate)
|
||||||
|
|
||||||
|
within ".comment", text: "Any estimates?" do
|
||||||
|
click_link "Reply"
|
||||||
|
fill_in "Leave your comment", with: "It will be done next week."
|
||||||
|
click_button "Publish reply"
|
||||||
|
end
|
||||||
|
|
||||||
|
within ".comment .comment", text: "It will be done next week" do
|
||||||
|
click_link "Reply"
|
||||||
|
fill_in "Leave your comment", with: "Probably if government approves."
|
||||||
|
click_button "Publish reply"
|
||||||
|
|
||||||
|
expect(page).not_to have_selector("form")
|
||||||
|
|
||||||
|
within ".comment" do
|
||||||
|
expect(page).to have_content "Probably if government approves."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
scenario "Errors on reply", :js do
|
scenario "Errors on reply", :js do
|
||||||
comment = create(:comment, commentable: debate, user: user)
|
comment = create(:comment, commentable: debate, user: user)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user