PageSourceSearch

https://www.toms-foodmarkets.com/wp-content/themes/fp-wp-f/resources/scripts/fpClient.js?ver=1.0.0

js toms-foodmarkets.com collected 2026-09-26 15:11:11 UTC 18,636 bytes, 411 lines download raw bytes

1(function($) {
2	window.fpClient = {
3		store: {}
4		,user: {}
5        //,newUser: $.cookie('cn-new-user') || true
6		,URLs: {
7			myFavoritesUrl: user_trailingslashit('/shop') + '#!/?filter=is_favorite'
8            ,storeLocator: user_trailingslashit('/store/store-locator')
9		}
10		,init: function () {
11            this.initMobileHeader();
12			this.initMyFavorites();
13		}
14        ,showSubNav: function() {
15            var $subNav = $('#freshop-account .sub-menu').removeClass('hidden')
16                ,route = freshop.ui.getRoute()[0].toLowerCase();
17
18            $subNav.find('a')
19                .removeClass('is-selected')
20                    .filter('[href$="#!/' + route + '"]')
21                    .first().addClass('is-selected');
22
23            if($subNav.find('.is-selected').length <= 0){
24                $subNav.find('.link-my-account').addClass('is-selected');
25            }
26        }
27        ,initMyFavorites: function() {
28            var $menuFavorites = $('#menu-header-menu, #menu-footer-menu-mobile');
29
30            $menuFavorites.find('.nav-my-favorites a')
31            .attr('href', this.URLs.myFavoritesUrl)
32            .append('&nbsp;<span class="icon-star"></span>');
33
34            $('#top-my-favorites').attr('href', this.URLs.myFavoritesUrl);
35        }
36        ,initAccountMenu: function(accountNav) {
37            accountNav = accountNav || {};
38
39            $('.user-session-indicator-mobile')
40                .off('click', '.fp-my-account-right-angle')
41                .on('click', '.fp-my-account-right-angle', function(event) {
42                    var $myAccountLink = $('#menu-footer-menu-mobile .mobile-my-account');
43                    $myAccountLink.trigger('click');
44                });
45
46            freshop.ui.on('routeChanged', toggleSubNav);
47
48            toggleSubNav();
49
50            function toggleSubNav() {
51                var $subNavContainer = $('#freshop-account-left')
52                    ,$mobileSubNavContainer = $('#menu-footer-menu-mobile .mobile-my-account')
53                    ,html = ''
54                    ,freshopConfig = freshop.ui.getConfig()
55                    ,hasChildren = _.size(accountNav.children);
56
57                $('#freshop-account').toggleClass('full-width', !hasChildren);
58
59                if(hasChildren) {
60                    $mobileSubNavContainer
61                        .addClass('menu-item-has-children')
62                        .find('> a').addClass('fp-icon-caret-right').wrapInner('<span></span>');
63                }
64                else $mobileSubNavContainer.removeClass('menu-item-has-children');
65
66
67                var freshopUi = freshop.ui
68                    ,title
69                    ,menuClass;
70
71                _.each(accountNav.children, function(item) {
72                    title = freshopUi.encodeForHtml(item.title);
73                    menuClass = '';
74                    if(item.url.toLowerCase().indexOf('my-favorites') >= 0) {
75                        menuClass = 'nav-my-favorites';
76                        title += '&nbsp;<span class="fp-icon fp-icon-star"></span>';
77                        title = '<span>' + title + '</span>';
78                    }
79                    else title = '<span>' + title + '</span>';
80
81                    html += '<li><a href="' + freshopUi.encodeForHtml(item.url) + '" class="menu-item ' + menuClass + '">' + title + '</a></li>';
82                });
83
84                if(html) html = '<ul class="sub-menu second-menu">' + html + '</ul>';
85
86                $subNavContainer.html(html);
87
88              var $accountSubMenu = $mobileSubNavContainer.find('ul.sub-menu');
89              if ($accountSubMenu) {
90                var $subMenu = $(html);
91                $subMenu.attr('style', $accountSubMenu.attr('style'));
92
93                $mobileSubNavContainer.find('ul.sub-menu').remove();
94                $mobileSubNavContainer.append($subMenu);
95              }
96
97                var route = freshop.ui.getLocation()
98                    ,$items = $subNavContainer.find('a').removeClass('is-selected')
99                    ,$firstChild = $items.filter('[href="' + route + '"]')
100                    .first().addClass('is-selected');
101
102                if (!$firstChild.length) $items.first().addClass('is-selected');
103            }
104        }
105		,onFreshopInit: function(){
106			var pref = $.cookie('pref') || {}
107                ,event = window.hasTouch ? 'touch' : 'click'
108                ,$search = $('#header .header-wrapper .search')
109                ,freshopUi = freshop.ui;
110
111            if(pref.showSearch) $search.trigger(event);
112
113            freshopUi
114                .on('loaded', function(event) {
115                    fpClient.storeChanged(event, fpClient.store);
116                })
117                .on('search', function() {
118                    var $body = $(document.body);
119                    $body.removeClass('mobile-menu-active');
120                });
121
122            freshop
123            	.on('storeChanged', fpClient.storeChanged)
124                .on('storeLoaded', fpClient.storeChanged)
125                .on('circularLoaded', function(event, circular) {
126                    var $title = $('#circular-title')
127                    , startDate = circular.display_start_date ? circular.display_start_date : circular.start_date
128                    , endDate = circular.display_end_date ? circular.display_end_date : circular.end_date;
129
130                    if($title.length) {
131                        $title.find('.start-date').text(fpClientUtil.formatDate(startDate));
132                        $title.find('.end-date').text(fpClientUtil.formatDate(endDate));
133                        $title.find('> span').css('visibility', '');
134                    }
135                });
136		}
137        ,initMobileHeader: function(){
138            var eventType = window.hasTouch ? 'touchstart.minilist.fc' : 'click.minilist.fc'
139                ,$mobileMenu = $('.mobile-header-wrapper');
140
141            $mobileMenu
142                .off()
143                .on(eventType, '#navbar-toggle', function(event) {
144                    event.preventDefault();
145                    if($(document.body).hasClass('mobile-menu-active')) {
146                        var $navWrapper = $('#mobile-nav-wrapper')
147                            ,$currentMenu = $navWrapper.data('currentMenu')
148                            ,level = $navWrapper.data('level') || 0;
149                        if(level == 0) navigation.toggleNav();
150                        else $navWrapper.trigger('click');
151                        return;
152                    }
153                    navigation.toggleNav();
154                })
155                .on(eventType, '.logo', function(event) {
156                    if($(document.body).hasClass('mobile-menu-active')) {
157                        event.preventDefault();
158                        event.stopImmediatePropagation();
159                        navigation.toggleNav();
160                    }
161                })
162                .on(eventType, '.mobile-search-icon', function (event) {
163                    event.preventDefault();
164                    if ($('.fp-mini-list').hasClass('hidden')) {
165                        event.stopImmediatePropagation();
166                    }
167
168                    if(window.freshop) {
169                        var pref = $.cookie('pref') || {}
170                            ,$headerSearch = $('.mobile-header-wrapper .mobile-search')
171                            ,$mobileSearchInput = $headerSearch.find('[name=fp-input-search]');
172
173                        if($headerSearch.filter(':visible').length) {
174                            pref.showSearch = false;
175                            $headerSearch.slideUp(function() {
176                                $headerSearch.show().addClass('hidden-xs hidden-sm');
177                            });
178                        }
179                        else {
180                            pref.showSearch = true;
181                            $headerSearch.removeClass('hidden-xs hidden-sm');
182                            freshop.trigger('mediaWidthChange');
183                            $headerSearch.hide().slideDown(function() {
184                                //$mobileSearchInput.blur();
185                                //var origValue = $mobileSearchInput.val();
186                                //$mobileSearchInput.val('').focus().val(origValue);
187                            });
188                        }
189                        $.cookie('pref', pref, {path: '/'});
190                    }
191                });
192        }
193		/*,toggleMinilist: function(){
194			var open = $('#fp-minilist').filter(':visible').length > 0
195				,$parent = $('.mini-list #mini-list-wrapper');
196
197			if(open){
198				freshop.trigger('miniListHide');
199			}
200			else {
201				freshop.trigger('miniListShow');
202				$parent.addClass('opened');
203			}
204		}*/
205		,storeChanged: function(event, store){
206            var href
207                ,$anchor = $('#mobile-selected-store > .nav-my-store > a')
208                ,$mainNavMyStore = $('#menu-main-menu').find('.nav-my-store > a')
209                ,$breadcrumbMyStore = $('.breadcrumb > li > a[title^=" My Store"]')
210                ,$footerMyStore = $('#menu-footer-menu-col-1 > .nav-my-store > a')
211                ,$mobileStoreLink = $('#mobile-selected-store')
212                ,$headerSelectStore = $('.nav-my-store > .dropdown > .link-my-store')
213                ,$headerMyStore = $('.nav-my-store > .link-my-store-primary')
214                ,oldStore = fpClient.store;
215
216            //fpCheckWeeklyAd.check();
217
218            if(store.id) {
219                if(store.name) {
220                    $('.my-store-name').text(store.name);
221
222                    href = store.url;
223                    //$anchor.text(store.name);
224                    $headerSelectStore.find('.name').text(store.name);
225                    $mobileStoreLink.find('a').text(store.name);
226
227                    //print view, adding address
228                    var $storeInfo = $('#store-main-info');
229                    var $storeAddress = freshop.ui.encodeForHtml(store.address_0);
230
231                    if(store.address_0) $storeAddress += '<br />';
232                    if(store.address_1) $storeAddress += freshop.ui.encodeForHtml(store.address_1);
233                    if(store.address_2) $storeAddress += '<br />' + freshop.ui.encodeForHtml(store.address_2);
234                    $storeAddress += '<br />' + freshop.ui.encodeForHtml(store.city) + ', ' + freshop.ui.encodeForHtml(store.state) + ' ' + freshop.ui.encodeForHtml(store.postal_code);
235                    $storeInfo.html(freshop.ui.encodeForHtml(store.name) + '<br />' + $storeAddress);
236
237                    fpClient.store = store;
238
239                    $headerSelectStore.attr('href', 'javascript:;').attr('data-href', href);
240                    $mobileStoreLink.removeClass('hidden');
241                    fpClient.setMyStoreBox(store);
242                }
243            }
244            else {
245                href = fpClient.URLs.storeLocator;
246                // $anchor.text("My Store");
247                // $headerSelectStore.find('.name').text('Select Store');
248                // $mobileStoreLink.find('.nav-my-store a').text('Select Store');
249                fpClient.setMyStoreBox(null);
250            }
251
252            fpClient.setStoreLinks($anchor.add($mainNavMyStore).add($headerMyStore), href);
253
254            var storeId = store ? store.id : null;
255            if(!storeId || !oldStore.id || (oldStore.id && oldStore.id != storeId)) {
256                freshop.ui.getNavigation(function (resp) {
257                    fpClient.initAccountMenu(resp.account);
258                    $('#fp-departments').html(navigation.getNavHtml(resp.shop, 1));
259                    $('#recipe-categories').html(navigation.getNavHtml(resp.recipe, 1));
260
261                    if (navigation.menuInitialized) {
262                        if (window.isSmall) {
263                            //trigger reset of menu styles
264                            navigation.initMenu();
265                            navigation.onDepartments();
266
267                            if (window.matchMedia) {
268                                navigation.matchMediaHandler(window.matchMedia("screen and (max-width: 991px)"));
269                            }
270                        }
271                        else navigation.onDepartments();
272
273                        navigation.initMenuTouchSupport();
274                    }
275                });
276            }
277
278			if(wpConfig.hasSiteBanner) fpClient.loadSiteBanner(storeId);
279		}
280        ,setStoreLinks: function($links, url) {
281            $links.each(function() {
282                var $this = $(this)
283                    ,href = $this.data('origHref');
284
285                if(!href) {
286                    $this.data('origHref', $this.attr('href'));
287                }
288                if(url) {
289                    href = url;
290                }
291                if((href || '').indexOf('www') == 0) {
292                    href = 'http://' + href;
293                }
294
295                $this.attr('href', href);
296            });
297        }
298        ,setMyStoreBox: function(store){
299            var $myStoreLink = $('#header').find('.link-my-store')
300                ,$myStoreBox = $('#header').find('.dropdown-selected-store')
301                ,$storeName = $myStoreBox.find('.store-name > span.name')
302                ,$storeAddress = $myStoreBox.find('.store-address')
303                ,$storeHours = $myStoreBox.find('.store-hours > span')
304                ,$storePhone = $myStoreBox.find('.store-phone > span')
305                ,$storeDirections = $myStoreBox.find('.store-directions')
306                ,address = '';
307
308            if(store){
309                $myStoreLink.attr('data-toggle', 'dropdown');
310                if(store.name) $storeName.html('<a href="' + store.url +'">'+ freshop.ui.encodeForHtml(store.name) +'</a>');
311                if(store.address_1 && store.state && store.postal_code) {
312                    address = freshop.ui.encodeForHtml(store.address_1);
313                    if(store.address_2) address += ',' + freshop.ui.encodeForHtml(store.address_2);
314                    address += '<br />' + freshop.ui.encodeForHtml(store.city) + ', ' + freshop.ui.encodeForHtml(store.state) + ' ' + freshop.ui.encodeForHtml(store.postal_code);
315                }
316                if(address) $storeAddress.html(address);
317                if(store.hours) $storeHours.html(freshop.ui.encodeForHtml(store.hours));
318                if(store.phone) $storePhone.html(freshop.ui.encodeForHtml(store.phone));
319                if(store.latitude && store.longitude) $storeDirections.html('<a href="https://www.google.com/maps/dir//' + encodeURIComponent(address.replace("<br />", ' ')) + '" target="_blank">Get Directions</a>');
320
321            }
322            else{
323                $myStoreLink.attr('data-toggle', '');
324            }
325        }
326        ,initMinilistIndicator : function() {
327            var mobileSelector = '';
328            if(window.isSmall) mobileSelector = '-mobile';
329            $('#mini-list' + mobileSelector + '-wrapper').append($('#mini-list-indicator'));
330        }
331
332		,loadSiteBanner: function(storeId){
333            console.log('******* storeId');
334            console.log(storeId);
335
336            var prefKey = 'site_banner_' + (storeId || '') + '_disabled';
337            if(freshop.ui.getPrefCookie()[prefKey]) return;
338            $.ajax({
339                    url: ajax_objectClient.rest_url + '/freshop/v1/content/site-banner',
340                    dataType: 'json',
341                    data: {
342                        store_id: storeId
343                    }
344                })
345                .done(function(resp) {
346                    console.log('******** resp');
347                    console.log(resp);
348
349                    var html = $.trim(_.isObject(resp) ? resp.html : ''),
350                        $siteBanner = $('#site-banner').css('display', ''),
351                        $accountMenu = $siteBanner.closest('.account-menu'),
352                        $container = $('#main-menu-container > .row').filter(':visible'),
353                        $body = $('body'),
354                        hadBanner = $body.hasClass('has-site-banner'),
355                        hasBanner = html.length > 0;
356                    
357                    $siteBanner.toggleClass('hidden', html.length == 0);
358                    $body.toggleClass('has-site-banner', hasBanner);
359
360                    function closeSiteBanner() {
361                        var pref = {};
362                        pref[prefKey] = true;
363                        freshop.ui.setPrefCookie(pref);
364                        $body.removeClass('has-site-banner');
365                        $container
366                            .css('margin-top', '')
367                            .animate({'margin-top': $accountMenu.height()}, 'fast');
368
369                        $siteBanner
370                            .css('display', 'block')
371                            .slideUp('fast', function() {
372                                $siteBanner.html('');
373                            });
374                    }
375                    if(!hadBanner && hasBanner) {
376                        var html = $.trim(_.isObject(resp) ? resp.html : ''),
377                        $siteBanner = $('#site-banner')
378                            .toggleClass('hidden', html.length == 0)
379                            .html(html),
380                        bgColor = $siteBanner.find('.page-banner').css('backgroundColor');
381
382                        if(bgColor == 'rgba(0, 0, 0, 0)') bgColor = '';
383                        $siteBanner.css('backgroundColor', bgColor);
384
385                        html += '<button type="button" class="close" data-dismiss="alert" aria-label="Close" style="top:7.5px;right:7.5px;position:absolute;"><span aria-hidden="true">×</span></button>';
386                        $siteBanner
387                            .css('position', 'relative')
388                            .on('close.bs.alert', function (event) {
389                                event.preventDefault();
390                                closeSiteBanner();
391                            });
392                            
393                        $siteBanner.html(html);
394
395                        $container
396                            .css('margin-top', '')
397                            .animate({'margin-top': $accountMenu.height()}, 'fast');
398
399                        $siteBanner
400                            .css('display', 'none')
401                            .slideDown('fast');
402                    }
403                    else if(hadBanner && !hasBanner) {
404                        closeSiteBanner();
405                    } 
406                });
407        }
408	};
409
410    $(document).on('freshopInitialized', fpClient.onFreshopInit);
411})(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.