aboutsummaryrefslogtreecommitdiff
path: root/js/redirectorpage.js
diff options
context:
space:
mode:
authorEinar Egilsson <einar@einaregilsson.com>2019-12-12 10:07:21 +0000
committerEinar Egilsson <einar@einaregilsson.com>2019-12-12 10:07:21 +0000
commit72e3f6da46d4e8586e9d1982453dc9f3f7d4b1c2 (patch)
tree01ef4547baaf8ab2d79f9d363f3fe12501a046a7 /js/redirectorpage.js
parent0fcc8c5e734d5e3ea769c5ef7be9f2200c3aca06 (diff)
Fix inline handlers
Diffstat (limited to 'js/redirectorpage.js')
-rw-r--r--js/redirectorpage.js43
1 files changed, 25 insertions, 18 deletions
diff --git a/js/redirectorpage.js b/js/redirectorpage.js
index fd5be8c..482838f 100644
--- a/js/redirectorpage.js
+++ b/js/redirectorpage.js
@@ -99,12 +99,7 @@ function updateBindings() {
}
}
-function indexFromClickEvent(ev) {
- return parseInt(ev.target.getAttribute('data-index') || ev.target.parentNode.getAttribute('data-index'));
-}
-
-function duplicateRedirect(ev) {
- let index = indexFromClickEvent(ev);
+function duplicateRedirect(index) {
let redirect = new Redirect(REDIRECTS[index]);
REDIRECTS.splice(index, 0, redirect);
@@ -115,8 +110,7 @@ function duplicateRedirect(ev) {
saveChanges();
}
-function toggleDisabled(ev) {
- let index = indexFromClickEvent(ev);
+function toggleDisabled(index) {
let redirect = REDIRECTS[index];
redirect.disabled = !redirect.disabled
updateBindings();
@@ -124,11 +118,7 @@ function toggleDisabled(ev) {
}
-function moveUp(ev) {
- if (ev.target.classList.contains('disabled')) {
- return;
- }
- let index = indexFromClickEvent(ev);
+function moveUp(index) {
let prev = REDIRECTS[index-1];
REDIRECTS[index-1] = REDIRECTS[index];
REDIRECTS[index] = prev;
@@ -136,11 +126,7 @@ function moveUp(ev) {
saveChanges();
}
-function moveDown(ev) {
- if (ev.target.classList.contains('disabled')) {
- return;
- }
- let index = indexFromClickEvent(ev);
+function moveDown(index) {
let next = REDIRECTS[index+1];
REDIRECTS[index+1] = REDIRECTS[index];
REDIRECTS[index] = next;
@@ -171,6 +157,27 @@ function pageLoad() {
if(navigator.userAgent.toLowerCase().indexOf("chrome") > -1){
show('#storage-sync-option');
}
+
+
+ //Setup event listeners
+ el('#hide-message').addEventListener('click', hideMessage);
+ el('#storage-sync-option input').addEventListener('click', toggleSyncSetting);
+
+ el('.redirect-rows').addEventListener('click', function(ev) {
+ let action = ev.target.getAttribute('data-action');
+
+ //We clone and re-use nodes all the time, so instead of attaching and removing event handlers endlessly we just put
+ //a data-action attribute on them with the name of the function that should be called...
+ if (!action) {
+ return;
+ }
+
+ let handler = window[action];
+
+ let index = parseInt(ev.target.getAttribute('data-index'));
+
+ handler(index);
+ });
}
pageLoad(); \ No newline at end of file