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

Delta Between Two Patch Sets: new-options.js

Issue 29338983: issue 3741 - Add "remove" option to list items in new options page (Closed)
Left Patch Set: Rebase to changeset #83 Created May 10, 2016, 2:17 p.m.
Right Patch Set: Removed label's "for" attribute, added "aria-lable" to addItem Created June 24, 2016, 4:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « new-options.html ('k') | skin/new-options.css » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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);
24 var filtersMap = Object.create(null); 23 var filtersMap = Object.create(null);
25 var collections = Object.create(null); 24 var collections = Object.create(null);
26 var acceptableAdsUrl = null; 25 var acceptableAdsUrl = null;
27 var maxLabelId = 0;
28 var getMessage = ext.i18n.getMessage; 26 var getMessage = ext.i18n.getMessage;
29 var filterErrors = 27 var filterErrors =
30 { 28 {
31 "synchronize_invalid_url": "options_filterList_lastDownload_invalidURL", 29 "synchronize_invalid_url": "options_filterList_lastDownload_invalidURL",
32 "synchronize_connection_error": "options_filterList_lastDownload_connectionE rror", 30 "synchronize_connection_error": "options_filterList_lastDownload_connectionE rror",
33 "synchronize_invalid_data": "options_filterList_lastDownload_invalidData", 31 "synchronize_invalid_data": "options_filterList_lastDownload_invalidData",
34 "synchronize_checksum_mismatch": "options_filterList_lastDownload_checksumMi smatch" 32 "synchronize_checksum_mismatch": "options_filterList_lastDownload_checksumMi smatch"
35 }; 33 };
36 34
37 function Collection(details) 35 function Collection(details)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 94
97 for (var j = 0; j < this.details.length; j++) 95 for (var j = 0; j < this.details.length; j++)
98 { 96 {
99 var table = E(this.details[j].id); 97 var table = E(this.details[j].id);
100 var template = table.querySelector("template"); 98 var template = table.querySelector("template");
101 for (var i = 0; i < arguments.length; i++) 99 for (var i = 0; i < arguments.length; i++)
102 { 100 {
103 var item = arguments[i]; 101 var item = arguments[i];
104 var listItem = document.createElement("li"); 102 var listItem = document.createElement("li");
105 listItem.appendChild(document.importNode(template.content, true)); 103 listItem.appendChild(document.importNode(template.content, true));
104 listItem.setAttribute("aria-label", this._getItemTitle(item, j));
106 listItem.setAttribute("data-access", item.url || item.text); 105 listItem.setAttribute("data-access", item.url || item.text);
107 106 listItem.setAttribute("role", "section");
108 var labelId = "label-" + (++maxLabelId); 107
109 var label = listItem.querySelector(".display"); 108 var label = listItem.querySelector(".display");
110 label.setAttribute("id", labelId); 109 if (item.recommended && label.hasAttribute("data-tooltip"))
111 110 {
112 var control = listItem.querySelector(".control"); 111 var tooltipId = label.getAttribute("data-tooltip");
113 if (control) 112 tooltipId = tooltipId.replace("%value%", item.recommended);
114 { 113 label.setAttribute("data-tooltip", tooltipId);
115 control.setAttribute("aria-labelledby", labelId); 114 }
116 control.addEventListener("click", this.details[j].onClick, false); 115
117 116 var controls = listItem.querySelectorAll(".control");
118 var role = control.getAttribute("role"); 117 for (var k = 0; k < controls.length; k++)
119 if (role == "checkbox" && !label.hasAttribute("data-action")) 118 {
120 { 119 if (controls[k].hasAttribute("title"))
121 var controlId = "control-" + maxLabelId; 120 {
122 control.setAttribute("id", controlId); 121 var titleValue = getMessage(controls[k].getAttribute("title"));
123 label.setAttribute("for", controlId); 122 controls[k].setAttribute("title", titleValue)
124 } 123 }
125 } 124 }
126 125
127 this._setEmpty(table, null); 126 this._setEmpty(table, null);
128 if (table.hasChildNodes()) 127 if (table.hasChildNodes())
129 { 128 {
130 table.insertBefore(listItem, 129 table.insertBefore(listItem,
131 table.childNodes[this.items.indexOf(item)]); 130 table.childNodes[this.items.indexOf(item)]);
132 } 131 }
133 else 132 else
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 var access = (item.url || item.text).replace(/'/g, "\\'"); 181 var access = (item.url || item.text).replace(/'/g, "\\'");
183 for (var i = 0; i < this.details.length; i++) 182 for (var i = 0; i < this.details.length; i++)
184 { 183 {
185 var table = E(this.details[i].id); 184 var table = E(this.details[i].id);
186 var element = table.querySelector("[data-access='" + access + "']"); 185 var element = table.querySelector("[data-access='" + access + "']");
187 if (!element) 186 if (!element)
188 continue; 187 continue;
189 188
190 var title = this._getItemTitle(item, i); 189 var title = this._getItemTitle(item, i);
191 element.querySelector(".display").textContent = title; 190 element.querySelector(".display").textContent = title;
192 if (title) 191 element.setAttribute("aria-label", title);
192 if (this.details[i].searchable)
193 element.setAttribute("data-search", title.toLowerCase()); 193 element.setAttribute("data-search", title.toLowerCase());
194 var control = element.querySelector(".control[role='checkbox']"); 194 var control = element.querySelector(".control[role='checkbox']");
195 if (control) 195 if (control)
196 { 196 {
197 control.setAttribute("aria-checked", item.disabled == false); 197 control.setAttribute("aria-checked", item.disabled == false);
198 if (item.url == acceptableAdsUrl && this.details[i].onClick == 198 if (item.url == acceptableAdsUrl && this == collections.filterLists)
199 toggleDisableSubscription)
200 control.setAttribute("disabled", true); 199 control.setAttribute("disabled", true);
201 } 200 }
202 201
203 var dateElement = element.querySelector(".date"); 202 var dateElement = element.querySelector(".date");
204 var timeElement = element.querySelector(".time"); 203 var timeElement = element.querySelector(".time");
205 if (dateElement && timeElement) 204 if (dateElement && timeElement)
206 { 205 {
207 var message = element.querySelector(".message"); 206 var message = element.querySelector(".message");
208 if (item.isDownloading) 207 if (item.isDownloading)
209 { 208 {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 index += (index == focusables.length - 1) ? -1 : 1; 269 index += (index == focusables.length - 1) ? -1 : 1;
271 270
272 var nextElement = focusables[index]; 271 var nextElement = focusables[index];
273 if (!nextElement) 272 if (!nextElement)
274 return false; 273 return false;
275 274
276 nextElement.focus(); 275 nextElement.focus();
277 return true; 276 return true;
278 } 277 }
279 278
280 function toggleRemoveSubscription(e)
281 {
282 e.preventDefault();
283 var subscriptionUrl = findParentData(e.target, "access", false);
284 if (e.target.getAttribute("aria-checked") == "true")
285 {
286 ext.backgroundPage.sendMessage({
287 type: "subscriptions.remove",
288 url: subscriptionUrl
289 });
290 }
291 else
292 addEnableSubscription(subscriptionUrl);
293 }
294
295 function toggleDisableSubscription(e)
296 {
297 e.preventDefault();
298 var subscriptionUrl = findParentData(e.target, "access", false);
299 ext.backgroundPage.sendMessage(
300 {
301 type: "subscriptions.toggle",
302 keepInstalled: true,
303 url: subscriptionUrl
304 });
305 }
306
307 function onAddLanguageSubscriptionClick(e)
308 {
309 e.preventDefault();
310 var url = findParentData(this, "access", false);
311 addEnableSubscription(url);
312 }
313
314 function onRemoveFilterClick()
315 {
316 var filter = findParentData(this, "access", false);
317 ext.backgroundPage.sendMessage(
318 {
319 type: "filters.remove",
320 text: filter
321 });
322 }
323
324 collections.popular = new Collection( 279 collections.popular = new Collection(
325 [ 280 [
326 { 281 {
327 id: "recommend-list-table", 282 id: "recommend-list-table"
328 onClick: toggleRemoveSubscription
329 } 283 }
330 ]); 284 ]);
331 collections.langs = new Collection( 285 collections.langs = new Collection(
332 [ 286 [
333 { 287 {
334 id: "blocking-languages-table", 288 id: "blocking-languages-table",
335 emptyText: "options_dialog_language_added_empty", 289 emptyText: "options_dialog_language_added_empty"
336 onClick: toggleDisableSubscription
337 }, 290 },
338 { 291 {
339 id: "blocking-languages-dialog-table", 292 id: "blocking-languages-dialog-table",
340 emptyText: "options_dialog_language_added_empty" 293 emptyText: "options_dialog_language_added_empty"
341 } 294 }
342 ]); 295 ]);
343 collections.allLangs = new Collection( 296 collections.allLangs = new Collection(
344 [ 297 [
345 { 298 {
346 id: "all-lang-table", 299 id: "all-lang-table",
347 emptyText: "options_dialog_language_other_empty", 300 emptyText: "options_dialog_language_other_empty",
348 onClick: onAddLanguageSubscriptionClick 301 searchable: true
349 } 302 }
350 ]); 303 ]);
351 collections.acceptableAds = new Collection( 304 collections.acceptableAds = new Collection(
352 [ 305 [
353 { 306 {
354 id: "acceptableads-table", 307 id: "acceptableads-table"
355 onClick: toggleRemoveSubscription
356 } 308 }
357 ]); 309 ]);
358 collections.custom = new Collection( 310 collections.custom = new Collection(
359 [ 311 [
360 { 312 {
361 id: "custom-list-table", 313 id: "custom-list-table"
362 onClick: toggleDisableSubscription
363 } 314 }
364 ]); 315 ]);
365 collections.whitelist = new Collection( 316 collections.whitelist = new Collection(
366 [ 317 [
367 { 318 {
368 id: "whitelisting-table", 319 id: "whitelisting-table",
369 emptyText: "options_whitelisted_empty", 320 emptyText: "options_whitelisted_empty"
370 onClick: onRemoveFilterClick
371 } 321 }
372 ]); 322 ]);
373 collections.customFilters = new Collection( 323 collections.customFilters = new Collection(
374 [ 324 [
375 { 325 {
376 id: "custom-filters-table", 326 id: "custom-filters-table",
377 emptyText: "options_customFilters_empty" 327 emptyText: "options_customFilters_empty"
378 } 328 }
379 ]); 329 ]);
380 collections.filterLists = new Collection( 330 collections.filterLists = new Collection(
381 [ 331 [
382 { 332 {
383 id: "all-filter-lists-table", 333 id: "all-filter-lists-table",
384 onClick: toggleDisableSubscription,
385 useOriginalTitle: true 334 useOriginalTitle: true
386 } 335 }
387 ]); 336 ]);
388 337
389 function updateLanguageCollections(subscription) 338 function updateLanguageCollections(subscription)
390 { 339 {
391 var recommendation = recommendationsMap[subscription.url]; 340 if (subscription.recommended == "ads")
392
393 if (recommendation && recommendation.type == "ads")
394 { 341 {
395 if (subscription.disabled) 342 if (subscription.disabled)
396 { 343 {
397 collections.allLangs.addItems(subscription); 344 collections.allLangs.addItems(subscription);
398 collections.langs.removeItem(subscription); 345 collections.langs.removeItem(subscription);
399 } 346 }
400 else 347 else
401 { 348 {
402 collections.allLangs.removeItem(subscription); 349 collections.allLangs.removeItem(subscription);
403 collections.langs.addItems(subscription); 350 collections.langs.addItems(subscription);
404 } 351 }
405 } 352 }
406 } 353 }
407 354
408 function addSubscription(subscription) 355 function addSubscription(subscription)
409 { 356 {
410 var collection; 357 var collection;
411 if (subscription.url in recommendationsMap) 358 if (subscription.recommended)
412 { 359 {
413 var recommendation = recommendationsMap[subscription.url]; 360 if (subscription.recommended != "ads")
414 if (recommendation.type != "ads")
415 collection = collections.popular; 361 collection = collections.popular;
416 else if (subscription.disabled == false) 362 else if (subscription.disabled == false)
417 collection = collections.langs; 363 collection = collections.langs;
418 else 364 else
419 collection = collections.allLangs; 365 collection = collections.allLangs;
420 } 366 }
421 else if (subscription.url == acceptableAdsUrl) 367 else if (subscription.url == acceptableAdsUrl)
422 collection = collections.acceptableAds; 368 collection = collections.acceptableAds;
423 else 369 else
424 collection = collections.custom; 370 collection = collections.custom;
425 371
426 collection.addItems(subscription); 372 collection.addItems(subscription);
427 subscriptionsMap[subscription.url] = subscription; 373 subscriptionsMap[subscription.url] = subscription;
374 updateTooltips();
428 } 375 }
429 376
430 function updateSubscription(subscription) 377 function updateSubscription(subscription)
431 { 378 {
432 var knownSubscription = subscriptionsMap[subscription.url]; 379 var knownSubscription = subscriptionsMap[subscription.url];
433 for (var property in subscription) 380 for (var property in subscription)
434 { 381 {
435 if (property == "title" && subscription.url in recommendationsMap) 382 if (property == "title" && subscription.recommended)
436 knownSubscription.originalTitle = subscription.title; 383 knownSubscription.originalTitle = subscription.title;
437 else 384 else
438 knownSubscription[property] = subscription[property]; 385 knownSubscription[property] = subscription[property];
439 } 386 }
440 387
441 for (var name in collections) 388 for (var name in collections)
442 collections[name].updateItem(knownSubscription); 389 collections[name].updateItem(knownSubscription);
443 390
444 return knownSubscription; 391 return knownSubscription;
445 } 392 }
(...skipping 20 matching lines...) Expand all
466 return response.text(); 413 return response.text();
467 }) 414 })
468 .then(function(text) 415 .then(function(text)
469 { 416 {
470 var list = document.getElementById("subscriptionSelector"); 417 var list = document.getElementById("subscriptionSelector");
471 var doc = new DOMParser().parseFromString(text, "application/xml"); 418 var doc = new DOMParser().parseFromString(text, "application/xml");
472 var elements = doc.documentElement.getElementsByTagName("subscription"); 419 var elements = doc.documentElement.getElementsByTagName("subscription");
473 for (var i = 0; i < elements.length; i++) 420 for (var i = 0; i < elements.length; i++)
474 { 421 {
475 var element = elements[i]; 422 var element = elements[i];
476 var subscription = Object.create(null); 423 var type = element.getAttribute("type");
477 subscription.originalTitle = element.getAttribute("title"); 424 var subscription = {
478 subscription.url = element.getAttribute("url"); 425 disabled: null,
479 subscription.disabled = true; 426 downloadStatus: null,
480 subscription.downloadStatus = null; 427 homepage: null,
481 subscription.homepage = null; 428 originalTitle: element.getAttribute("title"),
482 var recommendation = Object.create(null); 429 recommended: type,
483 recommendation.type = element.getAttribute("type"); 430 url: element.getAttribute("url")
431 };
432
484 var prefix = element.getAttribute("prefixes"); 433 var prefix = element.getAttribute("prefixes");
485 if (prefix) 434 if (prefix)
486 { 435 {
487 prefix = prefix.replace(/\W/g, "_"); 436 prefix = prefix.replace(/\W/g, "_");
488 subscription.title = getMessage("options_language_" + prefix); 437 subscription.title = getMessage("options_language_" + prefix);
489 } 438 }
490 else 439 else
491 { 440 {
492 var type = recommendation.type.replace(/\W/g, "_"); 441 type = type.replace(/\W/g, "_");
493 subscription.title = getMessage("common_feature_" + type + "_title") ; 442 subscription.title = getMessage("common_feature_" + type + "_title") ;
494 } 443 }
495 444
496 recommendationsMap[subscription.url] = recommendation;
497 addSubscription(subscription); 445 addSubscription(subscription);
498 } 446 }
499 }); 447 });
500 } 448 }
501 449
502 function findParentData(element, dataName, returnElement) 450 function findParentData(element, dataName, returnElement)
503 { 451 {
504 while (element) 452 while (element)
505 { 453 {
506 if (element.hasAttribute("data-" + dataName)) 454 if (element.hasAttribute("data-" + dataName))
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 url: findParentData(element, "access", false) 570 url: findParentData(element, "access", false)
623 }); 571 });
624 break; 572 break;
625 case "remove-subscription": 573 case "remove-subscription":
626 ext.backgroundPage.sendMessage( 574 ext.backgroundPage.sendMessage(
627 { 575 {
628 type: "subscriptions.remove", 576 type: "subscriptions.remove",
629 url: findParentData(element, "access", false) 577 url: findParentData(element, "access", false)
630 }); 578 });
631 break; 579 break;
580 case "toggle-remove-subscription":
581 var subscriptionUrl = findParentData(element, "access", false);
582 if (element.getAttribute("aria-checked") == "true")
583 {
584 ext.backgroundPage.sendMessage({
585 type: "subscriptions.remove",
586 url: subscriptionUrl
587 });
588 }
589 else
590 addEnableSubscription(subscriptionUrl);
591 break;
592 case "toggle-disable-subscription":
593 ext.backgroundPage.sendMessage(
594 {
595 type: "subscriptions.toggle",
596 keepInstalled: true,
597 url: findParentData(element, "access", false)
598 });
599 break;
600 case "add-language-subscription":
601 addEnableSubscription(findParentData(element, "access", false));
602 break;
603 case "remove-filter":
604 ext.backgroundPage.sendMessage(
605 {
606 type: "filters.remove",
607 text: findParentData(element, "access", false)
608 });
609 break;
632 } 610 }
633 } 611 }
634 } 612 }
635 613
636 function onDOMLoaded() 614 function onDOMLoaded()
637 { 615 {
638 populateLists(); 616 populateLists();
639 function onFindLanguageKeyUp() 617 function onFindLanguageKeyUp()
640 { 618 {
641 var searchStyle = E("search-style"); 619 var searchStyle = E("search-style");
(...skipping 30 matching lines...) Expand all
672 { 650 {
673 E("link-version").setAttribute("href", link); 651 E("link-version").setAttribute("href", link);
674 }); 652 });
675 653
676 getDocLink("contribute", function(link) 654 getDocLink("contribute", function(link)
677 { 655 {
678 document.querySelector("#tab-contribute a").setAttribute("href", link); 656 document.querySelector("#tab-contribute a").setAttribute("href", link);
679 }); 657 });
680 658
681 updateShareLink(); 659 updateShareLink();
660 updateTooltips();
682 661
683 // Initialize interactive UI elements 662 // Initialize interactive UI elements
684 document.body.addEventListener("click", onClick, false); 663 document.body.addEventListener("click", onClick, false);
685 var placeholderValue = getMessage("options_dialog_language_find"); 664 var placeholderValue = getMessage("options_dialog_language_find");
686 E("find-language").setAttribute("placeholder", placeholderValue); 665 E("find-language").setAttribute("placeholder", placeholderValue);
687 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); 666 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false);
688 E("whitelisting-textbox").addEventListener("keypress", function(e) 667 E("whitelisting-textbox").addEventListener("keypress", function(e)
689 { 668 {
690 if (getKey(e) == "Enter") 669 if (getKey(e) == "Enter")
691 addWhitelistedDomain(); 670 addWhitelistedDomain();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 dialog.setAttribute("aria-hidden", true); 772 dialog.setAttribute("aria-hidden", true);
794 dialog.removeAttribute("aria-labelledby"); 773 dialog.removeAttribute("aria-labelledby");
795 document.body.removeAttribute("data-dialog"); 774 document.body.removeAttribute("data-dialog");
796 focusedBeforeDialog.focus(); 775 focusedBeforeDialog.focus();
797 } 776 }
798 777
799 function populateLists() 778 function populateLists()
800 { 779 {
801 subscriptionsMap = Object.create(null); 780 subscriptionsMap = Object.create(null);
802 filtersMap = Object.create(null); 781 filtersMap = Object.create(null);
803 recommendationsMap = Object.create(null);
804 782
805 // Empty collections and lists 783 // Empty collections and lists
806 for (var property in collections) 784 for (var property in collections)
807 collections[property].clearAll(); 785 collections[property].clearAll();
808 786
809 ext.backgroundPage.sendMessage( 787 ext.backgroundPage.sendMessage(
810 { 788 {
811 type: "subscriptions.get", 789 type: "subscriptions.get",
812 special: true 790 special: true
813 }, 791 },
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 if (subscription.url in subscriptionsMap) 920 if (subscription.url in subscriptionsMap)
943 subscription = updateSubscription(subscription); 921 subscription = updateSubscription(subscription);
944 else 922 else
945 addSubscription(subscription); 923 addSubscription(subscription);
946 924
947 collections.filterLists.addItems(subscription); 925 collections.filterLists.addItems(subscription);
948 updateLanguageCollections(subscription); 926 updateLanguageCollections(subscription);
949 break; 927 break;
950 case "removed": 928 case "removed":
951 var knownSubscription = subscriptionsMap[subscription.url]; 929 var knownSubscription = subscriptionsMap[subscription.url];
952 930 if (subscription.url == acceptableAdsUrl || subscription.recommended)
953 if (subscription.url == acceptableAdsUrl ||
954 subscription.url in recommendationsMap)
955 { 931 {
956 subscription.disabled = true; 932 subscription.disabled = true;
957 onSubscriptionMessage("disabled", subscription); 933 onSubscriptionMessage("disabled", subscription);
958 } 934 }
959 else 935 else
960 { 936 {
961 collections.custom.removeItem(knownSubscription); 937 collections.custom.removeItem(knownSubscription);
962 delete subscriptionsMap[subscription.url]; 938 delete subscriptionsMap[subscription.url];
963 } 939 }
964 collections.filterLists.removeItem(knownSubscription); 940 collections.filterLists.removeItem(knownSubscription);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 tab.hidden = true; 1034 tab.hidden = true;
1059 tab.removeEventListener("click", onShareLinkClick, false); 1035 tab.removeEventListener("click", onShareLinkClick, false);
1060 } 1036 }
1061 else 1037 else
1062 tab.addEventListener("click", onShareLinkClick, false); 1038 tab.addEventListener("click", onShareLinkClick, false);
1063 } 1039 }
1064 } 1040 }
1065 1041
1066 for (var i = 0; i < shareResources.length; i++) 1042 for (var i = 0; i < shareResources.length; i++)
1067 checkShareResource(shareResources[i], onResult); 1043 checkShareResource(shareResources[i], onResult);
1044 }
1045
1046 function getMessages(id)
1047 {
1048 var messages = [];
1049 for (var i = 1; true; i++)
1050 {
1051 var message = ext.i18n.getMessage(id + "_" + i);
1052 if (!message)
1053 break;
1054
1055 messages.push(message);
1056 }
1057 return messages;
1058 }
1059
1060 function updateTooltips()
1061 {
1062 var anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]");
1063 for (var i = 0; i < anchors.length; i++)
1064 {
1065 var anchor = anchors[i];
1066 var id = anchor.getAttribute("data-tooltip");
1067
1068 var wrapper = document.createElement("div");
1069 wrapper.className = "tooltip";
1070 anchor.parentNode.replaceChild(wrapper, anchor);
1071 wrapper.appendChild(anchor);
1072
1073 var topTexts = getMessages(id);
1074 var bottomTexts = getMessages(id + "_notes");
1075
1076 // We have to use native tooltips to avoid issues when attaching a tooltip
1077 // to an element in a scrollable list or otherwise it might get cut off
1078 if (anchor.hasAttribute("data-tooltip-native"))
1079 {
1080 var title = topTexts.concat(bottomTexts).join("\n\n");
1081 anchor.setAttribute("title", title);
1082 continue;
1083 }
1084
1085 var tooltip = document.createElement("div");
1086 tooltip.setAttribute("role", "tooltip");
1087
1088 var flip = anchor.getAttribute("data-tooltip-flip");
1089 if (flip)
1090 tooltip.className = "flip-" + flip;
1091
1092 var imageSource = anchor.getAttribute("data-tooltip-image");
1093 if (imageSource)
1094 {
1095 var image = document.createElement("img");
1096 image.src = imageSource;
1097 image.alt = "";
1098 tooltip.appendChild(image);
1099 }
1100
1101 for (var j = 0; j < topTexts.length; j++)
1102 {
1103 var paragraph = document.createElement("p");
1104 paragraph.innerHTML = topTexts[j];
1105 tooltip.appendChild(paragraph);
1106 }
1107 if (bottomTexts.length > 0)
1108 {
1109 var notes = document.createElement("div");
1110 notes.className = "notes";
1111 for (var j = 0; j < bottomTexts.length; j++)
1112 {
1113 var paragraph = document.createElement("p");
1114 paragraph.innerHTML = bottomTexts[j];
1115 notes.appendChild(paragraph);
1116 }
1117 tooltip.appendChild(notes);
1118 }
1119
1120 wrapper.appendChild(tooltip);
1121 }
1068 } 1122 }
1069 1123
1070 ext.onMessage.addListener(function(message) 1124 ext.onMessage.addListener(function(message)
1071 { 1125 {
1072 switch (message.type) 1126 switch (message.type)
1073 { 1127 {
1074 case "app.respond": 1128 case "app.respond":
1075 switch (message.action) 1129 switch (message.action)
1076 { 1130 {
1077 case "addSubscription": 1131 case "addSubscription":
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 }); 1171 });
1118 ext.backgroundPage.sendMessage( 1172 ext.backgroundPage.sendMessage(
1119 { 1173 {
1120 type: "subscriptions.listen", 1174 type: "subscriptions.listen",
1121 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1175 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1122 "title", "downloadStatus", "downloading"] 1176 "title", "downloadStatus", "downloading"]
1123 }); 1177 });
1124 1178
1125 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1179 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1126 })(); 1180 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld