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

Delta Between Two Patch Sets: options.js

Issue 29321198: Issue 2376 - Implement custom filters in new options page (Closed)
Left Patch Set: Addressed initial comments Created July 8, 2015, 6:13 p.m.
Right Patch Set: Nit fixes Created July 15, 2015, 2:35 p.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 | « options.html ('k') | skin/options.css » ('j') | 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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 table.appendChild(template); 100 table.appendChild(template);
101 } 101 }
102 this.items.length = 0; 102 this.items.length = 0;
103 }; 103 };
104 104
105 function onToggleSubscriptionClick(e) 105 function onToggleSubscriptionClick(e)
106 { 106 {
107 e.preventDefault(); 107 e.preventDefault();
108 var subscriptionUrl = e.target.parentNode.dataset.access; 108 var subscriptionUrl = e.target.parentNode.dataset.access;
109 if (!e.target.checked) 109 if (!e.target.checked)
110 removeSubscription(subscriptionUrl); 110 {
111 ext.backgroundPage.sendMessage(
112 {
113 type: "subscriptions.remove",
114 url: subscriptionUrl
115 });
116 }
111 else 117 else
112 addEnableSubscription(subscriptionUrl); 118 addEnableSubscription(subscriptionUrl);
113 } 119 }
114 120
115 function onAddLanguageSubscriptionClick(e) 121 function onAddLanguageSubscriptionClick(e)
116 { 122 {
117 e.preventDefault(); 123 e.preventDefault();
118 var url = this.parentNode.dataset.access; 124 var url = this.parentNode.dataset.access;
119 addEnableSubscription(url); 125 addEnableSubscription(url);
120 } 126 }
121 127
122 function onRemoveFilterClick() 128 function onRemoveFilterClick()
123 { 129 {
124 var filter = this.parentNode.dataset.access; 130 var filter = this.parentNode.dataset.access;
125 removeFilter(filter); 131 ext.backgroundPage.sendMessage(
132 {
133 type: "filters.remove",
134 text: filter
135 });
126 } 136 }
127 137
128 collections.popular = new Collection( 138 collections.popular = new Collection(
129 [ 139 [
130 { 140 {
131 id: "recommend-list-table", 141 id: "recommend-list-table",
132 onClick: onToggleSubscriptionClick 142 onClick: onToggleSubscriptionClick
133 } 143 }
134 ]); 144 ]);
135 collections.langs = new Collection( 145 collections.langs = new Collection(
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 var searchStyle = E("search-style"); 356 var searchStyle = E("search-style");
347 if (!this.value) 357 if (!this.value)
348 searchStyle.innerHTML = ""; 358 searchStyle.innerHTML = "";
349 else 359 else
350 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }"; 360 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }";
351 } 361 }
352 362
353 function isEnterPressed(e) 363 function isEnterPressed(e)
354 { 364 {
355 // e.keyCode has been deprecated so we attempt to use e.key 365 // e.keyCode has been deprecated so we attempt to use e.key
356 // keyCode "13" corresponds to "Enter" 366 if ("key" in e)
357 return (e.key && e.key == "Enter") || (!e.key && e.keyCode == 13); 367 return e.key == "Enter";
Sebastian Noack 2015/07/09 12:12:15 Please don't duplicate the check for presence of e
saroyanm 2015/07/09 16:31:42 Done.
368 return e.keyCode == 13; // keyCode "13" corresponds to "Enter"
358 } 369 }
359 370
360 // Initialize navigation sidebar 371 // Initialize navigation sidebar
361 ext.backgroundPage.sendMessage( 372 ext.backgroundPage.sendMessage(
362 { 373 {
363 type: "app.get", 374 type: "app.get",
364 what: "addonVersion" 375 what: "addonVersion"
365 }, 376 },
366 function(addonVersion) 377 function(addonVersion)
367 { 378 {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 addWhitelistedDomain(); 422 addWhitelistedDomain();
412 }, false); 423 }, false);
413 E("import-blockingList-button").addEventListener("click", function() 424 E("import-blockingList-button").addEventListener("click", function()
414 { 425 {
415 var url = E("blockingList-textbox").value; 426 var url = E("blockingList-textbox").value;
416 addEnableSubscription(url); 427 addEnableSubscription(url);
417 delete document.body.dataset.dialog; 428 delete document.body.dataset.dialog;
418 }, false); 429 }, false);
419 430
420 // Advanced tab 431 // Advanced tab
421 var filterTextbox = document.querySelector("#custom-filter-add input"); 432 var filterTextbox = document.querySelector("#custom-filters-add input");
422 placeholderValue = ext.i18n.getMessage("options_customFilters_textbox_placeh older"); 433 placeholderValue = ext.i18n.getMessage("options_customFilters_textbox_placeh older");
423 filterTextbox.setAttribute("placeholder", placeholderValue); 434 filterTextbox.setAttribute("placeholder", placeholderValue);
424 function addCustomFilters() 435 function addCustomFilters()
425 { 436 {
437 var filterText = filterTextbox.value;
426 ext.backgroundPage.sendMessage( 438 ext.backgroundPage.sendMessage(
427 { 439 {
428 type: "filter.parse", 440 type: "filters.add",
429 text: filterTextbox.value 441 text: filterText
430 },
431 function(result)
432 {
433 if (result.error)
434 {
435 alert(result.error);
436 return;
437 }
438 if (result.filter)
439 {
440 ext.backgroundPage.sendMessage(
441 {
442 type: "filters.add",
443 text: result.filter.text
444 });
445 }
446
447 filterTextbox.value = "";
448 }); 442 });
449 } 443 filterTextbox.value = "";
450 E("custom-filter-add").addEventListener("submit", function(e) 444 }
445 E("custom-filters-add").addEventListener("submit", function(e)
451 { 446 {
452 e.preventDefault(); 447 e.preventDefault();
453 addCustomFilters(); 448 addCustomFilters();
454 }, false); 449 }, false);
455 var customFilterEditButtons = document.querySelectorAll("#custom-filters-edi t-wrapper button"); 450 var customFilterEditButtons = document.querySelectorAll("#custom-filters-edi t-wrapper button");
456 E("custom-filters-edit-wrapper").addEventListener("click", function(e) 451 E("custom-filters-edit-wrapper").addEventListener("click", function(e)
457 { 452 {
458 var target = null; 453 var target = null;
459 if (e.target.tagName == "BUTTON") 454 if (e.target.localName == "button")
Thomas Greiner 2015/07/09 11:07:56 Use `e.target.localName == "button"` instead becau
saroyanm 2015/07/09 16:31:42 Done.
460 target = e.target; 455 target = e.target;
461 else if (e.target.parentElement.tagName == "BUTTON") 456 else if (e.target.parentElement.localName == "button")
462 target = e.target.parentElement; 457 target = e.target.parentElement;
463 else 458 else
464 return; 459 return;
Thomas Greiner 2015/07/09 11:07:56 The most flexible way to achieve this is to go up
saroyanm 2015/07/09 16:31:42 Should we keep it as it is now and add merge it in
Thomas Greiner 2015/07/10 12:38:53 Yes, either in #2357 or a later review.
465 460
466 var id = target.id; 461 var id = target.id;
467 E("custom-filters").classList.toggle("mode-edit"); 462 E("custom-filters").classList.toggle("mode-edit");
Sebastian Noack 2015/07/09 12:12:15 classList.toggle() isn't supported in older Safari
saroyanm 2015/07/09 16:31:42 According to MDN it's supported from 5.1, but webk
Sebastian Noack 2015/07/10 07:31:00 It might be that I confused this with the second p
468 if (id == "custom-filters-edit-btn") 463 if (id == "custom-filters-show-edit")
469 editCustomFilters(); 464 editCustomFilters();
470 else if (id == "custom-filters-save-btn") 465 else if (id == "custom-filters-raw-save")
471 { 466 {
472 ext.backgroundPage.sendMessage( 467 ext.backgroundPage.sendMessage(
473 { 468 {
474 type: "filters.importRaw", 469 type: "filters.importRaw",
475 text: E("custom-filters-raw").value 470 text: E("custom-filters-raw").value
476 }); 471 });
477 } 472 }
478 }, false); 473 }, false);
479 } 474 }
480 475
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 var message = { 586 var message = {
592 type: messageType, 587 type: messageType,
593 url: url 588 url: url
594 }; 589 };
595 if (title) 590 if (title)
596 message.title = title; 591 message.title = title;
597 if (homepage) 592 if (homepage)
598 message.homepage = homepage; 593 message.homepage = homepage;
599 594
600 ext.backgroundPage.sendMessage(message); 595 ext.backgroundPage.sendMessage(message);
601 }
602
603 function removeSubscription(url)
604 {
605 ext.backgroundPage.sendMessage(
606 {
607 type: "subscriptions.remove",
608 url: url
609 });
610 }
611
612 function removeFilter(filter)
613 {
614 ext.backgroundPage.sendMessage(
615 {
616 type: "filters.remove",
617 text: filter
618 });
619 } 596 }
620 597
621 function onFilterMessage(action, filter) 598 function onFilterMessage(action, filter)
622 { 599 {
623 switch (action) 600 switch (action)
624 { 601 {
625 case "added": 602 case "added":
626 updateFilter(filter); 603 updateFilter(filter);
627 updateShareLink(); 604 updateShareLink();
628 break; 605 break;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 link: link 692 link: link
716 }, callback); 693 }, callback);
717 } 694 }
718 695
719 ext.onMessage.addListener(function(message) 696 ext.onMessage.addListener(function(message)
720 { 697 {
721 switch (message.type) 698 switch (message.type)
722 { 699 {
723 case "app.listen": 700 case "app.listen":
724 if (message.action == "addSubscription") 701 if (message.action == "addSubscription")
725 showAddSubscriptionDialog(message.args[0]); 702 {
703 E("blockingList-textbox").value = message.args[0].url;
704 openDialog("customlist");
705 }
706 else if (message.action == "error")
707 {
708 alert(message.args.join("\n"));
709 }
726 break; 710 break;
727 case "filters.listen": 711 case "filters.listen":
728 onFilterMessage(message.action, message.args[0]); 712 onFilterMessage(message.action, message.args[0]);
729 break; 713 break;
730 case "subscriptions.listen": 714 case "subscriptions.listen":
731 onSubscriptionMessage(message.action, message.args[0]); 715 onSubscriptionMessage(message.action, message.args[0]);
732 break; 716 break;
733 } 717 }
734 }); 718 });
735 719
736 ext.backgroundPage.sendMessage( 720 ext.backgroundPage.sendMessage(
737 { 721 {
738 type: "app.listen", 722 type: "app.listen",
739 filter: ["addSubscription"] 723 filter: ["addSubscription", "error"]
740 }); 724 });
741 ext.backgroundPage.sendMessage( 725 ext.backgroundPage.sendMessage(
742 { 726 {
743 type: "filters.listen", 727 type: "filters.listen",
744 filter: ["added", "loaded", "removed"] 728 filter: ["added", "loaded", "removed"]
745 }); 729 });
746 ext.backgroundPage.sendMessage( 730 ext.backgroundPage.sendMessage(
747 { 731 {
748 type: "subscriptions.listen", 732 type: "subscriptions.listen",
749 filter: ["added", "disabled", "homepage", "removed", "title"] 733 filter: ["added", "disabled", "homepage", "removed", "title"]
750 }); 734 });
751 735
752 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 736 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
753 })(); 737 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld