 Issue 29333819:
  Issue 2375 - Implement "Blocking lists" section in new options page  (Closed)
    
  
    Issue 29333819:
  Issue 2375 - Implement "Blocking lists" section in new options page  (Closed) 
  | Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 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-2016 Eyeo GmbH | 
| 4 * | 4 * | 
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify | 
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as | 
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. | 
| 8 * | 8 * | 
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, | 
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. | 
| 13 * | 13 * | 
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License | 
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 
| 16 */ | 16 */ | 
| 17 | 17 | 
| 18 "use strict"; | 18 "use strict"; | 
| 19 | 19 | 
| 20 (function() | 20 (function() | 
| 21 { | 21 { | 
| 22 var subscriptionsMap = Object.create(null); | 22 var subscriptionsMap = Object.create(null); | 
| 23 var recommendationsMap = Object.create(null); | 23 var recommendationsMap = Object.create(null); | 
| 24 var filtersMap = Object.create(null); | 24 var filtersMap = Object.create(null); | 
| 25 var collections = Object.create(null); | 25 var collections = Object.create(null); | 
| 26 var maxLabelId = 0; | |
| 27 var getMessage = ext.i18n.getMessage; | |
| 28 var filterErrors = | |
| 29 { | |
| 30 "synchronize_invalid_url": "options_filterList_lastDownload_invalidURL", | |
| 31 "synchronize_connection_error": "options_filterList_lastDownload_connectionE rror", | |
| 32 "synchronize_invalid_data": "options_filterList_lastDownload_invalidData", | |
| 33 "synchronize_checksum_mismatch": "options_filterList_lastDownload_checksumMi smatch" | |
| 34 }; | |
| 26 | 35 | 
| 27 function Collection(details) | 36 function Collection(details) | 
| 28 { | 37 { | 
| 29 this.details = details; | 38 this.details = details; | 
| 30 this.items = []; | 39 this.items = []; | 
| 31 } | 40 } | 
| 32 | 41 | 
| 33 Collection.prototype._setEmpty = function(table, text) | 42 Collection.prototype._setEmpty = function(table, text) | 
| 34 { | 43 { | 
| 35 var placeholder = table.querySelector(".empty-placeholder"); | 44 var placeholder = table.querySelector(".empty-placeholder"); | 
| 36 if (text && !placeholder) | 45 if (text && !placeholder) | 
| 37 { | 46 { | 
| 38 placeholder = document.createElement("li"); | 47 placeholder = document.createElement("li"); | 
| 39 placeholder.className = "empty-placeholder"; | 48 placeholder.className = "empty-placeholder"; | 
| 40 placeholder.textContent = ext.i18n.getMessage(text); | 49 placeholder.textContent = getMessage(text); | 
| 41 table.appendChild(placeholder); | 50 table.appendChild(placeholder); | 
| 42 } | 51 } | 
| 43 else if (placeholder) | 52 else if (placeholder) | 
| 44 table.removeChild(placeholder); | 53 table.removeChild(placeholder); | 
| 45 } | 54 } | 
| 46 | 55 | 
| 47 Collection.prototype._createElementQuery = function(item) | 56 Collection.prototype._createElementQuery = function(item) | 
| 48 { | 57 { | 
| 49 var access = (item.url || item.text).replace(/'/g, "\\'"); | 58 var access = (item.url || item.text).replace(/'/g, "\\'"); | 
| 50 return function(container) | 59 return function(container) | 
| (...skipping 15 matching lines...) Expand all Loading... | |
| 66 return aValue.localeCompare(bValue); | 75 return aValue.localeCompare(bValue); | 
| 67 }); | 76 }); | 
| 68 | 77 | 
| 69 for (var j = 0; j < this.details.length; j++) | 78 for (var j = 0; j < this.details.length; j++) | 
| 70 { | 79 { | 
| 71 var table = E(this.details[j].id); | 80 var table = E(this.details[j].id); | 
| 72 var template = table.querySelector("template"); | 81 var template = table.querySelector("template"); | 
| 73 for (var i = 0; i < arguments.length; i++) | 82 for (var i = 0; i < arguments.length; i++) | 
| 74 { | 83 { | 
| 75 var item = arguments[i]; | 84 var item = arguments[i]; | 
| 76 var text = item.title || item.url || item.text; | |
| 77 var listItem = document.createElement("li"); | 85 var listItem = document.createElement("li"); | 
| 78 listItem.appendChild(document.importNode(template.content, true)); | 86 listItem.appendChild(document.importNode(template.content, true)); | 
| 79 listItem.setAttribute("data-access", item.url || item.text); | 87 listItem.setAttribute("data-access", item.url || item.text); | 
| 80 listItem.querySelector(".display").textContent = text; | 88 | 
| 81 if (text) | 89 var labelId = "label-" + (++maxLabelId); | 
| 82 listItem.setAttribute("data-search", text.toLowerCase()); | 90 listItem.querySelector(".display").setAttribute("id", labelId); | 
| 83 | |
| 84 updateBlockingList(listItem, item); | |
| 85 var control = listItem.querySelector(".control"); | 91 var control = listItem.querySelector(".control"); | 
| 86 if (control) | 92 if (control) | 
| 87 { | 93 { | 
| 94 // We use aria-labelledby to avoid triggering the control when | |
| 95 // interacting with the label | |
| 96 control.setAttribute("aria-labelledby", labelId); | |
| 88 control.addEventListener("click", this.details[j].onClick, false); | 97 control.addEventListener("click", this.details[j].onClick, false); | 
| 89 control.checked = item.disabled == false; | |
| 90 } | 98 } | 
| 91 | 99 | 
| 92 this._setEmpty(table, null); | 100 this._setEmpty(table, null); | 
| 93 if (table.hasChildNodes()) | 101 if (table.hasChildNodes()) | 
| 94 { | 102 { | 
| 95 table.insertBefore(listItem, | 103 table.insertBefore(listItem, | 
| 96 table.childNodes[this.items.indexOf(item)]); | 104 table.childNodes[this.items.indexOf(item)]); | 
| 97 } | 105 } | 
| 98 else | 106 else | 
| 99 table.appendChild(listItem); | 107 table.appendChild(listItem); | 
| 108 this.updateItem(item); | |
| 100 } | 109 } | 
| 101 } | 110 } | 
| 102 return length; | 111 return length; | 
| 103 }; | 112 }; | 
| 104 | 113 | 
| 105 Collection.prototype.removeItem = function(item) | 114 Collection.prototype.removeItem = function(item) | 
| 106 { | 115 { | 
| 107 var index = this.items.indexOf(item); | 116 var index = this.items.indexOf(item); | 
| 108 if (index == -1) | 117 if (index == -1) | 
| 109 return; | 118 return; | 
| 110 | 119 | 
| 111 this.items.splice(index, 1); | 120 this.items.splice(index, 1); | 
| 112 var getListElement = this._createElementQuery(item); | 121 var getListElement = this._createElementQuery(item); | 
| 113 for (var i = 0; i < this.details.length; i++) | 122 for (var i = 0; i < this.details.length; i++) | 
| 114 { | 123 { | 
| 115 var table = E(this.details[i].id); | 124 var table = E(this.details[i].id); | 
| 116 var element = getListElement(table); | 125 var element = getListElement(table); | 
| 126 | |
| 127 // Element gets removed so make sure to handle focus appropriately | |
| 128 var control = element.querySelector(".control"); | |
| 129 if (control && control == document.activeElement) | |
| 130 { | |
| 131 if (!focusNextElement(element.parentElement, control)) | |
| 132 { | |
| 133 // Fall back to next focusable element within same tab or dialog | |
| 134 var focusableElement = element.parentElement; | |
| 135 while (focusableElement) | |
| 136 { | |
| 137 if (focusableElement.classList.contains("tab-content") | |
| 138 || focusableElement.classList.contains("dialog-content")) | |
| 139 break; | |
| 140 | |
| 141 focusableElement = focusableElement.parentElement; | |
| 142 } | |
| 143 focusNextElement(focusableElement || document, control); | |
| 144 } | |
| 145 } | |
| 146 | |
| 117 element.parentElement.removeChild(element); | 147 element.parentElement.removeChild(element); | 
| 118 if (this.items.length == 0) | 148 if (this.items.length == 0) | 
| 119 this._setEmpty(table, this.details[i].emptyText); | 149 this._setEmpty(table, this.details[i].emptyText); | 
| 120 } | 150 } | 
| 121 }; | 151 }; | 
| 122 | 152 | 
| 153 Collection.prototype.updateItem = function(item) | |
| 154 { | |
| 155 var access = (item.url || item.text).replace(/'/g, "\\'"); | |
| 156 for (var i = 0; i < this.details.length; i++) | |
| 157 { | |
| 158 var table = E(this.details[i].id); | |
| 159 var element = table.querySelector("[data-access='" + access + "']"); | |
| 160 if (!element) | |
| 161 continue; | |
| 162 | |
| 163 var title = item.title || item.url || item.text; | |
| 164 element.querySelector(".display").textContent = title; | |
| 165 if (title) | |
| 166 element.setAttribute("data-search", title.toLowerCase()); | |
| 167 var control = element.querySelector(".control[role='checkbox']"); | |
| 168 if (control) | |
| 169 control.setAttribute("aria-checked", item.disabled == false); | |
| 170 | |
| 171 var downloadStatus = item.downloadStatus; | |
| 172 var dateElement = element.querySelector(".date"); | |
| 173 var timeElement = element.querySelector(".time"); | |
| 174 if(dateElement && timeElement) | |
| 175 { | |
| 176 var message = element.querySelector(".message"); | |
| 177 ext.backgroundPage.sendMessage( | |
| 178 { | |
| 179 type: "subscriptions.isDownloading", | |
| 180 url: item.url | |
| 181 }, | |
| 182 function(isDownloading) | |
| 183 { | |
| 184 if (isDownloading) | |
| 185 { | |
| 186 var text = getMessage("options_filterList_lastDownload_inProgress"); | |
| 187 message.textContent = text; | |
| 188 element.classList.add("show-message"); | |
| 189 } | |
| 190 else if (downloadStatus && downloadStatus != "synchronize_ok") | |
| 191 { | |
| 192 if (downloadStatus in filterErrors) | |
| 193 message.textContent = getMessage(filterErrors[downloadStatus]); | |
| 194 else | |
| 195 message.textContent = item.downloadStatus; | |
| 196 element.classList.add("show-message"); | |
| 197 } | |
| 198 else if (item.lastDownload > 0) | |
| 199 { | |
| 200 var dateTime = i18n_formatDateTime(item.lastDownload * 1000); | |
| 201 dateElement.textContent = dateTime[0]; | |
| 202 timeElement.textContent = dateTime[1]; | |
| 203 element.classList.remove("show-message"); | |
| 204 } | |
| 205 }); | |
| 206 } | |
| 207 var websiteElement = element.querySelector(".context-menu .website"); | |
| 208 var sourceElement = element.querySelector(".context-menu .source"); | |
| 209 if (websiteElement && item.homepage) | |
| 210 websiteElement.setAttribute("href", item.homepage); | |
| 211 if (sourceElement) | |
| 212 sourceElement.setAttribute("href", item.url); | |
| 213 } | |
| 214 }; | |
| 215 | |
| 123 Collection.prototype.clearAll = function() | 216 Collection.prototype.clearAll = function() | 
| 124 { | 217 { | 
| 125 this.items = []; | 218 this.items = []; | 
| 126 for (var i = 0; i < this.details.length; i++) | 219 for (var i = 0; i < this.details.length; i++) | 
| 127 { | 220 { | 
| 128 var table = E(this.details[i].id); | 221 var table = E(this.details[i].id); | 
| 129 var element = table.firstChild; | 222 var element = table.firstChild; | 
| 130 while (element) | 223 while (element) | 
| 131 { | 224 { | 
| 132 if ((element.tagName == "LI" && !element.classList.contains("static")) | | | 225 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); | 226 table.removeChild(element); | 
| 135 element = element.nextSibling | 227 element = element.nextElementSibling; | 
| 136 } | 228 } | 
| 137 | 229 | 
| 138 this._setEmpty(table, this.details[i].emptyText); | 230 this._setEmpty(table, this.details[i].emptyText); | 
| 139 } | 231 } | 
| 140 }; | 232 }; | 
| 141 | 233 | 
| 142 Collection.prototype.hasId = function(id) | 234 function focusNextElement(container, currentElement) | 
| 143 { | 235 { | 
| 144 for (var i = 0; i < this.details.length; i++) | 236 var focusables = container.querySelectorAll("a, button, input, .control"); | 
| 145 if (this.details[i].id == id) | 237 focusables = Array.prototype.slice.call(focusables); | 
| 146 return true; | 238 var index = focusables.indexOf(currentElement); | 
| 147 | 239 index += (index == focusables.length - 1) ? -1 : 1; | 
| 148 return false; | 240 | 
| 149 }; | 241 var nextElement = focusables[index]; | 
| 150 | 242 if (!nextElement) | 
| 151 function updateBlockingList(listItem, subscription) | 243 return false; | 
| 152 { | 244 | 
| 153 var dateElement = listItem.querySelector(".date"); | 245 nextElement.focus(); | 
| 154 var timeElement = listItem.querySelector(".time"); | 246 return true; | 
| 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 } | 247 } | 
| 187 | 248 | 
| 188 function toggleRemoveSubscription(e) | 249 function toggleRemoveSubscription(e) | 
| 189 { | 250 { | 
| 190 e.preventDefault(); | 251 e.preventDefault(); | 
| 191 var subscriptionUrl = findParentData(e.target, "access", false); | 252 var subscriptionUrl = findParentData(e.target, "access", false); | 
| 192 if (!e.target.checked) | 253 if (e.target.getAttribute("aria-checked") == "true") | 
| 193 { | 254 { | 
| 194 ext.backgroundPage.sendMessage({ | 255 ext.backgroundPage.sendMessage({ | 
| 195 type: "subscriptions.remove", | 256 type: "subscriptions.remove", | 
| 196 url: subscriptionUrl | 257 url: subscriptionUrl | 
| 197 }); | 258 }); | 
| 198 } | 259 } | 
| 199 else | 260 else | 
| 200 addEnableSubscription(subscriptionUrl); | 261 addEnableSubscription(subscriptionUrl); | 
| 201 } | 262 } | 
| 202 | 263 | 
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 onClick: toggleDisableSubscription | 353 onClick: toggleDisableSubscription | 
| 293 } | 354 } | 
| 294 ]); | 355 ]); | 
| 295 | 356 | 
| 296 function observeSubscription(subscription) | 357 function observeSubscription(subscription) | 
| 297 { | 358 { | 
| 298 function onObjectChanged(change) | 359 function onObjectChanged(change) | 
| 299 { | 360 { | 
| 300 for (var i = 0; i < change.length; i++) | 361 for (var i = 0; i < change.length; i++) | 
| 301 { | 362 { | 
| 302 var property = change[i].name; | 363 if (change[i].name == "disabled") | 
| 303 if (property == "disabled") | 364 { | 
| 304 { | 365 var recommendation = recommendationsMap[subscription.url]; | 
| 305 var access = (subscription.url || | 366 if (recommendation && recommendation.type == "ads") | 
| 306 subscription.text).replace(/'/g, "\\'"); | 367 { | 
| 307 var elements = document.querySelectorAll("[data-access='" + access + " ']"); | 368 if (subscription.disabled == false) | 
| 308 for (var i = 0; i < elements.length; i++) | |
| 309 { | |
| 310 var element = elements[i]; | |
| 311 var tableId = element.parentElement ? element.parentElement.id : ""; | |
| 312 var control = element.querySelector(".control"); | |
| 313 if (control && control.localName == "input") | |
| 314 control.checked = subscription.disabled == false; | |
| 315 if (subscription.url in recommendationsMap) | |
| 316 { | 369 { | 
| 317 var recommendation = recommendationsMap[subscription.url]; | 370 collections.allLangs.removeItem(subscription); | 
| 318 if (recommendation.type == "ads" && | 371 collections.langs.addItems(subscription); | 
| 319 (collections.langs.hasId(tableId) || | |
| 320 collections.allLangs.hasId(tableId))) | |
| 321 { | |
| 322 if (subscription.disabled == false) | |
| 323 { | |
| 324 collections.allLangs.removeItem(subscription); | |
| 325 collections.langs.addItems(subscription); | |
| 326 } | |
| 327 else | |
| 328 { | |
| 329 collections.allLangs.addItems(subscription); | |
| 330 collections.langs.removeItem(subscription); | |
| 331 } | |
| 332 } | |
| 333 } | 372 } | 
| 373 else | |
| 374 { | |
| 375 collections.allLangs.addItems(subscription); | |
| 376 collections.langs.removeItem(subscription); | |
| 377 } | |
| 334 } | 378 } | 
| 335 } | 379 } | 
| 336 else | 380 for (var i in collections) | 
| 337 { | 381 collections[i].updateItem(subscription); | 
| 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 } | 382 } | 
| 346 } | 383 } | 
| 347 | 384 | 
| 348 if (!Object.observe) | 385 if (!Object.observe) | 
| 349 { | 386 { | 
| 350 ["disabled", "lastDownload"].forEach(function(property) | 387 ["disabled", "lastDownload"].forEach(function(property) | 
| 351 { | 388 { | 
| 352 subscription["$" + property] = subscription[property]; | 389 subscription["$" + property] = subscription[property]; | 
| 353 Object.defineProperty(subscription, property, | 390 Object.defineProperty(subscription, property, | 
| 354 { | 391 { | 
| 355 get: function() | 392 get: function() | 
| 356 { | 393 { | 
| 357 return this["$" + property]; | 394 return this["$" + property]; | 
| 358 }, | 395 }, | 
| 359 set: function(value) | 396 set: function(newValue) | 
| 360 { | 397 { | 
| 361 this["$" + property] = value; | 398 var oldValue = this["$" + property]; | 
| 362 var change = Object.create(null); | 399 if (oldValue != newValue) | 
| 363 change.name = property; | 400 { | 
| 364 onObjectChanged([change]); | 401 this["$" + property] = newValue; | 
| 402 var change = Object.create(null); | |
| 403 change.name = property; | |
| 404 onObjectChanged([change]); | |
| 405 } | |
| 365 } | 406 } | 
| 366 }); | 407 }); | 
| 367 }); | 408 }); | 
| 368 } | 409 } | 
| 369 else | 410 else | 
| 370 { | 411 { | 
| 371 Object.observe(subscription, onObjectChanged); | 412 Object.observe(subscription, onObjectChanged); | 
| 372 } | 413 } | 
| 373 } | 414 } | 
| 374 | 415 | 
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 subscription.url = element.getAttribute("url"); | 484 subscription.url = element.getAttribute("url"); | 
| 444 subscription.disabled = null; | 485 subscription.disabled = null; | 
| 445 subscription.downloadStatus = null; | 486 subscription.downloadStatus = null; | 
| 446 subscription.homepage = null; | 487 subscription.homepage = null; | 
| 447 var recommendation = Object.create(null); | 488 var recommendation = Object.create(null); | 
| 448 recommendation.type = element.getAttribute("type"); | 489 recommendation.type = element.getAttribute("type"); | 
| 449 var prefix = element.getAttribute("prefixes"); | 490 var prefix = element.getAttribute("prefixes"); | 
| 450 if (prefix) | 491 if (prefix) | 
| 451 { | 492 { | 
| 452 prefix = prefix.replace(/\W/g, "_"); | 493 prefix = prefix.replace(/\W/g, "_"); | 
| 453 subscription.title = ext.i18n.getMessage("options_language_" + prefi x); | 494 subscription.title = getMessage("options_language_" + prefix); | 
| 454 } | 495 } | 
| 455 else | 496 else | 
| 456 { | 497 { | 
| 457 var type = recommendation.type.replace(/\W/g, "_"); | 498 var type = recommendation.type.replace(/\W/g, "_"); | 
| 458 subscription.title = ext.i18n.getMessage("common_feature_" + type + "_title"); | 499 subscription.title = getMessage("common_feature_" + type + "_title") ; | 
| 459 } | 500 } | 
| 460 | 501 | 
| 461 recommendationsMap[subscription.url] = recommendation; | 502 recommendationsMap[subscription.url] = recommendation; | 
| 462 updateSubscription(subscription); | 503 updateSubscription(subscription); | 
| 463 } | 504 } | 
| 464 }); | 505 }); | 
| 465 } | 506 } | 
| 466 | 507 | 
| 467 function findParentData(element, dataName, returnElement) | 508 function findParentData(element, dataName, returnElement) | 
| 468 { | 509 { | 
| 469 while (element) | 510 while (element) | 
| 470 { | 511 { | 
| 471 if (element.hasAttribute("data-" + dataName)) | 512 if (element.hasAttribute("data-" + dataName)) | 
| 472 return returnElement ? element : element.getAttribute("data-" + dataName ); | 513 return returnElement ? element : element.getAttribute("data-" + dataName ); | 
| 473 | 514 | 
| 474 element = element.parentElement; | 515 element = element.parentElement; | 
| 475 } | 516 } | 
| 476 return null; | 517 return null; | 
| 477 } | 518 } | 
| 478 | 519 | 
| 479 function onClick(e) | 520 function onClick(e) | 
| 480 { | 521 { | 
| 522 var context = document.querySelector(".show-context-menu"); | |
| 523 if (context) | |
| 524 context.classList.remove("show-context-menu"); | |
| 525 | |
| 481 var element = e.target; | 526 var element = e.target; | 
| 482 while (true) | 527 while (true) | 
| 483 { | 528 { | 
| 484 if (!element) | 529 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"); | |
| 489 return; | 530 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 } | |
| 491 | 531 | 
| 492 if (element.hasAttribute("data-action")) | 532 if (element.hasAttribute("data-action")) | 
| 493 break; | 533 break; | 
| 494 | 534 | 
| 495 element = element.parentElement; | 535 element = element.parentElement; | 
| 496 } | 536 } | 
| 497 | 537 | 
| 498 var actions = element.getAttribute("data-action").split(","); | 538 var actions = element.getAttribute("data-action").split(","); | 
| 499 for (var i = 0; i < actions.length; i++) | 539 for (var i = 0; i < actions.length; i++) | 
| 500 { | 540 { | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 element.getAttribute("data-tab")); | 589 element.getAttribute("data-tab")); | 
| 550 break; | 590 break; | 
| 551 case "update-all-subscriptions": | 591 case "update-all-subscriptions": | 
| 552 ext.backgroundPage.sendMessage( | 592 ext.backgroundPage.sendMessage( | 
| 553 { | 593 { | 
| 554 type: "subscriptions.update" | 594 type: "subscriptions.update" | 
| 555 }); | 595 }); | 
| 556 break; | 596 break; | 
| 557 case "open-context-menu": | 597 case "open-context-menu": | 
| 558 var listItem = findParentData(element, "access", true); | 598 var listItem = findParentData(element, "access", true); | 
| 559 var contextMenu = listItem.querySelector(".content"); | 599 if (listItem != context) | 
| 
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"); | 600 listItem.classList.add("show-context-menu"); | 
| 561 break; | 601 break; | 
| 562 case "update-now": | 602 case "update-subscription": | 
| 563 ext.backgroundPage.sendMessage( | 603 ext.backgroundPage.sendMessage( | 
| 564 { | 604 { | 
| 565 type: "subscriptions.update", | 605 type: "subscriptions.update", | 
| 566 url: findParentData(element, "access") | 606 url: findParentData(element, "access", false) | 
| 
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 }); | 607 }); | 
| 568 break; | 608 break; | 
| 569 case "remove-subscription": | 609 case "remove-subscription": | 
| 570 ext.backgroundPage.sendMessage( | 610 ext.backgroundPage.sendMessage( | 
| 571 { | 611 { | 
| 572 type: "subscriptions.remove", | 612 type: "subscriptions.remove", | 
| 573 url: findParentData(element, "access") | 613 url: findParentData(element, "access", false) | 
| 574 }); | 614 }); | 
| 575 break; | |
| 576 case "close-context-menu": | |
| 577 var access = findParentData(element, "access", true); | |
| 578 if (access) | |
| 579 access.classList.remove("context"); | |
| 580 break; | 615 break; | 
| 581 } | 616 } | 
| 582 } | 617 } | 
| 583 } | 618 } | 
| 584 | 619 | 
| 585 function onDOMLoaded() | 620 function onDOMLoaded() | 
| 586 { | 621 { | 
| 587 populateLists(); | 622 populateLists(); | 
| 588 function onFindLanguageKeyUp() | 623 function onFindLanguageKeyUp() | 
| 589 { | 624 { | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 | 659 | 
| 625 getDocLink("contribute", function(link) | 660 getDocLink("contribute", function(link) | 
| 626 { | 661 { | 
| 627 document.querySelector("#tab-contribute a").setAttribute("href", link); | 662 document.querySelector("#tab-contribute a").setAttribute("href", link); | 
| 628 }); | 663 }); | 
| 629 | 664 | 
| 630 updateShareLink(); | 665 updateShareLink(); | 
| 631 | 666 | 
| 632 // Initialize interactive UI elements | 667 // Initialize interactive UI elements | 
| 633 document.body.addEventListener("click", onClick, false); | 668 document.body.addEventListener("click", onClick, false); | 
| 634 var placeholderValue = ext.i18n.getMessage("options_dialog_language_find"); | 669 var placeholderValue = getMessage("options_dialog_language_find"); | 
| 635 E("find-language").setAttribute("placeholder", placeholderValue); | 670 E("find-language").setAttribute("placeholder", placeholderValue); | 
| 636 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); | 671 E("find-language").addEventListener("keyup", onFindLanguageKeyUp, false); | 
| 637 E("whitelisting-textbox").addEventListener("keypress", function(e) | 672 E("whitelisting-textbox").addEventListener("keypress", function(e) | 
| 638 { | 673 { | 
| 639 if (getKey(e) == "Enter") | 674 if (getKey(e) == "Enter") | 
| 640 addWhitelistedDomain(); | 675 addWhitelistedDomain(); | 
| 641 }, false); | 676 }, false); | 
| 642 | 677 | 
| 643 // Advanced tab | 678 // Advanced tab | 
| 644 var filterTextbox = document.querySelector("#custom-filters-add input"); | 679 var filterTextbox = document.querySelector("#custom-filters-add input"); | 
| 645 placeholderValue = ext.i18n.getMessage("options_customFilters_textbox_placeh older"); | 680 placeholderValue = getMessage("options_customFilters_textbox_placeholder"); | 
| 646 filterTextbox.setAttribute("placeholder", placeholderValue); | 681 filterTextbox.setAttribute("placeholder", placeholderValue); | 
| 647 function addCustomFilters() | 682 function addCustomFilters() | 
| 648 { | 683 { | 
| 649 var filterText = filterTextbox.value; | 684 var filterText = filterTextbox.value; | 
| 650 ext.backgroundPage.sendMessage( | 685 ext.backgroundPage.sendMessage( | 
| 651 { | 686 { | 
| 652 type: "filters.add", | 687 type: "filters.add", | 
| 653 text: filterText | 688 text: filterText | 
| 654 }); | 689 }); | 
| 655 filterTextbox.value = ""; | 690 filterTextbox.value = ""; | 
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 743 updateFilter(filters[i]); | 778 updateFilter(filters[i]); | 
| 744 }); | 779 }); | 
| 745 } | 780 } | 
| 746 }); | 781 }); | 
| 747 loadRecommendations(); | 782 loadRecommendations(); | 
| 748 getAcceptableAdsURL(function(acceptableAdsUrl) | 783 getAcceptableAdsURL(function(acceptableAdsUrl) | 
| 749 { | 784 { | 
| 750 var subscription = Object.create(null); | 785 var subscription = Object.create(null); | 
| 751 subscription.url = acceptableAdsUrl; | 786 subscription.url = acceptableAdsUrl; | 
| 752 subscription.disabled = true; | 787 subscription.disabled = true; | 
| 753 subscription.title = ext.i18n.getMessage("options_acceptableAds_descriptio n"); | 788 subscription.title = getMessage("options_acceptableAds_description"); | 
| 754 updateSubscription(subscription); | 789 updateSubscription(subscription); | 
| 755 | 790 | 
| 756 // Load user subscriptions | 791 // Load user subscriptions | 
| 757 ext.backgroundPage.sendMessage( | 792 ext.backgroundPage.sendMessage( | 
| 758 { | 793 { | 
| 759 type: "subscriptions.get", | 794 type: "subscriptions.get", | 
| 760 downloadable: true | 795 downloadable: true | 
| 761 }, | 796 }, | 
| 762 function(subscriptions) | 797 function(subscriptions) | 
| 763 { | 798 { | 
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 983 filter: ["added", "loaded", "removed"] | 1018 filter: ["added", "loaded", "removed"] | 
| 984 }); | 1019 }); | 
| 985 ext.backgroundPage.sendMessage( | 1020 ext.backgroundPage.sendMessage( | 
| 986 { | 1021 { | 
| 987 type: "subscriptions.listen", | 1022 type: "subscriptions.listen", | 
| 988 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ] | 1023 filter: ["added", "disabled", "homepage", "lastDownload", "removed", "title" ] | 
| 989 }); | 1024 }); | 
| 990 | 1025 | 
| 991 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1026 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 
| 992 })(); | 1027 })(); | 
| LEFT | RIGHT |