Comments (10)
Modified.
@christian-fei Thanks~ Anyway I did it by myself.
Still I think having this functionality (as an opt-in) helps people like me.
SimpleJekyllSearch({keyboardNavigation: true});
My implementation was so naive and dirty but ... for your/other's reference.
// ...
var self = this;
$('#search').on('keydown', function(e) {
var key = e.which;
var target = $('#search-results').find('li');
if ((key !== 38 && key !== 40 && key !== 13) || target.length < 1) {
return;
}
var navigate = function(direction) {
var down = (direction == 'down') ? true : false;
if (self.selected) {
self.selected.removeClass('active');
var next = down ? self.selected.next() : self.selected.prev();
if (next.length > 0) {
self.selected = next.addClass('active');
} else {
self.selected = down
? target.first().addClass('active')
: target.last().addClass('active');
}
} else {
self.selected = down
? target.first().addClass('active')
: target.last().addClass('active');
}
};
if (key === 40) {
navigate('down');
} else if (key === 38) {
navigate('up');
} else if (key === 13) {
if (self.selected) {
window.location.href = self.selected.find('a').attr('href');
}
}
e.preventDefault();
});
from simple-jekyll-search.
@appkr you can actually tab through the results and use shift + tab to go backwards.
from simple-jekyll-search.
@daviddarnes Thanks for the info. I checked it works. But people are comfortable with using up/down arrows in search box...
from simple-jekyll-search.
@appkr that seems fair, but I don't think it needs to be in the main code as it forces these controls onto everyone. Others might be using up and down for different controls.
from simple-jekyll-search.
@daviddarnes That sounds reasonable. I'll need to dig more to make it work. Thanks.
from simple-jekyll-search.
Thanks @appkr and @daviddarnes !
When I find some time I may look into this and see what we can do to get this to work
from simple-jekyll-search.
@appkr Thank you for the idea, will work on it
from simple-jekyll-search.
Up/Down in an autocomplete is pretty standard. I thought it was a bug when i tried to use it and it didn't work.
As @appkr said above, maybe have it as an option?
from simple-jekyll-search.
Hi @appkr may I ask how you implement it? I don't know where should I fork your snippet.
from simple-jekyll-search.
@damiannmm Since it was long time ago, i cannot remember the context at that time. Hope this link helps.
https://github.com/appkr/blog/blob/master/scripts/main.js#L197-L241
https://blog.appkr.dev/
from simple-jekyll-search.
Related Issues (20)
- Is it possible to redirect the search button to a new page? HOT 3
- Can we add custom fields to search.json? HOT 2
- Unexpected token in JSON at position 892 at JSON.parse HOT 1
- Doesn't like double quotes in code highlighter HOT 1
- SimpleJekyllSearch --- failed to get JSON (/search.json) HOT 10
- Could I trigger a search by modifying the Element value? HOT 1
- How can I know the json has been loaded HOT 4
- Callback when search results are displayed HOT 2
- switch mit license to GPL?
- Why my export zip file is 0 size?
- Search by entire phrase? HOT 3
- is't support search content. only support title HOT 6
- Code snippet breaking SimpleJekyllSearch HOT 1
- Use with GitHub Pages? HOT 3
- Highlight searched word in results
- Stating default options in README
- BUG: “Uncaught TypeError: str.trim is not a function”
- BUG: Uncaugnt TypeError: e.trim is not a function
- Missing tag for v1.10.0
- Error: SimpleJekyllSearch --- failed to get JSON (/search.json)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple-jekyll-search.