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.

4.3 KB
Raw Blame
@inject IContextAccessor contextAccessor
@{
    var lang = contextAccessor.WorkContext.WorkingLanguage.LanguageCulture;
}
@*
    The island wrapper is load-bearing, not decoration. _Layout renders this
    component straight into <main>, which deliberately carries no island, and the
    block below is a bare <template> - markup no island compiles renders as
    nothing at all, with no error and nothing in the DOM to show for it. The
    button was dead for exactly that reason until this wrapper was added.

    The <template v-if> cannot be the mount point itself: Vue reads a mount
    point's innerHTML, so a directive on it is ignored.

    The JSON island below stays outside the wrapper - initViews() has already
    consumed it by the time this mounts, and Vue would otherwise re-render it.
*@
<div class="voice-navigation" vue-island="voicenavigator">
<template v-if="voicenavigator.allowed">
    <button id="voicePageButton"
            @@touchstart="voicenavigator.recording = true"
            @@touchcancel="voicenavigator.recording = false;"
            @@touchend="voicenavigator.recording = false;"
            @@mousedown="voicenavigator.recording = true"
            @@mouseup="voicenavigator.recording = false"
            @@mouseleave="voicenavigator.recording = false"
            ref="voicePageButton" type="button" v-bind:class="[{ focus: voicenavigator.recording }, 'btn btn-link voice-page-button']">
        <template v-if="voicenavigator.recording">
            <i class="b-icon bi bi-mic text-info" aria-hidden="true"></i>
        </template>
        <template v-else>
            <i class="b-icon bi bi-mic-mute text-danger" aria-hidden="true"></i>
        </template>
    </button>
    <div v-if="voicenavigator.recording"
         class="alert voice-alert position-fixed fixed-top m-0 rounded-0"
         :class="'alert-' + voicenavigator.variant" role="alert">
        <div class="recording-window">
            <div class="recording-aniamtion">
                <template v-if="voicenavigator.variant !== 'success'">
                    <i class="b-icon bi bi-mic text-info" aria-hidden="true"></i>
                </template>
                <template v-else>
                    <i class="b-icon bi bi-check text-success" aria-hidden="true"></i>
                </template>
            </div>
            <input type="text" placeholder="@Loc["voicenavigator.voice.placeholder"]" v-model="voicenavigator.transcript" class="form-control" readonly/>
        </div>
        <small class="form-text w-100">@Loc["voicenavigator.voice.annotation"]</small>
    </div>
</template>
</div>
@{
    var voiceCommands = new[] {
        new { name = "cart", url = "/cart", triggers = Loc["voicenavigator.commands.cart"].Value.Split(',') },
        new { name = "blog", url = "/blog", triggers = Loc["voicenavigator.commands.blog"].Value.Split(',') },
        new { name = "homepage", url = "/", triggers = Loc["voicenavigator.commands.homepage"].Value.Split(',') },
        new { name = "wishlist", url = "/wishlist", triggers = Loc["voicenavigator.commands.wishlist"].Value.Split(',') },
        new { name = "login", url = "/login", triggers = Loc["voicenavigator.commands.login"].Value.Split(',') },
        new { name = "register", url = "/register", triggers = Loc["voicenavigator.commands.register"].Value.Split(',') },
        new { name = "contactus", url = "/contactus", triggers = Loc["voicenavigator.commands.contactus"].Value.Split(',') }
    };
}
<script type="application/json" data-grand-vm="voiceNavigation">@Json.Serialize(new {
                                                                    lang,
                                                                    commands = voiceCommands,
                                                                    res = new {
                                                                        micHold = Loc["voicenavigator.voice.holdtospeak"].ToString(),
                                                                        micPlaceholder = Loc["voicenavigator.voice.placeholder"].ToString(),
                                                                        tryAgain = Loc["voicenavigator.voice.tryagain"].ToString()
                                                                    }
                                                                })</script>