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

Side by Side Diff: options.js

Issue 29333819: Issue 2375 - Implement "Blocking lists" section in new options page (Closed)
Patch Set: Small fixes and improved download messages for filter lists Created Feb. 3, 2016, 5:41 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 "use strict"; 18 "use strict";
19 19
20 (function() 20 (function()
21 { 21 {
22 var subscriptionsMap = Object.create(null); 22 var subscriptionsMap = Object.create(null);
23 var recommendationsMap = Object.create(null); 23 var recommendationsMap = Object.create(null);
24 var filtersMap = Object.create(null); 24 var filtersMap = Object.create(null);
25 var collections = Object.create(null); 25 var collections = Object.create(null);
26 var maxLabelId = 0; 26 var maxLabelId = 0;
27 var getMessage = ext.i18n.getMessage;
28 var filterErrors =
29 {
30 "synchronize_invalid_url": "options_filterList_lastDownload_invalidURL",
31 "synchronize_connection_error": "options_filterList_lastDownload_connectionE rror",
32 "synchronize_invalid_data": "options_filterList_lastDownload_invalidData",
33 "synchronize_checksum_mismatch": "options_filterList_lastDownload_checksumMi smatch"
34 };
27 35
28 function Collection(details) 36 function Collection(details)
29 { 37 {
30 this.details = details; 38 this.details = details;
31 this.items = []; 39 this.items = [];
32 } 40 }
33 41
34 Collection.prototype._setEmpty = function(table, text) 42 Collection.prototype._setEmpty = function(table, text)
35 { 43 {
36 var placeholder = table.querySelector(".empty-placeholder"); 44 var placeholder = table.querySelector(".empty-placeholder");
37 if (text && !placeholder) 45 if (text && !placeholder)
38 { 46 {
39 placeholder = document.createElement("li"); 47 placeholder = document.createElement("li");
40 placeholder.className = "empty-placeholder"; 48 placeholder.className = "empty-placeholder";
41 placeholder.textContent = ext.i18n.getMessage(text); 49 placeholder.textContent = getMessage(text);
42 table.appendChild(placeholder); 50 table.appendChild(placeholder);
43 } 51 }
44 else if (placeholder) 52 else if (placeholder)
45 table.removeChild(placeholder); 53 table.removeChild(placeholder);
46 } 54 }
47 55
56 Collection.prototype._createElementQuery = function(item)
57 {
58 var access = (item.url || item.text).replace(/'/g, "\\'");
59 return function(container)
60 {
61 return container.querySelector("[data-access='" + access + "']");
62 };
63 };
64
48 Collection.prototype.addItems = function() 65 Collection.prototype.addItems = function()
49 { 66 {
50 var length = Array.prototype.push.apply(this.items, arguments); 67 var length = Array.prototype.push.apply(this.items, arguments);
51 if (length == 0) 68 if (length == 0)
52 return; 69 return;
53 70
54 this.items.sort(function(a, b) 71 this.items.sort(function(a, b)
55 { 72 {
56 var aValue = (a.title || a.text || a.url).toLowerCase(); 73 var aValue = (a.title || a.text || a.url).toLowerCase();
57 var bValue = (b.title || b.text || b.url).toLowerCase(); 74 var bValue = (b.title || b.text || b.url).toLowerCase();
(...skipping 17 matching lines...) Expand all
75 if (control) 92 if (control)
76 { 93 {
77 // We use aria-labelledby to avoid triggering the control when 94 // We use aria-labelledby to avoid triggering the control when
78 // interacting with the label 95 // interacting with the label
79 control.setAttribute("aria-labelledby", labelId); 96 control.setAttribute("aria-labelledby", labelId);
80 control.addEventListener("click", this.details[j].onClick, false); 97 control.addEventListener("click", this.details[j].onClick, false);
81 } 98 }
82 99
83 this._setEmpty(table, null); 100 this._setEmpty(table, null);
84 if (table.hasChildNodes()) 101 if (table.hasChildNodes())
85 table.insertBefore(listItem, table.childNodes[this.items.indexOf(item) ]); 102 {
103 table.insertBefore(listItem,
104 table.childNodes[this.items.indexOf(item)]);
105 }
86 else 106 else
87 table.appendChild(listItem); 107 table.appendChild(listItem);
88 this.updateItem(item); 108 this.updateItem(item);
89 } 109 }
90 } 110 }
91 return length; 111 return length;
92 }; 112 };
93 113
94 Collection.prototype.removeItem = function(item) 114 Collection.prototype.removeItem = function(item)
95 { 115 {
96 var index = this.items.indexOf(item); 116 var index = this.items.indexOf(item);
97 if (index == -1) 117 if (index == -1)
98 return; 118 return;
99 119
100 this.items.splice(index, 1); 120 this.items.splice(index, 1);
121 var getListElement = this._createElementQuery(item);
101 for (var i = 0; i < this.details.length; i++) 122 for (var i = 0; i < this.details.length; i++)
102 { 123 {
103 var table = E(this.details[i].id); 124 var table = E(this.details[i].id);
104 var element = table.childNodes[index]; 125 var element = getListElement(table);
105 126
106 // Element gets removed so make sure to handle focus appropriately 127 // Element gets removed so make sure to handle focus appropriately
107 var control = element.querySelector(".control"); 128 var control = element.querySelector(".control");
108 if (control && control == document.activeElement) 129 if (control && control == document.activeElement)
109 { 130 {
110 if (!focusNextElement(element.parentElement, control)) 131 if (!focusNextElement(element.parentElement, control))
111 { 132 {
112 // Fall back to next focusable element within same tab or dialog 133 // Fall back to next focusable element within same tab or dialog
113 var focusableElement = element.parentElement; 134 var focusableElement = element.parentElement;
114 while (focusableElement) 135 while (focusableElement)
(...skipping 17 matching lines...) Expand all
132 Collection.prototype.updateItem = function(item) 153 Collection.prototype.updateItem = function(item)
133 { 154 {
134 var access = (item.url || item.text).replace(/'/g, "\\'"); 155 var access = (item.url || item.text).replace(/'/g, "\\'");
135 for (var i = 0; i < this.details.length; i++) 156 for (var i = 0; i < this.details.length; i++)
136 { 157 {
137 var table = E(this.details[i].id); 158 var table = E(this.details[i].id);
138 var element = table.querySelector("[data-access='" + access + "']"); 159 var element = table.querySelector("[data-access='" + access + "']");
139 if (!element) 160 if (!element)
140 continue; 161 continue;
141 162
142 var text = item.title || item.url || item.text; 163 var title = item.title || item.url || item.text;
143 element.querySelector(".display").textContent = text; 164 element.querySelector(".display").textContent = title;
144 if (text) 165 if (title)
145 element.setAttribute("data-search", text.toLowerCase()); 166 element.setAttribute("data-search", title.toLowerCase());
146 var control = element.querySelector(".control[role='checkbox']"); 167 var control = element.querySelector(".control[role='checkbox']");
147 if (control) 168 if (control)
148 control.setAttribute("aria-checked", item.disabled == false); 169 control.setAttribute("aria-checked", item.disabled == false);
170
171 var downloadStatus = item.downloadStatus;
172 var dateElement = element.querySelector(".date");
173 var timeElement = element.querySelector(".time");
174 if(dateElement && timeElement)
175 {
176 var error = element.querySelector(".error");
177 if (downloadStatus && downloadStatus != "synchronize_ok")
178 {
179 if (downloadStatus in filterErrors)
180 error.textContent = getMessage(filterErrors[downloadStatus]);
181 else
182 error.textContent = item.downloadStatus;
183 element.classList.add("error");
184 }
185 else if (item.lastDownload > 0)
186 {
187 var dateTime = i18n_formatDateTime(item.lastDownload * 1000);
188 dateElement.textContent = dateTime[0];
189 timeElement.textContent = dateTime[1];
190 element.classList.remove("error", "progress");
191 }
192 else
193 {
194 var text = getMessage("options_filterList_lastDownload_inProgress");
Thomas Greiner 2016/02/04 15:28:17 Interesting that you would set the text only when
saroyanm 2016/02/04 17:50:06 You are right, I've updated the implementation, A
Thomas Greiner 2016/02/04 20:23:44 Agreed, let's leave it for now if it's merely a mi
195 element.querySelector(".progress").textContent = text;
196 element.classList.add("progress");
197 }
198 }
199 var websiteElement = element.querySelector(".context-menu .website");
200 var sourceElement = element.querySelector(".context-menu .source");
201 if (websiteElement && item.homepage)
202 websiteElement.setAttribute("href", item.homepage);
203 if (sourceElement)
204 sourceElement.setAttribute("href", item.url);
149 } 205 }
150 }; 206 };
151 207
152 Collection.prototype.clearAll = function() 208 Collection.prototype.clearAll = function()
153 { 209 {
154 this.items = []; 210 this.items = [];
155 for (var i = 0; i < this.details.length; i++) 211 for (var i = 0; i < this.details.length; i++)
156 { 212 {
157 var table = E(this.details[i].id); 213 var table = E(this.details[i].id);
158 var template = table.querySelector("template"); 214 var element = table.firstChild;
159 table.innerHTML = ""; 215 while (element)
160 table.appendChild(template); 216 {
217 if (element.tagName == "LI" && !element.classList.contains("static"))
218 table.removeChild(element);
219 element = element.nextElementSibling;
220 }
221
161 this._setEmpty(table, this.details[i].emptyText); 222 this._setEmpty(table, this.details[i].emptyText);
162 } 223 }
163 }; 224 };
164 225
165 function focusNextElement(container, currentElement) 226 function focusNextElement(container, currentElement)
166 { 227 {
167 var focusables = container.querySelectorAll("a, button, input, .control"); 228 var focusables = container.querySelectorAll("a, button, input, .control");
168 focusables = Array.prototype.slice.call(focusables); 229 focusables = Array.prototype.slice.call(focusables);
169 var index = focusables.indexOf(currentElement); 230 var index = focusables.indexOf(currentElement);
170 index += (index == focusables.length - 1) ? -1 : 1; 231 index += (index == focusables.length - 1) ? -1 : 1;
171 232
172 var nextElement = focusables[index]; 233 var nextElement = focusables[index];
173 if (!nextElement) 234 if (!nextElement)
174 return false; 235 return false;
175 236
176 nextElement.focus(); 237 nextElement.focus();
177 return true; 238 return true;
178 } 239 }
179 240
180 function onToggleSubscriptionClick(e) 241 function toggleRemoveSubscription(e)
181 { 242 {
182 e.preventDefault(); 243 e.preventDefault();
183 var checkbox = e.target; 244 var subscriptionUrl = findParentData(e.target, "access", false);
184 var subscriptionUrl = checkbox.parentElement.getAttribute("data-access"); 245 if (e.target.getAttribute("aria-checked") == "true")
185 if (checkbox.getAttribute("aria-checked") == "true")
186 { 246 {
187 ext.backgroundPage.sendMessage({ 247 ext.backgroundPage.sendMessage({
188 type: "subscriptions.remove", 248 type: "subscriptions.remove",
189 url: subscriptionUrl 249 url: subscriptionUrl
190 }); 250 });
191 } 251 }
192 else 252 else
193 addEnableSubscription(subscriptionUrl); 253 addEnableSubscription(subscriptionUrl);
194 } 254 }
195 255
256 function toggleDisableSubscription(e)
257 {
258 e.preventDefault();
259 var subscriptionUrl = findParentData(e.target, "access", false);
260 ext.backgroundPage.sendMessage(
261 {
262 type: "subscriptions.toggle",
263 keepInstalled: true,
264 url: subscriptionUrl
265 });
266 }
267
196 function onAddLanguageSubscriptionClick(e) 268 function onAddLanguageSubscriptionClick(e)
197 { 269 {
198 e.preventDefault(); 270 e.preventDefault();
199 var url = this.parentNode.getAttribute("data-access"); 271 var url = findParentData(this, "access", false);
200 addEnableSubscription(url); 272 addEnableSubscription(url);
201 } 273 }
202 274
203 function onRemoveFilterClick() 275 function onRemoveFilterClick()
204 { 276 {
205 var filter = this.parentNode.getAttribute("data-access"); 277 var filter = findParentData(this, "access", false);
206 ext.backgroundPage.sendMessage( 278 ext.backgroundPage.sendMessage(
207 { 279 {
208 type: "filters.remove", 280 type: "filters.remove",
209 text: filter 281 text: filter
210 }); 282 });
211 } 283 }
212 284
213 collections.popular = new Collection( 285 collections.popular = new Collection(
214 [ 286 [
215 { 287 {
216 id: "recommend-list-table", 288 id: "recommend-list-table",
217 onClick: onToggleSubscriptionClick 289 onClick: toggleRemoveSubscription
218 } 290 }
219 ]); 291 ]);
220 collections.langs = new Collection( 292 collections.langs = new Collection(
221 [ 293 [
222 { 294 {
223 id: "blocking-languages-table", 295 id: "blocking-languages-table",
224 emptyText: "options_dialog_language_added_empty", 296 emptyText: "options_dialog_language_added_empty",
225 onClick: onToggleSubscriptionClick 297 onClick: toggleRemoveSubscription
226 }, 298 },
227 { 299 {
228 id: "blocking-languages-dialog-table", 300 id: "blocking-languages-dialog-table",
229 emptyText: "options_dialog_language_added_empty" 301 emptyText: "options_dialog_language_added_empty"
230 } 302 }
231 ]); 303 ]);
232 collections.allLangs = new Collection( 304 collections.allLangs = new Collection(
233 [ 305 [
234 { 306 {
235 id: "all-lang-table", 307 id: "all-lang-table",
236 emptyText: "options_dialog_language_other_empty", 308 emptyText: "options_dialog_language_other_empty",
237 onClick: onAddLanguageSubscriptionClick 309 onClick: onAddLanguageSubscriptionClick
238 } 310 }
239 ]); 311 ]);
240 collections.acceptableAds = new Collection( 312 collections.acceptableAds = new Collection(
241 [ 313 [
242 { 314 {
243 id: "acceptableads-table", 315 id: "acceptableads-table",
244 onClick: onToggleSubscriptionClick 316 onClick: toggleRemoveSubscription
245 } 317 }
246 ]); 318 ]);
247 collections.custom = new Collection( 319 collections.custom = new Collection(
248 [ 320 [
249 { 321 {
250 id: "custom-list-table", 322 id: "custom-list-table",
251 onClick: onToggleSubscriptionClick 323 onClick: toggleRemoveSubscription
252 } 324 }
253 ]); 325 ]);
254 collections.whitelist = new Collection( 326 collections.whitelist = new Collection(
255 [ 327 [
256 { 328 {
257 id: "whitelisting-table", 329 id: "whitelisting-table",
258 emptyText: "options_whitelisted_empty", 330 emptyText: "options_whitelisted_empty",
259 onClick: onRemoveFilterClick 331 onClick: onRemoveFilterClick
260 } 332 }
261 ]); 333 ]);
262 collections.customFilters = new Collection( 334 collections.customFilters = new Collection(
263 [ 335 [
264 { 336 {
265 id: "custom-filters-table", 337 id: "custom-filters-table",
266 emptyText: "options_customFilters_empty" 338 emptyText: "options_customFilters_empty"
267 } 339 }
268 ]); 340 ]);
341 collections.filterLists = new Collection(
342 [
343 {
344 id: "all-filter-lists-table",
345 onClick: toggleDisableSubscription
346 }
347 ]);
269 348
270 function updateSubscription(subscription) 349 function observeSubscription(subscription)
271 { 350 {
272 var subscriptionUrl = subscription.url; 351 function onObjectChanged(change)
273 var knownSubscription = subscriptionsMap[subscriptionUrl];
274 if (knownSubscription)
275 knownSubscription.disabled = subscription.disabled;
276 else
277 { 352 {
278 getAcceptableAdsURL(function(acceptableAdsUrl) 353 for (var i = 0; i < change.length; i++)
279 { 354 {
280 function onObjectChanged() 355 if (change[i].name == "disabled")
281 { 356 {
282 for (var i in collections) 357 var recommendation = recommendationsMap[subscription.url];
283 collections[i].updateItem(subscription);
284
285 var recommendation = recommendationsMap[subscriptionUrl];
286 if (recommendation && recommendation.type == "ads") 358 if (recommendation && recommendation.type == "ads")
287 { 359 {
288 if (subscription.disabled == false) 360 if (subscription.disabled == false)
289 { 361 {
290 collections.allLangs.removeItem(subscription); 362 collections.allLangs.removeItem(subscription);
291 collections.langs.addItems(subscription); 363 collections.langs.addItems(subscription);
292 } 364 }
293 else 365 else
294 { 366 {
295 collections.allLangs.addItems(subscription); 367 collections.allLangs.addItems(subscription);
296 collections.langs.removeItem(subscription); 368 collections.langs.removeItem(subscription);
297 } 369 }
298 } 370 }
299 } 371 }
372 for (var i in collections)
373 collections[i].updateItem(subscription);
374 }
375 }
300 376
301 if (!Object.observe) 377 if (!Object.observe)
378 {
379 ["disabled", "lastDownload"].forEach(function(property)
380 {
381 subscription["$" + property] = subscription[property];
382 Object.defineProperty(subscription, property,
302 { 383 {
303 // Currently only "disabled" property of subscription used for observa tion 384 get: function()
304 // but with Advanced tab implementation we should also add more proper ties.
305 ["disabled"].forEach(function(property)
306 { 385 {
307 subscription["$" + property] = subscription[property]; 386 return this["$" + property];
308 Object.defineProperty(subscription, property, 387 },
388 set: function(newValue)
389 {
390 var oldValue = this["$" + property];
391 if (oldValue != newValue)
309 { 392 {
310 get: function() 393 this["$" + property] = newValue;
311 { 394 var change = Object.create(null);
312 return this["$" + property]; 395 change.name = property;
313 }, 396 onObjectChanged([change]);
314 set: function(value) 397 }
315 { 398 }
316 this["$" + property] = value; 399 });
317 onObjectChanged(); 400 });
318 } 401 }
319 }); 402 else
320 }); 403 {
321 } 404 Object.observe(subscription, onObjectChanged);
322 else 405 }
323 { 406 }
324 Object.observe(subscription, onObjectChanged);
325 }
326 407
408 function updateSubscription(subscription)
409 {
410 var subscriptionUrl = subscription.url;
411 var knownSubscription = subscriptionsMap[subscriptionUrl];
412 if (knownSubscription)
413 {
414 for (var property in subscription)
415 if (property != "title")
416 knownSubscription[property] = subscription[property];
417 }
418 else
419 {
420 observeSubscription(subscription);
421 getAcceptableAdsURL(function(acceptableAdsUrl)
422 {
327 var collection = null; 423 var collection = null;
328 if (subscriptionUrl in recommendationsMap) 424 if (subscriptionUrl in recommendationsMap)
329 { 425 {
330 var recommendation = recommendationsMap[subscriptionUrl]; 426 var recommendation = recommendationsMap[subscriptionUrl];
331 if (recommendation.type != "ads") 427 if (recommendation.type != "ads")
332 collection = collections.popular; 428 collection = collections.popular;
333 else if (subscription.disabled == false) 429 else if (subscription.disabled == false)
334 collection = collections.langs; 430 collection = collections.langs;
335 else 431 else
336 collection = collections.allLangs; 432 collection = collections.allLangs;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 var elements = doc.documentElement.getElementsByTagName("subscription"); 470 var elements = doc.documentElement.getElementsByTagName("subscription");
375 for (var i = 0; i < elements.length; i++) 471 for (var i = 0; i < elements.length; i++)
376 { 472 {
377 var element = elements[i]; 473 var element = elements[i];
378 var subscription = Object.create(null); 474 var subscription = Object.create(null);
379 subscription.title = element.getAttribute("title"); 475 subscription.title = element.getAttribute("title");
380 subscription.url = element.getAttribute("url"); 476 subscription.url = element.getAttribute("url");
381 subscription.disabled = null; 477 subscription.disabled = null;
382 subscription.downloadStatus = null; 478 subscription.downloadStatus = null;
383 subscription.homepage = null; 479 subscription.homepage = null;
384 subscription.lastSuccess = null;
385 var recommendation = Object.create(null); 480 var recommendation = Object.create(null);
386 recommendation.type = element.getAttribute("type"); 481 recommendation.type = element.getAttribute("type");
387 var prefix = element.getAttribute("prefixes"); 482 var prefix = element.getAttribute("prefixes");
388 if (prefix) 483 if (prefix)
389 { 484 {
390 prefix = prefix.replace(/\W/g, "_"); 485 prefix = prefix.replace(/\W/g, "_");
391 subscription.title = ext.i18n.getMessage("options_language_" + prefi x); 486 subscription.title = getMessage("options_language_" + prefix);
392 } 487 }
393 else 488 else
394 { 489 {
395 var type = recommendation.type.replace(/\W/g, "_"); 490 var type = recommendation.type.replace(/\W/g, "_");
396 subscription.title = ext.i18n.getMessage("common_feature_" + type + "_title"); 491 subscription.title = getMessage("common_feature_" + type + "_title") ;
397 } 492 }
398 493
399 recommendationsMap[subscription.url] = recommendation; 494 recommendationsMap[subscription.url] = recommendation;
400 updateSubscription(subscription); 495 updateSubscription(subscription);
401 } 496 }
402 }); 497 });
403 } 498 }
404 499
500 function findParentData(element, dataName, returnElement)
501 {
502 while (element)
503 {
504 if (element.hasAttribute("data-" + dataName))
505 return returnElement ? element : element.getAttribute("data-" + dataName );
506
507 element = element.parentElement;
508 }
509 return null;
510 }
511
405 function onClick(e) 512 function onClick(e)
406 { 513 {
514 var context = document.querySelector(".show-context-menu");
515 if (context)
516 context.classList.remove("show-context-menu");
517
407 var element = e.target; 518 var element = e.target;
408 while (true) 519 while (true)
409 { 520 {
410 if (!element) 521 if (!element)
411 return; 522 return;
412 523
413 if (element.hasAttribute("data-action")) 524 if (element.hasAttribute("data-action"))
414 break; 525 break;
415 526
416 element = element.parentElement; 527 element = element.parentElement;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 { 573 {
463 type: "filters.importRaw", 574 type: "filters.importRaw",
464 text: E("custom-filters-raw").value 575 text: E("custom-filters-raw").value
465 }); 576 });
466 E("custom-filters").classList.remove("mode-edit"); 577 E("custom-filters").classList.remove("mode-edit");
467 break; 578 break;
468 case "switch-tab": 579 case "switch-tab":
469 document.body.setAttribute("data-tab", 580 document.body.setAttribute("data-tab",
470 element.getAttribute("data-tab")); 581 element.getAttribute("data-tab"));
471 break; 582 break;
583 case "update-all-subscriptions":
584 ext.backgroundPage.sendMessage(
585 {
586 type: "subscriptions.update"
587 });
588 break;
589 case "open-context-menu":
590 var listItem = findParentData(element, "access", true);
591 if (listItem != context)
592 listItem.classList.add("show-context-menu");
593 break;
594 case "update-subscription":
595 ext.backgroundPage.sendMessage(
596 {
597 type: "subscriptions.update",
598 url: findParentData(element, "access", false)
599 });
600 break;
601 case "remove-subscription":
602 ext.backgroundPage.sendMessage(
603 {
604 type: "subscriptions.remove",
605 url: findParentData(element, "access", false)
606 });
607 break;
472 } 608 }
473 } 609 }
474 } 610 }
475 611
476 function onDOMLoaded() 612 function onDOMLoaded()
477 { 613 {
478 var recommendationTemplate = document.querySelector("#recommend-list-table t emplate");
479 var popularText = ext.i18n.getMessage("options_popular");
480 recommendationTemplate.content.querySelector(".popular").textContent = popul arText;
481 var languagesTemplate = document.querySelector("#all-lang-table template");
482 var buttonText = ext.i18n.getMessage("options_button_add");
483 languagesTemplate.content.querySelector(".button-add span").textContent = bu ttonText;
484
485 populateLists(); 614 populateLists();
486
487 function onFindLanguageKeyUp() 615 function onFindLanguageKeyUp()
488 { 616 {
489 var searchStyle = E("search-style"); 617 var searchStyle = E("search-style");
490 if (!this.value) 618 if (!this.value)
491 searchStyle.innerHTML = ""; 619 searchStyle.innerHTML = "";
492 else 620 else
493 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }"; 621 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }";
494 } 622 }
495 623
496 function getKey(e) 624 function getKey(e)
(...skipping 26 matching lines...) Expand all
523 651
524 getDocLink("contribute", function(link) 652 getDocLink("contribute", function(link)
525 { 653 {
526 document.querySelector("#tab-contribute a").setAttribute("href", link); 654 document.querySelector("#tab-contribute a").setAttribute("href", link);
527 }); 655 });
528 656
529 updateShareLink(); 657 updateShareLink();
530 658
531 // Initialize interactive UI elements 659 // Initialize interactive UI elements
532 document.body.addEventListener("click", onClick, false); 660 document.body.addEventListener("click", onClick, false);
533 var placeholderValue = ext.i18n.getMessage("options_dialog_language_find"); 661 var placeholderValue = getMessage("options_dialog_language_find");
534 E("find-language").setAttribute("placeholder", placeholderValue); 662 E("find-language").setAttribute("placeholder", placeholderValue);
535 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); 663 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
536 E("whitelisting-textbox").addEventListener("keypress", function(e) 664 E("whitelisting-textbox").addEventListener("keypress", function(e)
537 { 665 {
538 if (getKey(e) == "Enter") 666 if (getKey(e) == "Enter")
539 addWhitelistedDomain(); 667 addWhitelistedDomain();
540 }, false); 668 }, false);
541 669
542 // Advanced tab 670 // Advanced tab
543 var filterTextbox = document.querySelector("#custom-filters-add input"); 671 var filterTextbox = document.querySelector("#custom-filters-add input");
544 placeholderValue = ext.i18n.getMessage("options_customFilters_textbox_placeh older"); 672 placeholderValue = getMessage("options_customFilters_textbox_placeholder");
545 filterTextbox.setAttribute("placeholder", placeholderValue); 673 filterTextbox.setAttribute("placeholder", placeholderValue);
546 function addCustomFilters() 674 function addCustomFilters()
547 { 675 {
548 var filterText = filterTextbox.value; 676 var filterText = filterTextbox.value;
549 ext.backgroundPage.sendMessage( 677 ext.backgroundPage.sendMessage(
550 { 678 {
551 type: "filters.add", 679 type: "filters.add",
552 text: filterText 680 text: filterText
553 }); 681 });
554 filterTextbox.value = ""; 682 filterTextbox.value = "";
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 updateFilter(filters[i]); 770 updateFilter(filters[i]);
643 }); 771 });
644 } 772 }
645 }); 773 });
646 loadRecommendations(); 774 loadRecommendations();
647 getAcceptableAdsURL(function(acceptableAdsUrl) 775 getAcceptableAdsURL(function(acceptableAdsUrl)
648 { 776 {
649 var subscription = Object.create(null); 777 var subscription = Object.create(null);
650 subscription.url = acceptableAdsUrl; 778 subscription.url = acceptableAdsUrl;
651 subscription.disabled = true; 779 subscription.disabled = true;
652 subscription.title = ext.i18n.getMessage("options_acceptableAds_descriptio n"); 780 subscription.title = getMessage("options_acceptableAds_description");
653 updateSubscription(subscription); 781 updateSubscription(subscription);
654 782
655 // Load user subscriptions 783 // Load user subscriptions
656 ext.backgroundPage.sendMessage( 784 ext.backgroundPage.sendMessage(
657 { 785 {
658 type: "subscriptions.get", 786 type: "subscriptions.get",
659 downloadable: true 787 downloadable: true
660 }, 788 },
661 function(subscriptions) 789 function(subscriptions)
662 { 790 {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 updateShareLink(); 876 updateShareLink();
749 break; 877 break;
750 } 878 }
751 } 879 }
752 880
753 function onSubscriptionMessage(action, subscription) 881 function onSubscriptionMessage(action, subscription)
754 { 882 {
755 switch (action) 883 switch (action)
756 { 884 {
757 case "added": 885 case "added":
886 updateSubscription(subscription);
887 updateShareLink();
888
889 var knownSubscription = subscriptionsMap[subscription.url];
890 if (knownSubscription)
891 collections.filterLists.addItems(knownSubscription);
892 else
893 collections.filterLists.addItems(subscription);
894 break;
758 case "disabled": 895 case "disabled":
759 updateSubscription(subscription); 896 updateSubscription(subscription);
760 updateShareLink(); 897 updateShareLink();
761 break; 898 break;
899 case "lastDownload":
900 updateSubscription(subscription);
901 break;
762 case "homepage": 902 case "homepage":
763 // TODO: NYI 903 // TODO: NYI
764 break; 904 break;
765 case "removed": 905 case "removed":
906 var knownSubscription = subscriptionsMap[subscription.url];
766 getAcceptableAdsURL(function(acceptableAdsUrl) 907 getAcceptableAdsURL(function(acceptableAdsUrl)
767 { 908 {
768 if (subscription.url == acceptableAdsUrl) 909 if (subscription.url == acceptableAdsUrl)
769 { 910 {
770 subscription.disabled = true; 911 subscription.disabled = true;
771 updateSubscription(subscription); 912 updateSubscription(subscription);
772 } 913 }
773 else 914 else
774 { 915 {
775 var knownSubscription = subscriptionsMap[subscription.url];
776 if (subscription.url in recommendationsMap) 916 if (subscription.url in recommendationsMap)
777 knownSubscription.disabled = true; 917 knownSubscription.disabled = true;
778 else 918 else
779 { 919 {
780 collections.custom.removeItem(knownSubscription); 920 collections.custom.removeItem(knownSubscription);
781 delete subscriptionsMap[subscription.url]; 921 delete subscriptionsMap[subscription.url];
782 } 922 }
783 } 923 }
784 updateShareLink(); 924 updateShareLink();
925 collections.filterLists.removeItem(knownSubscription);
785 }); 926 });
786 break; 927 break;
787 case "title": 928 case "title":
788 // TODO: NYI 929 // TODO: NYI
789 break; 930 break;
790 } 931 }
791 } 932 }
792 933
793 function onShareLinkClick(e) 934 function onShareLinkClick(e)
794 { 935 {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 filter: ["addSubscription", "error"] 1005 filter: ["addSubscription", "error"]
865 }); 1006 });
866 ext.backgroundPage.sendMessage( 1007 ext.backgroundPage.sendMessage(
867 { 1008 {
868 type: "filters.listen", 1009 type: "filters.listen",
869 filter: ["added", "loaded", "removed"] 1010 filter: ["added", "loaded", "removed"]
870 }); 1011 });
871 ext.backgroundPage.sendMessage( 1012 ext.backgroundPage.sendMessage(
872 { 1013 {
873 type: "subscriptions.listen", 1014 type: "subscriptions.listen",
874 filter: ["added", "disabled", "homepage", "removed", "title"] 1015 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ]
875 }); 1016 });
876 1017
877 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1018 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
878 })(); 1019 })();
OLDNEW

Powered by Google App Engine
This is Rietveld