We need to use page body event delegation so it will work with any element even with the ones added through ajax, in this case the annotation comments box form. By doing this way we do not need this code on the server response anymore. Furthermore JS events defined at ajax responses are not part of application javascript and are lost when restoring a page from browser cache, you can try to apply the same event delegation technique to the `erb` file and it wont work just because events added dinamically are not treated the same than `application.js` code. To reproduce the error: 1. Load an annotatable draft version 2. Move to any other page 3. Go back Now "Publish comment" button wont work.
6 lines
248 B
Plaintext
6 lines
248 B
Plaintext
<% if comment.errors.any? %>
|
|
$("#comments-box-<%= @annotation.id %> a.publish-comment").hide();
|
|
$("#js-comment-form-annotation-<%= annotation.id %>").toggle();
|
|
$("#js-comment-form-annotation-<%= annotation.id %> textarea").focus();
|
|
<% end %>
|