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

Delta Between Two Patch Sets: block.js

Issue 29336084: Issue 2426 - Open block.html as a popup window (Closed)
Left Patch Set: Reduce callback checking boilerplate Created Feb. 15, 2016, 3:45 p.m.
Right Patch Set: Assume createData parameter has been given Created Feb. 17, 2016, 8:50 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 | « block.html ('k') | blockElement.postload.js » ('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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 var searchParams = {}; 18 var targetPageId = null;
19 19
20 function onKeyDown(event) 20 function onKeyDown(event)
21 { 21 {
22 if (event.keyCode == 27) 22 if (event.keyCode == 27)
23 { 23 {
24 event.preventDefault(); 24 event.preventDefault();
25 closeDialog(); 25 closeDialog();
26 } 26 }
27 else if (event.keyCode == 13 && !event.shiftKey && !event.ctrlKey) 27 else if (event.keyCode == 13 && !event.shiftKey && !event.ctrlKey)
28 { 28 {
(...skipping 16 matching lines...) Expand all
45 else 45 else
46 alert(response.error); 46 alert(response.error);
47 }); 47 });
48 } 48 }
49 49
50 function closeDialog(success) 50 function closeDialog(success)
51 { 51 {
52 ext.backgroundPage.sendMessage( 52 ext.backgroundPage.sendMessage(
53 { 53 {
54 type: "forward", 54 type: "forward",
55 targetPageId: searchParams.targetPageId, 55 targetPageId: targetPageId,
56 payload: 56 payload:
57 { 57 {
58 type: "blockelement-finished", 58 type: "blockelement-finished",
59 remove: (typeof success == "boolean" ? success : false) 59 remove: (typeof success == "boolean" ? success : false)
60 } 60 }
61 }); 61 });
62 window.close(); 62 window.close();
63 } 63 }
64 64
65 function init() 65 function init()
66 { 66 {
67 // Parse the search parameters. We expect both the targetPageId and suggested
68 // filters to be provided.
69 window.location.search.substr(1).split("&").forEach(function(pair)
70 {
71 var parts = pair.split("=");
72 searchParams[parts[0]] = JSON.parse(decodeURIComponent(parts[1]));
73 });
74
75 // Attach event listeners 67 // Attach event listeners
76 window.addEventListener("keydown", onKeyDown, false); 68 window.addEventListener("keydown", onKeyDown, false);
77 69
78 document.getElementById("addButton").addEventListener("click", addFilters); 70 document.getElementById("addButton").addEventListener("click", addFilters);
79 document.getElementById("cancelButton").addEventListener( 71 document.getElementById("cancelButton").addEventListener(
80 "click", closeDialog.bind(null, false) 72 "click", closeDialog.bind(null, false)
81 ); 73 );
82 74
83 // Apply jQuery UI styles 75 // Apply jQuery UI styles
84 $("button").button(); 76 $("button").button();
85 77
86 document.getElementById("filters").value = searchParams.filters.join("\n");
87 document.getElementById("filters").focus(); 78 document.getElementById("filters").focus();
88 79
89 ext.onMessage.addListener(function(msg, sender, sendResponse) 80 ext.onMessage.addListener(function(msg, sender, sendResponse)
90 { 81 {
91 switch (msg.type) 82 switch (msg.type)
92 { 83 {
84 case "blockelement-popup-init":
85 targetPageId = msg.sender;
86 document.getElementById("filters").value = msg.filters.join("\n");
87 break;
93 case "blockelement-close-popup": 88 case "blockelement-close-popup":
94 window.close(); 89 window.close();
95 break; 90 break;
96 } 91 }
97 }); 92 });
98 93
99 window.removeEventListener("load", init); 94 window.removeEventListener("load", init);
100 } 95 }
101 window.addEventListener("load", init, false); 96 window.addEventListener("load", init, false);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld