Skip to content

Commit 9151874

Browse files
committed
Use more jQuery to avoid displaying Expand Description more often.
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.
1 parent 5dfb7a6 commit 9151874

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
}
@@ -765,20 +765,21 @@
765765
});
766766

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

771771
$(".method").each(function() {
772772
if ($(this).next().is(".docblock")) {
773-
$(this).children().first().after(toggle);
773+
$(this).children().first().after(toggle[0]);
774774
}
775775
});
776776

777-
var mainToggle = $(toggle);
778-
mainToggle.append("<span class='toggle-label' style='display:none'>"
779-
+ "&nbsp;Expand&nbsp;description</span></a>")
780-
var wrapper = $("<div class='toggle-wrapper'>");
781-
wrapper.append(mainToggle);
777+
var mainToggle =
778+
$(toggle).append(
779+
$('<span/>', {'class': 'toggle-label'})
780+
.css('display', 'none')
781+
.html('&nbsp;Expand&nbsp;description'));
782+
var wrapper = $("<div class='toggle-wrapper'>").append(mainToggle);
782783
$("#main > .docblock").before(wrapper);
783784
});
784785

0 commit comments

Comments
 (0)