Rollup merge of #45812 - GuillaumeGomez:links-and-search, r=QuietMisdreavus
Fix navbar click while in a search Fixes #45790.
This commit is contained in:
@@ -52,14 +52,14 @@
|
|||||||
var start = elemClass.indexOf(className);
|
var start = elemClass.indexOf(className);
|
||||||
if (start == -1) {
|
if (start == -1) {
|
||||||
return false;
|
return false;
|
||||||
} else if (elemClass.length == className.length) {
|
} else if (elemClass.length === className.length) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (start > 0 && elemClass[start - 1] != ' ') {
|
if (start > 0 && elemClass[start - 1] !== ' ') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var end = start + className.length;
|
var end = start + className.length;
|
||||||
if (end < elemClass.length && elemClass[end] != ' ') {
|
if (end < elemClass.length && elemClass[end] !== ' ') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -122,6 +122,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function highlightSourceLines(ev) {
|
function highlightSourceLines(ev) {
|
||||||
|
var search = document.getElementById("search");
|
||||||
var i, from, to, match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
|
var i, from, to, match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
|
||||||
if (match) {
|
if (match) {
|
||||||
from = parseInt(match[1], 10);
|
from = parseInt(match[1], 10);
|
||||||
@@ -145,6 +146,17 @@
|
|||||||
for (i = from; i <= to; ++i) {
|
for (i = from; i <= to; ++i) {
|
||||||
addClass(document.getElementById(i), 'line-highlighted');
|
addClass(document.getElementById(i), 'line-highlighted');
|
||||||
}
|
}
|
||||||
|
} else if (ev !== null && search && !hasClass(search, "hidden") && ev.newURL) {
|
||||||
|
addClass(search, "hidden");
|
||||||
|
removeClass(document.getElementById("main"), "hidden");
|
||||||
|
var hash = ev.newURL.slice(ev.newURL.indexOf('#') + 1);
|
||||||
|
if (browserSupportsHistoryApi()) {
|
||||||
|
history.replaceState(hash, "", "?search=#" + hash);
|
||||||
|
}
|
||||||
|
var elem = document.getElementById(hash);
|
||||||
|
if (elem) {
|
||||||
|
elem.scrollIntoView();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
highlightSourceLines(null);
|
highlightSourceLines(null);
|
||||||
@@ -1552,6 +1564,22 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var search_input = document.getElementsByClassName("search-input")[0];
|
||||||
|
|
||||||
|
if (search_input) {
|
||||||
|
search_input.onfocus = function() {
|
||||||
|
if (search_input.value !== "") {
|
||||||
|
addClass(document.getElementById("main"), "hidden");
|
||||||
|
removeClass(document.getElementById("search"), "hidden");
|
||||||
|
if (browserSupportsHistoryApi()) {
|
||||||
|
history.replaceState(search_input.value,
|
||||||
|
"",
|
||||||
|
"?search=" + encodeURIComponent(search_input.value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}());
|
}());
|
||||||
|
|
||||||
// Sets the focus on the search bar at the top of the page
|
// Sets the focus on the search bar at the top of the page
|
||||||
|
|||||||
Reference in New Issue
Block a user