PageSourceSearch

https://shop.commissaries.com/wp-content/themes/fp-wp-c/functions/…/includes/stores_dropdown.js?ver=1.1.8

js commissaries.com collected 2026-09-24 09:32:19 UTC 3,721 bytes, 75 lines download raw bytes

1(function($) {
2    // a temporary fix for the race condition issue
3    var initialized = false,
4        selectedStoreId = $.urlParam('store_id');
5
6    $(document).on('freshopInitialized', function () {
7        if(window.freshop) {
8            freshop.on('initialized', init);
9
10            // Load the data from the stores
11            function init(){
12                if(initialized) return;
13
14                initialized = true;
15
16                var $listContainer = $("#dropdown-store .dropdown-list");
17
18                if($listContainer && $listContainer.length > 0){
19                    freshop.getStores(function(data) {
20                        var items = data.items;
21
22                        if(window.wpConfig.storeHideFromStoreDropdown) items = _.reject(items, function(item){ return _.contains(window.wpConfig.storeHideFromStoreDropdown, item.store_number) || !item.is_selectable });
23                        
24                        var sortedArray =   _.sortBy(items, function(item) {
25                            return [item.state, item.name];
26                        });
27
28                        var listContainer = $("#dropdown-store .dropdown-list");
29
30                        $.each(sortedArray, function(index, store) {
31                            isSelected = '';
32                            if(store.id == selectedStoreId) isSelected = ' data-selected="true"';
33                            var listItem = '<li class="dropdown-list-item" role="presentation" data-store-id="'+ freshop.ui.encodeForHtml(store.id) + '"><a href="javascript:;" role="menuitem" data-store-name="' + freshop.ui.encodeForHtml(store.name) + '"data-value="' + freshop.ui.encodeForHtml(store.store_number) + '"' + isSelected + '>' + freshop.ui.encodeForHtml(store.state) + ' - ' + freshop.ui.encodeForHtml(store.name) + '</a></li>';
34                            
35                            listContainer.append(listItem);
36                        });
37
38                        $("#dropdown-store").dropdown(function(value) {
39                            var $item = $(this).data('dropdown').__getSelected()
40                                ,$storeName = $('#store-name').add($('#dropdown-store').closest('.store-dropdown-wrapper').next('input[type="hidden"]')).val($item.attr('data-store-name'))
41                                ,$storeNumber = $storeName.parents('form').find('.contact-store-number input');
42
43                                var selectedStore = _.findWhere(sortedArray, {name: $item.attr('data-store-name')});
44                                if(selectedStore) $storeNumber.val('store_id:' + selectedStore.id);
45                                else $storeNumber.val('');
46                        })
47                        .data('dropdown').onChange();
48
49                        //
50                        //  TODO: Update so that store names are shown for email templates
51                        //
52                        // var storeList = [
53                        //     {id:'0', text:'Not relevent', value:'na'}
54                        // ];
55
56                        // _.each(data.items, function(store, index) {
57                        //     storeList.push({id:store.id, text:store.name, value:store.store_number});
58                        // });
59
60                        // $("#dropdown-store").select2({
61                        //     placeholder: "Select a store",
62                        //     data: storeList,
63                        //     minimumResultsForSearch: Infinity
64                        // });
65                    });
66                }
67            }
68            
69            setTimeout(function() {
70                if(freshop.initialized) init();
71            }, 1000);
72        }
73    });
74
75})(jQuery);

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.