From dd6b62cca83cfd5e00b2cb96a112103906d0db0a Mon Sep 17 00:00:00 2001 From: Michael Wiencek Date: Mon, 29 Dec 2014 01:32:12 -0600 Subject: [PATCH] Use event delegation --- batch-add-recording-relationships.user.js | 52 +++++++++++++---------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/batch-add-recording-relationships.user.js b/batch-add-recording-relationships.user.js index 0f49693..3a93ac6 100644 --- a/batch-add-recording-relationships.user.js +++ b/batch-add-recording-relationships.user.js @@ -665,23 +665,36 @@ function batch_recording_rels() { $(".tbl > thead > tr").append("Performance Attributes"); - var date_element = $('') - .attr('type', "text") + var $date_element = $('') + .attr('type', 'text') .addClass('date') + .addClass('bpr-date-input') .val("yyyy-mm-dd") - .css({"color": "#ddd", "width": "7em", "border": "1px #999 solid"}) - .bind("focus", function () { + .css({ color : "#ddd", "width": "7em", border: "1px #999 solid" }); + + $recordings.append(td( + $('part./' + + 'live/' + + 'inst./' + + 'cover') + .css("cursor", "pointer") + .data("checked", false), + ' ', + $date_element).addClass("bpr_attrs")); + + $(document) + .on('focus', 'input.bpr-date-input', function () { if (this.value === "yyyy-mm-dd") { $(this).val("").css("color", "#000"); } }) - .bind("blur", function () { + .on('blur', 'input.bpr-date-input', function () { if (this.value === "") { $(this).val("yyyy-mm-dd").css("color", "#ddd"); $(this).parent().data("date", null); } }) - .bind("input", function () { + .on('input', 'input.bpr-date-input', function () { var $input = $(this); function error() { @@ -704,23 +717,18 @@ function batch_recording_rels() { $(this).parent().data("date", parsedDate); } } - }); + }) + .on('click', 'span.bpr-attr', function () { + var $this = $(this); + var checked = !$this.data('checked'); - $recordings.append(td( - $('part./' + - 'live/' + - 'inst./' + - 'cover') - .css("cursor", "pointer") - .data("checked", false) - .click(function () { - var checked = !$(this).data("checked"); - $(this).data("checked", checked) - .css({"background": checked ? "blue": "inherit", - "color": checked ? "white" : "black"}); - }), - ' ', - date_element).addClass("bpr_attrs")); + $this + .data('checked', checked) + .css({ + background: checked ? 'blue': 'inherit', + color: checked ? 'white' : 'black' + }); + }) // Style buttons