Skip to content

Commit

Permalink
Deferred event listener addition.
Browse files Browse the repository at this point in the history
Until after elements are attached, so that removeChild followed by
appendChild doesn't leave the element with no listeners. Fixes #230.
  • Loading branch information
Ortham committed Aug 23, 2014
1 parent 6b518a4 commit 4051894
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
26 changes: 17 additions & 9 deletions resources/report/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ var pluginMenuProto = Object.create(HTMLElement.prototype, {
var clone = document.importNode(template.content, true);

this.createShadowRoot().appendChild(clone);
}
},

this.id = 'activePluginMenu';

attachedCallback: {
value: function() {
/* Add event listeners for the menu items. */
this.shadowRoot.getElementById('editMetadata').addEventListener('click', this.onMenuItemClick, false);
this.shadowRoot.getElementById('copyMetadata').addEventListener('click', this.onMenuItemClick, false);
Expand Down Expand Up @@ -545,17 +547,19 @@ var pluginCardProto = Object.create(HTMLElement.prototype, {

var messages = document.createElement('ul');
this.appendChild(messages);
}
},

attachedCallback: {
value: function() {
this.shadowRoot.getElementById('menuButton').addEventListener('click', this.onMenuButtonClick, false);

var hoverTargets = this.shadowRoot.querySelectorAll('[title]');
for (var i = 0; i < hoverTargets.length; ++i) {
hoverTargets[i].addEventListener('mouseenter', showHoverText, false);
hoverTargets[i].addEventListener('mouseleave', hideHoverText, false);
}

}

},

detachedCallback: {
Expand Down Expand Up @@ -591,15 +595,17 @@ var pluginLIProto = Object.create(HTMLLIElement.prototype, {
var priority = document.createElement('span');
priority.className = 'priority';
this.appendChild(priority);
}
},

attachedCallback: {
value: function() {
var hoverTargets = this.shadowRoot.querySelectorAll('[title]');
for (var i = 0; i < hoverTargets.length; ++i) {
hoverTargets[i].addEventListener('mouseenter', showHoverText, false);
hoverTargets[i].addEventListener('mouseleave', hideHoverText, false);
}

}

},

detachedCallback: {
Expand Down Expand Up @@ -692,7 +698,11 @@ var messageDialogProto = Object.create(HTMLDialogElement.prototype, {
cancel.className = 'cancel';
cancel.textContent = 'Cancel';
buttons.appendChild(cancel);
}
},

attachedCallback: {
value: function() {
this.addEventListener('close', this.onClose, false);
}
},
Expand Down Expand Up @@ -849,13 +859,11 @@ var EditableTableProto = Object.create(HTMLTableElement.prototype, {
}
},

createdCallback: {

attachedCallback: {
value: function() {
/* Add new row listener. */
this.querySelector('tbody tr:last-child').addEventListener('click', this.addEmptyRow, false);
}

},

detachedCallback: {
Expand Down
12 changes: 6 additions & 6 deletions resources/report/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,12 +660,6 @@ function updateSettingsUI() {
var li = document.createElement('li');
li.setAttribute('data-folder', loot.settings.games[i].folder);

if (loot.installedGames.indexOf(loot.settings.games[i].folder) == -1) {
li.classList.toggle('disabled', true);
} else {
li.addEventListener('click', changeGame, false);
}

var icon = document.createElement('span');
icon.className = 'fa fa-fw';
li.appendChild(icon);
Expand All @@ -676,6 +670,12 @@ function updateSettingsUI() {

gameMenu.appendChild(li);

if (loot.installedGames.indexOf(loot.settings.games[i].folder) == -1) {
li.classList.toggle('disabled', true);
} else {
li.addEventListener('click', changeGame, false);
}

var row = gameTable.addRow(loot.settings.games[i]);
gameTable.setReadOnly(row, ['name','folder','type']);
}
Expand Down

0 comments on commit 4051894

Please sign in to comment.