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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 // Click-to-hide stuff 18 // Click-to-hide stuff
19 var clickHide_activated = false; 19 var clickHide_activated = false;
20 var clickHide_filters = null; 20 var clickHide_filters = null;
21 var currentElement = null; 21 var currentElement = null;
22 var highlightedElementsSelector = null; 22 var highlightedElementsSelector = null;
23 var highlightedElementsInterval = null;
23 var clickHideFiltersDialog = null; 24 var clickHideFiltersDialog = null;
24 var lastRightClickEvent = null; 25 var lastRightClickEvent = null;
25 var lastRightClickEventValid = false; 26 var lastRightClickEventValid = false;
26 var lastMouseOverEvent = null; 27 var lastMouseOverEvent = null;
27 28
28 function highlightElement(element, shadowColor, backgroundColor) 29 function highlightElement(element, shadowColor, backgroundColor)
29 { 30 {
30 unhighlightElement(element); 31 unhighlightElement(element);
31 32
32 var highlightWithOverlay = function() 33 var highlightWithOverlay = function()
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 element._unhighlight(); 90 element._unhighlight();
90 delete element._unhighlight; 91 delete element._unhighlight;
91 } 92 }
92 } 93 }
93 94
94 // Highlight elements according to selector string. This would include 95 // Highlight elements according to selector string. This would include
95 // all elements that would be affected by proposed filters. 96 // all elements that would be affected by proposed filters.
96 function highlightElements(selectorString) { 97 function highlightElements(selectorString) {
97 unhighlightElements(); 98 unhighlightElements();
98 99
99 var highlightedElements = document.querySelectorAll(selectorString); 100 var elements = Array.prototype.slice.call(document.querySelectorAll(selectorSt ring));
100 highlightedElementsSelector = selectorString; 101 highlightedElementsSelector = selectorString;
101 102
102 for(var i = 0; i < highlightedElements.length; i++) 103 // Highlight elements progressively. Otherwise the page freezes
103 highlightElement(highlightedElements[i], "#fd6738", "#f6e1e5"); 104 // when a lot of elements get highlighted at the same time.
105 highlightedElementsInterval = setInterval(function()
106 {
107 if (elements.length > 0)
108 {
109 var element = elements.shift();
110 if (element != currentElement)
111 highlightElement(element, "#fd6738", "#f6e1e5");
112 }
113 else
114 {
115 clearInterval(highlightedElementsInterval);
116 highlightedElementsInterval = null;
117 }
118 }, 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
104 } 119 }
105 120
106 // Unhighlight all elements, including those that would be affected by 121 // Unhighlight all elements, including those that would be affected by
107 // the proposed filters 122 // the proposed filters
108 function unhighlightElements() { 123 function unhighlightElements() {
124 if (highlightedElementsInterval)
125 {
126 clearInterval(highlightedElementsInterval)
127 highlightedElementsInterval = null;
128 }
129
109 if (highlightedElementsSelector) 130 if (highlightedElementsSelector)
110 { 131 {
111 Array.prototype.forEach.call( 132 Array.prototype.forEach.call(
112 document.querySelectorAll(highlightedElementsSelector), 133 document.querySelectorAll(highlightedElementsSelector),
113 unhighlightElement 134 unhighlightElement
114 ); 135 );
115 136
116 highlightedElementsSelector = null; 137 highlightedElementsSelector = null;
117 } 138 }
118 } 139 }
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 lastRightClickEventValid = false; 764 lastRightClickEventValid = false;
744 else 765 else
745 lastRightClickEvent = null; 766 lastRightClickEvent = null;
746 break; 767 break;
747 } 768 }
748 }); 769 });
749 770
750 if (window == window.top) 771 if (window == window.top)
751 ext.backgroundPage.sendMessage({type: "report-html-page"}); 772 ext.backgroundPage.sendMessage({type: "report-html-page"});
752 } 773 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld