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: Rebase to d12b18c2a168 Created Jan. 28, 2016, 1:38 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
« no previous file with comments | « options.html ('k') | skin/options.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 27 matching lines...) Expand all
38 { 38 {
39 placeholder = document.createElement("li"); 39 placeholder = document.createElement("li");
40 placeholder.className = "empty-placeholder"; 40 placeholder.className = "empty-placeholder";
41 placeholder.textContent = ext.i18n.getMessage(text); 41 placeholder.textContent = ext.i18n.getMessage(text);
42 table.appendChild(placeholder); 42 table.appendChild(placeholder);
43 } 43 }
44 else if (placeholder) 44 else if (placeholder)
45 table.removeChild(placeholder); 45 table.removeChild(placeholder);
46 } 46 }
47 47
48 Collection.prototype._createElementQuery = function(item)
49 {
50 var access = (item.url || item.text).replace(/'/g, "\\'");
51 return function(container)
52 {
53 return container.querySelector("[data-access='" + access + "']");
54 };
55 };
56
48 Collection.prototype.addItems = function() 57 Collection.prototype.addItems = function()
49 { 58 {
50 var length = Array.prototype.push.apply(this.items, arguments); 59 var length = Array.prototype.push.apply(this.items, arguments);
51 if (length == 0) 60 if (length == 0)
52 return; 61 return;
53 62
54 this.items.sort(function(a, b) 63 this.items.sort(function(a, b)
55 { 64 {
56 var aValue = (a.title || a.text || a.url).toLowerCase(); 65 var aValue = (a.title || a.text || a.url).toLowerCase();
57 var bValue = (b.title || b.text || b.url).toLowerCase(); 66 var bValue = (b.title || b.text || b.url).toLowerCase();
58 return aValue.localeCompare(bValue); 67 return aValue.localeCompare(bValue);
59 }); 68 });
60 69
61 for (var j = 0; j < this.details.length; j++) 70 for (var j = 0; j < this.details.length; j++)
62 { 71 {
63 var table = E(this.details[j].id); 72 var table = E(this.details[j].id);
64 var template = table.querySelector("template"); 73 var template = table.querySelector("template");
65 for (var i = 0; i < arguments.length; i++) 74 for (var i = 0; i < arguments.length; i++)
66 { 75 {
67 var item = arguments[i]; 76 var item = arguments[i];
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 80
72 var labelId = "label-" + (++maxLabelId); 81 var labelId = "label-" + (++maxLabelId);
73 listItem.querySelector(".display").setAttribute("id", labelId); 82 listItem.querySelector(".display").setAttribute("id", labelId);
83 updateBlockingList(listItem, item);
Thomas Greiner 2016/01/28 14:09:58 Detail: Don't use `\t` for whitespaces.
74 var control = listItem.querySelector(".control"); 84 var control = listItem.querySelector(".control");
75 if (control) 85 if (control)
76 { 86 {
77 // We use aria-labelledby to avoid triggering the control when 87 // We use aria-labelledby to avoid triggering the control when
78 // interacting with the label 88 // interacting with the label
79 control.setAttribute("aria-labelledby", labelId); 89 control.setAttribute("aria-labelledby", labelId);
80 control.addEventListener("click", this.details[j].onClick, false); 90 control.addEventListener("click", this.details[j].onClick, false);
81 } 91 }
82 92
83 this._setEmpty(table, null); 93 this._setEmpty(table, null);
84 if (table.hasChildNodes()) 94 if (table.hasChildNodes())
85 table.insertBefore(listItem, table.childNodes[this.items.indexOf(item) ]); 95 {
96 table.insertBefore(listItem,
97 table.childNodes[this.items.indexOf(item)]);
98 }
86 else 99 else
87 table.appendChild(listItem); 100 table.appendChild(listItem);
88 this.updateItem(item); 101 this.updateItem(item);
89 } 102 }
90 } 103 }
91 return length; 104 return length;
92 }; 105 };
93 106
94 Collection.prototype.removeItem = function(item) 107 Collection.prototype.removeItem = function(item)
95 { 108 {
96 var index = this.items.indexOf(item); 109 var index = this.items.indexOf(item);
97 if (index == -1) 110 if (index == -1)
98 return; 111 return;
99 112
100 this.items.splice(index, 1); 113 this.items.splice(index, 1);
114 var getListElement = this._createElementQuery(item);
101 for (var i = 0; i < this.details.length; i++) 115 for (var i = 0; i < this.details.length; i++)
102 { 116 {
103 var table = E(this.details[i].id); 117 var table = E(this.details[i].id);
104 var element = table.childNodes[index]; 118 var element = getListElement(table);
105 119
106 // Element gets removed so make sure to handle focus appropriately 120 // Element gets removed so make sure to handle focus appropriately
107 var control = element.querySelector(".control"); 121 var control = element.querySelector(".control");
108 if (control && control == document.activeElement) 122 if (control && control == document.activeElement)
109 { 123 {
110 if (!focusNextElement(element.parentElement, control)) 124 if (!focusNextElement(element.parentElement, control))
111 { 125 {
112 // Fall back to next focusable element within same tab or dialog 126 // Fall back to next focusable element within same tab or dialog
113 var focusableElement = element.parentElement; 127 var focusableElement = element.parentElement;
114 while (focusableElement) 128 while (focusableElement)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 control.setAttribute("aria-checked", item.disabled == false); 162 control.setAttribute("aria-checked", item.disabled == false);
149 } 163 }
150 }; 164 };
151 165
152 Collection.prototype.clearAll = function() 166 Collection.prototype.clearAll = function()
153 { 167 {
154 this.items = []; 168 this.items = [];
155 for (var i = 0; i < this.details.length; i++) 169 for (var i = 0; i < this.details.length; i++)
156 { 170 {
157 var table = E(this.details[i].id); 171 var table = E(this.details[i].id);
158 var template = table.querySelector("template"); 172 var element = table.firstChild;
159 table.innerHTML = ""; 173 while (element)
160 table.appendChild(template); 174 {
175 if ((element.tagName == "LI" && !element.classList.contains("static")) | |
176 element.nodeType == 3)
177 table.removeChild(element);
178 element = element.nextSibling
179 }
180
161 this._setEmpty(table, this.details[i].emptyText); 181 this._setEmpty(table, this.details[i].emptyText);
162 } 182 }
163 }; 183 };
164 184
185 function updateBlockingList(listItem, subscription)
186 {
187 var dateElement = listItem.querySelector(".date");
188 var timeElement = listItem.querySelector(".time");
189
190 if(dateElement && timeElement)
191 {
192 if (subscription.downloadStatus &&
193 subscription.downloadStatus != "synchronize_ok")
194 {
195 var map =
196 {
197 "synchronize_invalid_url": "options_subscription_lastDownload_invalidU RL",
198 "synchronize_connection_error": "options_subscription_lastDownload_con nectionError",
199 "synchronize_invalid_data": "options_subscription_lastDownload_invalid Data",
200 "synchronize_checksum_mismatch": "options_subscription_lastDownload_ch ecksumMismatch"
201 };
202 if (subscription.downloadStatus in map)
203 timeElement.textContent = ext.i18n.getMessage(map[subscription.downloa dStatus]);
204 else
205 timeElement.textContent = subscription.downloadStatus;
206 }
207 else if (subscription.lastDownload > 0)
208 {
209 var dateTime = i18n_formatDateTime(subscription.lastDownload * 1000);
210 dateElement.textContent = dateTime[0];
211 timeElement.textContent = dateTime[1];
212 }
213 }
214 var websiteElement = listItem.querySelector(".context-menu .website");
215 var sourceElement = listItem.querySelector(".context-menu .source");
216 if (websiteElement && subscription.homepage)
217 websiteElement.setAttribute("href", subscription.homepage);
218 if (sourceElement)
219 sourceElement.setAttribute("href", subscription.url);
220 }
221
165 function focusNextElement(container, currentElement) 222 function focusNextElement(container, currentElement)
166 { 223 {
167 var focusables = container.querySelectorAll("a, button, input, .control"); 224 var focusables = container.querySelectorAll("a, button, input, .control");
168 focusables = Array.prototype.slice.call(focusables); 225 focusables = Array.prototype.slice.call(focusables);
169 var index = focusables.indexOf(currentElement); 226 var index = focusables.indexOf(currentElement);
170 index += (index == focusables.length - 1) ? -1 : 1; 227 index += (index == focusables.length - 1) ? -1 : 1;
171 228
172 var nextElement = focusables[index]; 229 var nextElement = focusables[index];
173 if (!nextElement) 230 if (!nextElement)
174 return false; 231 return false;
175 232
176 nextElement.focus(); 233 nextElement.focus();
177 return true; 234 return true;
178 } 235 }
179 236
180 function onToggleSubscriptionClick(e) 237 function toggleRemoveSubscription(e)
181 { 238 {
182 e.preventDefault(); 239 e.preventDefault();
183 var checkbox = e.target; 240 var subscriptionUrl = findParentData(e.target, "access", false);
184 var subscriptionUrl = checkbox.parentElement.getAttribute("data-access"); 241 if (e.target.getAttribute("aria-checked") == "true")
185 if (checkbox.getAttribute("aria-checked") == "true")
186 { 242 {
187 ext.backgroundPage.sendMessage({ 243 ext.backgroundPage.sendMessage({
188 type: "subscriptions.remove", 244 type: "subscriptions.remove",
189 url: subscriptionUrl 245 url: subscriptionUrl
190 }); 246 });
191 } 247 }
192 else 248 else
193 addEnableSubscription(subscriptionUrl); 249 addEnableSubscription(subscriptionUrl);
194 } 250 }
195 251
252 function toggleDisableSubscription(e)
253 {
254 e.preventDefault();
255 var subscriptionUrl = findParentData(e.target, "access", false);
256 ext.backgroundPage.sendMessage(
257 {
258 type: "subscriptions.toggle",
259 keepInstalled: true,
260 url: subscriptionUrl
261 });
262 }
263
196 function onAddLanguageSubscriptionClick(e) 264 function onAddLanguageSubscriptionClick(e)
197 { 265 {
198 e.preventDefault(); 266 e.preventDefault();
199 var url = this.parentNode.getAttribute("data-access"); 267 var url = findParentData(this, "access", false);
200 addEnableSubscription(url); 268 addEnableSubscription(url);
201 } 269 }
202 270
203 function onRemoveFilterClick() 271 function onRemoveFilterClick()
204 { 272 {
205 var filter = this.parentNode.getAttribute("data-access"); 273 var filter = findParentData(this, "access", false);
206 ext.backgroundPage.sendMessage( 274 ext.backgroundPage.sendMessage(
207 { 275 {
208 type: "filters.remove", 276 type: "filters.remove",
209 text: filter 277 text: filter
210 }); 278 });
211 } 279 }
212 280
213 collections.popular = new Collection( 281 collections.popular = new Collection(
214 [ 282 [
215 { 283 {
216 id: "recommend-list-table", 284 id: "recommend-list-table",
217 onClick: onToggleSubscriptionClick 285 onClick: toggleRemoveSubscription
218 } 286 }
219 ]); 287 ]);
220 collections.langs = new Collection( 288 collections.langs = new Collection(
221 [ 289 [
222 { 290 {
223 id: "blocking-languages-table", 291 id: "blocking-languages-table",
224 emptyText: "options_dialog_language_added_empty", 292 emptyText: "options_dialog_language_added_empty",
225 onClick: onToggleSubscriptionClick 293 onClick: toggleRemoveSubscription
226 }, 294 },
227 { 295 {
228 id: "blocking-languages-dialog-table", 296 id: "blocking-languages-dialog-table",
229 emptyText: "options_dialog_language_added_empty" 297 emptyText: "options_dialog_language_added_empty"
230 } 298 }
231 ]); 299 ]);
232 collections.allLangs = new Collection( 300 collections.allLangs = new Collection(
233 [ 301 [
234 { 302 {
235 id: "all-lang-table", 303 id: "all-lang-table",
236 emptyText: "options_dialog_language_other_empty", 304 emptyText: "options_dialog_language_other_empty",
237 onClick: onAddLanguageSubscriptionClick 305 onClick: onAddLanguageSubscriptionClick
238 } 306 }
239 ]); 307 ]);
240 collections.acceptableAds = new Collection( 308 collections.acceptableAds = new Collection(
241 [ 309 [
242 { 310 {
243 id: "acceptableads-table", 311 id: "acceptableads-table",
244 onClick: onToggleSubscriptionClick 312 onClick: toggleRemoveSubscription
245 } 313 }
246 ]); 314 ]);
247 collections.custom = new Collection( 315 collections.custom = new Collection(
248 [ 316 [
249 { 317 {
250 id: "custom-list-table", 318 id: "custom-list-table",
251 onClick: onToggleSubscriptionClick 319 onClick: toggleRemoveSubscription
252 } 320 }
253 ]); 321 ]);
254 collections.whitelist = new Collection( 322 collections.whitelist = new Collection(
255 [ 323 [
256 { 324 {
257 id: "whitelisting-table", 325 id: "whitelisting-table",
258 emptyText: "options_whitelisted_empty", 326 emptyText: "options_whitelisted_empty",
259 onClick: onRemoveFilterClick 327 onClick: onRemoveFilterClick
260 } 328 }
261 ]); 329 ]);
262 collections.customFilters = new Collection( 330 collections.customFilters = new Collection(
263 [ 331 [
264 { 332 {
265 id: "custom-filters-table", 333 id: "custom-filters-table",
266 emptyText: "options_customFilters_empty" 334 emptyText: "options_customFilters_empty"
267 } 335 }
268 ]); 336 ]);
337 collections.filterLists = new Collection(
338 [
339 {
340 id: "all-filter-lists-table",
341 onClick: toggleDisableSubscription
342 }
343 ]);
269 344
270 function updateSubscription(subscription) 345 function observeSubscription(subscription)
271 { 346 {
272 var subscriptionUrl = subscription.url; 347 function onObjectChanged(change)
273 var knownSubscription = subscriptionsMap[subscriptionUrl];
274 if (knownSubscription)
275 knownSubscription.disabled = subscription.disabled;
276 else
277 { 348 {
278 getAcceptableAdsURL(function(acceptableAdsUrl) 349 for (var i = 0; i < change.length; i++)
279 { 350 {
280 function onObjectChanged() 351 if (change[i].name == "disabled")
281 { 352 {
282 for (var i in collections) 353 for (var i in collections)
283 collections[i].updateItem(subscription); 354 collections[i].updateItem(subscription);
284 355
285 var recommendation = recommendationsMap[subscriptionUrl]; 356 var recommendation = recommendationsMap[subscription.url];
286 if (recommendation && recommendation.type == "ads") 357 if (recommendation && recommendation.type == "ads")
287 { 358 {
288 if (subscription.disabled == false) 359 if (subscription.disabled == false)
289 { 360 {
290 collections.allLangs.removeItem(subscription); 361 collections.allLangs.removeItem(subscription);
291 collections.langs.addItems(subscription); 362 collections.langs.addItems(subscription);
292 } 363 }
293 else 364 else
294 { 365 {
295 collections.allLangs.addItems(subscription); 366 collections.allLangs.addItems(subscription);
296 collections.langs.removeItem(subscription); 367 collections.langs.removeItem(subscription);
297 } 368 }
298 } 369 }
299 } 370 }
371 else
372 {
373 var blockingListId = collections.filterLists.details[0].id;
374 var blockingList = document.getElementById(blockingListId);
375 var listItem = blockingList.querySelector("[data-access='" +
376 subscription.url + "']");
377 if (listItem)
378 updateBlockingList(listItem, subscription);
379 }
380 }
381 }
300 382
301 if (!Object.observe) 383 if (!Object.observe)
384 {
385 ["disabled", "lastDownload"].forEach(function(property)
386 {
387 subscription["$" + property] = subscription[property];
388 Object.defineProperty(subscription, property,
302 { 389 {
303 // Currently only "disabled" property of subscription used for observa tion 390 get: function()
304 // but with Advanced tab implementation we should also add more proper ties.
305 ["disabled"].forEach(function(property)
306 { 391 {
307 subscription["$" + property] = subscription[property]; 392 return this["$" + property];
308 Object.defineProperty(subscription, property, 393 },
309 { 394 set: function(value)
310 get: function() 395 {
311 { 396 this["$" + property] = value;
312 return this["$" + property]; 397 var change = Object.create(null);
313 }, 398 change.name = property;
314 set: function(value) 399 onObjectChanged([change]);
315 { 400 }
316 this["$" + property] = value; 401 });
317 onObjectChanged(); 402 });
318 } 403 }
319 }); 404 else
320 }); 405 {
321 } 406 Object.observe(subscription, onObjectChanged);
322 else 407 }
323 { 408 }
324 Object.observe(subscription, onObjectChanged);
325 }
326 409
410 function updateSubscription(subscription)
411 {
412 var subscriptionUrl = subscription.url;
413 var knownSubscription = subscriptionsMap[subscriptionUrl];
414 if (knownSubscription)
415 {
416 for (var property in subscription)
417 if (property != "title")
418 knownSubscription[property] = subscription[property];
419 }
420 else
421 {
422 observeSubscription(subscription);
423 getAcceptableAdsURL(function(acceptableAdsUrl)
424 {
327 var collection = null; 425 var collection = null;
328 if (subscriptionUrl in recommendationsMap) 426 if (subscriptionUrl in recommendationsMap)
329 { 427 {
330 var recommendation = recommendationsMap[subscriptionUrl]; 428 var recommendation = recommendationsMap[subscriptionUrl];
331 if (recommendation.type != "ads") 429 if (recommendation.type != "ads")
332 collection = collections.popular; 430 collection = collections.popular;
333 else if (subscription.disabled == false) 431 else if (subscription.disabled == false)
334 collection = collections.langs; 432 collection = collections.langs;
335 else 433 else
336 collection = collections.allLangs; 434 collection = collections.allLangs;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 var elements = doc.documentElement.getElementsByTagName("subscription"); 472 var elements = doc.documentElement.getElementsByTagName("subscription");
375 for (var i = 0; i < elements.length; i++) 473 for (var i = 0; i < elements.length; i++)
376 { 474 {
377 var element = elements[i]; 475 var element = elements[i];
378 var subscription = Object.create(null); 476 var subscription = Object.create(null);
379 subscription.title = element.getAttribute("title"); 477 subscription.title = element.getAttribute("title");
380 subscription.url = element.getAttribute("url"); 478 subscription.url = element.getAttribute("url");
381 subscription.disabled = null; 479 subscription.disabled = null;
382 subscription.downloadStatus = null; 480 subscription.downloadStatus = null;
383 subscription.homepage = null; 481 subscription.homepage = null;
384 subscription.lastSuccess = null;
385 var recommendation = Object.create(null); 482 var recommendation = Object.create(null);
386 recommendation.type = element.getAttribute("type"); 483 recommendation.type = element.getAttribute("type");
387 var prefix = element.getAttribute("prefixes"); 484 var prefix = element.getAttribute("prefixes");
388 if (prefix) 485 if (prefix)
389 { 486 {
390 prefix = prefix.replace(/\W/g, "_"); 487 prefix = prefix.replace(/\W/g, "_");
391 subscription.title = ext.i18n.getMessage("options_language_" + prefi x); 488 subscription.title = ext.i18n.getMessage("options_language_" + prefi x);
392 } 489 }
393 else 490 else
394 { 491 {
395 var type = recommendation.type.replace(/\W/g, "_"); 492 var type = recommendation.type.replace(/\W/g, "_");
396 subscription.title = ext.i18n.getMessage("common_feature_" + type + "_title"); 493 subscription.title = ext.i18n.getMessage("common_feature_" + type + "_title");
397 } 494 }
398 495
399 recommendationsMap[subscription.url] = recommendation; 496 recommendationsMap[subscription.url] = recommendation;
400 updateSubscription(subscription); 497 updateSubscription(subscription);
401 } 498 }
402 }); 499 });
403 } 500 }
404 501
502 function findParentData(element, dataName, returnElement)
503 {
504 while (element)
505 {
506 if (element.hasAttribute("data-" + dataName))
507 return returnElement ? element : element.getAttribute("data-" + dataName );
508
509 element = element.parentElement;
510 }
511 return null;
512 }
513
405 function onClick(e) 514 function onClick(e)
406 { 515 {
407 var element = e.target; 516 var element = e.target;
408 while (true) 517 while (true)
409 { 518 {
410 if (!element) 519 if (!element)
520 {
521 var context = document.querySelector(".context");
522 if (context)
523 context.classList.remove("context");
411 return; 524 return;
525 }
412 526
413 if (element.hasAttribute("data-action")) 527 if (element.hasAttribute("data-action"))
414 break; 528 break;
415 529
416 element = element.parentElement; 530 element = element.parentElement;
417 } 531 }
418 532
419 var actions = element.getAttribute("data-action").split(","); 533 var actions = element.getAttribute("data-action").split(",");
420 for (var i = 0; i < actions.length; i++) 534 for (var i = 0; i < actions.length; i++)
421 { 535 {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 { 576 {
463 type: "filters.importRaw", 577 type: "filters.importRaw",
464 text: E("custom-filters-raw").value 578 text: E("custom-filters-raw").value
465 }); 579 });
466 E("custom-filters").classList.remove("mode-edit"); 580 E("custom-filters").classList.remove("mode-edit");
467 break; 581 break;
468 case "switch-tab": 582 case "switch-tab":
469 document.body.setAttribute("data-tab", 583 document.body.setAttribute("data-tab",
470 element.getAttribute("data-tab")); 584 element.getAttribute("data-tab"));
471 break; 585 break;
586 case "update-all-subscriptions":
587 ext.backgroundPage.sendMessage(
588 {
589 type: "subscriptions.update"
590 });
591 break;
592 case "open-context-menu":
593 var listItem = findParentData(element, "access", true);
594 var contextMenu = listItem.querySelector(".content");
595 listItem.classList.add("context");
596 break;
597 case "update-now":
598 ext.backgroundPage.sendMessage(
599 {
600 type: "subscriptions.update",
601 url: findParentData(element, "access")
602 });
603 break;
604 case "remove-subscription":
605 ext.backgroundPage.sendMessage(
606 {
607 type: "subscriptions.remove",
608 url: findParentData(element, "access")
609 });
610 break;
611 case "close-context-menu":
612 var access = findParentData(element, "access", true);
613 if (access)
614 access.classList.remove("context");
615 break;
472 } 616 }
473 } 617 }
474 } 618 }
475 619
476 function onDOMLoaded() 620 function onDOMLoaded()
477 { 621 {
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(); 622 populateLists();
486
487 function onFindLanguageKeyUp() 623 function onFindLanguageKeyUp()
488 { 624 {
489 var searchStyle = E("search-style"); 625 var searchStyle = E("search-style");
490 if (!this.value) 626 if (!this.value)
491 searchStyle.innerHTML = ""; 627 searchStyle.innerHTML = "";
492 else 628 else
493 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }"; 629 searchStyle.innerHTML = "#all-lang-table li:not([data-search*=\"" + this .value.toLowerCase() + "\"]) { display: none; }";
494 } 630 }
495 631
496 function getKey(e) 632 function getKey(e)
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 updateShareLink(); 884 updateShareLink();
749 break; 885 break;
750 } 886 }
751 } 887 }
752 888
753 function onSubscriptionMessage(action, subscription) 889 function onSubscriptionMessage(action, subscription)
754 { 890 {
755 switch (action) 891 switch (action)
756 { 892 {
757 case "added": 893 case "added":
894 updateSubscription(subscription);
895 updateShareLink();
896
897 var knownSubscription = subscriptionsMap[subscription.url];
898 if (knownSubscription)
899 collections.filterLists.addItems(knownSubscription);
900 else
901 collections.filterLists.addItems(subscription);
902 break;
758 case "disabled": 903 case "disabled":
759 updateSubscription(subscription); 904 updateSubscription(subscription);
760 updateShareLink(); 905 updateShareLink();
761 break; 906 break;
907 case "lastDownload":
908 updateSubscription(subscription);
909 break;
762 case "homepage": 910 case "homepage":
763 // TODO: NYI 911 // TODO: NYI
764 break; 912 break;
765 case "removed": 913 case "removed":
914 var knownSubscription = subscriptionsMap[subscription.url];
766 getAcceptableAdsURL(function(acceptableAdsUrl) 915 getAcceptableAdsURL(function(acceptableAdsUrl)
767 { 916 {
768 if (subscription.url == acceptableAdsUrl) 917 if (subscription.url == acceptableAdsUrl)
769 { 918 {
770 subscription.disabled = true; 919 subscription.disabled = true;
771 updateSubscription(subscription); 920 updateSubscription(subscription);
772 } 921 }
773 else 922 else
774 { 923 {
775 var knownSubscription = subscriptionsMap[subscription.url];
776 if (subscription.url in recommendationsMap) 924 if (subscription.url in recommendationsMap)
777 knownSubscription.disabled = true; 925 knownSubscription.disabled = true;
778 else 926 else
779 { 927 {
780 collections.custom.removeItem(knownSubscription); 928 collections.custom.removeItem(knownSubscription);
781 delete subscriptionsMap[subscription.url]; 929 delete subscriptionsMap[subscription.url];
782 } 930 }
783 } 931 }
784 updateShareLink(); 932 updateShareLink();
933 collections.filterLists.removeItem(knownSubscription);
785 }); 934 });
786 break; 935 break;
787 case "title": 936 case "title":
788 // TODO: NYI 937 // TODO: NYI
789 break; 938 break;
790 } 939 }
791 } 940 }
792 941
793 function onShareLinkClick(e) 942 function onShareLinkClick(e)
794 { 943 {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 filter: ["addSubscription", "error"] 1013 filter: ["addSubscription", "error"]
865 }); 1014 });
866 ext.backgroundPage.sendMessage( 1015 ext.backgroundPage.sendMessage(
867 { 1016 {
868 type: "filters.listen", 1017 type: "filters.listen",
869 filter: ["added", "loaded", "removed"] 1018 filter: ["added", "loaded", "removed"]
870 }); 1019 });
871 ext.backgroundPage.sendMessage( 1020 ext.backgroundPage.sendMessage(
872 { 1021 {
873 type: "subscriptions.listen", 1022 type: "subscriptions.listen",
874 filter: ["added", "disabled", "homepage", "removed", "title"] 1023 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ]
875 }); 1024 });
876 1025
877 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1026 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
878 })(); 1027 })();
OLDNEW
« no previous file with comments | « options.html ('k') | skin/options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld