Search query back button (#1981)
* Always allow history to go back/forward when using browser history * Add a back button which is visible when using the query parser
This commit is contained in:
parent
0e4b769390
commit
0a8992d215
@ -92,11 +92,6 @@ class DisplayHistory extends EventDispatcher {
|
||||
}
|
||||
|
||||
_go(forward) {
|
||||
const target = forward ? this._current.next : this._current.previous;
|
||||
if (target === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this._useBrowserHistory) {
|
||||
if (forward) {
|
||||
history.forward();
|
||||
@ -104,6 +99,8 @@ class DisplayHistory extends EventDispatcher {
|
||||
history.back();
|
||||
}
|
||||
} else {
|
||||
const target = forward ? this._current.next : this._current.previous;
|
||||
if (target === null) { return false; }
|
||||
this._current = target;
|
||||
this._updateHistoryFromCurrent(true);
|
||||
}
|
||||
|
@ -1538,9 +1538,7 @@ class Display extends EventDispatcher {
|
||||
}
|
||||
|
||||
_triggerContentUpdateStart() {
|
||||
let {content} = this._history;
|
||||
if (typeof content !== 'object' || content === null) { content = {}; }
|
||||
this.trigger('contentUpdateStart', {type: this._contentType, query: this._query, content});
|
||||
this.trigger('contentUpdateStart', {type: this._contentType, query: this._query});
|
||||
}
|
||||
|
||||
_triggerContentUpdateEntry(dictionaryEntry, element, index) {
|
||||
|
@ -28,6 +28,7 @@ class SearchDisplayController {
|
||||
this._displayAudio = displayAudio;
|
||||
this._searchPersistentStateController = searchPersistentStateController;
|
||||
this._searchButton = document.querySelector('#search-button');
|
||||
this._searchBackButton = document.querySelector('#search-back-button');
|
||||
this._queryInput = document.querySelector('#search-textbox');
|
||||
this._introElement = document.querySelector('#intro');
|
||||
this._clipboardMonitorEnableCheckbox = document.querySelector('#clipboard-monitor-enable');
|
||||
@ -75,6 +76,7 @@ class SearchDisplayController {
|
||||
this._display.setHistorySettings({useBrowserHistory: true});
|
||||
|
||||
this._searchButton.addEventListener('click', this._onSearch.bind(this), false);
|
||||
this._searchBackButton.addEventListener('click', this._onSearchBackButtonClick.bind(this), false);
|
||||
this._wanakanaEnableCheckbox.addEventListener('change', this._onWanakanaEnableChange.bind(this));
|
||||
window.addEventListener('copy', this._onCopy.bind(this));
|
||||
this._clipboardMonitor.on('change', this._onExternalSearchUpdate.bind(this));
|
||||
@ -146,15 +148,20 @@ class SearchDisplayController {
|
||||
this._setWanakanaEnabled(enableWanakana);
|
||||
}
|
||||
|
||||
_onContentUpdateStart({type, query, content}) {
|
||||
_onContentUpdateStart({type, query}) {
|
||||
let animate = false;
|
||||
let valid = false;
|
||||
let showBackButton = false;
|
||||
switch (type) {
|
||||
case 'terms':
|
||||
case 'kanji':
|
||||
animate = !!content.animate;
|
||||
{
|
||||
const {content, state} = this._display.history;
|
||||
animate = (typeof content === 'object' && content !== null && content.animate === true);
|
||||
showBackButton = (typeof state === 'object' && state !== null && state.cause === 'queryParser');
|
||||
valid = (typeof query === 'string' && query.length > 0);
|
||||
this._display.blurElement(this._queryInput);
|
||||
}
|
||||
break;
|
||||
case 'clear':
|
||||
valid = false;
|
||||
@ -165,6 +172,8 @@ class SearchDisplayController {
|
||||
|
||||
if (typeof query !== 'string') { query = ''; }
|
||||
|
||||
this._searchBackButton.hidden = !showBackButton;
|
||||
|
||||
if (this._queryInput.value !== query) {
|
||||
this._queryInput.value = query;
|
||||
this._updateSearchHeight(true);
|
||||
@ -193,6 +202,10 @@ class SearchDisplayController {
|
||||
this._search(true, 'new', true, null);
|
||||
}
|
||||
|
||||
_onSearchBackButtonClick() {
|
||||
this._display.history.back();
|
||||
}
|
||||
|
||||
_onCopy() {
|
||||
// ignore copy from search page
|
||||
this._clipboardMonitor.setPreviousText(window.getSelection().toString().trim());
|
||||
|
@ -50,6 +50,7 @@
|
||||
</div>
|
||||
<div class="search-textbox-container">
|
||||
<textarea id="search-textbox" class="scrollbar" placeholder="Input a term, expression, sentence, or block of text" autocomplete="off" lang="ja" autofocus></textarea>
|
||||
<button id="search-back-button" class="search-button" hidden><span class="icon" data-icon="left-chevron"></span></button>
|
||||
<button id="search-button" class="search-button"><span class="icon" data-icon="magnifying-glass"></span></button>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user