Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: new-options.js

Issue 29373665: issue 4264 - centralize action handling (Closed)
Left Patch Set: Fixed ESLint conflicts Created April 26, 2017, 6:19 p.m.
Right Patch Set: Moved key handling into onKeyUp Created May 16, 2017, 10:32 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « new-options.html ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 else 467 else
468 location.href = link; 468 location.href = link;
469 }); 469 });
470 } 470 }
471 471
472 function switchTab(id) 472 function switchTab(id)
473 { 473 {
474 location.hash = id; 474 location.hash = id;
475 } 475 }
476 476
477 function execAction(action, key, element) 477 function execAction(action, element)
Thomas Greiner 2017/05/05 14:33:05 `key` is only used for keyboard-initiated actions
saroyanm 2017/05/16 10:36:42 Done.
478 { 478 {
479 switch (action) 479 switch (action)
480 { 480 {
481 case "add-domain-exception": 481 case "add-domain-exception":
482 addWhitelistedDomain(); 482 addWhitelistedDomain();
483 break; 483 break;
484 case "add-language-subscription": 484 case "add-language-subscription":
485 addEnableSubscription(findParentData(element, "access", false)); 485 addEnableSubscription(findParentData(element, "access", false));
486 break; 486 break;
487 case "add-predefined-subscription": { 487 case "add-predefined-subscription": {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 type: "filters.importRaw", 550 type: "filters.importRaw",
551 text: E("custom-filters-raw").value, 551 text: E("custom-filters-raw").value,
552 removeExisting: true 552 removeExisting: true
553 }, 553 },
554 () => 554 () =>
555 { 555 {
556 E("custom-filters").classList.remove("mode-edit"); 556 E("custom-filters").classList.remove("mode-edit");
557 }); 557 });
558 break; 558 break;
559 case "switch-tab": 559 case "switch-tab":
560 if (key == "Enter") 560 let tabId = findParentData(element, "tab", false);
561 { 561 switchTab(tabId);
562 let tabId = findParentData(element, "tab", false);
563 switchTab(tabId);
564 }
565 else if (element.hasAttribute("aria-selected"))
566 {
567 let container = findParentData(element, "action", true);
568 if (key == "ArrowLeft" || key == "ArrowUp")
569 {
570 element = element.previousElementSibling ||
571 container.lastElementChild;
572 }
573 else if (key == "ArrowRight" || key == "ArrowDown")
574 {
575 element = element.nextElementSibling ||
576 container.firstElementChild;
577 }
578 let tabId = findParentData(element, "tab", false);
579 switchTab(tabId);
580 }
581 break; 562 break;
582 case "toggle-disable-subscription": 563 case "toggle-disable-subscription":
583 ext.backgroundPage.sendMessage({ 564 ext.backgroundPage.sendMessage({
584 type: "subscriptions.toggle", 565 type: "subscriptions.toggle",
585 keepInstalled: true, 566 keepInstalled: true,
586 url: findParentData(element, "access", false) 567 url: findParentData(element, "access", false)
587 }); 568 });
588 break; 569 break;
589 case "toggle-pref": 570 case "toggle-pref":
590 ext.backgroundPage.sendMessage({ 571 ext.backgroundPage.sendMessage({
591 type: "prefs.toggle", 572 type: "prefs.toggle",
592 key: findParentData(element, "pref", false) 573 key: findParentData(element, "pref", false)
593 }); 574 });
594 break; 575 break;
595 case "toggle-remove-subscription": 576 case "toggle-remove-subscription":
596 let subscriptionUrl = findParentData(element, "access", false); 577 let subscriptionUrl = findParentData(element, "access", false);
597 if (element.getAttribute("aria-checked") == "true") 578 if (element.getAttribute("aria-checked") == "true")
Thomas Greiner 2017/05/05 14:33:05 Did you verify that this still works? The reason w
saroyanm 2017/05/16 10:36:42 It does work, until we introduce child element to
598 { 579 {
599 ext.backgroundPage.sendMessage({ 580 ext.backgroundPage.sendMessage({
600 type: "subscriptions.remove", 581 type: "subscriptions.remove",
601 url: subscriptionUrl 582 url: subscriptionUrl
602 }); 583 });
603 } 584 }
604 else 585 else
605 addEnableSubscription(subscriptionUrl); 586 addEnableSubscription(subscriptionUrl);
606 break; 587 break;
607 case "update-all-subscriptions": 588 case "update-all-subscriptions":
(...skipping 16 matching lines...) Expand all
624 if (context) 605 if (context)
625 context.classList.remove("show-context-menu"); 606 context.classList.remove("show-context-menu");
626 607
627 let actions = findParentData(e.target, "action", false); 608 let actions = findParentData(e.target, "action", false);
628 if (!actions) 609 if (!actions)
629 return; 610 return;
630 611
631 actions = actions.split(","); 612 actions = actions.split(",");
632 for (let action of actions) 613 for (let action of actions)
633 { 614 {
634 execAction(action, "Enter", e.target); 615 execAction(action, e.target);
635 } 616 }
636 } 617 }
637 618
638 function getKey(e) 619 function getKey(e)
639 { 620 {
640 // e.keyCode has been deprecated so we attempt to use e.key 621 // e.keyCode has been deprecated so we attempt to use e.key
641 if ("key" in e) 622 if ("key" in e)
642 return e.key; 623 return e.key;
643 return getKey.keys[e.keyCode]; 624 return getKey.keys[e.keyCode];
644 } 625 }
(...skipping 15 matching lines...) Expand all
660 return; 641 return;
661 642
662 let container = findParentData(element, "action", true); 643 let container = findParentData(element, "action", true);
663 if (!container || !container.hasAttribute("data-keys")) 644 if (!container || !container.hasAttribute("data-keys"))
664 return; 645 return;
665 646
666 let keys = container.getAttribute("data-keys").split(" "); 647 let keys = container.getAttribute("data-keys").split(" ");
667 if (keys.indexOf(key) < 0) 648 if (keys.indexOf(key) < 0)
668 return; 649 return;
669 650
651 if (element.getAttribute("role") == "tab")
652 {
653 if (key == "ArrowLeft" || key == "ArrowUp")
654 element = element.previousElementSibling || container.lastElementChild;
655 else if (key == "ArrowRight" || key == "ArrowDown")
656 element = element.nextElementSibling || container.firstElementChild;
657 }
658
670 let actions = container.getAttribute("data-action").split(","); 659 let actions = container.getAttribute("data-action").split(",");
671 for (let action of actions) 660 for (let action of actions)
672 { 661 {
673 execAction(action, key, element); 662 execAction(action, element);
674 } 663 }
675 } 664 }
676 665
677 function selectTabItem(tabId, container, focus) 666 function selectTabItem(tabId, container, focus)
678 { 667 {
679 // Show tab content 668 // Show tab content
680 document.body.setAttribute("data-tab", tabId); 669 document.body.setAttribute("data-tab", tabId);
681 670
682 // Select tab 671 // Select tab
683 let tabList = container.querySelector("[role='tablist']"); 672 let tabList = container.querySelector("[role='tablist']");
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 }); 1289 });
1301 ext.backgroundPage.sendMessage({ 1290 ext.backgroundPage.sendMessage({
1302 type: "subscriptions.listen", 1291 type: "subscriptions.listen",
1303 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1292 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1304 "title", "downloadStatus", "downloading"] 1293 "title", "downloadStatus", "downloading"]
1305 }); 1294 });
1306 1295
1307 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1296 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1308 window.addEventListener("hashchange", onHashChange, false); 1297 window.addEventListener("hashchange", onHashChange, false);
1309 } 1298 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld