1(function($) { 2 // a temporary fix for the race condition issue 3 var initialized = false; 4 5 var selectedStoreId = $.urlParam('store_id'); 6 7 $(document).on('freshopInitialized', function () { 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) { 23 items = items.filter(function() { 24 return window.wpConfig.storeHideFromStoreDropdown.includes(item.store_number) || !item.is_selectable; 25 }); 26 } 27 28 var sortedArray = items 29 .sort(fpClientUtil 30 .sortFirstBy(function (item1, item2) { 31 return fpClientUtil.sortHelper(item1.state, item2.state); 32 }) 33 .thenBy(function (item1, item2) { 34 return fpClientUtil.sortHelper(item1.name, item2.name); 35 }) 36 ); 37 38 var listContainer = $("#dropdown-store .dropdown-list"); 39 40 $.each(sortedArray, function(index, store) { 41 isSelected = ''; 42 if(store.id == selectedStoreId) isSelected = ' data-selected="true"'; 43 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>'; 44 45 listContainer.append(listItem); 46 }); 47 48 $("#dropdown-store").dropdown(function(value) { 49 const $item = $(this).data('dropdown').__getSelected(), 50 $storeName = $('#store-name').add($('#dropdown-store').closest('.store-dropdown-wrapper').next('input[type="hidden"]')).val($item.attr('data-store-name')), 51 $storeNumber = $storeName.parents('form').find('.contact-store-number input'), 52 storeName = $item.attr('data-store-name'), 53 selectedStore = sortedArray.find(function(item) { 54 return item.name === storeName; 55 }); 56 if(selectedStore) $storeNumber.val('store_id:' + selectedStore.id); 57 else $storeNumber.val(''); 58 }) 59 .data('dropdown').onChange(); 60 }); 61 } 62 } 63 64 setTimeout(function() { 65 if(freshop.initialized) init(); 66 }, 1000); 67 }); 68 69})(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.