Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

voice search box - minor changes

DanielŻuławskid7c7e7ec686a
diff --git a/src/Web/Grand.Web/Views/Shared/Components/SearchBox/Default.cshtml b/src/Web/Grand.Web/Views/Shared/Components/SearchBox/Default.cshtml
index 2be335c1d..cad4e9c33 100644
--- a/src/Web/Grand.Web/Views/Shared/Components/SearchBox/Default.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Components/SearchBox/Default.cshtml
@@ -15,7 +15,7 @@
@await Component.InvokeAsync("Widget", new { widgetZone = "searchbox_before_search_button" })
<div class="input-group-append">
- <button id="voiceSearchButton" @@mousedown="searchbox.recording = true" @@mouseup="searchbox.recording = false" :title="searchbox.micMessage" ref="micBtn" type="button" class="btn btn-link">
+ <button id="voiceSearchButton" @@touchstart="searchbox.recording = true" @@touchend="searchbox.recording = false" @@mousedown="searchbox.recording = true" @@mouseup="searchbox.recording = false" :data-title="searchbox.micMessage" ref="micBtn" type="button" v-bind:class="[{ focus: searchbox.recording }, 'btn btn-link']">
<template v-if="searchbox.recording">
<b-icon icon="mic" variant="info"></b-icon>
</template>
@@ -30,7 +30,7 @@
</div>
</div>
<template v-if="searchbox.searchitems !== null">
- <div id="adv_search" class="advanced-search-results">
+ <div id="adv_search" class="advanced-search-results" onclick="StopPropagation(event)">
<div class="col-12">
<div class="form-row">
<div class="col-md-6 col-12">
@@ -110,7 +110,7 @@
focus: false,
text: "",
placeholder: "@Loc["Search.SearchBox.Tooltip"]",
- micMessage: "Allow access to your mircophone",
+ micMessage: "Hold to Speak",
searchcategories: null,
searchbrands: null,
searchblog: null,
@@ -235,88 +235,4 @@
}
});
var searchbox = new searchBox().$mount('#small-search-box-form')
-</script>
-@*<script>
- const searchForm = document.querySelector("#search-form");
- const searchFormInput = searchForm.querySelector("input"); // <=> document.querySelector("#search-form input");
- const info = document.querySelector(".info");
-
- // The speech recognition interface lives on the browser’s window object
- const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; // if none exists -> undefined
-
- if (SpeechRecognition) {
- console.log("Your Browser supports speech Recognition");
-
- const recognition = new SpeechRecognition();
- recognition.continuous = true;
- // recognition.lang = "en-US";
-
- searchForm.insertAdjacentHTML("beforeend", '<button type="button"><i class="fas fa-microphone"></i></button>');
- searchFormInput.style.paddingRight = "50px";
-
- const micBtn = searchForm.querySelector("button");
- const micIcon = micBtn.firstElementChild;
-
- micBtn.addEventListener("click", micBtnClick);
- function micBtnClick() {
- if (micIcon.classList.contains("fa-microphone")) { // Start Voice Recognition
- recognition.start(); // First time you have to allow access to mic!
- }
- else {
- recognition.stop();
- }
- }
-
- recognition.addEventListener("start", startSpeechRecognition); // <=> recognition.onstart = function() {...}
- function startSpeechRecognition() {
- micIcon.classList.remove("fa-microphone");
- micIcon.classList.add("fa-microphone-slash");
- searchFormInput.focus();
- console.log("Voice activated, SPEAK");
- }
-
- recognition.addEventListener("end", endSpeechRecognition); // <=> recognition.onend = function() {...}
- function endSpeechRecognition() {
- micIcon.classList.remove("fa-microphone-slash");
- micIcon.classList.add("fa-microphone");
- searchFormInput.focus();
- console.log("Speech recognition service disconnected");
- }
-
- recognition.addEventListener("result", resultOfSpeechRecognition); // <=> recognition.onresult = function(event) {...} - Fires when you stop talking
- function resultOfSpeechRecognition(event) {
- const current = event.resultIndex;
- const transcript = event.results[current][0].transcript;
-
- if (transcript.toLowerCase().trim() === "stop recording") {
- recognition.stop();
- }
- else if (!searchFormInput.value) {
- searchFormInput.value = transcript;
- }
- else {
- if (transcript.toLowerCase().trim() === "go") {
- searchForm.submit();
- }
- else if (transcript.toLowerCase().trim() === "reset input") {
- searchFormInput.value = "";
- }
- else {
- searchFormInput.value = transcript;
- }
- }
- // searchFormInput.value = transcript;
- // searchFormInput.focus();
- // setTimeout(() => {
- // searchForm.submit();
- // }, 500);
- }
-
- info.textContent = 'Voice Commands: "stop recording", "reset input", "go"';
-
- }
- else {
- console.log("Your Browser does not support speech Recognition");
- info.textContent = "Your Browser does not support Speech Recognition";
- }
- </script>*@
\ No newline at end of file
+</script>
\ No newline at end of file
diff --git a/src/Web/Grand.Web/wwwroot/theme/css/common/common.css b/src/Web/Grand.Web/wwwroot/theme/css/common/common.css
index c8a3131d1..ad609d684 100644
--- a/src/Web/Grand.Web/wwwroot/theme/css/common/common.css
+++ b/src/Web/Grand.Web/wwwroot/theme/css/common/common.css
@@ -734,8 +734,60 @@ input:checked ~ .color-container .color::before {
#voiceSearchButton, .search-box-button {
font-size: 28px;
}
-#voiceSearchButton:focus {
+#voiceSearchButton {
+ position: relative;
+ border-radius: 100%;
+ background-color: #fff;
box-shadow: none;
+ transition: all .2s ease-in-out;
+ -webkit-transition: all .2s ease-in-out;
+ z-index: 4;
+}
+#voiceSearchButton.focus {
+ box-shadow: 0px 12px 28px rgb(0 123 255 / 25%), 0 -4px 14px rgb(0 123 255 / 22%)
+}
+#voiceSearchButton::before {
+ content: attr(data-title);
+ position: absolute;
+ left: 5px;
+ bottom: -45px;
+ color: #fff;
+ background: #000;
+ border-radius: .25rem;
+ font-size: 18px;
+ font-weight: 500;
+ padding: 5px 12px;
+ white-space: nowrap;
+ opacity: 0;
+ visibility: hidden;
+ transform: translateY(10px);
+ -webkit-transform: translateY(10px);
+ transition: all .2s ease-in-out;
+ -webkit-transition: all .2s ease-in-out;
+}
+#voiceSearchButton::after {
+ content: "";
+ position: absolute;
+ bottom: -8px;
+ left: 20px;
+ width: 0px;
+ height: 0px;
+ border-top: 10px solid transparent;
+ border-right: 10px solid transparent;
+ border-bottom: 10px solid #000;
+ border-left: 10px solid transparent;
+ opacity: 0;
+ visibility: hidden;
+ transform: translateY(10px);
+ -webkit-transform: translateY(10px);
+ transition: all .2s ease-in-out;
+ -webkit-transition: all .2s ease-in-out;
+}
+#voiceSearchButton:hover::before, #voiceSearchButton:hover::after {
+ opacity: 1;
+ visibility: visible;
+ transform: translateY(0);
+ -webkit-transform: translateY(0);
}
.search-box-text::placeholder {
color: #000;
@@ -1326,6 +1378,23 @@ footer .list-group-item span:last-child {
.up-btn {
bottom: 75px;
}
+ #search-box .modal-body {
+ padding: 15px;
+ }
+ #search-box .modal-body .search-box-text, #voiceSearchButton, .search-box-button {
+ font-size: 20px;
+ }
+ #voiceSearchButton::before {
+ bottom: -35px;
+ font-size: 12px;
+ padding: 5px 8px;
+ }
+ #voiceSearchButton::after {
+ border-top: 7px solid transparent;
+ border-right: 7px solid transparent;
+ border-bottom: 7px solid #000;
+ border-left: 7px solid transparent;
+ }
}
@media (max-width: 768px) {
.product-box.list .picture-container {
diff --git a/src/Web/Grand.Web/wwwroot/theme/css/common/common.rtl.css b/src/Web/Grand.Web/wwwroot/theme/css/common/common.rtl.css
index 7508a4566..e5b29414d 100644
--- a/src/Web/Grand.Web/wwwroot/theme/css/common/common.rtl.css
+++ b/src/Web/Grand.Web/wwwroot/theme/css/common/common.rtl.css
@@ -820,8 +820,60 @@ input:checked ~ .color-container .color::before {
#voiceSearchButton, .search-box-button {
font-size: 28px;
}
-#voiceSearchButton:focus {
+#voiceSearchButton {
+ position: relative;
+ border-radius: 100%;
+ background-color: #fff;
box-shadow: none;
+ transition: all .2s ease-in-out;
+ -webkit-transition: all .2s ease-in-out;
+ z-index: 4;
+}
+#voiceSearchButton.focus {
+ box-shadow: 0px 12px 28px rgb(0 123 255 / 25%), 0 -4px 14px rgb(0 123 255 / 22%)
+}
+#voiceSearchButton::before {
+ content: attr(data-title);
+ position: absolute;
+ right: 5px;
+ bottom: -45px;
+ color: #fff;
+ background: #000;
+ border-radius: .25rem;
+ font-size: 18px;
+ font-weight: 500;
+ padding: 5px 12px;
+ white-space: nowrap;
+ opacity: 0;
+ visibility: hidden;
+ transform: translateY(10px);
+ -webkit-transform: translateY(10px);
+ transition: all .2s ease-in-out;
+ -webkit-transition: all .2s ease-in-out;
+}
+#voiceSearchButton::after {
+ content: "";
+ position: absolute;
+ bottom: -8px;
+ right: 20px;
+ width: 0px;
+ height: 0px;
+ border-top: 10px solid transparent;
+ border-right: 10px solid transparent;
+ border-bottom: 10px solid #000;
+ border-left: 10px solid transparent;
+ opacity: 0;
+ visibility: hidden;
+ transform: translateY(10px);
+ -webkit-transform: translateY(10px);
+ transition: all .2s ease-in-out;
+ -webkit-transition: all .2s ease-in-out;
+}
+#voiceSearchButton:hover::before, #voiceSearchButton:hover::after {
+ opacity: 1;
+ visibility: visible;
+ transform: translateY(0);
+ -webkit-transform: translateY(0);
}
.search-box-text::placeholder {
color: #000;
@@ -1422,6 +1474,23 @@ footer .list-group-item span:last-child {
.up-btn {
bottom: 75px;
}
+ #search-box .modal-body {
+ padding: 15px;
+ }
+ #search-box .modal-body .search-box-text, #voiceSearchButton, .search-box-button {
+ font-size: 20px;
+ }
+ #voiceSearchButton::before {
+ bottom: -35px;
+ font-size: 12px;
+ padding: 5px 8px;
+ }
+ #voiceSearchButton::after {
+ border-top: 7px solid transparent;
+ border-right: 7px solid transparent;
+ border-bottom: 7px solid #000;
+ border-left: 7px solid transparent;
+ }
}
@media (max-width: 768px) {
.product-box.list .picture-container {
diff --git a/src/Web/Grand.Web/wwwroot/theme/script/public.common.js b/src/Web/Grand.Web/wwwroot/theme/script/public.common.js
index b36833695..6ec68aed8 100644
--- a/src/Web/Grand.Web/wwwroot/theme/script/public.common.js
+++ b/src/Web/Grand.Web/wwwroot/theme/script/public.common.js
@@ -489,7 +489,8 @@ function displayPopupNotification(message, messagetype) {
function CloseSearchBox() {
window.addEventListener('click', function () {
if (document.getElementById('adv_search')) {
- document.getElementById('adv_search').style.display = "none";
+ searchbox.text = "";
+ searchbox.searchitems = null;
}
});
}