Do not remove click event definition before defining it

Use delegated handlers instead so there is not risk to run method
multiple times.
This commit is contained in:
Senén Rodero Rodríguez
2020-07-27 11:29:37 +02:00
parent 009c33d4e5
commit 45a80af793
2 changed files with 8 additions and 8 deletions

View File

@@ -9,13 +9,13 @@
});
},
submitOnChange: function() {
$(".js-submit-on-change").off("change").on("change", function() {
$("body").on("change", ".js-submit-on-change", function() {
$(this).closest("form").submit();
return false;
});
},
toggleLink: function() {
$(".js-toggle-link").off("click").on("click", function() {
$("body").on("click", ".js-toggle-link", function() {
var toggle_txt;
$($(this).data("toggle-selector")).toggle("down");
if ($(this).data("toggle-text") !== undefined) {

View File

@@ -69,14 +69,14 @@
$("#comments-box").html("");
App.LegislationAllegations.show_comments();
$("#comments-box").show();
$.event.trigger({
$("body").trigger({
type: "renderLegislationAnnotation",
annotation_id: target.data("annotation-id"),
annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url"),
offset: target.offset().top
});
parents_ids.each(function(i, pid) {
$.event.trigger({
$("body").trigger({
type: "renderLegislationAnnotation",
annotation_id: pid,
annotation_url: target.closest(".legislation-annotatable").data("legislation-annotatable-base-url")
@@ -144,7 +144,7 @@
$("html,body").animate({
scrollTop: el.offset().top
});
$.event.trigger({
$("body").trigger({
type: "renderLegislationAnnotation",
annotation_id: ann_id,
annotation_url: el.closest(".legislation-annotatable").data("legislation-annotatable-base-url"),
@@ -188,9 +188,9 @@
},
initialize: function() {
var current_user_id;
$(document).off("renderLegislationAnnotation").on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments);
$(document).off("click", "[data-annotation-id]").on("click", "[data-annotation-id]", App.LegislationAnnotatable.onClick);
$(document).off("click", "[data-cancel-annotation]").on("click", "[data-cancel-annotation]", function(e) {
$("body").on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments);
$("body").on("click", "[data-annotation-id]", App.LegislationAnnotatable.onClick);
$("body").on("click", "[data-cancel-annotation]", function(e) {
e.preventDefault();
$("#comments-box").html("");
$("#comments-box").hide();