comparison options/options.js @ 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 688d75e554e0
children 46c0595f2dcc
comparison
equal deleted inserted replaced
56:d863a1c9be15 57:3c97046c2348
27 feedReadersForm.elements['move-down'].textContent = 27 feedReadersForm.elements['move-down'].textContent =
28 browser.i18n.getMessage('feedReaderMoveDownButton'); 28 browser.i18n.getMessage('feedReaderMoveDownButton');
29 feedReadersForm.elements['remove'].textContent = 29 feedReadersForm.elements['remove'].textContent =
30 browser.i18n.getMessage('feedReaderRemoveButton'); 30 browser.i18n.getMessage('feedReaderRemoveButton');
31 feedReadersForm.addEventListener('change', this); 31 feedReadersForm.addEventListener('change', this);
32 // FIXME remove once the Firefox ESR release supports SubmitEvent
33 if (typeof SubmitEvent === 'undefined') {
34 for (let element of [
35 feedReadersForm.elements['move-up'],
36 feedReadersForm.elements['move-down'],
37 feedReadersForm.elements['remove']
38 ]) {
39 element.addEventListener('click', ev => {
40 ev.preventDefault();
41 let submitEvent = new Event('submit', {
42 'bubbles':true,
43 'cancelable':true
44 });
45 submitEvent.submitter = ev.target;
46 feedReadersForm.dispatchEvent(submitEvent)
47 });
48 }
49 }
32 50
33 let addFeedReaderForm = document.forms['add-feed-reader']; 51 let addFeedReaderForm = document.forms['add-feed-reader'];
34 addFeedReaderForm.elements['add'].textContent = 52 addFeedReaderForm.elements['add'].textContent =
35 browser.i18n.getMessage('feedReaderAddButton'); 53 browser.i18n.getMessage('feedReaderAddButton');
36 let titleElement = addFeedReaderForm.elements['title']; 54 let titleElement = addFeedReaderForm.elements['title'];
223 } else if (ev.type === 'submit' && ev.target.id === 'feed-readers') { 241 } else if (ev.type === 'submit' && ev.target.id === 'feed-readers') {
224 // remove feed reader or move feed reader up or down 242 // remove feed reader or move feed reader up or down
225 ev.preventDefault(); 243 ev.preventDefault();
226 244
227 let feedReaders = this.serializeFeedReaders(); 245 let feedReaders = this.serializeFeedReaders();
228 if (ev.explicitOriginalTarget.name === 'move-up') { 246 if (ev.submitter.name === 'move-up') {
229 if (this.selectedFeedReader - 1 < 0) { 247 if (this.selectedFeedReader - 1 < 0) {
230 // the first feed reader is selected 248 // the first feed reader is selected
231 return; 249 return;
232 } 250 }
233 [feedReaders[this.selectedFeedReader - 1], 251 [feedReaders[this.selectedFeedReader - 1],
234 feedReaders[this.selectedFeedReader]] = 252 feedReaders[this.selectedFeedReader]] =
235 [feedReaders[this.selectedFeedReader], 253 [feedReaders[this.selectedFeedReader],
236 feedReaders[this.selectedFeedReader - 1]]; 254 feedReaders[this.selectedFeedReader - 1]];
237 this.selectedFeedReader--; 255 this.selectedFeedReader--;
238 } else if (ev.explicitOriginalTarget.name === 'move-down') { 256 } else if (ev.submitter.name === 'move-down') {
239 if (this.selectedFeedReader + 1 === feedReaders.length) { 257 if (this.selectedFeedReader + 1 === feedReaders.length) {
240 // the last feed reader is selected 258 // the last feed reader is selected
241 return; 259 return;
242 } 260 }
243 [feedReaders[this.selectedFeedReader + 1], 261 [feedReaders[this.selectedFeedReader + 1],
244 feedReaders[this.selectedFeedReader]] = 262 feedReaders[this.selectedFeedReader]] =
245 [feedReaders[this.selectedFeedReader], 263 [feedReaders[this.selectedFeedReader],
246 feedReaders[this.selectedFeedReader + 1]]; 264 feedReaders[this.selectedFeedReader + 1]];
247 this.selectedFeedReader++; 265 this.selectedFeedReader++;
248 } else if (ev.explicitOriginalTarget.name === 'remove') { 266 } else if (ev.submitter.name === 'remove') {
249 feedReaders.splice(this.selectedFeedReader, 1); 267 feedReaders.splice(this.selectedFeedReader, 1);
250 this.selectedFeedReader--; 268 this.selectedFeedReader--;
251 } 269 }
252 browser.storage.sync.set({feedReaders}); 270 browser.storage.sync.set({feedReaders});
253 console.log('set feedReaders to ', feedReaders); 271 console.log('set feedReaders to ', feedReaders);