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

Unified Diff: include.postload.js

Issue 4829486721794048: Issue 700 - Generate filters based on the style attribute as last resort (Closed)
Patch Set: Created June 24, 2014, 9:05 a.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 | « no previous file | no next file » | 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
@@ -219,7 +219,7 @@
return;
var target = e.target;
- while (target.parentNode && !(target.id || target.className || target.src))
+ while (target.parentNode && target.attributes.length == 0)
target = target.parentNode;
if (target == document.documentElement || target == document.body)
target = null;
@@ -294,34 +294,52 @@
clickHideFilters = new Array();
selectorList = new Array();
- if (elementId)
+
+ var addSelector = function(selector)
{
- clickHideFilters.push(document.domain + "###" + elementId);
- selectorList.push("#" + elementId);
- }
- if (elementClasses && elementClasses.length > 0)
- {
- var selector = elementClasses.map(function(elClass)
- {
- return "." + elClass.replace(/([^\w-])/, "\\$1");
- }).join("");
-
clickHideFilters.push(document.domain + "##" + selector);
selectorList.push(selector);
+ };
+
+ if (elementId)
+ addSelector("#" + elementId);
+
+ if (elt.classList.length > 0)
+ {
+ var selector = "";
+
+ for (var i = 0; i < elt.classList.length; i++)
+ selector += "." + elt.classList[i].replace(/([^\w-])/, "\\$1");
+
+ addSelector(selector);
}
+
if (url)
{
clickHideFilters.push(relativeToAbsoluteUrl(url));
selectorList.push(elt.localName + '[src="' + url + '"]');
}
+ // restore the original style, before generating the fallback filter that
+ // will include the style, and to prevent highlightElements from saving those
+ currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxShadow);
+ currentElement.style.backgroundColor = currentElement_backgroundColor;
+
+ // as last resort, create a filter based on tag's name
+ // and all of its attributes, if everything else fails
+ if (clickHideFilters.length == 0)
+ {
+ var selector = elt.localName;
+
+ for (var i = 0; i < elt.attributes.length; i++)
+ selector += "[" + elt.attributes[i].name + '="' + elt.attributes[i].value.replace('"', '\\"') + '"]';
+
+ addSelector(selector);
+ }
+
// Show popup
clickHide_showDialog(e.clientX, e.clientY, clickHideFilters);
- // Highlight the unlucky elements
- // Restore currentElement's box-shadow and bgcolor so that highlightElements won't save those
- currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxShadow);
- currentElement.style.backgroundColor = currentElement_backgroundColor;
// Highlight the elements specified by selector in yellow
highlightElements(selectorList.join(","));
// Now, actually highlight the element the user clicked on in red
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld