Skip to content

Commit eecb29b

Browse files
authored
Merge pull request #170 from dynamsoft-docs/preview
update to internal commit 816d5dbd
2 parents b17771f + 7c6b0cc commit eecb29b

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

_includes/search-input.html

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
</button>
1212
</div>
1313
<div class="d-search-result">
14-
<div id="hits"></div>
14+
<div class="hit-container">
15+
<div class="loading" style="display: none;">
16+
<div class="lds-ring"><div></div><div></div><div></div><div></div></div>
17+
</div>
18+
<div id="hits"></div>
19+
</div>
1520
<div class="allResults"><a href="javascript:;" class="orangeLink">See all results ></a></div>
1621
</div>
1722
</div>
@@ -20,6 +25,7 @@
2025
var product = getCurrentUrlProductName(document.URL)
2126
var lang = getCurrentUrlLang(document.URL, true)
2227
var isNeedFilter = "{{site.searchNeedFilter}}"
28+
var isUserInput = true
2329

2430
const mySearch = instantsearch({
2531
indexName: '{{site.searchIndexName}}',
@@ -116,9 +122,22 @@
116122
]);
117123
}
118124

125+
mySearch.on('render', function() {
126+
if (mySearch.status === 'loading' || mySearch.status === 'stalled') {
127+
$(".hit-container .loading").show()
128+
} else {
129+
$(".hit-container .loading").hide()
130+
}
131+
});
132+
119133
mySearch.start();
120134

121135
$('#searchbox').on("keyup", function () {
136+
if (e.key== undefined && e.keyCode == undefined && e.code == undefined) {
137+
isUserInput = false
138+
} else {
139+
isUserInput = true
140+
}
122141
let value = $(this).val()
123142
if (value && value != "") {
124143
$(".ais-SearchBox-reset").show()
@@ -128,6 +147,10 @@
128147
})
129148

130149
$('#searchbox').keydown(function (e) {
150+
if (e.key== undefined && e.keyCode == undefined && e.code == undefined) {
151+
isUserInput = false
152+
return
153+
}
131154
if (e.keyCode == 13) {
132155
let value = $(this).val()
133156
if (value && value != "") {
@@ -139,6 +162,12 @@
139162
}
140163
})
141164

165+
$('#searchbox').on("input", function(e) {
166+
if (!isUserInput) {
167+
$("#searchbox").trigger($.Event("keydown", { key: "Enter", keyCode: 13, which: 13 }));
168+
}
169+
})
170+
142171
$(".ais-SearchBox-reset").on("click", function () {
143172
$('#searchbox').val("")
144173
$(".d-search-result").hide()

_layouts/search-layout.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ <h1 class="h2 fontOswald tc">{{page.h1}}</h1>
8888
var product = getCurrentUrlProductName(document.URL)
8989
var lang = getCurrentUrlLang(document.URL, true)
9090
var isNeedFilter = "{{site.searchNeedFilter}}"
91+
var isUserInput = true
9192

9293
const mySearch = instantsearch({
9394
indexName: '{{indexName}}',
@@ -193,6 +194,11 @@ <h1 class="h2 fontOswald tc">{{page.h1}}</h1>
193194
const searchButton = document.querySelector('#search-button');
194195

195196
$('#custom-searchbox').on("keyup", function () {
197+
if (e.key== undefined && e.keyCode == undefined && e.code == undefined) {
198+
isUserInput = false
199+
} else {
200+
isUserInput = true
201+
}
196202
let value = $(this).val()
197203
if (value && value != "") {
198204
$(".ais-SearchBox-reset").show()
@@ -206,11 +212,21 @@ <h1 class="h2 fontOswald tc">{{page.h1}}</h1>
206212
})
207213

208214
$('#custom-searchbox').keydown(function (e) {
215+
if (e.key== undefined && e.keyCode == undefined && e.code == undefined) {
216+
isUserInput = false
217+
return
218+
}
209219
if (e.keyCode == 13) {
210220
mySearch.helper.setQuery($("#custom-searchbox").val()).search();
211221
}
212222
})
213223

224+
$('#custom-searchbox').on("input", function(e) {
225+
if (!isUserInput) {
226+
$("#searchbox").trigger($.Event("keydown", { key: "Enter", keyCode: 13, which: 13 }));
227+
}
228+
})
229+
214230
$(".ais-SearchBox-reset").on("click", function () {
215231
$('#custom-searchbox').val("")
216232
$("#search-button").click()

0 commit comments

Comments
 (0)