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

Powered by Google App Engine
This is Rietveld