| OLD | NEW |
| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 }, | 43 }, |
| 44 errors => | 44 errors => |
| 45 { | 45 { |
| 46 if (errors.length > 0) | 46 if (errors.length > 0) |
| 47 alert(errors.join("\n")); | 47 alert(errors.join("\n")); |
| 48 else | 48 else |
| 49 closeDialog(true); | 49 closeDialog(true); |
| 50 }); | 50 }); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // We'd rather just call window.close, but that isn't working consistently with |
| 54 // Firefox 57, even when allowScriptsToClose is passed to browser.windows.create |
| 55 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1418394 |
| 56 function closeMe() |
| 57 { |
| 58 browser.runtime.sendMessage({ |
| 59 type: "app.get", |
| 60 what: "senderId" |
| 61 }).then(tabId => browser.tabs.remove(tabId)); |
| 62 } |
| 63 |
| 53 function closeDialog(success) | 64 function closeDialog(success) |
| 54 { | 65 { |
| 55 browser.runtime.sendMessage({ | 66 browser.runtime.sendMessage({ |
| 56 type: "forward", | 67 type: "forward", |
| 57 targetPageId, | 68 targetPageId, |
| 58 payload: | 69 payload: |
| 59 { | 70 { |
| 60 type: "composer.content.finished", | 71 type: "composer.content.finished", |
| 61 remove: (typeof success == "boolean" ? success : false) | 72 remove: (typeof success == "boolean" ? success : false) |
| 62 } | 73 } |
| 63 }); | 74 }); |
| 64 window.close(); | 75 closeMe(); |
| 65 } | 76 } |
| 66 | 77 |
| 67 function init() | 78 function init() |
| 68 { | 79 { |
| 69 // Attach event listeners | 80 // Attach event listeners |
| 70 window.addEventListener("keydown", onKeyDown, false); | 81 window.addEventListener("keydown", onKeyDown, false); |
| 71 | 82 |
| 72 document.getElementById("addButton").addEventListener("click", addFilters); | 83 document.getElementById("addButton").addEventListener("click", addFilters); |
| 73 document.getElementById("cancelButton").addEventListener( | 84 document.getElementById("cancelButton").addEventListener( |
| 74 "click", closeDialog.bind(null, false) | 85 "click", closeDialog.bind(null, false) |
| 75 ); | 86 ); |
| 76 | 87 |
| 77 // Apply jQuery UI styles | 88 // Apply jQuery UI styles |
| 78 $("button").button(); | 89 $("button").button(); |
| 79 | 90 |
| 80 document.getElementById("filters").focus(); | 91 document.getElementById("filters").focus(); |
| 81 | 92 |
| 82 ext.onMessage.addListener((msg, sender, sendResponse) => | 93 ext.onMessage.addListener((msg, sender, sendResponse) => |
| 83 { | 94 { |
| 84 switch (msg.type) | 95 switch (msg.type) |
| 85 { | 96 { |
| 86 case "composer.dialog.init": | 97 case "composer.dialog.init": |
| 87 targetPageId = msg.sender; | 98 targetPageId = msg.sender; |
| 88 document.getElementById("filters").value = msg.filters.join("\n"); | 99 document.getElementById("filters").value = msg.filters.join("\n"); |
| 89 break; | 100 break; |
| 90 case "composer.dialog.close": | 101 case "composer.dialog.close": |
| 91 window.close(); | 102 closeMe(); |
| 92 break; | 103 break; |
| 93 } | 104 } |
| 94 }); | 105 }); |
| 95 | 106 |
| 96 window.removeEventListener("load", init); | 107 window.removeEventListener("load", init); |
| 97 } | 108 } |
| 98 window.addEventListener("load", init, false); | 109 window.addEventListener("load", init, false); |
| OLD | NEW |