Left: | ||
Right: |
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-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 26 matching lines...) Expand all Loading... | |
37 { | 37 { |
38 placeholder = document.createElement("li"); | 38 placeholder = document.createElement("li"); |
39 placeholder.className = "empty-placeholder"; | 39 placeholder.className = "empty-placeholder"; |
40 placeholder.textContent = ext.i18n.getMessage(text); | 40 placeholder.textContent = ext.i18n.getMessage(text); |
41 table.appendChild(placeholder); | 41 table.appendChild(placeholder); |
42 } | 42 } |
43 else if (placeholder) | 43 else if (placeholder) |
44 table.removeChild(placeholder); | 44 table.removeChild(placeholder); |
45 } | 45 } |
46 | 46 |
47 Collection.prototype._createElementQuery = function(item) | |
48 { | |
49 var access = (item.url || item.text).replace(/'/g, "\\'"); | |
50 return function(container) | |
51 { | |
52 return container.querySelector("[data-access='" + access + "']"); | |
53 }; | |
54 }; | |
55 | |
47 Collection.prototype.addItems = function() | 56 Collection.prototype.addItems = function() |
48 { | 57 { |
49 var length = Array.prototype.push.apply(this.items, arguments); | 58 var length = Array.prototype.push.apply(this.items, arguments); |
50 if (length == 0) | 59 if (length == 0) |
51 return; | 60 return; |
52 | 61 |
53 this.items.sort(function(a, b) | 62 this.items.sort(function(a, b) |
54 { | 63 { |
55 var aValue = (a.title || a.text || a.url).toLowerCase(); | 64 var aValue = (a.title || a.text || a.url).toLowerCase(); |
56 var bValue = (b.title || b.text || b.url).toLowerCase(); | 65 var bValue = (b.title || b.text || b.url).toLowerCase(); |
57 return aValue.localeCompare(bValue); | 66 return aValue.localeCompare(bValue); |
58 }); | 67 }); |
59 | 68 |
60 for (var j = 0; j < this.details.length; j++) | 69 for (var j = 0; j < this.details.length; j++) |
61 { | 70 { |
62 var table = E(this.details[j].id); | 71 var table = E(this.details[j].id); |
63 var template = table.querySelector("template"); | 72 var template = table.querySelector("template"); |
64 for (var i = 0; i < arguments.length; i++) | 73 for (var i = 0; i < arguments.length; i++) |
65 { | 74 { |
66 var item = arguments[i]; | 75 var item = arguments[i]; |
67 var text = item.title || item.url || item.text; | 76 var text = item.title || item.url || item.text; |
68 var listItem = document.createElement("li"); | 77 var listItem = document.createElement("li"); |
69 listItem.appendChild(document.importNode(template.content, true)); | 78 listItem.appendChild(document.importNode(template.content, true)); |
70 listItem.setAttribute("data-access", item.url || item.text); | 79 listItem.setAttribute("data-access", item.url || item.text); |
71 listItem.querySelector(".display").textContent = text; | 80 listItem.querySelector(".display").textContent = text; |
72 if (text) | 81 if (text) |
73 listItem.setAttribute("data-search", text.toLowerCase()); | 82 listItem.setAttribute("data-search", text.toLowerCase()); |
74 | 83 |
84 updateBlockingList(listItem, item); | |
Thomas Greiner
2016/01/27 17:16:57
This doesn't belong into Collection since it's spe
saroyanm
2016/01/28 17:00:11
We are calling this method on observer as well, Th
Thomas Greiner
2016/01/29 17:48:08
This code is only relevant for subscriptions. Howe
| |
75 var control = listItem.querySelector(".control"); | 85 var control = listItem.querySelector(".control"); |
76 if (control) | 86 if (control) |
77 { | 87 { |
78 control.addEventListener("click", this.details[j].onClick, false); | 88 control.addEventListener("click", this.details[j].onClick, false); |
79 control.checked = item.disabled == false; | 89 control.checked = item.disabled == false; |
80 } | 90 } |
81 | 91 |
82 this._setEmpty(table, null); | 92 this._setEmpty(table, null); |
83 if (table.hasChildNodes()) | 93 if (table.hasChildNodes()) |
84 table.insertBefore(listItem, table.childNodes[this.items.indexOf(item) ]); | 94 table.insertBefore(listItem, |
95 table.childNodes[this.items.indexOf(item)]); | |
Thomas Greiner
2016/01/25 15:40:32
Detail: Please use braces around it if you occupy
saroyanm
2016/01/26 18:36:19
Done.
Thomas Greiner
2016/01/27 17:16:58
Detail: What I meant with "indent using double-spa
saroyanm
2016/01/28 17:00:12
Got it, sorry for that, I was thinking that we nee
| |
85 else | 96 else |
86 table.appendChild(listItem); | 97 table.appendChild(listItem); |
87 } | 98 } |
88 } | 99 } |
89 return length; | 100 return length; |
90 }; | 101 }; |
91 | 102 |
92 Collection.prototype.removeItem = function(item) | 103 Collection.prototype.removeItem = function(item) |
93 { | 104 { |
94 var index = this.items.indexOf(item); | 105 var index = this.items.indexOf(item); |
95 if (index == -1) | 106 if (index == -1) |
96 return; | 107 return; |
97 | 108 |
98 this.items.splice(index, 1); | 109 this.items.splice(index, 1); |
110 var getListElement = this._createElementQuery(item); | |
99 for (var i = 0; i < this.details.length; i++) | 111 for (var i = 0; i < this.details.length; i++) |
100 { | 112 { |
101 var table = E(this.details[i].id); | 113 var table = E(this.details[i].id); |
102 var element = table.childNodes[index]; | 114 var element = getListElement(table); |
103 element.parentElement.removeChild(element); | 115 element.parentElement.removeChild(element); |
104 if (this.items.length == 0) | 116 if (this.items.length == 0) |
105 this._setEmpty(table, this.details[i].emptyText); | 117 this._setEmpty(table, this.details[i].emptyText); |
106 } | 118 } |
107 }; | 119 }; |
108 | 120 |
109 Collection.prototype.clearAll = function() | 121 Collection.prototype.clearAll = function() |
110 { | 122 { |
111 this.items = []; | 123 this.items = []; |
112 for (var i = 0; i < this.details.length; i++) | 124 for (var i = 0; i < this.details.length; i++) |
113 { | 125 { |
114 var table = E(this.details[i].id); | 126 var table = E(this.details[i].id); |
115 var template = table.querySelector("template"); | 127 var template = table.querySelector("template"); |
116 table.innerHTML = ""; | 128 var staticElements = []; |
Thomas Greiner
2016/01/25 15:40:33
The above two variables are no longer used.
saroyanm
2016/01/26 18:36:19
Done.
| |
117 table.appendChild(template); | 129 var element = table.firstChild; |
130 while (element) | |
131 { | |
132 if ((element.tagName == "LI" && !element.classList.contains("static")) | | | |
133 element.nodeType == 3) | |
134 table.removeChild(element); | |
135 element = element.nextSibling | |
136 } | |
137 | |
118 this._setEmpty(table, this.details[i].emptyText); | 138 this._setEmpty(table, this.details[i].emptyText); |
119 } | 139 } |
120 }; | 140 }; |
121 | 141 |
122 function onToggleSubscriptionClick(e) | 142 Collection.prototype.hasId = function(id) |
143 { | |
144 for (var i = 0; i < this.details.length; i++) | |
145 if (this.details[i].id == id) | |
146 return true; | |
147 | |
148 return false; | |
149 }; | |
150 | |
151 function updateBlockingList(listItem, subscription) | |
152 { | |
153 var dateElement = listItem.querySelector(".date"); | |
154 var timeElement = listItem.querySelector(".time"); | |
155 | |
156 if(dateElement && timeElement) | |
157 { | |
158 if (subscription.downloadStatus && | |
159 subscription.downloadStatus != "synchronize_ok") | |
160 { | |
161 var map = | |
162 { | |
163 "synchronize_invalid_url": "options_subscription_lastDownload_invalidU RL", | |
164 "synchronize_connection_error": "options_subscription_lastDownload_con nectionError", | |
165 "synchronize_invalid_data": "options_subscription_lastDownload_invalid Data", | |
166 "synchronize_checksum_mismatch": "options_subscription_lastDownload_ch ecksumMismatch" | |
167 }; | |
168 if (subscription.downloadStatus in map) | |
169 timeElement.textContent = ext.i18n.getMessage(map[subscription.downloa dStatus]); | |
170 else | |
171 timeElement.textContent = subscription.downloadStatus; | |
172 } | |
173 else if (subscription.lastDownload > 0) | |
174 { | |
175 var timedate = i18n_timeDateStrings(subscription.lastDownload * 1000); | |
176 var date = new Date(subscription.lastDownload * 1000); | |
177 dateElement.textContent = date.getFullYear() + "-" + | |
178 date.getMonth()+1 + "-" + date.getDate(); | |
179 timeElement.textContent = date.getHours() + ":" + date.getMinutes(); | |
180 } | |
181 } | |
182 var websiteElement = listItem.querySelector(".context-menu .website"); | |
183 var sourceElement = listItem.querySelector(".context-menu .source"); | |
184 if (websiteElement && subscription.homepage) | |
185 websiteElement.setAttribute("href", subscription.homepage); | |
186 if (sourceElement) | |
187 sourceElement.setAttribute("href", subscription.url); | |
188 } | |
189 | |
190 function toggleRemoveSubscription(e) | |
123 { | 191 { |
124 e.preventDefault(); | 192 e.preventDefault(); |
125 var subscriptionUrl = e.target.parentNode.getAttribute("data-access"); | 193 var subscriptionUrl = getParentAccessElement(e.target). |
194 getAttribute("data-access"); | |
126 if (!e.target.checked) | 195 if (!e.target.checked) |
127 { | 196 { |
128 ext.backgroundPage.sendMessage({ | 197 ext.backgroundPage.sendMessage({ |
129 type: "subscriptions.remove", | 198 type: "subscriptions.remove", |
130 url: subscriptionUrl | 199 url: subscriptionUrl |
131 }); | 200 }); |
132 } | 201 } |
133 else | 202 else |
134 addEnableSubscription(subscriptionUrl); | 203 addEnableSubscription(subscriptionUrl); |
135 } | 204 } |
136 | 205 |
206 function toggleDisableSubscription(e) | |
207 { | |
208 e.preventDefault(); | |
209 var subscriptionUrl = e.target.parentNode.getAttribute("data-access"); | |
210 ext.backgroundPage.sendMessage( | |
211 { | |
212 type: "subscriptions.toggle", | |
213 keepInstalled: true, | |
214 url: subscriptionUrl | |
215 }); | |
216 } | |
217 | |
137 function onAddLanguageSubscriptionClick(e) | 218 function onAddLanguageSubscriptionClick(e) |
138 { | 219 { |
139 e.preventDefault(); | 220 e.preventDefault(); |
140 var url = this.parentNode.getAttribute("data-access"); | 221 var url = this.parentNode.getAttribute("data-access"); |
141 addEnableSubscription(url); | 222 addEnableSubscription(url); |
142 } | 223 } |
143 | 224 |
144 function onRemoveFilterClick() | 225 function onRemoveFilterClick() |
145 { | 226 { |
146 var filter = this.parentNode.getAttribute("data-access"); | 227 var filter = this.parentNode.getAttribute("data-access"); |
147 ext.backgroundPage.sendMessage( | 228 ext.backgroundPage.sendMessage( |
148 { | 229 { |
149 type: "filters.remove", | 230 type: "filters.remove", |
150 text: filter | 231 text: filter |
151 }); | 232 }); |
152 } | 233 } |
153 | 234 |
154 collections.popular = new Collection( | 235 collections.popular = new Collection( |
155 [ | 236 [ |
156 { | 237 { |
157 id: "recommend-list-table", | 238 id: "recommend-list-table", |
158 onClick: onToggleSubscriptionClick | 239 onClick: toggleRemoveSubscription |
159 } | 240 } |
160 ]); | 241 ]); |
161 collections.langs = new Collection( | 242 collections.langs = new Collection( |
162 [ | 243 [ |
163 { | 244 { |
164 id: "blocking-languages-table", | 245 id: "blocking-languages-table", |
165 emptyText: "options_dialog_language_added_empty", | 246 emptyText: "options_dialog_language_added_empty", |
166 onClick: onToggleSubscriptionClick | 247 onClick: toggleRemoveSubscription |
167 }, | 248 }, |
168 { | 249 { |
169 id: "blocking-languages-dialog-table", | 250 id: "blocking-languages-dialog-table", |
170 emptyText: "options_dialog_language_added_empty" | 251 emptyText: "options_dialog_language_added_empty" |
171 } | 252 } |
172 ]); | 253 ]); |
173 collections.allLangs = new Collection( | 254 collections.allLangs = new Collection( |
174 [ | 255 [ |
175 { | 256 { |
176 id: "all-lang-table", | 257 id: "all-lang-table", |
177 emptyText: "options_dialog_language_other_empty", | 258 emptyText: "options_dialog_language_other_empty", |
178 onClick: onAddLanguageSubscriptionClick | 259 onClick: onAddLanguageSubscriptionClick |
179 } | 260 } |
180 ]); | 261 ]); |
181 collections.acceptableAds = new Collection( | 262 collections.acceptableAds = new Collection( |
182 [ | 263 [ |
183 { | 264 { |
184 id: "acceptableads-table", | 265 id: "acceptableads-table", |
185 onClick: onToggleSubscriptionClick | 266 onClick: toggleRemoveSubscription |
186 } | 267 } |
187 ]); | 268 ]); |
188 collections.custom = new Collection( | 269 collections.custom = new Collection( |
189 [ | 270 [ |
190 { | 271 { |
191 id: "custom-list-table", | 272 id: "custom-list-table", |
192 onClick: onToggleSubscriptionClick | 273 onClick: toggleRemoveSubscription |
193 } | 274 } |
194 ]); | 275 ]); |
195 collections.whitelist = new Collection( | 276 collections.whitelist = new Collection( |
196 [ | 277 [ |
197 { | 278 { |
198 id: "whitelisting-table", | 279 id: "whitelisting-table", |
199 emptyText: "options_whitelisted_empty", | 280 emptyText: "options_whitelisted_empty", |
200 onClick: onRemoveFilterClick | 281 onClick: onRemoveFilterClick |
201 } | 282 } |
202 ]); | 283 ]); |
203 collections.customFilters = new Collection( | 284 collections.customFilters = new Collection( |
204 [ | 285 [ |
205 { | 286 { |
206 id: "custom-filters-table", | 287 id: "custom-filters-table", |
207 emptyText: "options_customFilters_empty" | 288 emptyText: "options_customFilters_empty" |
208 } | 289 } |
209 ]); | 290 ]); |
291 collections.blockingLists = new Collection( | |
292 [ | |
293 { | |
294 id: "blocking-lists-table", | |
295 onClick: toggleDisableSubscription | |
296 } | |
297 ]); | |
210 | 298 |
211 function updateSubscription(subscription) | 299 function observeSubscription(subscription) |
212 { | 300 { |
213 var subscriptionUrl = subscription.url; | 301 function onObjectChanged(change) |
214 var knownSubscription = subscriptionsMap[subscriptionUrl]; | |
215 if (knownSubscription) | |
216 knownSubscription.disabled = subscription.disabled; | |
217 else | |
218 { | 302 { |
219 getAcceptableAdsURL(function(acceptableAdsUrl) | 303 for (var i = 0; i < change.length; i++) |
220 { | 304 { |
221 function onObjectChanged() | 305 var property = change[i].name; |
306 if (property == "disabled") | |
222 { | 307 { |
223 var access = (subscriptionUrl || subscription.text).replace(/'/g, "\\' "); | 308 var access = (subscription.url || |
309 subscription.text).replace(/'/g, "\\'"); | |
224 var elements = document.querySelectorAll("[data-access='" + access + " ']"); | 310 var elements = document.querySelectorAll("[data-access='" + access + " ']"); |
225 for (var i = 0; i < elements.length; i++) | 311 for (var i = 0; i < elements.length; i++) |
226 { | 312 { |
227 var element = elements[i]; | 313 var element = elements[i]; |
314 var tableId = element.parentElement ? element.parentElement.id : ""; | |
228 var control = element.querySelector(".control"); | 315 var control = element.querySelector(".control"); |
229 if (control.localName == "input") | 316 if (control && control.localName == "input") |
230 control.checked = subscription.disabled == false; | 317 control.checked = subscription.disabled == false; |
231 if (subscriptionUrl in recommendationsMap) | 318 if (subscription.url in recommendationsMap) |
232 { | 319 { |
233 var recommendation = recommendationsMap[subscriptionUrl]; | 320 var recommendation = recommendationsMap[subscription.url]; |
234 if (recommendation.type == "ads") | 321 if (recommendation.type == "ads" && |
322 (collections.langs.hasId(tableId) || | |
323 collections.allLangs.hasId(tableId))) | |
Thomas Greiner
2016/01/25 15:40:33
I've been thinking about this again. Wouldn't you
saroyanm
2016/01/26 18:36:18
I assume you are referring to the "Collection.prot
Thomas Greiner
2016/01/27 17:16:57
I guess you're right. We can leave it here for now
saroyanm
2016/01/28 17:00:11
Done, hope now it's more clear.
| |
235 { | 324 { |
236 if (subscription.disabled == false) | 325 if (subscription.disabled == false) |
237 { | 326 { |
238 collections.allLangs.removeItem(subscription); | 327 collections.allLangs.removeItem(subscription); |
239 collections.langs.addItems(subscription); | 328 collections.langs.addItems(subscription); |
240 } | 329 } |
241 else | 330 else |
242 { | 331 { |
243 collections.allLangs.addItems(subscription); | 332 collections.allLangs.addItems(subscription); |
244 collections.langs.removeItem(subscription); | 333 collections.langs.removeItem(subscription); |
245 } | 334 } |
246 } | 335 } |
247 } | 336 } |
248 } | 337 } |
249 } | 338 } |
339 else | |
340 { | |
341 var blockingListId = collections.blockingLists.details[0].id; | |
342 var blockingList = document.getElementById(blockingListId); | |
343 var listItem = blockingList.querySelector("[data-access='" + | |
344 subscription.url + "']"); | |
345 if (listItem) | |
346 updateBlockingList(listItem, subscription); | |
347 } | |
348 } | |
349 } | |
250 | 350 |
251 if (!Object.observe) | 351 if (!Object.observe) |
352 { | |
353 ["disabled", "lastDownload"].forEach(function(property) | |
354 { | |
355 subscription["$" + property] = subscription[property]; | |
356 Object.defineProperty(subscription, property, | |
252 { | 357 { |
253 // Currently only "disabled" property of subscription used for observa tion | 358 get: function() |
254 // but with Advanced tab implementation we should also add more proper ties. | |
255 ["disabled"].forEach(function(property) | |
256 { | 359 { |
257 subscription["$" + property] = subscription[property]; | 360 return this["$" + property]; |
258 Object.defineProperty(subscription, property, | 361 }, |
259 { | 362 set: function(value) |
260 get: function() | 363 { |
261 { | 364 this["$" + property] = value; |
262 return this["$" + property]; | 365 var change = Object.create(null); |
263 }, | 366 change.name = property; |
264 set: function(value) | 367 onObjectChanged([change]); |
265 { | 368 } |
266 this["$" + property] = value; | 369 }); |
267 onObjectChanged(); | 370 }); |
268 } | 371 } |
269 }); | 372 else |
270 }); | 373 { |
271 } | 374 Object.observe(subscription, onObjectChanged); |
272 else | 375 } |
273 { | 376 } |
274 Object.observe(subscription, onObjectChanged); | |
275 } | |
276 | 377 |
378 function updateSubscription(subscription) | |
379 { | |
380 var subscriptionUrl = subscription.url; | |
381 var knownSubscription = subscriptionsMap[subscriptionUrl]; | |
382 if (knownSubscription) | |
383 { | |
384 for (var param in subscription) | |
Thomas Greiner
2016/01/25 15:40:31
Detail: It's a property, not a parameter.
saroyanm
2016/01/26 18:36:19
Done.
| |
385 if (param != "title") | |
Thomas Greiner
2016/01/25 15:40:31
Why did you specifically exclude the "title" prope
saroyanm
2016/01/26 18:36:19
To use titles specified in Recommendation, so the
Thomas Greiner
2016/01/27 17:16:57
Right, forgot about that case.
It's actually tric
saroyanm
2016/01/28 17:00:11
Acknowledged.
| |
386 knownSubscription[param] = subscription[param]; | |
387 } | |
388 else | |
389 { | |
390 observeSubscription(subscription); | |
391 getAcceptableAdsURL(function(acceptableAdsUrl) | |
392 { | |
277 var collection = null; | 393 var collection = null; |
278 if (subscriptionUrl in recommendationsMap) | 394 if (subscriptionUrl in recommendationsMap) |
279 { | 395 { |
280 var recommendation = recommendationsMap[subscriptionUrl]; | 396 var recommendation = recommendationsMap[subscriptionUrl]; |
281 if (recommendation.type != "ads") | 397 if (recommendation.type != "ads") |
282 collection = collections.popular; | 398 collection = collections.popular; |
283 else if (subscription.disabled == false) | 399 else if (subscription.disabled == false) |
284 collection = collections.langs; | 400 collection = collections.langs; |
285 else | 401 else |
286 collection = collections.allLangs; | 402 collection = collections.allLangs; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 var elements = doc.documentElement.getElementsByTagName("subscription"); | 440 var elements = doc.documentElement.getElementsByTagName("subscription"); |
325 for (var i = 0; i < elements.length; i++) | 441 for (var i = 0; i < elements.length; i++) |
326 { | 442 { |
327 var element = elements[i]; | 443 var element = elements[i]; |
328 var subscription = Object.create(null); | 444 var subscription = Object.create(null); |
329 subscription.title = element.getAttribute("title"); | 445 subscription.title = element.getAttribute("title"); |
330 subscription.url = element.getAttribute("url"); | 446 subscription.url = element.getAttribute("url"); |
331 subscription.disabled = null; | 447 subscription.disabled = null; |
332 subscription.downloadStatus = null; | 448 subscription.downloadStatus = null; |
333 subscription.homepage = null; | 449 subscription.homepage = null; |
334 subscription.lastSuccess = null; | |
335 var recommendation = Object.create(null); | 450 var recommendation = Object.create(null); |
336 recommendation.type = element.getAttribute("type"); | 451 recommendation.type = element.getAttribute("type"); |
337 var prefix = element.getAttribute("prefixes"); | 452 var prefix = element.getAttribute("prefixes"); |
338 if (prefix) | 453 if (prefix) |
339 { | 454 { |
340 prefix = prefix.replace(/\W/g, "_"); | 455 prefix = prefix.replace(/\W/g, "_"); |
341 subscription.title = ext.i18n.getMessage("options_language_" + prefi x); | 456 subscription.title = ext.i18n.getMessage("options_language_" + prefi x); |
342 } | 457 } |
343 else | 458 else |
344 { | 459 { |
345 var type = recommendation.type.replace(/\W/g, "_"); | 460 var type = recommendation.type.replace(/\W/g, "_"); |
346 subscription.title = ext.i18n.getMessage("common_feature_" + type + "_title"); | 461 subscription.title = ext.i18n.getMessage("common_feature_" + type + "_title"); |
347 } | 462 } |
348 | 463 |
349 recommendationsMap[subscription.url] = recommendation; | 464 recommendationsMap[subscription.url] = recommendation; |
350 updateSubscription(subscription); | 465 updateSubscription(subscription); |
351 } | 466 } |
352 }); | 467 }); |
353 } | 468 } |
354 | 469 |
470 function getParentAccessElement(element) | |
471 { | |
472 while (!element.getAttribute("data-access")) | |
473 element = element.parentNode; | |
Thomas Greiner
2016/01/25 15:40:33
This may cause an exception if there is no parent
saroyanm
2016/01/26 18:36:19
Like it, thanks.
| |
474 | |
475 return element; | |
476 } | |
477 | |
355 function onClick(e) | 478 function onClick(e) |
356 { | 479 { |
357 var element = e.target; | 480 var element = e.target; |
358 while (true) | 481 while (true) |
359 { | 482 { |
360 if (!element) | 483 if (!element) |
484 { | |
485 var context = document.querySelector(".context"); | |
486 if (context) | |
487 context.classList.remove("context"); | |
361 return; | 488 return; |
489 } | |
362 | 490 |
363 if (element.hasAttribute("data-action")) | 491 if (element.hasAttribute("data-action")) |
364 break; | 492 break; |
365 | 493 |
366 element = element.parentElement; | 494 element = element.parentElement; |
367 } | 495 } |
368 | 496 |
369 var actions = element.getAttribute("data-action").split(","); | 497 var actions = element.getAttribute("data-action").split(","); |
370 for (var i = 0; i < actions.length; i++) | 498 for (var i = 0; i < actions.length; i++) |
371 { | 499 { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 { | 540 { |
413 type: "filters.importRaw", | 541 type: "filters.importRaw", |
414 text: E("custom-filters-raw").value | 542 text: E("custom-filters-raw").value |
415 }); | 543 }); |
416 E("custom-filters").classList.remove("mode-edit"); | 544 E("custom-filters").classList.remove("mode-edit"); |
417 break; | 545 break; |
418 case "switch-tab": | 546 case "switch-tab": |
419 document.body.setAttribute("data-tab", | 547 document.body.setAttribute("data-tab", |
420 element.getAttribute("data-tab")); | 548 element.getAttribute("data-tab")); |
421 break; | 549 break; |
550 case "update-all-subscriptions": | |
551 ext.backgroundPage.sendMessage( | |
552 { | |
553 type: "subscriptions.update" | |
554 }); | |
555 break; | |
556 case "open-context-menu": | |
557 var listItem = getParentAccessElement(element); | |
558 var contextMenu = listItem.querySelector(".content"); | |
559 listItem.classList.add("context"); | |
560 break; | |
561 case "update-now": | |
562 ext.backgroundPage.sendMessage( | |
563 { | |
564 type: "subscriptions.update", | |
565 url: getParentAccessElement(element).getAttribute("data-access") | |
566 }); | |
567 getParentAccessElement(element).classList.remove("context"); | |
Thomas Greiner
2016/01/25 15:40:33
Why not just add a "close-context-menu" action to
saroyanm
2016/01/26 18:36:19
Done.
| |
568 break; | |
569 case "website": | |
570 getParentAccessElement(element).classList.remove("context"); | |
571 break; | |
572 case "source": | |
573 getParentAccessElement(element).classList.remove("context"); | |
574 break; | |
575 case "delete": | |
Thomas Greiner
2016/01/25 15:40:33
Detail: This message name doesn't describe what it
saroyanm
2016/01/26 18:36:18
Done.
| |
576 ext.backgroundPage.sendMessage( | |
577 { | |
578 type: "subscriptions.remove", | |
579 url: getParentAccessElement(element).getAttribute("data-access") | |
580 }); | |
581 getParentAccessElement(element).classList.remove("context"); | |
582 break; | |
422 } | 583 } |
423 } | 584 } |
424 } | 585 } |
425 | 586 |
426 function onDOMLoaded() | 587 function onDOMLoaded() |
427 { | 588 { |
428 var recommendationTemplate = document.querySelector("#recommend-list-table t emplate"); | |
429 var popularText = ext.i18n.getMessage("options_popular"); | |
430 recommendationTemplate.content.querySelector(".popular").textContent = popul arText; | |
431 var languagesTemplate = document.querySelector("#all-lang-table template"); | |
432 var buttonText = ext.i18n.getMessage("options_button_add"); | |
433 languagesTemplate.content.querySelector(".button-add span").textContent = bu ttonText; | |
434 | |
435 populateLists(); | 589 populateLists(); |
436 | |
437 function onFindLanguageKeyUp() | 590 function onFindLanguageKeyUp() |
438 { | 591 { |
439 var searchStyle = E("search-style"); | 592 var searchStyle = E("search-style"); |
440 if (!this.value) | 593 if (!this.value) |
441 searchStyle.innerHTML = ""; | 594 searchStyle.innerHTML = ""; |
442 else | 595 else |
443 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }"; | 596 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }"; |
444 } | 597 } |
445 | 598 |
446 function getKey(e) | 599 function getKey(e) |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 updateShareLink(); | 851 updateShareLink(); |
699 break; | 852 break; |
700 } | 853 } |
701 } | 854 } |
702 | 855 |
703 function onSubscriptionMessage(action, subscription) | 856 function onSubscriptionMessage(action, subscription) |
704 { | 857 { |
705 switch (action) | 858 switch (action) |
706 { | 859 { |
707 case "added": | 860 case "added": |
861 updateSubscription(subscription); | |
862 updateShareLink(); | |
863 | |
864 var knownSubscription = subscriptionsMap[subscription.url]; | |
865 if (knownSubscription) | |
866 collections.blockingLists.addItems(knownSubscription); | |
867 else | |
868 collections.blockingLists.addItems(subscription); | |
869 break; | |
708 case "disabled": | 870 case "disabled": |
709 updateSubscription(subscription); | 871 updateSubscription(subscription); |
710 updateShareLink(); | 872 updateShareLink(); |
711 break; | 873 break; |
874 case "lastDownload": | |
875 updateSubscription(subscription); | |
876 break; | |
712 case "homepage": | 877 case "homepage": |
713 // TODO: NYI | 878 // TODO: NYI |
714 break; | 879 break; |
715 case "removed": | 880 case "removed": |
881 var knownSubscription = subscriptionsMap[subscription.url]; | |
716 getAcceptableAdsURL(function(acceptableAdsUrl) | 882 getAcceptableAdsURL(function(acceptableAdsUrl) |
717 { | 883 { |
718 if (subscription.url == acceptableAdsUrl) | 884 if (subscription.url == acceptableAdsUrl) |
719 { | 885 { |
720 subscription.disabled = true; | 886 subscription.disabled = true; |
721 updateSubscription(subscription); | 887 updateSubscription(subscription); |
722 } | 888 } |
723 else | 889 else |
724 { | 890 { |
725 var knownSubscription = subscriptionsMap[subscription.url]; | |
726 if (subscription.url in recommendationsMap) | 891 if (subscription.url in recommendationsMap) |
727 knownSubscription.disabled = true; | 892 knownSubscription.disabled = true; |
728 else | 893 else |
729 { | 894 { |
730 collections.custom.removeItem(knownSubscription); | 895 collections.custom.removeItem(knownSubscription); |
731 delete subscriptionsMap[subscription.url]; | 896 delete subscriptionsMap[subscription.url]; |
732 } | 897 } |
733 } | 898 } |
734 updateShareLink(); | 899 updateShareLink(); |
735 }); | 900 }); |
901 collections.blockingLists.removeItem(knownSubscription); | |
Thomas Greiner
2016/01/25 15:40:38
Detail: Semantically, updating the UI should happe
saroyanm
2016/01/26 18:36:18
Done.
| |
736 break; | 902 break; |
737 case "title": | 903 case "title": |
738 // TODO: NYI | 904 // TODO: NYI |
739 break; | 905 break; |
740 } | 906 } |
741 } | 907 } |
742 | 908 |
743 function onShareLinkClick(e) | 909 function onShareLinkClick(e) |
744 { | 910 { |
745 e.preventDefault(); | 911 e.preventDefault(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
814 filter: ["addSubscription", "error"] | 980 filter: ["addSubscription", "error"] |
815 }); | 981 }); |
816 ext.backgroundPage.sendMessage( | 982 ext.backgroundPage.sendMessage( |
817 { | 983 { |
818 type: "filters.listen", | 984 type: "filters.listen", |
819 filter: ["added", "loaded", "removed"] | 985 filter: ["added", "loaded", "removed"] |
820 }); | 986 }); |
821 ext.backgroundPage.sendMessage( | 987 ext.backgroundPage.sendMessage( |
822 { | 988 { |
823 type: "subscriptions.listen", | 989 type: "subscriptions.listen", |
824 filter: ["added", "disabled", "homepage", "removed", "title"] | 990 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" , "updated"] |
Thomas Greiner
2016/01/25 15:40:32
Detail: You removed the handling for "updated" so
saroyanm
2016/01/26 18:36:20
Done.
| |
825 }); | 991 }); |
826 | 992 |
827 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 993 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
828 })(); | 994 })(); |
OLD | NEW |