Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix busted JavaScript in error index generator #89535

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 19 additions & 34 deletions src/tools/error_index_generator/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,56 +143,41 @@ impl Formatter for HTMLFormatter {
r##"<script>
function onEach(arr, func) {{
if (arr && arr.length > 0 && func) {{
for (var i = 0; i < arr.length; i++) {{
func(arr[i]);
var length = arr.length;
var i;
for (i = 0; i < length; ++i) {{
if (func(arr[i])) {{
return true;
}}
}}
}}
return false;
}}

function onEachLazy(lazyArray, func) {{
return onEach(
Array.prototype.slice.call(lazyArray),
func);
}}

function hasClass(elem, className) {{
if (elem && className && elem.className) {{
var elemClass = elem.className;
var start = elemClass.indexOf(className);
if (start === -1) {{
return false;
}} else if (elemClass.length === className.length) {{
return true;
}} else {{
if (start > 0 && elemClass[start - 1] !== ' ') {{
return false;
}}
var end = start + className.length;
if (end < elemClass.length && elemClass[end] !== ' ') {{
return false;
}}
return true;
}}
if (start > 0 && elemClass[start - 1] !== ' ') {{
return false;
}}
var end = start + className.length;
if (end < elemClass.length && elemClass[end] !== ' ') {{
return false;
}}
return true;
}}
return false;
return elem && elem.classList && elem.classList.contains(className);
}}

onEach(document.getElementsByClassName('rust-example-rendered'), function(e) {{
onEachLazy(document.getElementsByClassName('rust-example-rendered'), function(e) {{
if (hasClass(e, 'compile_fail')) {{
e.addEventListener("mouseover", function(event) {{
e.previousElementSibling.childNodes[0].style.color = '#f00';
e.parentElement.previousElementSibling.childNodes[0].style.color = '#f00';
}});
e.addEventListener("mouseout", function(event) {{
e.previousElementSibling.childNodes[0].style.color = '';
e.parentElement.previousElementSibling.childNodes[0].style.color = '';
}});
}} else if (hasClass(e, 'ignore')) {{
e.addEventListener("mouseover", function(event) {{
e.previousElementSibling.childNodes[0].style.color = '#ff9200';
e.parentElement.previousElementSibling.childNodes[0].style.color = '#ff9200';
}});
e.addEventListener("mouseout", function(event) {{
e.previousElementSibling.childNodes[0].style.color = '';
e.parentElement.previousElementSibling.childNodes[0].style.color = '';
}});
}}
}});
Expand Down