Skip to content

Commit

Permalink
Refactor bindRemoveButtons for improved performance
Browse files Browse the repository at this point in the history
  • Loading branch information
mpchadwick committed Mar 28, 2015
1 parent 64a7430 commit 5cd7a90
Showing 1 changed file with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<td id="delete_button_container_<%- data.id %>" class="col-delete">
<input type="hidden" class="delete-flag" name="option[delete][<%- data.id %>]" value="" />
<?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()):?>
<button title="<?php echo __('Delete') ?>" type="button"
<button id="delete_button_<%- data.id %>" title="<?php echo __('Delete') ?>" type="button"
class="action- scalable delete delete-option"
>
<span><?php echo __('Delete') ?></span>
Expand Down Expand Up @@ -100,7 +100,7 @@ require([
if (isNewOption && !this.isReadOnly) {
this.enableNewOptionDeleteButton(data.id);
}
this.bindRemoveButtons();
this.bindRemoveButton(data.id);
this.itemCount++;
this.totalItems++;
this.updateItemsCountField();
Expand Down Expand Up @@ -139,19 +139,11 @@ require([
button.removeClassName('disabled');
});
},
bindRemoveButtons: function() {
var buttons = $$('.delete-option');
for (var i = 0; i < buttons.length; i++) {
if (!$(buttons[i]).binded) {
$(buttons[i]).binded = true;
Event.observe(buttons[i], 'click', this.remove.bind(this));
}
}
bindRemoveButton: function(id) {
$('delete_button_' + id).observe('click', this.remove.bind(this));
}
};

attributeOption.bindRemoveButtons();

if ($('add_new_option_button')) {
Event.observe('add_new_option_button', 'click', attributeOption.add.bind(attributeOption));
}
Expand Down

0 comments on commit 5cd7a90

Please sign in to comment.