LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 let runAsyncQueue = []; | 18 let runAsyncQueue; |
19 | 19 |
20 var Utils = exports.Utils = { | 20 var Utils = exports.Utils = { |
21 systemPrincipal: null, | 21 systemPrincipal: null, |
22 getString: function(id) | 22 getString: function(id) |
23 { | 23 { |
24 return id; | 24 return id; |
25 }, | 25 }, |
26 runAsync: function(callback, thisPtr) | 26 |
| 27 // This function can take additional parameters. Second paramater will be |
| 28 // passed as this variable to the callback and any additional parameters as |
| 29 // callback parameters. |
| 30 runAsync: function(callback) |
27 { | 31 { |
28 callback = callback.bind.apply(callback, Array.prototype.slice.call(argument
s, 1)); | 32 callback = callback.bind.apply(callback, Array.prototype.slice.call(argument
s, 1)); |
| 33 |
| 34 if (typeof runAsyncQueue == "undefined") |
| 35 { |
| 36 runAsyncQueue = (document.readyState == "loading" ? [] : null); |
| 37 if (runAsyncQueue) |
| 38 { |
| 39 // Hack: Opera will happily run asynchronous actions while scripts are |
| 40 // loading, queue them until the document is ready. |
| 41 let loadHandler = function() |
| 42 { |
| 43 document.removeEventListener("DOMContentLoaded", loadHandler, false); |
| 44 |
| 45 let queue = runAsyncQueue; |
| 46 runAsyncQueue = null; |
| 47 for each (let callback in queue) |
| 48 { |
| 49 try |
| 50 { |
| 51 callback(); |
| 52 } |
| 53 catch(e) |
| 54 { |
| 55 Cu.reportError(e); |
| 56 } |
| 57 } |
| 58 }; |
| 59 document.addEventListener("DOMContentLoaded", loadHandler, false); |
| 60 } |
| 61 } |
| 62 |
29 if (runAsyncQueue) | 63 if (runAsyncQueue) |
30 runAsyncQueue.push(callback); | 64 runAsyncQueue.push(callback); |
31 else | 65 else |
32 window.setTimeout(callback, 0); | 66 window.setTimeout(callback, 0); |
33 }, | 67 }, |
34 get appLocale() | 68 get appLocale() |
35 { | 69 { |
36 var locale = chrome.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); | 70 var locale = chrome.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); |
37 this.__defineGetter__("appLocale", function() {return locale}); | 71 this.__defineGetter__("appLocale", function() {return locale}); |
38 return this.appLocale; | 72 return this.appLocale; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 return selectedItem; | 133 return selectedItem; |
100 }, | 134 }, |
101 | 135 |
102 getDocLink: function(linkID) | 136 getDocLink: function(linkID) |
103 { | 137 { |
104 var Prefs = require("prefs").Prefs; | 138 var Prefs = require("prefs").Prefs; |
105 var docLink = Prefs.documentation_link; | 139 var docLink = Prefs.documentation_link; |
106 return docLink.replace(/%LINK%/g, linkID).replace(/%LANG%/g, Utils.appLocale
); | 140 return docLink.replace(/%LINK%/g, linkID).replace(/%LANG%/g, Utils.appLocale
); |
107 } | 141 } |
108 }; | 142 }; |
109 | |
110 Utils.runAsync.enable = function() | |
111 { | |
112 // Hack: Opera will happily run asynchronous actions while scripts are | |
113 // loading, queue them until Utils.runAsync.enable() is called. | |
114 if (!runAsyncQueue) | |
115 return; | |
116 | |
117 let queue = runAsyncQueue; | |
118 runAsyncQueue = null; | |
119 for each (let callback in queue) | |
120 { | |
121 try | |
122 { | |
123 callback(); | |
124 } | |
125 catch(e) | |
126 { | |
127 Cu.reportError(e); | |
128 } | |
129 } | |
130 } | |
LEFT | RIGHT |