changeset 57:3c97046c2348

Fix non-responsive buttons for managing feed readers In recent Firefox releases the "explicitOriginalTarget" property returns the associated form element instead of the originally clicked button so that the buttons for managing feed readers on the option page no longer worked. Determine the button used to submit the form using the "submitter" property of the new SubmitEvent instead. Add a polyfill for older Firefox releases not yet supporting this.
author Guido Berhoerster <guido+feed-preview@berhoerster.name>
date Wed, 06 May 2020 13:42:35 +0200
parents d863a1c9be15
children d9cc8e88d297
files options/options.js
diffstat 1 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/options/options.js	Mon Oct 28 15:04:06 2019 +0100
+++ b/options/options.js	Wed May 06 13:42:35 2020 +0200
@@ -29,6 +29,24 @@
         feedReadersForm.elements['remove'].textContent =
                 browser.i18n.getMessage('feedReaderRemoveButton');
         feedReadersForm.addEventListener('change', this);
+        // FIXME remove once the Firefox ESR release supports SubmitEvent
+        if (typeof SubmitEvent === 'undefined') {
+            for (let element of [
+                        feedReadersForm.elements['move-up'],
+                        feedReadersForm.elements['move-down'],
+                        feedReadersForm.elements['remove']
+                    ]) {
+                element.addEventListener('click', ev => {
+                    ev.preventDefault();
+                    let submitEvent = new Event('submit', {
+                        'bubbles':true,
+                        'cancelable':true
+                    });
+                    submitEvent.submitter = ev.target;
+                    feedReadersForm.dispatchEvent(submitEvent)
+                });
+            }
+        }
 
         let addFeedReaderForm = document.forms['add-feed-reader'];
         addFeedReaderForm.elements['add'].textContent =
@@ -225,7 +243,7 @@
             ev.preventDefault();
 
             let feedReaders = this.serializeFeedReaders();
-            if (ev.explicitOriginalTarget.name === 'move-up') {
+            if (ev.submitter.name === 'move-up') {
                 if (this.selectedFeedReader - 1 < 0) {
                     // the first feed reader is selected
                     return;
@@ -235,7 +253,7 @@
                         [feedReaders[this.selectedFeedReader],
                         feedReaders[this.selectedFeedReader - 1]];
                 this.selectedFeedReader--;
-            } else if (ev.explicitOriginalTarget.name === 'move-down') {
+            } else if (ev.submitter.name === 'move-down') {
                 if (this.selectedFeedReader + 1 === feedReaders.length) {
                     // the last feed reader is selected
                     return;
@@ -245,7 +263,7 @@
                         [feedReaders[this.selectedFeedReader],
                         feedReaders[this.selectedFeedReader + 1]];
                 this.selectedFeedReader++;
-            } else if (ev.explicitOriginalTarget.name === 'remove') {
+            } else if (ev.submitter.name === 'remove') {
                 feedReaders.splice(this.selectedFeedReader, 1);
                 this.selectedFeedReader--;
             }