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: Rebased Created Oct. 23, 2014, 10:36 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
@@ -309,7 +309,7 @@
return;
var target = e.target;
- while (target.parentNode && !(target.id || target.className || target.src))
+ while (target.parentNode && !(target.id || target.className || target.src || /:.+:/.test(target.getAttribute("style"))))
target = target.parentNode;
if (target == document.documentElement || target == document.body)
target = null;
@@ -374,21 +374,26 @@
clickHideFilters = new Array();
selectorList = new Array();
+
+ var addSelector = function(selector)
+ {
+ clickHideFilters.push(document.domain + "##" + selector);
+ selectorList.push(selector);
+ };
+
if (elementId)
- {
- clickHideFilters.push(document.domain + "###" + elementId);
- selectorList.push("#" + elementId);
- }
+ addSelector("#" + elementId);
+
if (elementClasses && elementClasses.length > 0)
{
- var selector = elementClasses.map(function(elClass)
- {
- return "." + elClass.replace(/([^\w-])/, "\\$1");
- }).join("");
+ var selector = "";
- clickHideFilters.push(document.domain + "##" + selector);
- selectorList.push(selector);
+ for (var i = 0; i < elt.classList.length; i++)
+ selector += "." + elt.classList[i].replace(/([^\w-])/, "\\$1");
+
+ addSelector(selector);
}
+
if (url)
{
clickHideFilters.push(url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"));
@@ -398,9 +403,14 @@
// 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
+ // restore the original style, before generating the fallback filter that
+ // will include the style, and to prevent highlightElements from saving those
unhighlightElement(currentElement);
+
+ // as last resort, create a filter based on inline styles
+ if (clickHideFilters.length == 0 && elt.hasAttribute("style"))
+ addSelector(elt.localName + '[style="' + elt.getAttribute("style").replace(/"/g, '\\"') + '"]');
+
// 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