PageSourceSearch

https://beautysociety.com/wp-content/plugins/beautysociety-wrapper…ety-filter-sidebar-directive.js?ver=6.0.132

js beautysociety.com collected 2026-09-24 10:10:11 UTC 9,545 bytes, 212 lines download raw bytes

1(function() {
2    'use strict';
3
4    const app = angular.module('app');
5
6    app.filter('beautysocietyOptionSelectedFilter', function() {
7        return function(input) {
8            if (!Array.isArray(input)) {
9                return input;
10            }
11
12            return input.filter(function(item) {
13                return item.Selected === true;
14            });
15        };
16    });
17
18    app.filter('beautysocietyJoinFilter', function() {
19        return function(input, delimiter) {
20            if (!Array.isArray(input)) {
21                return input;
22            }
23
24            return input.join(delimiter);
25        };
26    });
27
28    app.filter('beautysocietyMapFilter', function() {
29        return function(input, property) {
30            if (!Array.isArray(input)) {
31                return input;
32            }
33
34            return input.map(function(item) {
35                return item[property];
36            });
37        };
38    });
39
40    app.filter('capitalizeFirstLetterFilter', function() {
41        return function(input) {
42            if (!input || typeof input !== 'string') {
43                return input;
44            }
45            
46            const lower = input.toLowerCase();
47
48            return lower.charAt(0).toUpperCase() + lower.slice(1);
49        };
50    });
51
52    app.directive('beautisocietyFilterSidebar', function ($q, $location, beautysocietyCommonService) {
53        return {
54            restrict: 'E',
55            scope: {
56                parentControllerContext: '='
57            },
58            replace: true,
59            templateUrl: beautysocietyDirectivePluginRelativeUrl + '/assets/views/directives/beautysociety-filter-sidebar-directive.html',
60            controller: function ($scope, $rootScope) {
61                $scope.isSidebarOpen = false;
62                $scope.filterOptions = [];
63                $scope.beautysocietyDirectivePluginBaseUrl = beautysocietyDirectivePluginBaseUrl;
64
65                const deregisterMessageListener = $rootScope.$on('beautySocietyComponentMessage', function(event, data) {
66                    $scope.openedFilterOption = null;
67
68                    if (data?.action === 'showSidebar') {
69                        if ($rootScope.beautysocietyFilterOptions && $rootScope.beautysocietyFilterOptions.length > 0) {
70                            $scope.filterOptions = angular.copy($rootScope.beautysocietyFilterOptions).map((beautySocietyFilterOption) => {
71                                beautySocietyFilterOption.Options = beautySocietyFilterOption.Options.map((option) => {
72                                    option.Name = beautysocietyCommonService.ucFirst(option.Name.toLowerCase());
73                                    return option;
74                                });
75
76                                if (beautySocietyFilterOption.Name === data?.filterOptionName) {
77                                    beautySocietyFilterOption.isOpen = true;
78                                }
79
80                                return beautySocietyFilterOption;
81                            });
82
83                            const selectedFilterOptions = beautysocietyCommonService.getSelectedFilterOptions();
84
85                            if (selectedFilterOptions && selectedFilterOptions.length > 0) {
86                                $scope.filterOptions.forEach(filterOption => {
87                                    const selectedOptionsForCategory = selectedFilterOptions.filter(x => x.CategoryName === filterOption.Name);
88                                    if (selectedOptionsForCategory.length > 0) {
89                                        filterOption.Options.forEach(option => {
90                                            const isSelected = selectedOptionsForCategory.some(x => 
91                                                x.Name && option.Name && 
92                                                x.Name.toLowerCase() === option.Name.toLowerCase()
93                                            );
94
95                                            option.Selected = isSelected;
96                                        });
97                                    }
98                                });
99                            }
100                        }
101
102                        $scope.isSidebarOpen = true;
103                    } else if(data?.action === 'beautysocietyFilterOptionsBuilt') {
104                        $scope.filterOptions = angular.copy($rootScope.beautysocietyFilterOptions).map((beautySocietyFilterOption) => {
105                            beautySocietyFilterOption.Options = beautySocietyFilterOption.Options.map((option) => {
106                                option.Name = beautysocietyCommonService.ucFirst(option.Name.toLowerCase());
107                                return option;
108                            });
109
110                            return beautySocietyFilterOption;
111                        });
112
113                        const selectedFilterOptions = beautysocietyCommonService.getSelectedFilterOptions();
114                        if (selectedFilterOptions && selectedFilterOptions.length > 0) {
115                            $scope.filterOptions.forEach(filterOption => {
116                                const selectedOptionsForCategory = selectedFilterOptions.filter(x => x.CategoryName === filterOption.Name);
117
118                                if (selectedOptionsForCategory.length > 0) {
119                                    filterOption.Options.forEach(option => {
120                                        const isSelected = selectedOptionsForCategory.some(x => 
121                                            x.Name && option.Name && 
122                                            x.Name.toLowerCase() === option.Name.toLowerCase()
123                                        );
124
125                                        option.Selected = isSelected;
126                                    });
127                                }
128                            });
129                        }
130                    } else if (data?.action === 'clearAllFilters') {
131                        $scope.clearFilters();
132                    } else if (data?.action === 'clearFilterOption') {
133                        $scope.clearFilterOption(data?.filterOption);
134                    }
135                });
136
137                // Clean up event listener when scope is destroyed to prevent memory leaks and duplicate handlers
138                $scope.$on('$destroy', function() {
139                    if (deregisterMessageListener) {
140                        deregisterMessageListener();
141                    }
142                });
143
144                $scope.applyFilters = () => {
145                    if ($scope.filterOptions && $scope.filterOptions.length > 0) {
146                        $rootScope.beautysocietyFilterOptions = angular.copy($scope.filterOptions);
147                    }
148
149                    $rootScope.$broadcast('beautySocietyComponentMessage', {
150                        action: 'beautysocietyApplyFilters'
151                    });
152
153                    $scope.isSidebarOpen = false;
154                };
155
156                $scope.clearFilterOption = (filterOption) => {
157                    $scope.filterOptions?.forEach((filterCategory) => {
158                        if (filterCategory.Name === filterOption.CategoryName) {
159                            filterCategory?.Options?.forEach((option) => {
160                                if (option?.Name == filterOption?.Name) {
161                                    option.Selected = false;
162                                }
163                            });
164                        }
165                    });
166
167                    $rootScope.$broadcast('beautySocietyComponentMessage', {
168                        action: 'beautysocietyApplyFilters'
169                    });
170                };
171
172                $scope.clearFilters = () => {
173                    if ($scope.filterOptions && $scope.filterOptions.length > 0) {
174                        $scope.filterOptions.forEach(filterCategory => {
175                            if (filterCategory.Options) {
176                                filterCategory.Options.forEach(option => {
177                                    option.Selected = false;
178                                });
179                            }
180                        });
181
182                        $rootScope.beautysocietyFilterOptions = angular.copy($scope.filterOptions);
183                    }
184
185                    $rootScope.$broadcast('beautySocietyComponentMessage', {
186                        action: 'beautysocietyClearFilters'
187                    });
188
189                    $rootScope.$broadcast('beautySocietyComponentMessage', {
190                        action: 'beautysocietyApplyFilters'
191                    });
192
193                    $scope.isSidebarOpen = false;
194                };
195
196                $scope.toggleFilterOption = function(filterOption, index) {
197                    $scope.filterOptions.forEach(function(option, i) {
198                        if (i !== index) {
199                            option.isOpen = false;
200                        }
201                    });
202                    
203                    filterOption.isOpen = !filterOption.isOpen;
204                };
205            
206                $scope.close = () => {
207                    $scope.isSidebarOpen = false;
208                };
209            }
210        }
211    });
vendor: 5 bytes, line 212
212})();

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.