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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 327 |
328 // Turn on the choose element to create filter thing | 328 // Turn on the choose element to create filter thing |
329 function clickHide_activate() { | 329 function clickHide_activate() { |
330 if(document == null) | 330 if(document == null) |
331 return; | 331 return; |
332 | 332 |
333 // If we are already selecting, abort now | 333 // If we are already selecting, abort now |
334 if (clickHide_activated || clickHideFiltersDialog) | 334 if (clickHide_activated || clickHideFiltersDialog) |
335 clickHide_deactivate(); | 335 clickHide_deactivate(); |
336 | 336 |
337 // Add overlays for blockable elements that don't emit mouse events that they | 337 // Add overlays for blockable elements that don't emit mouse events, |
338 // can still be selected. While images generally emit mouse events we have | 338 // so that they can still be selected. |
339 // also to add overlays for them, in case <area> elments are used (#1868). | 339 var elts = document.querySelectorAll('object,embed,iframe,frame'); |
340 var elts = document.querySelectorAll('object,embed,iframe,frame,img'); | |
341 for(var i=0; i<elts.length; i++) | 340 for(var i=0; i<elts.length; i++) |
342 { | 341 { |
343 var element = elts[i]; | 342 var element = elts[i]; |
344 if (isBlockable(element)) | 343 if (isBlockable(element)) |
345 addElementOverlay(element); | 344 addElementOverlay(element); |
346 } | 345 } |
347 | 346 |
348 clickHide_activated = true; | 347 clickHide_activated = true; |
349 document.addEventListener("mouseover", clickHide_mouseOver, true); | 348 document.addEventListener("mouseover", clickHide_mouseOver, true); |
350 document.addEventListener("mouseout", clickHide_mouseOut, true); | 349 document.addEventListener("mouseout", clickHide_mouseOut, true); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 ext.onExtensionUnloaded.removeListener(clickHide_deactivate); | 400 ext.onExtensionUnloaded.removeListener(clickHide_deactivate); |
402 } | 401 } |
403 } | 402 } |
404 | 403 |
405 function clickHide_elementClickHandler(ev) { | 404 function clickHide_elementClickHandler(ev) { |
406 ev.preventDefault(); | 405 ev.preventDefault(); |
407 ev.stopPropagation(); | 406 ev.stopPropagation(); |
408 clickHide_mouseClick(ev); | 407 clickHide_mouseClick(ev); |
409 } | 408 } |
410 | 409 |
| 410 function getBlockableElementOrAncestor(element) |
| 411 { |
| 412 while (element && element != document.documentElement |
| 413 && element != document.body) |
| 414 { |
| 415 if (element instanceof HTMLElement && element.localName != "area") |
| 416 { |
| 417 // Handle <area> and their <map> elements specially, |
| 418 // blocking the image they are associated with |
| 419 if (element.localName == "map") |
| 420 { |
| 421 var images = document.querySelectorAll("img[usemap]"); |
| 422 for (var i = 0; i < images.length; i++) |
| 423 { |
| 424 var image = images[i]; |
| 425 var usemap = image.getAttribute("usemap"); |
| 426 var index = usemap.indexOf("#"); |
| 427 |
| 428 if (index != -1 && usemap.substr(index + 1) == element.name) |
| 429 return getBlockableElementOrAncestor(image); |
| 430 } |
| 431 |
| 432 return null; |
| 433 } |
| 434 |
| 435 if (isBlockable(element)) |
| 436 return element; |
| 437 } |
| 438 |
| 439 element = element.parentElement; |
| 440 } |
| 441 |
| 442 return null; |
| 443 } |
| 444 |
411 // Hovering over an element so highlight it | 445 // Hovering over an element so highlight it |
412 function clickHide_mouseOver(e) | 446 function clickHide_mouseOver(e) |
413 { | 447 { |
414 if (clickHide_activated == false) | 448 if (clickHide_activated == false) |
415 return; | 449 return; |
416 | 450 |
417 var target = e.target; | 451 var target = getBlockableElementOrAncestor(e.target); |
418 while (target.parentNode && !(target instanceof HTMLElement && isBlockable(tar
get))) | |
419 target = target.parentNode; | |
420 if (target == document.documentElement || target == document.body) | |
421 target = null; | |
422 | 452 |
423 if (target) | 453 if (target) |
424 { | 454 { |
425 currentElement = target; | 455 currentElement = target; |
426 | 456 |
427 highlightElement(target, "#d6d84b", "#f8fa47"); | 457 highlightElement(target, "#d6d84b", "#f8fa47"); |
428 target.addEventListener("contextmenu", clickHide_elementClickHandler, true); | 458 target.addEventListener("contextmenu", clickHide_elementClickHandler, true); |
429 } | 459 } |
430 } | 460 } |
431 | 461 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 case "clickhide-activate": | 706 case "clickhide-activate": |
677 clickHide_activate(); | 707 clickHide_activate(); |
678 break; | 708 break; |
679 case "clickhide-deactivate": | 709 case "clickhide-deactivate": |
680 clickHide_deactivate(); | 710 clickHide_deactivate(); |
681 break; | 711 break; |
682 case "clickhide-new-filter": | 712 case "clickhide-new-filter": |
683 if(lastRightClickEvent) | 713 if(lastRightClickEvent) |
684 { | 714 { |
685 clickHide_activated = true; | 715 clickHide_activated = true; |
686 currentElement = lastRightClickEvent.target; | 716 currentElement = getBlockableElementOrAncestor(lastRightClickEvent.tar
get); |
687 clickHide_mouseClick(lastRightClickEvent); | 717 clickHide_mouseClick(lastRightClickEvent); |
688 } | 718 } |
689 break; | 719 break; |
690 case "clickhide-init": | 720 case "clickhide-init": |
691 if (clickHideFiltersDialog) | 721 if (clickHideFiltersDialog) |
692 { | 722 { |
693 sendResponse({filters: clickHide_filters}); | 723 sendResponse({filters: clickHide_filters}); |
694 | 724 |
695 clickHideFiltersDialog.style.width = msg.width + "px"; | 725 clickHideFiltersDialog.style.width = msg.width + "px"; |
696 clickHideFiltersDialog.style.height = msg.height + "px"; | 726 clickHideFiltersDialog.style.height = msg.height + "px"; |
(...skipping 28 matching lines...) Expand all Loading... |
725 lastRightClickEventValid = false; | 755 lastRightClickEventValid = false; |
726 else | 756 else |
727 lastRightClickEvent = null; | 757 lastRightClickEvent = null; |
728 break; | 758 break; |
729 } | 759 } |
730 }); | 760 }); |
731 | 761 |
732 if (window == window.top) | 762 if (window == window.top) |
733 ext.backgroundPage.sendMessage({type: "report-html-page"}); | 763 ext.backgroundPage.sendMessage({type: "report-html-page"}); |
734 } | 764 } |
OLD | NEW |