OLD | NEW |
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 { | 61 { |
62 var table = E(this.details[j].id); | 62 var table = E(this.details[j].id); |
63 var template = table.querySelector("template"); | 63 var template = table.querySelector("template"); |
64 for (var i = 0; i < arguments.length; i++) | 64 for (var i = 0; i < arguments.length; i++) |
65 { | 65 { |
66 var item = arguments[i]; | 66 var item = arguments[i]; |
67 var text = item.title || item.url || item.text; | 67 var text = item.title || item.url || item.text; |
68 var listItem = document.createElement("li"); | 68 var listItem = document.createElement("li"); |
69 listItem.appendChild(document.importNode(template.content, true)); | 69 listItem.appendChild(document.importNode(template.content, true)); |
70 listItem.setAttribute("data-access", item.url || item.text); | 70 listItem.setAttribute("data-access", item.url || item.text); |
71 listItem.querySelector(".display").textContent = text; | 71 var display = listItem.querySelector(".display"); |
| 72 if (item.type) |
| 73 display.setAttribute("data-tooltip-value", item.type); |
| 74 display.textContent = text; |
72 if (text) | 75 if (text) |
73 listItem.setAttribute("data-search", text.toLowerCase()); | 76 listItem.setAttribute("data-search", text.toLowerCase()); |
74 | 77 |
75 var control = listItem.querySelector(".control"); | 78 var control = listItem.querySelector(".control"); |
76 if (control) | 79 if (control) |
77 { | 80 { |
78 control.addEventListener("click", this.details[j].onClick, false); | 81 control.addEventListener("click", this.details[j].onClick, false); |
79 control.checked = item.disabled == false; | 82 control.checked = item.disabled == false; |
80 } | 83 } |
81 | 84 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 collections.langs.addItems(subscription); | 242 collections.langs.addItems(subscription); |
240 } | 243 } |
241 else | 244 else |
242 { | 245 { |
243 collections.allLangs.addItems(subscription); | 246 collections.allLangs.addItems(subscription); |
244 collections.langs.removeItem(subscription); | 247 collections.langs.removeItem(subscription); |
245 } | 248 } |
246 } | 249 } |
247 } | 250 } |
248 } | 251 } |
| 252 updateTooltips(); |
249 } | 253 } |
250 | 254 |
251 if (!Object.observe) | 255 if (!Object.observe) |
252 { | 256 { |
253 // Currently only "disabled" property of subscription used for observa
tion | 257 // Currently only "disabled" property of subscription used for observa
tion |
254 // but with Advanced tab implementation we should also add more proper
ties. | 258 // but with Advanced tab implementation we should also add more proper
ties. |
255 ["disabled"].forEach(function(property) | 259 ["disabled"].forEach(function(property) |
256 { | 260 { |
257 subscription["$" + property] = subscription[property]; | 261 subscription["$" + property] = subscription[property]; |
258 Object.defineProperty(subscription, property, | 262 Object.defineProperty(subscription, property, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 return response.text(); | 322 return response.text(); |
319 }) | 323 }) |
320 .then(function(text) | 324 .then(function(text) |
321 { | 325 { |
322 var list = document.getElementById("subscriptionSelector"); | 326 var list = document.getElementById("subscriptionSelector"); |
323 var doc = new DOMParser().parseFromString(text, "application/xml"); | 327 var doc = new DOMParser().parseFromString(text, "application/xml"); |
324 var elements = doc.documentElement.getElementsByTagName("subscription"); | 328 var elements = doc.documentElement.getElementsByTagName("subscription"); |
325 for (var i = 0; i < elements.length; i++) | 329 for (var i = 0; i < elements.length; i++) |
326 { | 330 { |
327 var element = elements[i]; | 331 var element = elements[i]; |
328 var subscription = Object.create(null); | 332 var recommendation = {type: element.getAttribute("type")}; |
329 subscription.title = element.getAttribute("title"); | 333 var subscription = { |
330 subscription.url = element.getAttribute("url"); | 334 title: element.getAttribute("title"), |
331 subscription.disabled = null; | 335 url: element.getAttribute("url"), |
332 subscription.downloadStatus = null; | 336 disabled: null, |
333 subscription.homepage = null; | 337 downloadStatus: null, |
334 subscription.lastSuccess = null; | 338 homepage: null, |
335 var recommendation = Object.create(null); | 339 lastSuccess: null, |
336 recommendation.type = element.getAttribute("type"); | 340 type: recommendation.type |
| 341 }; |
337 var prefix = element.getAttribute("prefixes"); | 342 var prefix = element.getAttribute("prefixes"); |
338 if (prefix) | 343 if (prefix) |
339 { | 344 { |
340 prefix = prefix.replace(/\W/g, "_"); | 345 prefix = prefix.replace(/\W/g, "_"); |
341 subscription.title = ext.i18n.getMessage("options_language_" + prefi
x); | 346 subscription.title = ext.i18n.getMessage("options_language_" + prefi
x); |
342 } | 347 } |
343 else | 348 else |
344 { | 349 { |
345 var type = recommendation.type.replace(/\W/g, "_"); | 350 var type = recommendation.type.replace(/\W/g, "_"); |
346 subscription.title = ext.i18n.getMessage("common_feature_" + type +
"_title"); | 351 subscription.title = ext.i18n.getMessage("common_feature_" + type +
"_title"); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 } | 779 } |
775 else | 780 else |
776 tab.addEventListener("click", onShareLinkClick, false); | 781 tab.addEventListener("click", onShareLinkClick, false); |
777 } | 782 } |
778 } | 783 } |
779 | 784 |
780 for (var i = 0; i < shareResources.length; i++) | 785 for (var i = 0; i < shareResources.length; i++) |
781 checkShareResource(shareResources[i], onResult); | 786 checkShareResource(shareResources[i], onResult); |
782 } | 787 } |
783 | 788 |
| 789 function getMessages(id) |
| 790 { |
| 791 var messages = []; |
| 792 for (var i = 1; true; i++) |
| 793 { |
| 794 var message = ext.i18n.getMessage(id + "_" + i); |
| 795 if (!message) |
| 796 break; |
| 797 |
| 798 messages.push(message); |
| 799 } |
| 800 return messages; |
| 801 } |
| 802 |
| 803 function updateTooltips() |
| 804 { |
| 805 var anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]"); |
| 806 for (var i = 0; i < anchors.length; i++) |
| 807 { |
| 808 var anchor = anchors[i]; |
| 809 var id = anchor.getAttribute("data-tooltip"); |
| 810 id = id.replace("%value%", anchor.getAttribute("data-tooltip-value")); |
| 811 |
| 812 var wrapper = document.createElement("div"); |
| 813 wrapper.className = "tooltip"; |
| 814 anchor.parentNode.replaceChild(wrapper, anchor); |
| 815 wrapper.appendChild(anchor); |
| 816 |
| 817 var topTexts = getMessages(id); |
| 818 var bottomTexts = getMessages(id + "_notes"); |
| 819 |
| 820 // We have to use native tooltips to avoid issues when attaching a tooltip |
| 821 // to an element in a scrollable list or otherwise it might get cut off |
| 822 if (anchor.hasAttribute("data-tooltip-native")) |
| 823 { |
| 824 var title = topTexts.concat(bottomTexts).join("\n\n"); |
| 825 anchor.setAttribute("title", title); |
| 826 continue; |
| 827 } |
| 828 |
| 829 var tooltip = document.createElement("div"); |
| 830 tooltip.setAttribute("role", "tooltip"); |
| 831 |
| 832 var flip = anchor.getAttribute("data-tooltip-flip"); |
| 833 if (flip) |
| 834 tooltip.className = "flip-" + flip; |
| 835 |
| 836 var imageSource = anchor.getAttribute("data-tooltip-image"); |
| 837 if (imageSource) |
| 838 { |
| 839 var image = document.createElement("img"); |
| 840 image.src = imageSource; |
| 841 image.alt = ""; |
| 842 tooltip.appendChild(image); |
| 843 } |
| 844 |
| 845 for (var j = 0; j < topTexts.length; j++) |
| 846 { |
| 847 var paragraph = document.createElement("p"); |
| 848 paragraph.textContent = topTexts[j]; |
| 849 tooltip.appendChild(paragraph); |
| 850 } |
| 851 if (bottomTexts.length > 0) |
| 852 { |
| 853 var notes = document.createElement("div"); |
| 854 notes.className = "notes"; |
| 855 for (var j = 0; j < bottomTexts.length; j++) |
| 856 { |
| 857 var paragraph = document.createElement("p"); |
| 858 paragraph.textContent = bottomTexts[j]; |
| 859 notes.appendChild(paragraph); |
| 860 } |
| 861 tooltip.appendChild(notes); |
| 862 } |
| 863 |
| 864 wrapper.appendChild(tooltip); |
| 865 } |
| 866 } |
| 867 |
784 ext.onMessage.addListener(function(message) | 868 ext.onMessage.addListener(function(message) |
785 { | 869 { |
786 switch (message.type) | 870 switch (message.type) |
787 { | 871 { |
788 case "app.listen": | 872 case "app.listen": |
789 if (message.action == "addSubscription") | 873 if (message.action == "addSubscription") |
790 { | 874 { |
791 var subscription = message.args[0]; | 875 var subscription = message.args[0]; |
792 var dialog = E("dialog-content-predefined"); | 876 var dialog = E("dialog-content-predefined"); |
793 dialog.querySelector("h3").textContent = subscription.title || ""; | 877 dialog.querySelector("h3").textContent = subscription.title || ""; |
(...skipping 25 matching lines...) Expand all Loading... |
819 filter: ["added", "loaded", "removed"] | 903 filter: ["added", "loaded", "removed"] |
820 }); | 904 }); |
821 ext.backgroundPage.sendMessage( | 905 ext.backgroundPage.sendMessage( |
822 { | 906 { |
823 type: "subscriptions.listen", | 907 type: "subscriptions.listen", |
824 filter: ["added", "disabled", "homepage", "removed", "title"] | 908 filter: ["added", "disabled", "homepage", "removed", "title"] |
825 }); | 909 }); |
826 | 910 |
827 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 911 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
828 })(); | 912 })(); |
OLD | NEW |