1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
define(['underscore'], function (_) {
'use strict';
var baseUrls, sections, clientSideSections, canonize;
/**
* @param {String} url
* @return {String}
*/
canonize = function (url) {
var route = url,
key;
for (key in baseUrls) { //eslint-disable-line guard-for-in
route = url.replace(baseUrls[key], '');
if (route != url) { //eslint-disable-line eqeqeq
break;
}
}
return route.replace(/^\/?index.php\/?/, '').toLowerCase();
};
return {
/**
* @param {String} url
* @return {Array}
*/
getAffectedSections: function (url) {
var route = canonize(url),
actions = _.find(sections, function (val, section) {
var matched;
if (section.indexOf('*') >= 0) {
section = section.replace(/\*/g, '[^/]+') + '$';
matched = route.match(section);
return matched && matched[0] == route; //eslint-disable-line eqeqeq
}
return route.indexOf(section) === 0;
});
return _.union(_.toArray(actions), _.toArray(sections['*']));
},
/**
* @param {*} allSections
* @return {*}
*/
filterClientSideSections: function (allSections) {
if (Array.isArray(allSections)) {
return _.difference(allSections, clientSideSections);
}
return allSections;
},
/**
* @param {String} sectionName
* @return {Boolean}
*/
isClientSideSection: function (sectionName) {
return _.contains(clientSideSections, sectionName);
},
/**
* @param {Object} options
* @constructor
*/
'Magento_Customer/js/section-config': function (options) {
baseUrls = options.baseUrls;
sections = options.sections;
clientSideSections = options.clientSideSections;
}
};
});