PageSourceSearch

https://www.springerpub.com/static/version1789146322/frontend/Mage…/Magento_Customer/js/section-config.js

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

1/**
2 * Copyright © Magento, Inc. All rights reserved.
3 * See COPYING.txt for license details.
4 */
5
6define(['underscore'], function (_) {
7    'use strict';
8
9    var baseUrls = [],
10        sections = [],
11        clientSideSections = [],
12        sectionNames = [],
13        canonize;
14
15    /**
16     * @param {String} url
17     * @return {String}
18     */
19    canonize = function (url) {
20        var route = url;
21
22        _.some(baseUrls, function (baseUrl) {
23            route = url.replace(baseUrl, '');
24
25            return route !== url;
26        });
27
28        return route.replace(/^\/?index.php\/?/, '').toLowerCase();
29    };
30
31    return {
32        /**
33         * Returns a list of sections which should be invalidated for given URL.
34         * @param {String} url - URL which was requested.
35         * @return {Object} - List of sections to invalidate.
36         */
37        getAffectedSections: function (url) {
38            var route = canonize(url),
39                actions = _.find(sections, function (val, section) {
40                    var matched;
41
42                    // Covers the case where "*" works as a glob pattern.
43                    if (section.indexOf('*') >= 0) {
44                        section = section.replace(/\*/g, '[^/]+') + '$';
45                        matched = route.match(section);
46
47                        return matched && matched[0] === route;
48                    }
49
50                    return route.indexOf(section) === 0;
51                });
52
53            return _.union(_.toArray(actions), sections['*']);
54        },
55
56        /**
57         * Filters the list of given sections to the ones defined as client side.
58         * @param {Object} allSections - List of sections to check.
59         * @return {Object} - List of filtered sections.
60         */
61        filterClientSideSections: function (allSections) {
62            return _.difference(allSections, clientSideSections);
63        },
64
65        /**
66         * Tells if section is defined as client side.
67         * @param {String} sectionName - Name of the section to check.
68         * @return {Boolean}
69         */
70        isClientSideSection: function (sectionName) {
71            return _.contains(clientSideSections, sectionName);
72        },
73
74        /**
75         * Returns array of section names.
76         * @returns {Array}
77         */
78        getSectionNames: function () {
79            return sectionNames;
80        },
81
82        /**
83         * @param {Object} options
84         * @constructor
85         */
86        'Magento_Customer/js/section-config': function (options) {
87            baseUrls = options.baseUrls;
88            sections = options.sections;
89            clientSideSections = options.clientSideSections;
90            sectionNames = options.sectionNames;
91        }
92    };
93});

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.