Skip to content

Commit ccd2be5

Browse files
committed
fix busted JavaScript in error index generator
The old JavaScript didn't work. It filled the browser console with "e.previousElementSibling not defined" errors, because it didn't account for the example-wrap div that a newer version of rustdoc added. Additionally, it had copied versions of utility functions that had been optimized in rustdoc main.js. This version updates those.
1 parent 175b8db commit ccd2be5

File tree

1 file changed

+19
-34
lines changed
  • src/tools/error_index_generator

1 file changed

+19
-34
lines changed

src/tools/error_index_generator/main.rs

+19-34
Original file line numberDiff line numberDiff line change
@@ -143,56 +143,41 @@ impl Formatter for HTMLFormatter {
143143
r##"<script>
144144
function onEach(arr, func) {{
145145
if (arr && arr.length > 0 && func) {{
146-
for (var i = 0; i < arr.length; i++) {{
147-
func(arr[i]);
146+
var length = arr.length;
147+
var i;
148+
for (i = 0; i < length; ++i) {{
149+
if (func(arr[i])) {{
150+
return true;
151+
}}
148152
}}
149153
}}
154+
return false;
155+
}}
156+
157+
function onEachLazy(lazyArray, func) {{
158+
return onEach(
159+
Array.prototype.slice.call(lazyArray),
160+
func);
150161
}}
151162
152163
function hasClass(elem, className) {{
153-
if (elem && className && elem.className) {{
154-
var elemClass = elem.className;
155-
var start = elemClass.indexOf(className);
156-
if (start === -1) {{
157-
return false;
158-
}} else if (elemClass.length === className.length) {{
159-
return true;
160-
}} else {{
161-
if (start > 0 && elemClass[start - 1] !== ' ') {{
162-
return false;
163-
}}
164-
var end = start + className.length;
165-
if (end < elemClass.length && elemClass[end] !== ' ') {{
166-
return false;
167-
}}
168-
return true;
169-
}}
170-
if (start > 0 && elemClass[start - 1] !== ' ') {{
171-
return false;
172-
}}
173-
var end = start + className.length;
174-
if (end < elemClass.length && elemClass[end] !== ' ') {{
175-
return false;
176-
}}
177-
return true;
178-
}}
179-
return false;
164+
return elem && elem.classList && elem.classList.contains(className);
180165
}}
181166
182-
onEach(document.getElementsByClassName('rust-example-rendered'), function(e) {{
167+
onEachLazy(document.getElementsByClassName('rust-example-rendered'), function(e) {{
183168
if (hasClass(e, 'compile_fail')) {{
184169
e.addEventListener("mouseover", function(event) {{
185-
e.previousElementSibling.childNodes[0].style.color = '#f00';
170+
e.parentElement.previousElementSibling.childNodes[0].style.color = '#f00';
186171
}});
187172
e.addEventListener("mouseout", function(event) {{
188-
e.previousElementSibling.childNodes[0].style.color = '';
173+
e.parentElement.previousElementSibling.childNodes[0].style.color = '';
189174
}});
190175
}} else if (hasClass(e, 'ignore')) {{
191176
e.addEventListener("mouseover", function(event) {{
192-
e.previousElementSibling.childNodes[0].style.color = '#ff9200';
177+
e.parentElement.previousElementSibling.childNodes[0].style.color = '#ff9200';
193178
}});
194179
e.addEventListener("mouseout", function(event) {{
195-
e.previousElementSibling.childNodes[0].style.color = '';
180+
e.parentElement.previousElementSibling.childNodes[0].style.color = '';
196181
}});
197182
}}
198183
}});

0 commit comments

Comments
 (0)