Skip to content

Commit

Permalink
Focus on the searchbox when "/" key is pressed
Browse files Browse the repository at this point in the history
按下"/"键后聚焦搜索框
This commit addresses and closes tuna#371
本提交解决并关闭tuna#371
  • Loading branch information
axmmisaka committed Jul 27, 2023
1 parent 7043012 commit 40e2b65
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h3>暂时无法提供服务</h3>
<div class="row">
<h3 id="mirror-title">{% fa_svg fas.fa-cube %} 镜像列表 </h3>
{% unless page.legacy %}
<input type="search" v-model.trim="filter" id="search" placeholder="搜索" autocomplete="off">
<input type="search" v-model.trim="filter" id="search" ref="search" placeholder="搜索" autocomplete="off">
{% endunless %}
</div>
<table class="table" v-if="mirrorList.length">
Expand Down
10 changes: 10 additions & 0 deletions static/js/index.es6
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ var vmMirList = new Vue({
},
created () {
this.refreshMirrorList();
window.addEventListener("keypress", this.onKeyPress);
},
beforeDestroy() {
window.removeEventListener("keypress", this.onKeyPress);
},
updated () {
$('.mirror-item-label').popover();
Expand Down Expand Up @@ -76,6 +80,12 @@ var vmMirList = new Vue({
self.rawMirrorList = status_data;
setTimeout(() => {self.refreshMirrorList()}, 10000);
});
},
onKeyPress(event) {
if (event.key === '/' && document.activeElement !== this.$refs.search) {
event.preventDefault();
this.$refs.search.focus();
}
}
}
})
Expand Down

0 comments on commit 40e2b65

Please sign in to comment.