-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Have search boxes update on right-click paste #935
Open
jaredkhan
wants to merge
1
commit into
OneZoom:main
Choose a base branch
from
jaredkhan:search_on_paste
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+112
−118
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,45 +100,63 @@ | |
</div> | ||
<script> | ||
(function() { | ||
const update_search = (search_element, should_delay, debug_label) => { | ||
var search_term = search_element.value; | ||
var searchbox = $(search_element).closest('.searchbox'); | ||
var dropdown = $('.search_dropdown', searchbox); | ||
|
||
var searchresult = $('.searchresult', searchbox); | ||
if (searchresult && searchresult.attr('data-highlight')) { | ||
onezoom.controller.highlight_remove(searchresult.attr('data-highlight')); | ||
} | ||
|
||
if (search_term.length==0) { | ||
$('.popular_species', dropdown).show(); | ||
$('.recents', dropdown).show(); | ||
{{if is_testing:}}console.log("Hiding no_result section of dropdown");{{pass}} | ||
$('.no_results', dropdown).hide(); | ||
$('.search_hits', dropdown).empty(); | ||
OZui.search_manager.full_search(""); | ||
$('.searchinput', searchbox).removeClass('waiting_for_search_result'); | ||
return; | ||
} | ||
|
||
const trimmed_search_term = search_term.replace(/ /g,''); | ||
if ( | ||
trimmed_search_term.length > 2 || | ||
((trimmed_search_term.length > 1) && !should_delay) | ||
) { | ||
// never search for a single character | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this comment up before the if condition for readability. |
||
// and only search for two characters if enter has been pressed. | ||
OZui.search_manager.full_search( | ||
search_term, | ||
function(original_string, actual_search, results) { | ||
OZui.searchPopulate(searchbox, original_string, results); | ||
}, | ||
should_delay ? 1000 : 0, | ||
function() { | ||
{{if is_testing:}}console.log("Search for '" + search_term + "' sent to OneZoom API from " + debug_label + " search");{{pass}} | ||
|
||
if(!($(".searchinput").hasClass('waiting_for_search_result'))) | ||
{ | ||
$(".searchinput", searchbox).addClass('waiting_for_search_result'); // switch flag for search to on | ||
} | ||
} | ||
); | ||
} | ||
} | ||
|
||
var box_selector = $('#header_searchnav'); | ||
|
||
$('.searchinput input', box_selector) | ||
.on('keyup', function(event) { | ||
|
||
var search_term = this.value; | ||
var searchbox = $(this).closest('.searchbox'); | ||
var searchresult = $('.searchresult', searchbox); | ||
var dropdown = $('.search_dropdown', searchbox); | ||
if (search_term.length==0) { | ||
$('.popular_species', dropdown).show(); | ||
$('.recents', dropdown).show(); | ||
{{if is_testing:}}console.log("Hiding no_result section of dropdown");{{pass}} | ||
$('.no_results', dropdown).hide(); | ||
$('.search_hits', dropdown).empty(); | ||
OZui.search_manager.full_search(""); // this clears the search | ||
$('.searchinput', searchbox).removeClass('waiting_for_search_result'); | ||
} else { | ||
//$('.searchinput', searchbox).addClass('waiting_for_search_result'); | ||
var delay_ms = 1000; | ||
if (event.which == 13) { | ||
delay_ms = 1; //enter was pressed - don't delay | ||
} | ||
if ((search_term.replace(/ /g,'').length > 2)||((search_term.replace(/ /g,'').length > 1)&&(delay_ms == 1))) { // we're never going to search for a single character | ||
|
||
OZui.search_manager.full_search( | ||
search_term, | ||
function(original_string, actual_search, results) { | ||
OZui.searchPopulate(searchbox, original_string, results); | ||
}, | ||
delay_ms, | ||
function() { | ||
{{if is_testing:}}console.log("Search for '" + search_term + "' sent to OneZoom API from advanced search");{{pass}} | ||
if(!($(".searchinput").hasClass('waiting_for_search_result'))) { | ||
$(".searchinput", searchbox).addClass('waiting_for_search_result'); // switch flag for search to on | ||
}}); | ||
} | ||
} | ||
}); | ||
.on('input', function(event) { | ||
update_search(this, true, 'home page'); | ||
}) | ||
.on('keyup', function(event) { | ||
if (event.which == 13) { | ||
update_search(this, false, 'home page'); | ||
} | ||
}); | ||
}()) | ||
</script> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks intentionally identical to the code in the other layout file. Please add a comment to each noting that these should stay in sync.