Skip to content

Commit 4ce2384

Browse files
Improve JS code a bit by avoid erasing all event handlers
1 parent 0a440b1 commit 4ce2384

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Diff for: src/librustdoc/html/static/main.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ function getSearchElement() {
324324
}
325325

326326
function handleEscape(ev) {
327+
debugger;
327328
var help = getHelpElement();
328329
var search = getSearchElement();
329330
hideModal();
@@ -390,8 +391,8 @@ function getSearchElement() {
390391
return null;
391392
}
392393

393-
document.onkeypress = handleShortcut;
394-
document.onkeydown = handleShortcut;
394+
document.addEventListener("keypress", handleShortcut);
395+
document.addEventListener("keydown", handleShortcut);
395396

396397
var handleSourceHighlight = (function() {
397398
var prev_line_id = 0;
@@ -430,7 +431,7 @@ function getSearchElement() {
430431
}
431432
})();
432433

433-
document.onclick = function(ev) {
434+
document.addEventListener("click", function(ev) {
434435
if (hasClass(ev.target, "collapse-toggle")) {
435436
collapseDocs(ev.target, "toggle");
436437
} else if (hasClass(ev.target.parentNode, "collapse-toggle")) {
@@ -452,7 +453,7 @@ function getSearchElement() {
452453
expandSection(a.hash.replace(/^#/, ""));
453454
}
454455
}
455-
};
456+
});
456457

457458
var x = document.getElementsByClassName("version-selector");
458459
if (x.length > 0) {

0 commit comments

Comments
 (0)