Simplify initialization code for tags links

By using an event delegation handler on document body there is no need
to check if element was already initialized (idempotency) anymore.
This commit is contained in:
Senén Rodero Rodríguez
2020-07-10 18:12:04 +02:00
parent 45a80af793
commit 149ce945c0

View File

@@ -4,9 +4,7 @@
initialize: function() {
var $tag_input;
$tag_input = $("input.js-tag-list");
$("body .js-add-tag-link").each(function() {
if ($(this).data("initialized") !== "yes") {
$(this).on("click", function() {
$("body").on("click", ".js-add-tag-link", function() {
var current_tags, name;
name = "\"" + ($(this).text()) + "\"";
current_tags = $tag_input.val().split(",").filter(Boolean);
@@ -17,8 +15,6 @@
}
$tag_input.val(current_tags.join(","));
return false;
}).data("initialized", "yes");
}
});
}
};