PageSourceSearch

https://www.springerpub.com/static/version1789146322/base/Magento/base/default/mage/smart-keyboard-handler.js

js springerpub.com collected 2026-09-24 08:47:42 UTC 2,753 bytes, 92 lines download raw bytes

1/**
2 * Copyright © Magento, Inc. All rights reserved.
3 * See COPYING.txt for license details.
4 */
5define([
6    'jquery'
7], function ($) {
8    'use strict';
9
10    /**
11     * @return {Object}
12     * @constructor
13     */
14    function KeyboardHandler() {
15        var body = $('body'),
16            focusState = false,
17            tabFocusClass = '_keyfocus',
18            productsGrid = '[data-container="product-grid"]',
19            catalogProductsGrid = $(productsGrid),
20            CODE_TAB = 9;
21
22        /**
23         * Handle logic, when onTabKeyPress fired at first.
24         * Then it changes state.
25         */
26        function onFocusInHandler() {
27            focusState = true;
28            body.addClass(tabFocusClass)
29                .off('focusin.keyboardHandler', onFocusInHandler);
30        }
31
32        /**
33         * Handle logic to remove state after onTabKeyPress to normal.
34         */
35        function onClickHandler() {
36            focusState = false;
37            body.removeClass(tabFocusClass)
38                .off('click', onClickHandler);
39        }
40
41        /**
42         * Tab key onKeypress handler. Apply main logic:
43         *  - call differ actions onTabKeyPress and onClick
44         */
45        function smartKeyboardFocus() {
46            $(document).on('keydown keypress', function (event) {
47                if (event.which === CODE_TAB && !focusState) {
48                    body
49                        .on('focusin.keyboardHandler', onFocusInHandler)
50                        .on('click', onClickHandler);
51                }
52            });
53
54            // ARIA support for catalog grid products
55            if (catalogProductsGrid.length) {
56                body.on('focusin.gridProducts', productsGrid, function () {
57                    if (body.hasClass(tabFocusClass)) {
58                        $(this).addClass('active');
59                    }
60                });
61                body.on('focusout.gridProducts', productsGrid, function () {
62                    $(this).removeClass('active');
63                });
64            }
65        }
66
67        /**
68         * Attach smart focus on specific element.
69         * @param {jQuery} element
70         */
71        function handleFocus(element) {
72            element.on('focusin.emulateTabFocus', function () {
73                focusState = true;
74                body.addClass(tabFocusClass);
75                element.off();
76            });
77
78            element.on('focusout.emulateTabFocus', function () {
79                focusState = false;
80                body.removeClass(tabFocusClass);
81                element.off();
82            });
83        }
84
85        return {
86            apply: smartKeyboardFocus,
87            focus: handleFocus
88        };
89    }
90
91    return new KeyboardHandler;
92});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.