Skip to content
Snippets Groups Projects
Commit bbb4ec08 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

fix problem with iterating over HTML Collection and forgetting that it is live

parent 053f6f20
No related branches found
No related tags found
No related merge requests found
...@@ -142,6 +142,8 @@ function console_find_text(elem, evt, callback) { ...@@ -142,6 +142,8 @@ function console_find_text(elem, evt, callback) {
// start at top and highlight the first result after a search // start at top and highlight the first result after a search
function console_find_callback() { function console_find_callback() {
var highlight_checkbox = document.getElementById('console_find_highlight');
console_find_highlight_all(highlight_checkbox);
console_find_traverse.set_index(0); console_find_traverse.set_index(0);
console_find_traverse.next(); console_find_traverse.next();
} }
...@@ -151,15 +153,25 @@ function console_find_keypress(elem, e) { ...@@ -151,15 +153,25 @@ function console_find_keypress(elem, e) {
} }
function console_find_highlight_all(elem) { function console_find_highlight_all(elem) {
var matches = document.getElementById('p1').getElementsByTagName('mark'), var matches,
highlight_tag = 'console_find_highlighted', highlight_tag = 'console_find_highlighted',
state = elem.checked, state = elem.checked,
i; i, len;
for (i = 0; i < matches.length; i++) { matches = document.getElementById('p1')
if (state) { .getElementsByClassName(highlight_tag);
// remember-- matches is a _live_ collection, not an array.
// If you remove the highlight_tag from an element, it is
// automatically removed from the collection. I cannot yet
// see a single benefit to this behavior-- here, it means
// we must decrement i to keep from skipping over every
// other element... :(
for (i = matches.length - 1; i >= 0; i--) {
matches[i].classList.remove(highlight_tag);
}
if (state) {
matches = document.getElementById('p1').getElementsByTagName('mark');
for (i = 0; i < matches.length; i++) {
matches[i].classList.add(highlight_tag); matches[i].classList.add(highlight_tag);
} else {
matches[i].classList.remove(highlight_tag);
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment