1(function($) { 2 window.fpClient = { 3 session: '' 4 ,store: {} 5 ,user: {} 6 //,newUser: $.cookie('cn-new-user') || true 7 ,URLs: { 8 myFavoritesUrl: user_trailingslashit('/shop') + '#!/?filter=is_favorite' 9 ,storeLocator: user_trailingslashit('/store/store-locator') 10 } 11 ,init: function () { 12 this.initMobileHeader(); 13 this.initMyFavorites(); 14 } 15 ,showSubNav: function() { 16 var $subNav = $('#freshop-account .sub-menu').removeClass('hidden') 17 ,route = freshop.ui.getRoute()[0].toLowerCase(); 18 19 $subNav.find('a') 20 .removeClass('is-selected') 21 .filter('[href$="#!/' + route + '"]') 22 .first().addClass('is-selected'); 23 24 if($subNav.find('.is-selected').length <= 0){ 25 $subNav.find('.link-my-account').addClass('is-selected'); 26 } 27 } 28 ,initMyFavorites: function() { 29 var $menuFavorites = $('#menu-header-menu, #menu-footer-menu-mobile'); 30 31 $menuFavorites.find('.nav-my-favorites a') 32 .attr('href', this.URLs.myFavoritesUrl) 33 .append(' <span class="fp-icon-star"></span>'); 34 35 $('#top-my-favorites').attr('href', this.URLs.myFavoritesUrl); 36 } 37 ,initAccountMenu: function(accountNav) { 38 accountNav = accountNav || {}; 39 40 $('.user-session-indicator-mobile') 41 .off('click', '.fp-my-account-right-angle') 42 .on('click', '.fp-my-account-right-angle', function(event) { 43 var $myAccountLink = $('#menu-footer-menu-mobile .mobile-my-account'); 44 $myAccountLink.trigger('click'); 45 }); 46 47 freshop.ui.on('routeChanged', toggleSubNav); 48 49 toggleSubNav(); 50 51 function toggleSubNav() { 52 var $subNavContainer = $('#freshop-account-left') 53 ,$mobileSubNavContainer = $('#menu-footer-menu-mobile .mobile-my-account') 54 ,html = '' 55 ,freshopConfig = freshop.ui.getConfig() 56 ,hasChildren = _.size(accountNav.children); 57 58 $('#freshop-account').toggleClass('full-width', !hasChildren); 59 60 if(hasChildren) { 61 $mobileSubNavContainer 62 .addClass('menu-item-has-children') 63 .find('> a').addClass('fp-icon-chevron-right').wrapInner('<span></span>'); 64 } 65 else $mobileSubNavContainer.removeClass('menu-item-has-children'); 66 67 68 var freshopUi = freshop.ui 69 ,title 70 ,menuClass; 71 72 _.each(accountNav.children, function(item) { 73 title = freshopUi.encodeForHtml(item.title); 74 menuClass = ''; 75 if(item.url.toLowerCase().indexOf('my-favorites') >= 0) { 76 menuClass = 'nav-my-favorites'; 77 title += ' <span class="fp-icon fp-icon-star"></span>'; 78 title = '<span>' + title + '</span>'; 79 } 80 else title = '<span>' + title + '</span>'; 81 82 if (wpConfig.recipesFavoritesRedirect && item.id == 'recipe-my-recipes'){ 83 item.url = wpConfig.recipesFavoritesRedirect + '?shopper_identifier=' + fpClient.session.token + '&utm_source=my_recipes'; 84 menuClass = 'my-recipes-shopii'; 85 freshop.getCurrentUser(function(currentUser) { 86 if (currentUser.is_guest_user){ 87 $('.my-recipes-shopii').hide(); 88 } 89 }); 90 } 91 html += '<li class="menu-item ' + menuClass + '"><a href="' + freshopUi.encodeForHtml(item.url) + '">' + title + '</a></li>'; 92 }); 93 94 if(html) html = '<ul class="sub-menu second-menu">' + html + '</ul>'; 95 96 $subNavContainer.html(html); 97 98 var $accountSubMenu = $mobileSubNavContainer.find('ul.sub-menu'); 99 if ($accountSubMenu) { 100 var $subMenu = $(html); 101 $subMenu.attr('style', $accountSubMenu.attr('style')); 102 103 $mobileSubNavContainer.find('ul.sub-menu').remove(); 104 $mobileSubNavContainer.append($subMenu); 105 } 106 107 var route = freshop.ui.getLocation() 108 ,$items = $subNavContainer.find('a').removeClass('is-selected') 109 ,$firstChild = $items.filter('[href="' + route + '"]') 110 .first().addClass('is-selected'); 111 112 if (!$firstChild.length) $items.first().addClass('is-selected'); 113 } 114 } 115 ,onFreshopInit: function(){ 116 var pref = $.cookie('pref') || {} 117 ,event = window.hasTouch ? 'touch' : 'click' 118 ,$search = $('#header .header-wrapper .search') 119 ,freshopUi = freshop.ui; 120 121 if(pref.showSearch) $search.trigger(event); 122 123 124 freshopUi 125 //.on('loaded', function(event) {
126 // fpClient.storeChanged(event, fpClient.store); 127 //}) 128 .on('search', function() { 129 var $body = $(document.body); 130 $body.removeClass('mobile-menu-active'); 131 }); 132 133 freshop 134 .on('storeChanged', fpClient.storeChanged) 135 .on('storeLoaded', fpClient.storeChanged) 136 .on('sessionChanged', function(event){ 137 freshop.getCurrentSession(function(resp) { 138 fpClient.session = resp; 139 }); 140 }) 141 .on('circularLoaded', function(event, circular) { 142 var $title = $('#circular-title') 143 , startDate = circular.display_start_date ? circular.display_start_date : circular.start_date 144 , endDate = circular.display_end_date ? circular.display_end_date : circular.end_date; 145 146 if($title.length) { 147 $title.find('.start-date').text(fpClientUtil.formatDate(startDate)); 148 $title.find('.end-date').text(fpClientUtil.formatDate(endDate)); 149 $title.find('> span').css('visibility', ''); 150 } 151 }); 152 153 //Shopii Recipes Redirect 154 if (wpConfig.recipesRedirect){ 155 156 //login modal 157 var selectStore = '', 158 modalTitleMessage = '', 159 modalBodyMessage = '', 160 currentlySelectedStore = fpClient.store.id; 161 162 //location popup modal 163 164 if (wpConfig.recipesGuest && !currentlySelectedStore){ 165 //location popup modal 166 //ahref # may need to change to a span (with style added) due to a potential bug noticed on mobile food fair 167 selectStore = '<button type="button" class="btn btn-secondary" data-action="select-store">Select Store</button>'; 168 modalTitleMessage = 'Sign In or Select Store to Continue'; 169 modalBodyMessage = 'Please login to your account or <a href="#" data-action="select-store">select a store</a> to view recipes.'; 170 171 if (wpConfig.recipesLoginModalTitleGuest){ 172 modalTitleMessage = wpConfig.recipesLoginModalTitleGuest; 173 } 174 175 if (wpConfig.recipesLoginModalBodyGuest){ 176 modalBodyMessage = wpConfig.recipesLoginModalBodyGuest; 177 } 178 179 } 180 181 else{ 182 modalTitleMessage = 'Sign In To Continue'; 183 modalBodyMessage = 'Please login to your account to view recipes.'; 184 185 if (wpConfig.recipesLoginModalTitle){ 186 modalTitleMessage = wpConfig.recipesLoginModalTitle; 187 } 188 189 if (wpConfig.recipesLoginModalBody){ 190 modalBodyMessage = wpConfig.recipesLoginModalBody; 191 } 192 193 } 194 195 $('footer').after('<div class="modal" tabindex="-1" role="dialog" id="recipes-login">' + 196 '<div class="modal-dialog" role="document">' + 197 '<div class="modal-content">'+ 198 '<div class="modal-header">'+ 199 '<div class="modal-title"><strong>' + modalTitleMessage + '</strong></div>'+ 200 '<button type="button" class="close" data-dismiss="modal" aria-label="Close" style="margin-top: -25px;">'+ 201 '<span aria-hidden="true">×</span>'+ 202 '</button>'+ 203 '</div>'+ 204 '<div class="modal-body">'+ 205 '<br/>'+ 206 '<p>' + modalBodyMessage + '</p>'+ 207 '</div>'+ 208 '<div class="modal-footer">'+ 209 '<button type="button" class="btn btn-primary" data-action="login">Login</button>'+ 210 '<button type="button" class="btn btn-secondary" data-action="create">Create Account</button>'+ 211 //selectStore + 212 //'<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>'+ 213 '</div>'+ 214 '</div>'+ 215 '</div>'+ 216 '</div>'); 217 218 var currentUser 219 freshop 220 .on('initialized', function(event) { 221 freshop.ui.on('searchBeforeChange', function(event, payload) { 222 if(payload.selectedOption && payload.selectedOption.id == 'recipe') { 223 var q = '&q=' + (payload.q || '') + '&utm_source=search_recipes', 224 redirectPath = payload.selectedOption.path, 225 currentlySelectedStore = fpClient.store.id; 226 227 //logged in as a use OR not logged in as a guest user AND guest allowed AND has store selected OR logged in as a guest and guest login allowed 228 if((session && session.user_id
228) || (!currentUser.is_guest_user && wpConfig.recipesGuest && currentlySelectedStore) || (currentUser.is_guest_user && wpConfig.recipesGuestLoggedIn)) { 229 payload.selectedOption.disableRouteChange = true; 230 shopiiUrl = wpConfig.recipesRedirect + '/auth?shopper_identifier=' + session.token; 231 if(currentlySelectedStore) shopiiUrl += '&selected_store_id=' + currentlySelectedStore; 232 window.location.href = shopiiUrl + q; 233 } 234 235 //not logged in and guest is turned off 236 else { 237 redirectPath = wpConfig.recipesRedirect; 238 showLoginModal(redirectPath + '/auth?shopper_identifier=[token]' + q); 239 payload.selectedOption.disableRouteChange = true; 240 } 241 } 242 }); 243 }) 244 .on('userLoaded', function(event, resp) { 245 currentUser = resp; 246 }) 247 .on('sessionChanged', function(event){ 248 freshop.getCurrentSession(function(resp) { 249 session = resp; 250 }); 251 }) 252 .on('storeChanged', changeRecipeLink) 253 .on('storeLoaded', changeRecipeLink); 254 255 // changes the recipe link // checks for user_id (session) and store id (user) 256 function changeRecipeLink(event, resp) { 257 var shopiiLinkRecipes = document.querySelector(".shopii-link"); 258 if (shopiiLinkRecipes) { 259 var $shopiiLink = $('.shopii-link a').off('click.shopiiLink'); 260 if ($shopiiLink.parents('header').length) { 261 var $shopiiLinkHeader = $('header .shopii-link a').off('click.shopiiLink'); 262 } 263 if ($shopiiLink.parents('.mobile-nav-wrapper').length) { 264 var $shopiiLinkHeaderMobile = $('.mobile-nav-wrapper .shopii-link a').off('click.shopiiLink'); 265 } 266 if ($shopiiLink.parents('#content').length) { 267 var $shopiiLinkContent = $('#content .shopii-link a').off('click.shopiiLink') 268 } 269 if ($shopiiLink.parents('footer').length) { 270 var $shopiiLinkFooter = $('footer .shopii-link a').off('click.shopiiLink') 271 } 272 var shopiiLink = $shopiiLink.attr('href').split('?')[0], 273 currentlySelectedStore = (resp && resp.id) || (currentUser && currentUser.selected_store_id), 274 shopiiUrl; 275 276 //logged in as a use OR not logged in as a guest user AND guest allowed AND has store selected OR logged in as a guest and guest login allowed 277 if((session && session.user_id) || (!currentUser.is_guest_user && wpConfig.recipesGuest && currentlySelectedStore) || (currentUser.is_guest_user && wpConfig.recipesGuestLoggedIn)) { 278 currentUser.selected_store_id = currentlySelectedStore; 279 shopiiUrl = wpConfig.recipesRedirect + '/auth?shopper_identifier=' + session.token; 280 if(currentlySelectedStore) shopiiUrl += '&selected_store_id=' + currentlySelectedStore; 281 if ($shopiiLink.parents('header').length) { 282 $shopiiLinkHeader.attr('href', shopiiUrl + '&utm_source=menu_recipes'); 283 } 284 if ($shopiiLink.parents('.mobile-nav-wrapper').length) { 285 $shopiiLinkHeaderMobile.attr('href', shopiiUrl + '&utm_source=mobile_menu_recipes'); 286 } 287 if ($shopiiLink.parents('#content').length) { 288 $shopiiLinkContent.attr('href', shopiiUrl + '&utm_source=content'); 289 } 290 if ($shopiiLink.parents('footer').length) {
291 $shopiiLinkFooter.attr('href', shopiiUrl + '&utm_source=footer_nav'); 292 } 293 } 294 295 //not logged in and guest is turned off 296 else { 297 if ($shopiiLink.parents('header').length) { 298 $shopiiLinkHeader 299 .on('click.shopiiLinkHeader', function(event) { 300 event.preventDefault(); 301 var next = shopiiLink; 302 if(next.indexOf(location.hostname) >= 0) { 303 next = '/' + next.split('/').splice(3).join('/'); 304 } 305 showLoginModal(wpConfig.recipesRedirect + '/auth?shopper_identifier=[token]' + '&utm_source=menu_recipes'); 306 }); 307 } 308 if ($shopiiLink.parents('.mobile-nav-wrapper').length) { 309 $shopiiLinkHeaderMobile 310 .on('click.shopiiLinkHeaderMobile', function(event) { 311 event.preventDefault(); 312 var next = shopiiLink; 313 if(next.indexOf(location.hostname) >= 0) { 314 next = '/' + next.split('/').splice(3).join('/'); 315 } 316 showLoginModal(wpConfig.recipesRedirect + '/auth?shopper_identifier=[token]' + '&utm_source=mobile_menu_recipes'); 317 }); 318 } 319 if ($shopiiLink.parents('#content').length) { 320 $shopiiLinkContent 321 .on('click.shopiiLinkContent', function(event) { 322 event.preventDefault(); 323 var next = shopiiLink; 324 if(next.indexOf(location.hostname) >= 0) { 325 next = '/' + next.split('/').splice(3).join('/'); 326 } 327 showLoginModal(wpConfig.recipesRedirect + '/auth?shopper_identifier=[token]' + '&utm_source=content'); 328 }); 329 } 330 if ($shopiiLink.parents('footer').length) { 331 $shopiiLinkFooter 332 .on('click.shopiiLinkFooter', function(event) { 333 event.preventDefault(); 334 var next = shopiiLink; 335 if(next.indexOf(location.hostname) >= 0) { 336 next = '/' + next.split('/').splice(3).join('/'); 337 } 338 showLoginModal(wpConfig.recipesRedirect + '/auth?shopper_identifier=[token]' + '&utm_source=footer_nav'); 339 }); 340 } 341 } 342 } 343 344 //direct link from social 345 const baseURL = window.location.origin; 346 if (window.location.href.indexOf(baseURL + '/?recipe') != -1){ 347 const queryString = window.location.search;
348 const urlParams = new URLSearchParams(queryString); 349 const recipeID = urlParams.get('recipe'); 350 const utmSource = urlParams.get('utm_source'); 351 currentlySelectedStore = (resp && resp.id) || (currentUser && currentUser.selected_store_id); 352 353 //logged in as a use OR not logged in as a guest user AND guest allowed AND has store selected OR logged in as a guest and guest login allowed 354 if((session && session.user_id) || (!currentUser.is_guest_user && wpConfig.recipesGuest && currentlySelectedStore) || (currentUser.is_guest_user && wpConfig.recipesGuestLoggedIn)) { 355 shopiiUrl = wpConfig.recipesRedirect + '/recipe/' + recipeID + '?shopper_identifier=' + session.token; 356 if(currentlySelectedStore) shopiiUrl += '&selected_store_id=' + currentlySelectedStore; 357 window.location.href = shopiiUrl + '&utm_source=' + (utmSource !=null ? utmSource : '&utm_source=direct_link'); 358 //window.location.href = wpConfig.recipesRedirect + '/recipe/' + recipeID + '?shopper_identifier=' + session.token + '&selected_store_id=' + currentlySelectedStore + '&utm_source=' + (utmSource !=null ? utmSource : '&utm_source=direct_link'); 359 } 360 361 //not logged in and guest is turned off 362 else { 363 showLoginModal(wpConfig.recipesRedirect + '/recipe/' + recipeID + '?shopper_identifier=[token]&utm_source=' + (utmSource !=null ? utmSource : '&utm_source=direct_link')); 364 } 365 } 366 //redirect the /recipes directory to shopii 367 //potentially add a conditional here so we can redirect to recipes page on next 368 if (window.location.href.indexOf(baseURL + '/recipes') != -1){ 369 currentlySelectedStore = (resp && resp.id) || (currentUser && currentUser.selected_store_id); 370 371 //logged in as a use OR not logged in as a guest user AND guest allowed AND has store selected OR logged in as a guest and guest login allowed 372 if((session && session.user_id) || (!currentUser.is_guest_user && wpConfig.recipesGuest && currentlySelectedStore) || (currentUser.is_guest_user && wpConfig.recipesGuestLoggedIn)) { 373 shopiiUrl = wpConfig.recipesRedirect + '/auth?shopper_identifier=' + session.token; 374 if(currentlySelectedStore) shopiiUrl += '&selected_store_id=' + currentlySelectedStore; 375 window.location.href = shopiiUrl + '&utm_source=recipes_page'; 376 //window.location.href = wpConfig.recipesRedirect + '/auth?shopper_identifier=' + session.token + '&selected_store_id=' + currentlySelectedStore + '&utm_source=recipes_page'; 377 } 378 379 //not logged in and guest is turned off 380 else { 381 showLoginModal(wpConfig.recipesRedirect + '/auth?shopper_identifier=[token]&utm_source=recipes_page'); 382 } 383 } 384 } 385 386 //login modal next path 387 function showLoginModal(next) { 388 $('#recipes-login') 389 .one('shown.bs.modal', function () { 390 $(this).find('[data-action="login"]').one('click', function(event) { 391 event.preventDefault(); 392 if(!currentUser.is_guest_user) { 393 window.location.href = '/my-account#!/login?next=' + encodeURIComponent(next); 394 } 395 //logout 396 else{ 397 window.location.href = '/my-account#!/logout'; 398 } 399 }) 400 $(this).find('[data-action="create"]').one('click', function(event) { 401 event.preventDefault(); 402 window.location.href = '/my-account#!/create'; 403 }) 404 $(this).find('[data-action="select-store"]').one('click', function(event) { 405 next = window.location.href; 406 window.location.href = '/store-locator#!/?next=' + encodeURIComponent(next) + '&show_button=yes'; 407 }) 408 }) 409 .modal('show'); 410 } 411 } 412 } 413 ,initMobileHeader: function(){ 414 var eventType = window.hasTouch ? 'touchstart.minilist.fc' : 'click.minilist.fc' 415 ,$mobileMenu = $('.mobile-header-wrapper'); 416 417 $mobileMenu 418 .off() 419 .on(eventType, '#navbar-toggle', function(event) { 420 event.preventDefault(); 421 if($(document.body).hasClass('mobile-menu-active')) {
422 var $navWrapper = $('#mobile-nav-wrapper') 423 ,$currentMenu = $navWrapper.data('currentMenu') 424 ,level = $navWrapper.data('level') || 0; 425 if(level == 0) navigation.toggleNav(); 426 else $navWrapper.trigger('click'); 427 return; 428 } 429 navigation.toggleNav(); 430 }) 431 .on(eventType, '.logo', function(event) { 432 if($(document.body).hasClass('mobile-menu-active')) { 433 event.preventDefault(); 434 event.stopImmediatePropagation(); 435 navigation.toggleNav(); 436 } 437 }) 438 .on(eventType, '.mobile-search-icon', function (event) { 439 event.preventDefault(); 440 if ($('.fp-mini-list').hasClass('hidden')) { 441 event.stopImmediatePropagation(); 442 } 443 444 if(window.freshop) { 445 var pref = $.cookie('pref') || {} 446 ,$headerSearch = $('.mobile-header-wrapper .mobile-search') 447 ,$mobileSearchInput = $headerSearch.find('[name=fp-input-search]'); 448 449 if($headerSearch.filter(':visible').length) { 450 pref.showSearch = false; 451 $headerSearch.slideUp(function() { 452 $headerSearch.show().addClass('hidden-xs hidden-sm'); 453 }); 454 } 455 else { 456 pref.showSearch = true; 457 $headerSearch.removeClass('hidden-xs hidden-sm'); 458 freshop.trigger('mediaWidthChange'); 459 $headerSearch.hide().slideDown(function() { 460 //$mobileSearchInput.blur(); 461 //var origValue = $mobileSearchInput.val(); 462 //$mobileSearchInput.val('').focus().val(origValue); 463 }); 464 } 465 $.cookie('pref', pref, {path: '/'}); 466 } 467 }); 468 } 469 /*,toggleMinilist: function(){ 470 var open = $('#fp-minilist').filter(':visible').length > 0 471 ,$parent = $('.mini-list #mini-list-wrapper'); 472 473 if(open){ 474 freshop.trigger('miniListHide'); 475 } 476 else { 477 freshop.trigger('miniListShow'); 478 $parent.addClass('opened'); 479 } 480 }*/ 481 ,storeChanged: function(event, store){ 482 var href 483 ,$anchor = $('#mobile-selected-store > .nav-my-store > a') 484 ,$mainNavMyStore = $('#menu-main-menu').find('.nav-my-store > a') 485 ,$breadcrumbMyStore = $('.breadcrumb > li > a[title^=" My Store"]') 486 ,$footerMyStore = $('#menu-footer-menu-col-1 > .nav-my-store > a') 487 ,$footerbtmMyStore = $('#menu-footer-menu-bottom > .nav-my-store > a') 488 ,$mobileStoreLink = $('#mobile-selected-store') 489 ,$headerSelectStore = $('.nav-my-store > .dropdown > .link-my-store') 490 ,$headerMyStore = $('.nav-my-store > .link-my-store-primary') 491 ,oldStore = fpClient.store; 492 493 //fpCheckWeeklyAd.check(); 494 495 if(store.id) { 496 if(store.name) { 497 $('.my-store-name').text(store.name); 498 499 href = store.url; 500 //$anchor.text(store.name); 501 $headerSelectStore.find('.name').text(store.name); 502 $mobileStoreLink.find('a').text(store.name); 503 504 //print view, adding address 505 var $storeInfo = $('#store-main-info'); 506 var $storeAddress = freshop.ui.encodeForHtml(store.address_1); 507 if(store.address_2) $storeAddress += ',' + freshop.ui.encodeForHtml(store.address_2); 508 $storeAddress += '<br />' + freshop.ui.encodeForHtml(store.city) + ', ' + freshop.ui.encodeForHtml(store.state) + ' ' + freshop.ui.encodeForHtml(store.postal_code); 509 $storeInfo.html(freshop.ui.encodeForHtml(store.name) + '<br />' + $storeAddress); 510 511 fpClient.store = store; 512 513 $headerSelectStore.attr('href', 'javascript:;').attr('data-href', href); 514 $mobileStoreLink.removeClass('hidden'); 515 fpClient.setMyStoreBox(store); 516 } 517 } 518 else { 519 href = fpClient.URLs.storeLocator; 520 $anchor.text("My Store"); 521 $headerSelectStore.find('.name').text('Select Store'); 522 $mobileStoreLink.find('.nav-my-store a').text('Select Store'); 523 fpClient.setMyStoreBox(null); 524 } 525 526 fpClient.setStoreLinks($anchor.add($mainNavMyStore).add($headerMyStore), href); 527 528 fpClient.setStoreLinks($anchor.add($footerbtmMyStore).add($headerMyStore), href); 529 530 var storeId = store ? store.id : null; 531 if(!storeId || !oldStore.id || (oldStore.id && oldStore.id != storeId)) { 532 var getNavigation = _.isFunction(wpConfig.getNavigation) ? wpConfig.getNavigation : freshop.ui.getNavigation; 533 534 getNavigation(function (resp) { 535 fpClient.initAccountMenu(resp.account); 536 $('#fp-departments').html(navigation.getNavHtml(resp.shop, 1)); 537 $('#recipe-categories').html(navigation.getNavHtml(resp.recipe, 1)); 538 539 if (navigation.menuInitialized) { 540 if (window.isSmall) { 541 //trigger reset of menu styles 542 navigation.initMenu(); 543 navigation.onDepartments(); 544 545 if (window.matchMedia) { 546 navigation.matchMediaHandler(window.matchMedia("screen and (max-width: 991px)")); 547 } 548 } 549 else navigation.onDepartments(); 550 551 navigation.initMenuTouchSupport(); 552 } 553 }); 554 } 555 556 if(wpConfig.hasXhrSlider) fpClient.loadSlider(storeId); 557 if(wpConfig.hasSiteBanner) fpClient.loadSiteBanner(storeId); 558 } 559 ,setStoreLinks: function($links, url) { 560 $links.each(function() { 561 var $this = $(this) 562 ,href = $this.data('origHref'); 563 564 if(!href) { 565 $this.data('origHref', $this.attr('href')); 566 } 567 if(url) { 568 href = url; 569 } 570 if((href || '').indexOf('www') == 0) { 571 href = 'http://' + href; 572 } 573 574 $this.attr('href', href); 575 }); 576 } 577 ,setMyStoreBox: function(store){ 578 var $myStoreLink = $('#header').find('.link-my-store') 579 ,$myStoreBox = $('#header').find('.dropdown-selected-store') 580 ,$storeName = $myStoreBox.find('.store-name > span.name')
581 ,$storeAddress = $myStoreBox.find('.store-address') 582 ,$storeHours = $myStoreBox.find('.store-hours > span') 583 ,$storePhone = $myStoreBox.find('.store-phone > span') 584 ,$storeDirections = $myStoreBox.find('.store-directions') 585 ,address = ''; 586 587 if(store){ 588 $myStoreLink.attr('data-toggle', 'dropdown'); 589 if(store.name) $storeName.html('<a href="' + store.url +'">'+ freshop.ui.encodeForHtml(store.name) +'</a>'); 590 if(store.address_1 && store.state && store.postal_code) { 591 address = freshop.ui.encodeForHtml(store.address_1); 592 if(store.address_2) address += ',' + freshop.ui.encodeForHtml(store.address_2); 593 address += '<br />' + freshop.ui.encodeForHtml(store.city) + ', ' + freshop.ui.encodeForHtml(store.state) + ' ' + freshop.ui.encodeForHtml(store.postal_code); 594 } 595 if(address) $storeAddress.html(address); 596 if(store.hours) $storeHours.html(freshop.ui.encodeForHtml(store.hours)); 597 if(store.phone) $storePhone.html(freshop.ui.encodeForHtml(store.phone)); 598 if(store.latitude && store.longitude) $storeDirections.html('<a href="https://www.google.com/maps/dir//' + encodeURIComponent(address.replace("<br />", ' ')) + '" target="_blank">Get Directions</a>'); 599 600 } 601 else{ 602 $myStoreLink.attr('data-toggle', ''); 603 } 604 } 605 ,initMinilistIndicator : function() { 606 var mobileSelector = ''; 607 if(window.isSmall) mobileSelector = '-mobile'; 608 $('#mini-list' + mobileSelector + '-wrapper').append($('#mini-list-indicator')); 609 } 610 ,loadSlider: function(storeId){ 611 var deferred, 612 $slider = $('#slider').removeClass('hidden'), 613 slug = $slider.attr('data-slug'); 614 615 if(slug) { 616 deferred = $.ajax({ 617 url: ajax_objectClient.rest_url + '/freshop/v1/content/slider', 618 dataType: 'json', 619 data: { 620 store_id: storeId, 621 slider_slug: slug 622 } 623 }); 624 } 625 626 return $.when(deferred) 627 .always(function(resp) { 628 var html = (resp && resp.html) || ''; 629 $slider 630 .removeClass('loading') 631 .addClass('loaded') 632 .toggleClass('hidden', $.trim(html).length === 0) 633 .html(html); 634 }); 635 636 } 637 ,loadSiteBanner: function(storeId){ 638 var prefKey = 'site_banner_' + (storeId || '') + '_disabled'; 639 if(freshop.ui.getPrefCookie()[prefKey]) return; 640 $.ajax({ 641 url: ajax_objectClient.rest_url + '/freshop/v1/content/site-banner', 642 dataType: 'json', 643 data: { 644 store_id: storeId 645 } 646 }) 647 .done(function(resp) { 648 var html = $.trim(_.isObject(resp) ? resp.html : ''), 649 $siteBanner = $('#site-banner').css('display', ''), 650 $accountMenu = $siteBanner.closest('.account-menu'), 651 $container = $('#main-menu-container > .row').filter(':visible'), 652 $body = $('body'), 653 hadBanner = $body.hasClass('has-site-banner'), 654 hasBanner = html.length > 0; 655 656 $siteBanner.toggleClass('hidden', html.length == 0); 657 $body.toggleClass('has-site-banner', hasBanner); 658 659 function closeSiteBanner() { 660 var pref = {}; 661 pref[prefKey] = true; 662 freshop.ui.setPrefCookie(pref); 663 $body.removeClass('has-site-banner'); 664 $container 665 .css('margin-top', '') 666 .animate({'margin-top': $accountMenu.height()}, 'fast'); 667 668 $siteBanner 669 .css('display', 'block') 670 .slideUp('fast', function() { 671 $siteBanner.html(''); 672 }); 673 } 674 if(!hadBanner && hasBanner) { 675 var html = $.trim(_.isObject(resp) ? resp.html : ''), 676 $siteBanner = $('#site-banner') 677 .toggleClass('hidden', html.length == 0) 678 .html(html), 679 bgColor = $siteBanner.find('.page-banner').css('backgroundColor'); 680 681 if(bgColor == 'rgba(0, 0, 0, 0)') bgColor = ''; 682 $siteBanner.css('backgroundColor', bgColor); 683 684 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>'; 685 $siteBanner 686 .css('position', 'relative') 687 .on('close.bs.alert', function (event) { 688 event.preventDefault(); 689 closeSiteBanner(); 690 }); 691 692 $siteBanner.html(html); 693 694 $container 695 .css('margin-top', '') 696 .animate({'margin-top': $accountMenu.height()}, 'fast'); 697 698 $siteBanner 699 .css('display', 'none') 700 .slideDown('fast'); 701 } 702 else if(hadBanner && !hasBanner) { 703 closeSiteBanner(); 704 } 705 706 }); 707 } 708 }; 709 710 $(document).on('freshopInitialized', fpClient.onFreshopInit); 711})(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.