Skip to content

Commit 19dc574

Browse files
committed
auto merge of rust-lang#17035 : huonw/rust/moar-jquery, r=alexcrichton
Sometimes (e.g. on Rust CI) the "expand description" text of the collapse toggle was displayed by default, when a page is first loaded (even though the description is expanded), because some Content-Security-Policy settings disable inline CSS. Setting it the style with the `.css` method allows the output to be used in more places.
2 parents 86730e4 + 9151874 commit 19dc574

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/librustdoc/html/static/main.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
* A function to compute the Levenshtein distance between two strings
119119
* Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported
120120
* Full License can be found at http://creativecommons.org/licenses/by-sa/3.0/legalcode
121-
* This code is an unmodified version of the code written by Marco de Wit
121+
* This code is an unmodified version of the code written by Marco de Wit
122122
* and was found at http://stackoverflow.com/a/18514751/745719
123123
*/
124124
var levenshtein = (function() {
@@ -224,7 +224,7 @@
224224
});
225225
}
226226
} else if (
227-
(lev_distance = levenshtein(searchWords[j], val)) <=
227+
(lev_distance = levenshtein(searchWords[j], val)) <=
228228
MAX_LEV_DISTANCE) {
229229
if (typeFilter < 0 || typeFilter === searchIndex[j].ty) {
230230
results.push({
@@ -350,16 +350,16 @@
350350
function validateResult(name, path, keys, parent) {
351351
for (var i=0; i < keys.length; ++i) {
352352
// each check is for validation so we negate the conditions and invalidate
353-
if (!(
353+
if (!(
354354
// check for an exact name match
355355
name.toLowerCase().indexOf(keys[i]) > -1 ||
356356
// then an exact path match
357357
path.toLowerCase().indexOf(keys[i]) > -1 ||
358358
// next if there is a parent, check for exact parent match
359-
(parent !== undefined &&
359+
(parent !== undefined &&
360360
parent.name.toLowerCase().indexOf(keys[i]) > -1) ||
361361
// lastly check to see if the name was a levenshtein match
362-
levenshtein(name.toLowerCase(), keys[i]) <=
362+
levenshtein(name.toLowerCase(), keys[i]) <=
363363
MAX_LEV_DISTANCE)) {
364364
return false;
365365
}
@@ -757,20 +757,21 @@
757757
});
758758

759759
$(function() {
760-
var toggle = "<a href='javascript:void(0)'"
761-
+ "class='collapse-toggle'>[<span class='inner'>-</span>]</a>";
760+
var toggle = $("<a/>", {'href': 'javascript:void(0)', 'class': 'collapse-toggle'})
761+
.html("[<span class='inner'>-</span>]");
762762

763763
$(".method").each(function() {
764764
if ($(this).next().is(".docblock")) {
765-
$(this).children().first().after(toggle);
765+
$(this).children().first().after(toggle[0]);
766766
}
767767
});
768768

769-
var mainToggle = $(toggle);
770-
mainToggle.append("<span class='toggle-label' style='display:none'>"
771-
+ "&nbsp;Expand&nbsp;description</span></a>")
772-
var wrapper = $("<div class='toggle-wrapper'>");
773-
wrapper.append(mainToggle);
769+
var mainToggle =
770+
$(toggle).append(
771+
$('<span/>', {'class': 'toggle-label'})
772+
.css('display', 'none')
773+
.html('&nbsp;Expand&nbsp;description'));
774+
var wrapper = $("<div class='toggle-wrapper'>").append(mainToggle);
774775
$("#main > .docblock").before(wrapper);
775776
});
776777

0 commit comments

Comments
 (0)