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

Unified Diff: include.postload.js

Issue 4806142987337728: Issue 2215 - Prevent page from freezing when highlighting a lot of elements (Closed)
Patch Set: Created April 8, 2015, 10:30 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
@@ -20,6 +20,7 @@
var clickHide_filters = null;
var currentElement = null;
var highlightedElementsSelector = null;
+var highlightedElementsInterval = null;
var clickHideFiltersDialog = null;
var lastRightClickEvent = null;
var lastRightClickEventValid = false;
@@ -96,16 +97,36 @@
function highlightElements(selectorString) {
unhighlightElements();
- var highlightedElements = document.querySelectorAll(selectorString);
+ var elements = Array.prototype.slice.call(document.querySelectorAll(selectorString));
highlightedElementsSelector = selectorString;
- for(var i = 0; i < highlightedElements.length; i++)
- highlightElement(highlightedElements[i], "#fd6738", "#f6e1e5");
+ // Highlight elements progressively. Otherwise the page freezes
+ // when a lot of elements get highlighted at the same time.
+ highlightedElementsInterval = setInterval(function()
+ {
+ if (elements.length > 0)
+ {
+ var element = elements.shift();
+ if (element != currentElement)
+ highlightElement(element, "#fd6738", "#f6e1e5");
+ }
+ else
+ {
+ clearInterval(highlightedElementsInterval);
+ highlightedElementsInterval = null;
+ }
+ }, 0);
Wladimir Palant 2015/04/14 16:06:17 Using setInterval() instead of setTimeout() here h
Sebastian Noack 2015/04/20 11:02:21 I see your point, but IMO not worth a follow up co
}
// Unhighlight all elements, including those that would be affected by
// the proposed filters
function unhighlightElements() {
+ if (highlightedElementsInterval)
+ {
+ clearInterval(highlightedElementsInterval)
+ highlightedElementsInterval = null;
+ }
+
if (highlightedElementsSelector)
{
Array.prototype.forEach.call(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld