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 fix for Object.defineProperty Created Feb. 3, 2016, 2:02 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 24 matching lines...) Expand all
139 if (!element) 160 if (!element)
140 continue; 161 continue;
141 162
142 var text = item.title || item.url || item.text; 163 var text = item.title || item.url || item.text;
143 element.querySelector(".display").textContent = text; 164 element.querySelector(".display").textContent = text;
144 if (text) 165 if (text)
145 element.setAttribute("data-search", text.toLowerCase()); 166 element.setAttribute("data-search", text.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 if (downloadStatus && downloadStatus != "synchronize_ok")
177 {
178 if (downloadStatus in filterErrors)
179 timeElement.textContent = getMessage(filterErrors[downloadStatus]);
180 else
181 timeElement.textContent = item.downloadStatus;
182 }
183 else if (item.lastDownload > 0)
184 {
185 var dateTime = i18n_formatDateTime(item.lastDownload * 1000);
186 dateElement.textContent = dateTime[0];
187 timeElement.textContent = dateTime[1];
188 }
189 else
190 {
191 timeElement.textContent = getMessage("options_filterList_lastDownload_ inProgress");
Thomas Greiner 2016/02/03 14:50:14 Whenever adding a subscription I see two issues:
saroyanm 2016/02/03 17:43:12 Done.
192 }
193 }
194 var websiteElement = element.querySelector(".context-menu .website");
195 var sourceElement = element.querySelector(".context-menu .source");
196 if (websiteElement && item.homepage)
197 websiteElement.setAttribute("href", item.homepage);
198 if (sourceElement)
199 sourceElement.setAttribute("href", item.url);
149 } 200 }
150 }; 201 };
151 202
152 Collection.prototype.clearAll = function() 203 Collection.prototype.clearAll = function()
153 { 204 {
154 this.items = []; 205 this.items = [];
155 for (var i = 0; i < this.details.length; i++) 206 for (var i = 0; i < this.details.length; i++)
156 { 207 {
157 var table = E(this.details[i].id); 208 var table = E(this.details[i].id);
158 var template = table.querySelector("template"); 209 var element = table.firstChild;
159 table.innerHTML = ""; 210 while (element)
160 table.appendChild(template); 211 {
212 if (element.tagName == "LI" && !element.classList.contains("static"))
213 table.removeChild(element);
214 element = element.nextElementSibling;
215 }
216
161 this._setEmpty(table, this.details[i].emptyText); 217 this._setEmpty(table, this.details[i].emptyText);
162 } 218 }
163 }; 219 };
164 220
165 function focusNextElement(container, currentElement) 221 function focusNextElement(container, currentElement)
166 { 222 {
167 var focusables = container.querySelectorAll("a, button, input, .control"); 223 var focusables = container.querySelectorAll("a, button, input, .control");
168 focusables = Array.prototype.slice.call(focusables); 224 focusables = Array.prototype.slice.call(focusables);
169 var index = focusables.indexOf(currentElement); 225 var index = focusables.indexOf(currentElement);
170 index += (index == focusables.length - 1) ? -1 : 1; 226 index += (index == focusables.length - 1) ? -1 : 1;
171 227
172 var nextElement = focusables[index]; 228 var nextElement = focusables[index];
173 if (!nextElement) 229 if (!nextElement)
174 return false; 230 return false;
175 231
176 nextElement.focus(); 232 nextElement.focus();
177 return true; 233 return true;
178 } 234 }
179 235
180 function onToggleSubscriptionClick(e) 236 function toggleRemoveSubscription(e)
181 { 237 {
182 e.preventDefault(); 238 e.preventDefault();
183 var checkbox = e.target; 239 var subscriptionUrl = findParentData(e.target, "access", false);
184 var subscriptionUrl = checkbox.parentElement.getAttribute("data-access"); 240 if (e.target.getAttribute("aria-checked") == "true")
185 if (checkbox.getAttribute("aria-checked") == "true")
186 { 241 {
187 ext.backgroundPage.sendMessage({ 242 ext.backgroundPage.sendMessage({
188 type: "subscriptions.remove", 243 type: "subscriptions.remove",
189 url: subscriptionUrl 244 url: subscriptionUrl
190 }); 245 });
191 } 246 }
192 else 247 else
193 addEnableSubscription(subscriptionUrl); 248 addEnableSubscription(subscriptionUrl);
194 } 249 }
195 250
251 function toggleDisableSubscription(e)
252 {
253 e.preventDefault();
254 var subscriptionUrl = findParentData(e.target, "access", false);
255 ext.backgroundPage.sendMessage(
256 {
257 type: "subscriptions.toggle",
258 keepInstalled: true,
259 url: subscriptionUrl
260 });
261 }
262
196 function onAddLanguageSubscriptionClick(e) 263 function onAddLanguageSubscriptionClick(e)
197 { 264 {
198 e.preventDefault(); 265 e.preventDefault();
199 var url = this.parentNode.getAttribute("data-access"); 266 var url = findParentData(this, "access", false);
200 addEnableSubscription(url); 267 addEnableSubscription(url);
201 } 268 }
202 269
203 function onRemoveFilterClick() 270 function onRemoveFilterClick()
204 { 271 {
205 var filter = this.parentNode.getAttribute("data-access"); 272 var filter = findParentData(this, "access", false);
206 ext.backgroundPage.sendMessage( 273 ext.backgroundPage.sendMessage(
207 { 274 {
208 type: "filters.remove", 275 type: "filters.remove",
209 text: filter 276 text: filter
210 }); 277 });
211 } 278 }
212 279
213 collections.popular = new Collection( 280 collections.popular = new Collection(
214 [ 281 [
215 { 282 {
216 id: "recommend-list-table", 283 id: "recommend-list-table",
217 onClick: onToggleSubscriptionClick 284 onClick: toggleRemoveSubscription
218 } 285 }
219 ]); 286 ]);
220 collections.langs = new Collection( 287 collections.langs = new Collection(
221 [ 288 [
222 { 289 {
223 id: "blocking-languages-table", 290 id: "blocking-languages-table",
224 emptyText: "options_dialog_language_added_empty", 291 emptyText: "options_dialog_language_added_empty",
225 onClick: onToggleSubscriptionClick 292 onClick: toggleRemoveSubscription
226 }, 293 },
227 { 294 {
228 id: "blocking-languages-dialog-table", 295 id: "blocking-languages-dialog-table",
229 emptyText: "options_dialog_language_added_empty" 296 emptyText: "options_dialog_language_added_empty"
230 } 297 }
231 ]); 298 ]);
232 collections.allLangs = new Collection( 299 collections.allLangs = new Collection(
233 [ 300 [
234 { 301 {
235 id: "all-lang-table", 302 id: "all-lang-table",
236 emptyText: "options_dialog_language_other_empty", 303 emptyText: "options_dialog_language_other_empty",
237 onClick: onAddLanguageSubscriptionClick 304 onClick: onAddLanguageSubscriptionClick
238 } 305 }
239 ]); 306 ]);
240 collections.acceptableAds = new Collection( 307 collections.acceptableAds = new Collection(
241 [ 308 [
242 { 309 {
243 id: "acceptableads-table", 310 id: "acceptableads-table",
244 onClick: onToggleSubscriptionClick 311 onClick: toggleRemoveSubscription
245 } 312 }
246 ]); 313 ]);
247 collections.custom = new Collection( 314 collections.custom = new Collection(
248 [ 315 [
249 { 316 {
250 id: "custom-list-table", 317 id: "custom-list-table",
251 onClick: onToggleSubscriptionClick 318 onClick: toggleRemoveSubscription
252 } 319 }
253 ]); 320 ]);
254 collections.whitelist = new Collection( 321 collections.whitelist = new Collection(
255 [ 322 [
256 { 323 {
257 id: "whitelisting-table", 324 id: "whitelisting-table",
258 emptyText: "options_whitelisted_empty", 325 emptyText: "options_whitelisted_empty",
259 onClick: onRemoveFilterClick 326 onClick: onRemoveFilterClick
260 } 327 }
261 ]); 328 ]);
262 collections.customFilters = new Collection( 329 collections.customFilters = new Collection(
263 [ 330 [
264 { 331 {
265 id: "custom-filters-table", 332 id: "custom-filters-table",
266 emptyText: "options_customFilters_empty" 333 emptyText: "options_customFilters_empty"
267 } 334 }
268 ]); 335 ]);
336 collections.filterLists = new Collection(
337 [
338 {
339 id: "all-filter-lists-table",
340 onClick: toggleDisableSubscription
341 }
342 ]);
269 343
270 function updateSubscription(subscription) 344 function observeSubscription(subscription)
271 { 345 {
272 var subscriptionUrl = subscription.url; 346 function onObjectChanged(change)
273 var knownSubscription = subscriptionsMap[subscriptionUrl];
274 if (knownSubscription)
275 knownSubscription.disabled = subscription.disabled;
276 else
277 { 347 {
278 getAcceptableAdsURL(function(acceptableAdsUrl) 348 for (var i = 0; i < change.length; i++)
279 { 349 {
280 function onObjectChanged() 350 if (change[i].name == "disabled")
281 { 351 {
282 for (var i in collections) 352 var recommendation = recommendationsMap[subscription.url];
283 collections[i].updateItem(subscription);
284
285 var recommendation = recommendationsMap[subscriptionUrl];
286 if (recommendation && recommendation.type == "ads") 353 if (recommendation && recommendation.type == "ads")
287 { 354 {
288 if (subscription.disabled == false) 355 if (subscription.disabled == false)
289 { 356 {
290 collections.allLangs.removeItem(subscription); 357 collections.allLangs.removeItem(subscription);
291 collections.langs.addItems(subscription); 358 collections.langs.addItems(subscription);
292 } 359 }
293 else 360 else
294 { 361 {
295 collections.allLangs.addItems(subscription); 362 collections.allLangs.addItems(subscription);
296 collections.langs.removeItem(subscription); 363 collections.langs.removeItem(subscription);
297 } 364 }
298 } 365 }
299 } 366 }
367 for (var i in collections)
368 collections[i].updateItem(subscription);
369 }
370 }
300 371
301 if (!Object.observe) 372 if (!Object.observe)
373 {
374 ["disabled", "lastDownload"].forEach(function(property)
375 {
376 subscription["$" + property] = subscription[property];
377 Object.defineProperty(subscription, property,
302 { 378 {
303 // Currently only "disabled" property of subscription used for observa tion 379 get: function()
304 // but with Advanced tab implementation we should also add more proper ties.
305 ["disabled"].forEach(function(property)
306 { 380 {
307 subscription["$" + property] = subscription[property]; 381 return this["$" + property];
308 Object.defineProperty(subscription, property, 382 },
383 set: function(newValue)
384 {
385 var oldValue = this["$" + property];
386 this["$" + property] = newValue;
Thomas Greiner 2016/02/03 14:50:14 Detail: Shouldn't this only be set whenever the va
saroyanm 2016/02/03 17:43:12 Done.
387 if (oldValue != newValue)
309 { 388 {
310 get: function() 389 var change = Object.create(null);
311 { 390 change.name = property;
312 return this["$" + property]; 391 onObjectChanged([change]);
313 }, 392 }
314 set: function(value) 393 }
315 { 394 });
316 this["$" + property] = value; 395 });
317 onObjectChanged(); 396 }
318 } 397 else
319 }); 398 {
320 }); 399 Object.observe(subscription, onObjectChanged);
321 } 400 }
322 else 401 }
323 {
324 Object.observe(subscription, onObjectChanged);
325 }
326 402
403 function updateSubscription(subscription)
404 {
405 var subscriptionUrl = subscription.url;
406 var knownSubscription = subscriptionsMap[subscriptionUrl];
407 if (knownSubscription)
408 {
409 for (var property in subscription)
410 if (property != "title")
411 knownSubscription[property] = subscription[property];
412 }
413 else
414 {
415 observeSubscription(subscription);
416 getAcceptableAdsURL(function(acceptableAdsUrl)
417 {
327 var collection = null; 418 var collection = null;
328 if (subscriptionUrl in recommendationsMap) 419 if (subscriptionUrl in recommendationsMap)
329 { 420 {
330 var recommendation = recommendationsMap[subscriptionUrl]; 421 var recommendation = recommendationsMap[subscriptionUrl];
331 if (recommendation.type != "ads") 422 if (recommendation.type != "ads")
332 collection = collections.popular; 423 collection = collections.popular;
333 else if (subscription.disabled == false) 424 else if (subscription.disabled == false)
334 collection = collections.langs; 425 collection = collections.langs;
335 else 426 else
336 collection = collections.allLangs; 427 collection = collections.allLangs;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 var elements = doc.documentElement.getElementsByTagName("subscription"); 465 var elements = doc.documentElement.getElementsByTagName("subscription");
375 for (var i = 0; i < elements.length; i++) 466 for (var i = 0; i < elements.length; i++)
376 { 467 {
377 var element = elements[i]; 468 var element = elements[i];
378 var subscription = Object.create(null); 469 var subscription = Object.create(null);
379 subscription.title = element.getAttribute("title"); 470 subscription.title = element.getAttribute("title");
380 subscription.url = element.getAttribute("url"); 471 subscription.url = element.getAttribute("url");
381 subscription.disabled = null; 472 subscription.disabled = null;
382 subscription.downloadStatus = null; 473 subscription.downloadStatus = null;
383 subscription.homepage = null; 474 subscription.homepage = null;
384 subscription.lastSuccess = null;
385 var recommendation = Object.create(null); 475 var recommendation = Object.create(null);
386 recommendation.type = element.getAttribute("type"); 476 recommendation.type = element.getAttribute("type");
387 var prefix = element.getAttribute("prefixes"); 477 var prefix = element.getAttribute("prefixes");
388 if (prefix) 478 if (prefix)
389 { 479 {
390 prefix = prefix.replace(/\W/g, "_"); 480 prefix = prefix.replace(/\W/g, "_");
391 subscription.title = ext.i18n.getMessage("options_language_" + prefi x); 481 subscription.title = getMessage("options_language_" + prefix);
392 } 482 }
393 else 483 else
394 { 484 {
395 var type = recommendation.type.replace(/\W/g, "_"); 485 var type = recommendation.type.replace(/\W/g, "_");
396 subscription.title = ext.i18n.getMessage("common_feature_" + type + "_title"); 486 subscription.title = getMessage("common_feature_" + type + "_title") ;
397 } 487 }
398 488
399 recommendationsMap[subscription.url] = recommendation; 489 recommendationsMap[subscription.url] = recommendation;
400 updateSubscription(subscription); 490 updateSubscription(subscription);
401 } 491 }
402 }); 492 });
403 } 493 }
404 494
495 function findParentData(element, dataName, returnElement)
496 {
497 while (element)
498 {
499 if (element.hasAttribute("data-" + dataName))
500 return returnElement ? element : element.getAttribute("data-" + dataName );
501
502 element = element.parentElement;
503 }
504 return null;
505 }
506
405 function onClick(e) 507 function onClick(e)
406 { 508 {
509 var context = document.querySelector(".show-context-menu");
510 if (context)
511 context.classList.remove("show-context-menu");
512
407 var element = e.target; 513 var element = e.target;
408 while (true) 514 while (true)
409 { 515 {
410 if (!element) 516 if (!element)
411 return; 517 return;
412 518
413 if (element.hasAttribute("data-action")) 519 if (element.hasAttribute("data-action"))
414 break; 520 break;
415 521
416 element = element.parentElement; 522 element = element.parentElement;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 { 568 {
463 type: "filters.importRaw", 569 type: "filters.importRaw",
464 text: E("custom-filters-raw").value 570 text: E("custom-filters-raw").value
465 }); 571 });
466 E("custom-filters").classList.remove("mode-edit"); 572 E("custom-filters").classList.remove("mode-edit");
467 break; 573 break;
468 case "switch-tab": 574 case "switch-tab":
469 document.body.setAttribute("data-tab", 575 document.body.setAttribute("data-tab",
470 element.getAttribute("data-tab")); 576 element.getAttribute("data-tab"));
471 break; 577 break;
578 case "update-all-subscriptions":
579 ext.backgroundPage.sendMessage(
580 {
581 type: "subscriptions.update"
582 });
583 break;
584 case "open-context-menu":
585 var listItem = findParentData(element, "access", true);
586 if (listItem != context)
587 listItem.classList.add("show-context-menu");
588 break;
589 case "update-subscription":
590 ext.backgroundPage.sendMessage(
591 {
592 type: "subscriptions.update",
593 url: findParentData(element, "access", false)
594 });
595 break;
596 case "remove-subscription":
597 ext.backgroundPage.sendMessage(
598 {
599 type: "subscriptions.remove",
600 url: findParentData(element, "access", false)
601 });
602 break;
472 } 603 }
473 } 604 }
474 } 605 }
475 606
476 function onDOMLoaded() 607 function onDOMLoaded()
477 { 608 {
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(); 609 populateLists();
486
487 function onFindLanguageKeyUp() 610 function onFindLanguageKeyUp()
488 { 611 {
489 var searchStyle = E("search-style"); 612 var searchStyle = E("search-style");
490 if (!this.value) 613 if (!this.value)
491 searchStyle.innerHTML = ""; 614 searchStyle.innerHTML = "";
492 else 615 else
493 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }"; 616 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }";
494 } 617 }
495 618
496 function getKey(e) 619 function getKey(e)
(...skipping 26 matching lines...) Expand all
523 646
524 getDocLink("contribute", function(link) 647 getDocLink("contribute", function(link)
525 { 648 {
526 document.querySelector("#tab-contribute a").setAttribute("href", link); 649 document.querySelector("#tab-contribute a").setAttribute("href", link);
527 }); 650 });
528 651
529 updateShareLink(); 652 updateShareLink();
530 653
531 // Initialize interactive UI elements 654 // Initialize interactive UI elements
532 document.body.addEventListener("click", onClick, false); 655 document.body.addEventListener("click", onClick, false);
533 var placeholderValue = ext.i18n.getMessage("options_dialog_language_find"); 656 var placeholderValue = getMessage("options_dialog_language_find");
534 E("find-language").setAttribute("placeholder", placeholderValue); 657 E("find-language").setAttribute("placeholder", placeholderValue);
535 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); 658 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
536 E("whitelisting-textbox").addEventListener("keypress", function(e) 659 E("whitelisting-textbox").addEventListener("keypress", function(e)
537 { 660 {
538 if (getKey(e) == "Enter") 661 if (getKey(e) == "Enter")
539 addWhitelistedDomain(); 662 addWhitelistedDomain();
540 }, false); 663 }, false);
541 664
542 // Advanced tab 665 // Advanced tab
543 var filterTextbox = document.querySelector("#custom-filters-add input"); 666 var filterTextbox = document.querySelector("#custom-filters-add input");
544 placeholderValue = ext.i18n.getMessage("options_customFilters_textbox_placeh older"); 667 placeholderValue = getMessage("options_customFilters_textbox_placeholder");
545 filterTextbox.setAttribute("placeholder", placeholderValue); 668 filterTextbox.setAttribute("placeholder", placeholderValue);
546 function addCustomFilters() 669 function addCustomFilters()
547 { 670 {
548 var filterText = filterTextbox.value; 671 var filterText = filterTextbox.value;
549 ext.backgroundPage.sendMessage( 672 ext.backgroundPage.sendMessage(
550 { 673 {
551 type: "filters.add", 674 type: "filters.add",
552 text: filterText 675 text: filterText
553 }); 676 });
554 filterTextbox.value = ""; 677 filterTextbox.value = "";
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 updateFilter(filters[i]); 765 updateFilter(filters[i]);
643 }); 766 });
644 } 767 }
645 }); 768 });
646 loadRecommendations(); 769 loadRecommendations();
647 getAcceptableAdsURL(function(acceptableAdsUrl) 770 getAcceptableAdsURL(function(acceptableAdsUrl)
648 { 771 {
649 var subscription = Object.create(null); 772 var subscription = Object.create(null);
650 subscription.url = acceptableAdsUrl; 773 subscription.url = acceptableAdsUrl;
651 subscription.disabled = true; 774 subscription.disabled = true;
652 subscription.title = ext.i18n.getMessage("options_acceptableAds_descriptio n"); 775 subscription.title = getMessage("options_acceptableAds_description");
653 updateSubscription(subscription); 776 updateSubscription(subscription);
654 777
655 // Load user subscriptions 778 // Load user subscriptions
656 ext.backgroundPage.sendMessage( 779 ext.backgroundPage.sendMessage(
657 { 780 {
658 type: "subscriptions.get", 781 type: "subscriptions.get",
659 downloadable: true 782 downloadable: true
660 }, 783 },
661 function(subscriptions) 784 function(subscriptions)
662 { 785 {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 updateShareLink(); 871 updateShareLink();
749 break; 872 break;
750 } 873 }
751 } 874 }
752 875
753 function onSubscriptionMessage(action, subscription) 876 function onSubscriptionMessage(action, subscription)
754 { 877 {
755 switch (action) 878 switch (action)
756 { 879 {
757 case "added": 880 case "added":
881 updateSubscription(subscription);
882 updateShareLink();
883
884 var knownSubscription = subscriptionsMap[subscription.url];
885 if (knownSubscription)
886 collections.filterLists.addItems(knownSubscription);
887 else
888 collections.filterLists.addItems(subscription);
889 break;
758 case "disabled": 890 case "disabled":
759 updateSubscription(subscription); 891 updateSubscription(subscription);
760 updateShareLink(); 892 updateShareLink();
761 break; 893 break;
894 case "lastDownload":
895 updateSubscription(subscription);
896 break;
762 case "homepage": 897 case "homepage":
763 // TODO: NYI 898 // TODO: NYI
764 break; 899 break;
765 case "removed": 900 case "removed":
901 var knownSubscription = subscriptionsMap[subscription.url];
766 getAcceptableAdsURL(function(acceptableAdsUrl) 902 getAcceptableAdsURL(function(acceptableAdsUrl)
767 { 903 {
768 if (subscription.url == acceptableAdsUrl) 904 if (subscription.url == acceptableAdsUrl)
769 { 905 {
770 subscription.disabled = true; 906 subscription.disabled = true;
771 updateSubscription(subscription); 907 updateSubscription(subscription);
772 } 908 }
773 else 909 else
774 { 910 {
775 var knownSubscription = subscriptionsMap[subscription.url];
776 if (subscription.url in recommendationsMap) 911 if (subscription.url in recommendationsMap)
777 knownSubscription.disabled = true; 912 knownSubscription.disabled = true;
778 else 913 else
779 { 914 {
780 collections.custom.removeItem(knownSubscription); 915 collections.custom.removeItem(knownSubscription);
781 delete subscriptionsMap[subscription.url]; 916 delete subscriptionsMap[subscription.url];
782 } 917 }
783 } 918 }
784 updateShareLink(); 919 updateShareLink();
920 collections.filterLists.removeItem(knownSubscription);
785 }); 921 });
786 break; 922 break;
787 case "title": 923 case "title":
788 // TODO: NYI 924 // TODO: NYI
789 break; 925 break;
790 } 926 }
791 } 927 }
792 928
793 function onShareLinkClick(e) 929 function onShareLinkClick(e)
794 { 930 {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 filter: ["addSubscription", "error"] 1000 filter: ["addSubscription", "error"]
865 }); 1001 });
866 ext.backgroundPage.sendMessage( 1002 ext.backgroundPage.sendMessage(
867 { 1003 {
868 type: "filters.listen", 1004 type: "filters.listen",
869 filter: ["added", "loaded", "removed"] 1005 filter: ["added", "loaded", "removed"]
870 }); 1006 });
871 ext.backgroundPage.sendMessage( 1007 ext.backgroundPage.sendMessage(
872 { 1008 {
873 type: "subscriptions.listen", 1009 type: "subscriptions.listen",
874 filter: ["added", "disabled", "homepage", "removed", "title"] 1010 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ]
875 }); 1011 });
876 1012
877 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1013 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
878 })(); 1014 })();
OLDNEW
« background.js ('K') | « options.html ('k') | skin/options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld