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

Unified Diff: include.postload.js

Issue 5225119261655040: Issue 1282 - Don't generate filters conflicting with existing exception rules (Closed)
Patch Set: Rebased Created Jan. 25, 2015, 1:23 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « background.js ('k') | include.preload.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include.postload.js
===================================================================
--- a/include.postload.js
+++ b/include.postload.js
@@ -193,24 +193,6 @@
return getURLsFromAttributes(element);
}
-function isBlockable(element)
-{
- if (element.id)
- return true;
- if (element.classList.length > 0)
- return true;
- if (getURLsFromElement(element).length > 0)
- return true;
-
- // We only generate filters based on the "style" attribute,
- // if this is the only way we can generate a filter, and
- // only if there are at least two CSS properties defined.
- if (/:.+:/.test(element.getAttribute("style")))
- return true;
-
- return false;
-}
-
// Gets the absolute position of an element by walking up the DOM tree,
// adding up offsets.
// I hope there's a better way because it just seems absolutely stupid
@@ -321,13 +303,17 @@
clickHide_deactivate();
// Add overlays for blockable elements that don't emit mouse events that they can still be selected
- var elts = document.querySelectorAll('object,embed,iframe');
- for(var i=0; i<elts.length; i++)
- {
- var element = elts[i];
- if (isBlockable(element))
- addElementOverlay(element);
- }
+ [].forEach.call(
+ document.querySelectorAll('object,embed,iframe'),
+ function(element)
+ {
+ getFiltersForElement(element, function(filters)
+ {
+ if (filters.length > 0)
+ addElementOverlay(element);
+ });
+ }
+ );
clickHide_activated = true;
document.addEventListener("mouseover", clickHide_mouseOver, true);
@@ -388,31 +374,57 @@
clickHide_mouseClick(ev);
}
+function getBlockableElementOrAncestor(element, callback)
+{
+ if (element && element != document.documentElement &&
+ element != document.body)
+ {
+ if (element instanceof HTMLElement)
+ {
+ getFiltersForElement(element, function(filters)
+ {
+ if (filters.length > 0)
+ callback(element);
+ else
+ getBlockableElementOrAncestor(element.parentElement, callback);
+ });
+ }
+ else
+ {
+ getBlockableElementOrAncestor(element.parentElement, callback);
+ }
+ }
+ else
+ {
+ callback(null);
+ }
+}
+
// Hovering over an element so highlight it
function clickHide_mouseOver(e)
{
if (clickHide_activated == false)
return;
- var target = e.target;
- while (target.parentNode && !isBlockable(target))
- target = target.parentNode;
- if (target == document.documentElement || target == document.body)
- target = null;
+ getBlockableElementOrAncestor(e.target, function(element)
+ {
+ if (currentElement)
+ unhighlightElement(currentElement);
- if (target && target instanceof HTMLElement)
- {
- currentElement = target;
+ if (element)
+ {
+ highlightElement(element, "#d6d84b", "#f8fa47");
+ element.addEventListener("contextmenu", clickHide_elementClickHandler, true);
+ }
- highlightElement(target, "#d6d84b", "#f8fa47");
- target.addEventListener("contextmenu", clickHide_elementClickHandler, true);
- }
+ currentElement = element;
+ });
}
// No longer hovering over this element so unhighlight it
function clickHide_mouseOut(e)
{
- if (!clickHide_activated || !currentElement)
+ if (!clickHide_activated || currentElement != e.target)
return;
unhighlightElement(currentElement);
@@ -450,6 +462,7 @@
style: element.getAttribute("style"),
classes: [].slice.call(element.classList),
urls: getURLsFromElement(element),
+ mediatype: typeMap[element.localName],
baseURL: document.location.href
},
function(response)
« no previous file with comments | « background.js ('k') | include.preload.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld