<input type="text" class="form-control form-control-sm shipment-scan-input" placeholder="Focus here & scan" autofocus>
<script>
    (function() {
        function init() {
            const debounce = (func, delay) => {
                let inDebounce;
                return function() {
                    const context = this;
                    const args = arguments;
                    clearTimeout(inDebounce);
                    inDebounce = setTimeout(() => func.apply(context, args), delay);
                }
            }
            $(document)
                .off('keypress keyup', '.shipment-scan-input')
                .on('keypress keyup', '.shipment-scan-input', debounce(function () {
                    // console.log('ALIX', $(this).val());
                    gotoShipment($(this).val());
                }, 250));
            $(document)
                .off('focus', '.shipment-scan-input')
                .on('focus', '.shipment-scan-input', function () {
                    $(this).val('');
                });
        }
        function gotoShipment(_uid) {
            if(!$.trim(_uid)) return;
            let target = '/practice-management/shipments/view/' + _uid;
            $.get(target, (_data) => {
                fastLoad(target);
            }).fail((_x) => {
                console.warn('ALIX', _x.status);
            });
        }
        addMCInitializer('shipment-scan', init);
    }).call(window);
</script>
