Skip to content

Commit

Permalink
Manually set page title for page history
Browse files Browse the repository at this point in the history
...because apparently browsers ignore the title argument for some reason

see: whatwg/html#2174
  • Loading branch information
allejo committed Mar 14, 2019
1 parent c3efc48 commit f66a602
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion assets/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
});
idx.add(SearchIndex);

const originalTitle = document.title;
const srTemplate = document.getElementById('search-result').content;

if (!srTemplate) {
Expand Down Expand Up @@ -177,8 +178,23 @@
const searchResults = document.getElementById('search-results');
const searchForm = document.getElementById('search-field');

function getTitle(query) {
if (query) {
return 'Search - ' + query + ' - BZFlag';
}

return originalTitle;
}

function setTitle(title) {
document.title = title;
}

function pushHistory(query) {
history.pushState({}, 'Search - ' + query + ' - BZFlag', '/search/' + ((query.length)?'?query=' + encodeURIComponent(query):''));
const title = getTitle(query);

history.pushState({}, title, '/search/' + ((query.length) ? '?query=' + encodeURIComponent(query) : ''));
setTitle(title);
}

let pushHistoryTimeout;
Expand All @@ -194,6 +210,8 @@
function pullFromQueryString() {
const query = getParameterByName('query');

setTitle(getTitle(query));

if (query) {
searchForm.value = query.trim();
performSearch(searchForm.value);
Expand Down

0 comments on commit f66a602

Please sign in to comment.