1/** 2 * @file 3 * Main Javascript file. 4 */ 5 6var Beechnut = { 7 8 /** 9 * Define Bootstrap Breakpoints 10 */ 11 breakpoints: { 12 xs: 0, 13 sm: 768, 14 md: 992, 15 lg: 1200 16 }, 17 18 /** 19 * A namespace for all JS modules. 20 * @namespace 21 */ 22 Modules: {}, 23 24 /** 25 * A namespace for standard library functions. 26 * @namespace 27 */ 28 Lib: { 29 30 /** 31 * Get the current breakpoint to use. 32 * @returns {number} 33 */ 34 getCurrentBreakpoint: function(){ 35 var windowWidth = $(window).width(); 36 37 if(windowWidth < Beechnut.breakpoints.sm){ 38 return Beechnut.breakpoints.xs; 39 }else if(windowWidth >= Beechnut.breakpoints.sm && windowWidth < Beechnut.breakpoints.lg){ 40 return Beechnut.breakpoints.sm; 41 }else if (windowWidth >= Beechnut.breakpoints.lg){ 42 return Beechnut.breakpoints.lg; 43 }else{ 44 return 0; 45 } 46 }, 47 48 /** 49 * Get a url parameter value 50 * @param sParam 51 * @returns {*} 52 */ 53 getUrlParameter: function(sParam){ 54 var sPageURL = window.location.search.substring(1); 55 var sURLVariables = sPageURL.split('&'); 56 for (var i = 0; i < sURLVariables.length; i++){ 57 var sParameterName = sURLVariables[i].split('='); 58 if (sParameterName[0] == sParam){ 59 return sParameterName[1]; 60 } 61 } 62 return false; 63 }, 64 65 /** 66 * Smooth scroll to an element on the page. 67 * @param fromElement 68 * @param toElement 69 * @param duration 70 */ 71 smoothScrollOnClick: function(fromElement, toElement, duration){ 72 $(fromElement).on('click', function(e){ 73 e.preventDefault(); 74 if(!$(toElement).length)return; 75 $('html, body').animate({ 76 scrollTop: $(toElement).offset().top + 'px' 77 }, duration, 'swing'); 78 }); 79 } 80 81 }, 82 83 /** 84 * Initialize all custom JS modules when document finishes loading. 85 */ 86 initialize: function() { 87 // *Note: Should be loaded in dependency order. 88 var modules = [ 89 'Global', 90 'Home', 91 'CategoryPages', 92 'ProductsList', 93 'ContactUs', 94 'ProductDetail', 95 'Careers', 96 'WIC', 97 'Campaign', 98 'Faq', 99 'Search', 100 'OurStory', 101 'JoinCircle', 102 'RecipesAndBlog', 103 ]; 104 105 for (var i = 0; i < modules.length; i++) { 106 new Beechnut.Modules[modules[i]](); 107 } 108 } 109 110}; 111 112jQuery(document).ready(function() { 113 Beechnut.initialize(); 114}); 115 116(function($){ 117 118 Beechnut.Modules.Global = function() { 119 120 /** 121 * Initialize module on page load 122 * @returns {Beechnut.Modules.Global} 123 */ 124 this.init = function() { 125 126 // All back buttons. 127 $('a.go-back').click(function(e){ 128 e.preventDefault(); 129 }); 130 131 this.header(); 132 133 // Mobile slider. 134 if($('.slider-container').length){ 135 $('.slider-container').slick({ 136 dots: true, 137 infinite: true, 138 prevArrow: '<button type="button" class="slick-prev"><i class="fa fa-caret-left" aria-hidden="true"></i></button>', 139 nextArrow: '<button type="button" class="slick-next"><i class="fa fa-caret-right" aria-hidden="true"></i></button>', 140 }); 141 } 142 143 // Homepage and category grids 144 if ($('.grid .square.box').length) { 145 $(window).on('load resize', function() { 146 var midSet = false; 147 $('.grid .square.box').each(function() { 148 // the 20 accounts for the borders 149 var height = ($(this).width() + 20) + 'px'; 150 $(this).css('height', height); 151 if (!midSet && $(window).width() > 767) { 152 $('.middle-rect').css('height', height); 153 midSet = true; 154 } 155 else if (!midSet) { 156 $('.middle-rect').css('height', ''); 157 midSet = true; 158 } 159 }); 160 }); 161 } 162 163 if($('.content-contact-us').length){ 164 // Add select container. 165 setupFacadeSelect('.select-outer-state', true); 166 setupFacadeSelect('.select-outer-reason', true); 167 // Remove the value from the first option of the dropdown. 168 // This helps to trigger the 'required' indicator. 169 $('.select-outer-reason select option:first-child').attr('value', ''); 170 $('.select-outer-state select option:first-child').attr('value', ''); 171 } 172 if($('.content-wic').length){ 173 // Add select container. 174 setupFacadeSelect('.select-outer-state', true); 175 } 176 177 /** 178 * Setup the facade select functions. 179 */ 180 function setupFacadeSelect(container, skipFirst){ 181 copyOptionsToFacadeOptions(container, skipFirst); 182 changeSelectedText(container); 183 facadeOptionClick(container); 184 toggleFacadeOptionsMenu(container); 185 } 186 187 /** 188 * Copy select options to the facade options div. 189 */ 190 function copyOptionsToFacadeOptions(container, skipFirst){ 191 // Don't add multiple facade option divs. 192 if($(container +' .facade-options').length)return; 193 // Map select options into array.
194 var options = $(container + ' select option').map(function () { 195 return $(this).text(); 196 }).get(); 197 // Assemble facade options div. 198 var facadeOptions = '<div class="facade-options">'; 199 for($i=0;$i<options.length;$i++){ 200 if(skipFirst && !$i)continue; 201 facadeOptions += '<div data-option-num="'+($i+1)+'">'+options[$i]+'</div>'; 202 } 203 facadeOptions += '</div>'; 204 $(container).append(facadeOptions); 205 } 206 207 /** 208 * Change the selected text on the facade select dropdown. 209 */ 210 function changeSelectedText(container){ 211 // Add default option. 212 var text = 'Choose an option'; 213 // Get selected option text. 214 selectedText = $(container + ' select option:selected').text(); 215 text = !selectedText ? text : selectedText; 216 // Switch the top option. 217 $(container + ' span.top-option').remove(); 218 $(container).append('<span class="top-option">'+text+'</span>'); 219 } 220 221 /** 222 * Trigger select option change when a facade option is clicked. 223 */ 224 function facadeOptionClick(container){ 225 $(container).on('click', '.facade-options > div', function(){ 226 // Get the value. 227 var value = $(this).data('option-num'); 228 // Trigger select change event. 229 $(container + ' select').find('option:nth-child(' + value + ')').prop('selected',true).trigger('change'); 230 changeSelectedText(container); 231 }); 232 } 233 234 /** 235 * Show/hide facade options when clicking the dropdown. 236 */ 237 function toggleFacadeOptionsMenu(container){ 238 $(container).on('click', function(){ 239 if(!$(this).hasClass('is-active')){ 240 $(this).children('.facade-options').fadeIn('fast', function(){ 241 $(this).stop(true); 242 }); 243 $(this).addClass('is-active'); 244 }else{ 245 $(this).removeClass('is-active'); 246 $(this).children('.facade-options').fadeOut('fast', function(){ 247 $(this).stop(true); 248 }); 249 } 250 }); 251 252 $(':not('+container+')').on('click', function() { 253 var $container = $(container); 254 if ($container.hasClass('is-active')) { 255 $container.children('.facade-options').fadeOut('fast', function(){ 256 $container.removeClass('is-active'); 257 }); 258 } 259 }); 260 } 261 262 // Add target _blank to external links. 263 this.addTargetBlank(); 264 265 return this; 266 }; 267 268 /** 269 * Add target _blank to external links. 270 */ 271 this.addTargetBlank = function(){ 272 if($('.content-foods').length || $('.content-ages').length || $('.content-types').length || $('.content-blog-detail').length || $('.content-recipe-detail').length || $('body.home').length){ 273 $('a').each(function() { 274 var a = new RegExp('/' + window.location.host + '/', 'i'); 275 var b = new RegExp('javascript', 'i'); 276 if(!a.test(this.href) && !b.test(this.href)) { 277 $(this).click(function(event) { 278 event.preventDefault(); 279 event.stopPropagation(); 280 window.open(this.href, '_blank'); 281 }); 282 } 283 }); 284 } 285 }; 286 287 /** 288 * Header js 289 * @return {[type]} [description] 290 */ 291 this.header = function(){ 292 293 // Iterate over each nav list item. 294 $('.main-nav li').each(function(index, element){ 295 // Get sub nav object 296 var $subnav = $(element).find('.sub-nav'); 297 subNavPositioning($subnav, element); 298 $(window).resize(function(){ 299 subNavPositioning($subnav, element); 300 }); 301 }); 302 303 // Set subnav positioning. 304 function subNavPositioning($subnav, element){ 305 if ( !$subnav.hasClass('sub-nav-width-auto') ) { 306 // Set width of subnav to width of window. 307 $subnav.width($(window).width()); 308 // Set subnav positioning 309 $subnav.css('left', - $(element).offset().left); 310 } else { 311 $subnav.width('100%'); 312 } 313 } 314 315 $('#hamburger').click(function(e){ 316 e.preventDefault(); 317 $('nav.main-nav-mobile').fadeToggle('fast'); 318 }); 319 320 // Mobile nav events 321 $('nav.main-nav-mobile .to-sub-nav a, nav.main-nav-mobile .to-super-nav a').click(function(e){ 322 e.preventDefault(); 323 $('nav.main-nav-mobile').toggleClass('sub-nav-active'); 324 }); 325 326 }; 327 328 return this.init(); 329 }; 330 331})(jQuery); 332 333(function($){ 334 335 Beechnut.Modules.Home = function() { 336 337 /** 338 * Initialize module on page load 339 * @returns {Beechnut.Modules.Home} 340 */ 341 this.init = function() { 342 343 if(!$('.content-home').length)return this; //some shall pass 344 345 var $homeSlider = $('.home-slider'); 346 if ($homeSlider.length) { 347 $homeSlider.slick({ 348 dots: true,
349 arrows: false, 350 autoplay: true, 351 autoplaySpeed: 3000, 352 infinite: true, 353 appendDots: $('.home-slider-outer .dot-container'), 354 slidesToShow: 1, 355 slidesToScroll: 1, 356 prevArrow: '<button type="button" class="slick-prev"><i class="fa fa-caret-left" aria-hidden="true"></i></button>', 357 nextArrow: '<button type="button" class="slick-next"><i class="fa fa-caret-right" aria-hidden="true"></i></button>', 358 }); 359 } 360 361 $(window).load(function(){ 362 $('.content-home').css('visibility', 'visible'); 363 }); 364 365 return this; 366 }; 367 368 return this.init(); 369 }; 370 371})(jQuery); 372 373(function($){ 374 375 Beechnut.Modules.CategoryPages = function() { 376 377 /** 378 * Initialize module on page load 379 * @returns {Beechnut.Modules.CategoryPages} 380 */ 381 this.init = function() { 382 383 if(!$('.content-category').length)return this; //some shall pass 384 385 return this; 386 }; 387 388 return this.init(); 389 }; 390 391})(jQuery); 392 393/* 394 * Load YouTube Embed API JS on the homepage. 395 */ 396if($('.content-campaign, .content-foods').length){ 397 var tag = document.createElement('script'); 398 tag.src = "https://www.youtube.com/iframe_api"; 399 var firstScriptTag = document.getElementsByTagName('script')[0]; 400 firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 401 402 function onYouTubeIframeAPIReady() { 403 window.ytPlayer = new YT.Player('youtube-vid', { 404 videoId: $('#modal-video-container').data('vid-id'), 405 playerVars: { 406 'rel': 0 407 }, 408 events: {} 409 }); 410 } 411} 412 413(function($){ 414 415 Beechnut.Modules.Campaign = function() { 416 417 /** 418 * Initialize module on page load 419 * @returns {Beechnut.Modules.Campaign} 420 */ 421 this.init = function() { 422 423 if(!$('.content-campaign').length)return this; //some shall pass 424 425 $('#videoModal').on('hide.bs.modal', function (e) { 426 window.ytPlayer.pauseVideo(); 427 }); 428 429 $('#videoModal').on('shown.bs.modal', function (e) { 430 window.ytPlayer.playVideo(); 431 }); 432 433 var $slider = $('.campaign-slider-outer .slider'); 434 if ($slider.length) { 435 $slider.slick({ 436 dots: true, 437 arrows: true, 438 autoplay: true, 439 autoplaySpeed: 5000, 440 infinite: true, 441 // appendDots: $('.home-slider-outer .dot-container'), 442 slidesToShow: 1, 443 slidesToScroll: 1, 444 prevArrow: '<button type="button" class="slick-arrow slick-prev slick-white"><i class="fa fa-caret-left" aria-hidden="true"></i></button>', 445 nextArrow: '<button type="button" class="slick-arrow slick-next slick-white"><i class="fa fa-caret-right" aria-hidden="true"></i></button>', 446 }); 447 } 448 449 return this; 450 }; 451 452 return this.init(); 453 }; 454 455})(jQuery); 456 457 458var tag = document.createElement('script'); 459 tag.src = "https://www.youtube.com/iframe_api"; 460 var firstScriptTag = document.getElementsByTagName('script')[0]; 461 firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 462 463(function($){ 464 465 Beechnut.Modules.OurStory = function() { 466 $('.js-play-video').on('click', function ( e ) { 467 var $this = $(e.currentTarget), 468 url = $this.data('youtube-url'), 469 regex = /.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/, 470 match = url.match(regex), 471 id = match[1] 472 473 $('.js-video-modal').addClass('is-active') 474 $('.js-video-modal .js-close').on('click', function () { 475 window.ytPlayer.stopVideo() 476 window.ytPlayer.destroy() 477 window.ytPlayer = null 478 479 $('.js-video-modal').removeClass('is-active') 480 }) 481 482 window.ytPlayer = new YT.Player('youtube-player', { 483 height: '390', 484 width: '640', 485 videoId: id, 486 playerVars: { 487 modestbranding: 1, 488 iv_load_policy: 3, 489 showinfo: 0, 490 enablejsapi: 1 491 }, 492 events: { 493 'onReady': function ( e ) { 494 e.target.playVideo() 495 $('.js-video-modal').fitVids() 496 497 setTimeout(function () { 498 $('.js-video-modal').addClass('is-ready') 499 }, 1000) 500 } 501 } 502 }); 503 }) 504 505 /** 506 * Initialize module on page load 507 * @returns {Beechnut.Modules.OurStory} 508 */ 509 this.init = function() { 510 511 if(!$('.content-our-story').length) return this; 512 513 var $slider = $('.our-story-slider'); 514 if ($slider.length) { 515 $slider.slick({ 516 dots: false,
517 arrows: false, 518 autoplay: true, 519 autoplaySpeed: 5000, 520 fade: true, 521 pauseOnHover: false, 522 infinite: true, 523 slidesToShow: 1, 524 slidesToScroll: 1 525 }); 526 } 527 528 var $instagramFeedSlider = $('.instagram-feed__slider'); 529 if ($instagramFeedSlider.length) { 530 $instagramFeedSlider.slick({ 531 dots: false, 532 arrows: true, 533 infinite: true, 534 slidesToShow: 3, 535 slidesToScroll: 3, 536 prevArrow: '<div class="slider-arrow slider-arrow--prev"><img src="http://beechnut.sauce/wp-content/themes/beechnut/library/images/arrow_prev.png"></div>', 537 nextArrow: '<div class="slider-arrow slider-arrow--next"><img src="http://beechnut.sauce/wp-content/themes/beechnut/library/images/arrow_next.png"></div>', 538 responsive: [ 539 { 540 breakpoint: 768, 541 settings: { 542 slidesToShow: 2, 543 slidesToScroll: 2 544 } 545 } 546 ] 547 }); 548 } 549 550 return this; 551 }; 552 553 return this.init(); 554 }; 555 556})(jQuery); 557 558(function($){ 559 560 Beechnut.Modules.ProductsList = function() { 561 562 /** 563 * Initialize module on page load 564 * @returns {Beechnut.Modules.ProductsList} 565 */ 566 this.init = function() { 567 568 if(!$('.content-products').length)return this; //some shall pass 569 570 // Group button click event. 571 $('.groups a.group-btn').click(function(e){ 572 e.preventDefault(); 573 var grp = $(this).data('group'); 574 // Close all tab content 575 $('.food-list:not(.'+grp+')').stop(true).fadeOut('fast').promise().done(function(){ 576 $('.food-list.'+grp).stop(true).fadeIn('fast'); 577 }); 578 // Set active button 579 $('.groups a:not(.'+grp+')').removeClass('is-active'); 580 $('.groups a.'+grp).addClass('is-active'); 581 }); 582 583 // Allergens filter 584 $('.allergens a.group-btn').click(function(e){ 585 e.preventDefault(); 586 var allergen = $(this).data('allergen'); 587 // Close all tab content 588 $('.food-list:not(.allergen-'+allergen+')').stop(true).fadeOut('fast').promise().done(function(){ 589 $('.food-list.allergen-'+allergen).stop(true).fadeIn('fast'); 590 }); 591 // Set active button 592 $('.allergens a:not(.allergen-'+allergen+')').removeClass('is-active'); 593 $('.allergens a.allergen-'+allergen).addClass('is-active'); 594 }); 595 596 $('.allergens a.group-btn').each(function() { 597 var allergen = $(this).data('allergen'); 598 $(this).find('span').append('<div>('+$('.food-list.allergen-'+allergen+' .name').length+')</div>') 599 }); 600 601 return this; 602 }; 603 604 return this.init(); 605 }; 606 607})(jQuery); 608 609(function($){ 610 611 Beechnut.Modules.ContactUs = function() { 612 613 /** 614 * Initialize module on page load 615 * @returns {Beechnut.Modules.ContactUs} 616 */ 617 this.init = function() { 618 619 if(!$('.content-contact-us').length)return this; //some shall pass 620 621 // Phone number field mask. 622 $('#phone_number') 623 .keydown(function(e) { 624 var key = e.charCode || e.keyCode || 0; 625 var $phone = $(this); 626 627 var $value = $phone.val(); 628 // if ($value == '' || $value.replace(/\s{2,}/g, ' ') == ' ') { 629 // $phone.val('('); 630 // } 631 632 // if ($value != '' && $value[0] != '(') { 633 // $phone.val('(' + $value); 634 // } 635 636 // Auto-format- do not expose the mask as the user begins to type 637 if (key !== 8 && key !== 9) { 638 if ($phone.val().length === 3) { 639 $phone.val($phone.val() + '-'); 640 } 641 // if ($phone.val().length === 5) { 642 // $phone.val($phone.val() + ' '); 643 // } 644 if ($phone.val().length === 7) { 645 $phone.val($phone.val() + '-'); 646 } 647 } 648 649 // Allow numeric (and tab, backspace, delete) keys only 650 return (key == 8 || 651 key == 9 || 652 key == 46 || 653 (key >= 48 && key <= 57) || 654 (key >= 96 && key <= 105)); 655 }) 656 657 .bind('focus click', function() { 658 var $phone = $(this); 659 660 // if ($phone.val().length === 0) { 661 // $phone.val('('); 662 // } else { 663 var val = $phone.val(); 664 $phone.val('').val(val); // Ensure cursor remains at the end 665 // } 666 }) 667 668 .blur(function() { 669 var $phone = $(this); 670 671 // if ($phone.val() === '(') { 672 // $phone.val(''); 673 // } 674 }); 675 676 return this; 677 }; 678 679 return this.init(); 680 }; 681 682})(jQuery); 683 684(function($){ 685 686 Beechnut.Modules.ProductDetail = function() { 687 688 /** 689 * Initialize module on page load 690 * @returns {Beechnut.Modules.ProductDetail} 691 */ 692 this.init = function() { 693 var self = this; 694 695 if(!$('.content-product-detail').length)return this; //some shall pass 696 697 // Ingredients grid. 698 var $ingredientGrid = $('.ingredient-grid'); 699 if ($ingredientGrid.length) { 700 $(window).on('load resize', function() { 701 $ingredientGrid.css('min-height', ($ingredientGrid.width()/.78) + 'px');
702 $ingredientGrid.find('.ingredient').css('height', ($ingredientGrid.height()/2) + 'px'); 703 }); 704 } 705 706 // Init slider. 707 var $moreSlider = $('.more-slider-container'); 708 if ($moreSlider.length) { 709 $moreSlider.find('.more-slider').slick({ 710 dots: false, 711 arrows: false, 712 infinite: true, 713 slidesToShow: 3, 714 slidesToScroll: 1, 715 prevArrow: '<button type="button" class="slick-prev"><i class="fa fa-caret-left" aria-hidden="true"></i></button>', 716 nextArrow: '<button type="button" class="slick-next"><i class="fa fa-caret-right" aria-hidden="true"></i></button>', 717 responsive: [ 718 { 719 breakpoint: 992, 720 settings: { 721 initialSlide: 3, 722 slidesToShow: 1, 723 dots: true, 724 arrows: true, 725 } 726 } 727 ] 728 }); 729 } 730 731 // Equal heights for nutrition panel and slider. 732 // Set their height equal to the row height. 733 var $nutritionFacts = $('.nutrition-facts'); 734 var $factsSliderRow = $('.row-facts-slider'); 735 $(window).on('load resize', function() { 736 $nutritionFacts.removeAttr('style'); 737 $moreSlider.removeAttr('style'); 738 if($(window).width() >= 992){ 739 var factsSliderRowHeight = $factsSliderRow.outerHeight(); 740 // $nutritionFacts.outerHeight(factsSliderRowHeight); 741 // $moreSlider.outerHeight(factsSliderRowHeight); 742 } 743 }); 744 745 // Scale the product images in the slider. 746 // if($(window).width() >= 992){ 747 // this.scaleSliderProducts(); 748 // } 749 $(window).on('resize', function() { 750 if($(window).width() >= 992){ 751 self.scaleSliderProducts(); 752 }else{ 753 // // Remove any styles that may have been applied. 754 $('.more-slider .img-container img').removeAttr('style'); 755 } 756 }); 757 758 // Unhide container after window load. 759 $(window).on('load', function() { 760 $('.content-product-detail > div.container').css('visibility', 'visible'); 761 }); 762 763 // Mobile description read more 764 $('.desc-mobile a.read-more-desc').click(function(e){ 765 e.preventDefault(); 766 $('.desc-mobile').fadeOut('fast', function(){ 767 $('.desc-desktop').fadeIn('fast'); 768 }); 769 }); 770 // Mobile description read more 771 $('a.see-more-reviews').click(function(e){ 772 $(this).hide(); 773 e.preventDefault(); 774 $('ul.reviewslist li.review').css("display", "flex").hide().fadeIn(); 775 }); 776 return this; 777 }; 778 779 /** 780 * Naturally scale the products in the slider based on the raw image 781 * dimensions and as compared to the other products in the slider. 782 */ 783 this.scaleSliderProducts = function(){ 784 // Get the biggest widtheigh for each raw image in the slider. 785 // *raw meaning not scaled. 786 var widest = 0; 787 var tallest = 0; 788 $('.more-slider .img-container img').each(function(index, element){ 789 // Get the raw dimensions for the images. 790 var img_w = $(this).data('width'); 791 var img_h = $(this).data('height'); 792 // Get widest dimension. 793 if(img_w > widest){ 794 widest = img_w; 795 } 796 // Get tallest dimension. 797 if(img_h > tallest){ 798 tallest = img_h; 799 } 800 }); 801 // Get the aspect ratio for the biggest width and height of the raw images. 802 var mostest_aspect_ratio = widest / tallest; 803 804 // Get the aspact ratio for the product containers. 805 var $cont = $('.more-slider .img-container').first(); 806 var cont_w = $cont.width(); 807 var cont_h = $cont.height(); 808 var cont_aspect_ratio = cont_w / cont_h; 809 810 // Scaled down width and height of the biggest to fit into 811 // the product container. 812 var widest_w = cont_h * (widest / tallest); 813 var tallest_h = cont_w * (tallest / widest); 814 815 $('.more-slider .img-container img').each(function(index, element){ 816 // Reset heights and widths. 817 $(this).removeAttr('style'); 818 // Get the raw dimensions for the images. 819 var img_w = $(this).data('width'); 820 var img_h = $(this).data('height'); 821 // Find the naturally scalled product width. 822 if(mostest_aspect_ratio > cont_aspect_ratio){ 823 var width_decrease_percentage = widest_w / widest; 824 var img_w_new = img_w * width_decrease_percentage; 825 var final_w = (img_w_new < cont_w) ? img_w_new : cont_w; 826 $(this).width(final_w); 827 } 828 // Find the naturally scalled product height. 829 else{ 830 var height_decrease_percentage = tallest_h / tallest; 831 var img_h_new = img_h * height_decrease_percentage; 832 var final_h = (img_h_new < cont_h) ? img_h_new : cont_h; 833 $(this).height(final_h); 834 } 835 }); 836 }; 837 838 return this.init(); 839 }; 840 841})(jQuery); 842 843(function($){ 844 845 Beechnut.Modules.Careers = function() { 846 847 /** 848 * Initialize module on page load 849 * @returns {Beechnut.Modules.Careers} 850 */ 851 this.init = function() { 852 853 if(!$('.content-careers').length)return this; //some shall pass 854 855 this.topTabs(); 856 this.findJobs(); 857 858 return this; 859 }; 860 861 /** 862 * Equal heights for job finder section. 863 */ 864 this.findJobs = function(){ 865 var $row = $('.currently-hiring .row'); 866 var $container = $('.currently-hiring .container'); 867 var $leftSection = $('.currently-hiring .job-taxs'); 868 var $rightSection = $('.currently-hiring .job-lists'); 869 var $rightSectionContent = $('.currently-hiring .job-lists .tab-content'); 870 var $rightSectionDisclaimer = $('.currently-hiring .job-lists .disclaimer'); 871 $(window).on('load resize', function() { 872 $leftSection.removeAttr('style'); 873 $rightSection.removeAttr('style'); 874 if($(window).width() >= 768){ 875 var rowHeight = $row.outerHeight(); 876 var disclaimerHeight = $rightSectionDisclaimer.outerHeight(); 877 $leftSection.outerHeight(rowHeight); 878 $rightSection.outerHeight(rowHeight); 879 $rightSectionContent.outerHeight(rowHeight - disclaimerHeight); 880 } 881 $container.css('visibility', 'visible'); 882 }); 883 }; 884 885 /** 886 * Events for the tabs (& mobile dropdown) in the top section. 887 */ 888 this.topTabs = function(){ 889 // Tab & dropdown events. 890 $('a.tab-link').on('shown.bs.tab', function (e) { 891 // Get link number 892 var targetLinkNum = $(e.target).data('link-number'); 893 // Remove active class from mobile link.
894 $('#tab-controls-mobile').find('li.active').removeClass('active'); 895 // Desktop 896 if($(e.target).hasClass('tab-link-desktop')){ 897 // Add active class to mobile target link. 898 $('#tab-controls-mobile').find('a[data-link-number="'+targetLinkNum+'"]').parent().addClass('active'); 899 } 900 // Mobile 901 else{ 902 // Add active class to mobile target link. 903 $(e.target).parent().addClass('active'); 904 // Remove active class from all desktop links.// Remove active class from mobile link. 905 $('#tab-controls-desktop').find('li.active').removeClass('active'); 906 // Add active class to desktop target link. 907 $('#tab-controls-desktop').find('a[data-link-number="'+targetLinkNum+'"]').parent().addClass('active'); 908 } 909 // Add active text to mobile dropdown button. 910 var activeText = $(e.target).text(); 911 $('#tab-controls-mobile').find('button span').text(activeText); 912 }); 913 }; 914 915 return this.init(); 916 }; 917 918})(jQuery); 919 920(function($){ 921 922 Beechnut.Modules.Faq = function() { 923 924 /** 925 * Initialize module on page load 926 * @returns {Beechnut.Modules.Faq} 927 */ 928 this.init = function() { 929 930 if(!$('.content-faqs').length)return this; 931 932 // Question accordion 933 $('.question-block .question').click(function() { 934 var $block = $(this).parent(); 935 var open = !$block.hasClass('active') 936 $('.question-block .answer').slideUp(); 937 $('.question-block.active').removeClass('active'); 938 if (open) { 939 $block.addClass('active'); 940 $block.find('.answer').slideDown('fast'); 941 } 942 }); 943 944 // Mobile FAQ-type accordion 945 $('.mobile-tab-trigger').on('shown.bs.tab', function (e) { 946 $(e.target).parent().addClass('active'); 947 }); 948 949 return this; 950 }; 951 952 return this.init(); 953 }; 954 955})(jQuery); 956 957(function($){ 958 959 Beechnut.Modules.Search = function() { 960 961 /** 962 * Initialize module on page load 963 * @returns {Beechnut.Modules.Search} 964 */ 965 this.init = function() { 966 var lastString = ''; 967 $('input.search-form').keyup(function() { 968 var $this = $(this); 969 lastString = $.trim($this.val()); 970 var currString = lastString; 971 if (currString != '') { 972 $.ajax({ 973 type: 'POST', 974 url: '/', 975 data: { 976 's' : lastString, 977 'ajax' : 1 978 }, 979 success: function(response) { 980 if (lastString == currString) { 981 $this.parent().find('.instant-results').html(response + '<div class="all"><a href="#" class="submit">See all results for "<strong>'+currString+'</strong>"</a></div>'); 982 $this.parent().find('.instant-results .submit').click(function(e) { 983 e.preventDefault(); 984 $this.parent().parent().submit(); 985 }); 986 } 987 } 988 }); 989 } 990 else { 991 $this.parent().find('.instant-results').html(''); 992 } 993 }); 994 995 if(!$('.content-search').length) return this; 996 997 $('.tab-pane .load-more').click(function() { 998 $(this).parent().toggleClass('shown'); 999 }); 1000 1001 $('.tabs-outer').on('shown.bs.tab', function (e) { 1002 $('.tab-pane.shown').removeClass('shown'); 1003 }); 1004 1005 $('.searchform-main input.search-form').focus(); 1006 1007 this.mobileSearchOverlayOpen(); 1008 this.mobileSearchOverlayClose(); 1009 1010 return this; 1011 }; 1012 1013 /** 1014 * Click event to open the mobile search overlay. 1015 */ 1016 this.mobileSearchOverlayOpen = function(){ 1017 $('#mobile-search-trigger').on('click', function(e){ 1018 e.preventDefault(); 1019 $('.mobile-search-overlay').fadeIn('fast'); 1020 }); 1021 1022 // Trigger focus and also keyboard in mobile safari. 1023 // Doc: http://stackoverflow.com/questions/3227291/iphone-mobile-safari-force-keyboard-open 1024 $('.mobile-search-overlay .searchform-main input.search-form').bind('focus'); 1025 $('#mobile-search-trigger').bind('click', function(){ 1026 $('#mobile-search-trigger').trigger('keypress'); 1027 }); 1028 $('#mobile-search-trigger').bind('keypress', function(){ 1029 $('.mobile-search-overlay .searchform-main input.search-form').blur().focus(); 1030 }); 1031 1032 }; 1033 1034 /** 1035 * Click event to close the mobile search overlay. 1036 */ 1037 this.mobileSearchOverlayClose = function(){ 1038 $('.mobile-search-overlay .close-me').click(function(){ 1039 $('.mobile-search-overlay').fadeOut('fast'); 1040 }); 1041 }; 1042 1043 return this.init(); 1044 }; 1045 1046})(jQuery); 1047 1048(function($){ 1049 1050 Beechnut.Modules.WIC = function() { 1051 1052 /** 1053 * Initialize module on page load 1054 * @returns {Beechnut.Modules.WIC} 1055 */ 1056 this.init = function() { 1057 1058 if(!$('.content-wic').length)return this; //some shall pass 1059 1060 $('.jump-to-section .jump-to-link').on('click', function(e){ 1061 e.preventDefault(); 1062 var typeid = $(this).data('typeid'); 1063 $('html, body').animate({ 1064 scrollTop: $('#type-section-'+typeid).offset().top + 'px' 1065 }, 300, 'swing'); 1066 }); 1067 1068 $(window).on('load', function(){ 1069 if($(window).width() >= 768){ 1070 setRowHeight(); 1071 } 1072 $('.products-list-links').css('visibility', 'visible'); 1073 }); 1074 $(window).on('resize', function(){
1075 $('.products-list-links .food-list .row').removeAttr('style'); 1076 if($(window).width() >= 768){ 1077 setRowHeight(); 1078 } 1079 }); 1080 1081 function setRowHeight(){ 1082 $('.products-list-links .food-list .row').each(function(){ 1083 $(this).height($(this).height()); 1084 }); 1085 } 1086 1087 // Load more buttons. 1088 $('.load-more-outer > a').click(function(e){ 1089 e.preventDefault(); 1090 var group = $(this).data('group-slug'); 1091 $('.food-list .row.'+group).fadeIn('fast').removeClass('is-hidden'); 1092 if($(window).width() >= 768){ 1093 $('.products-list-links .food-list .row').removeAttr('style'); 1094 setRowHeight(); 1095 } 1096 $(this).parent().fadeOut('fast'); 1097 }); 1098 1099 return this; 1100 }; 1101 1102 return this.init(); 1103 }; 1104 1105})(jQuery); 1106 1107(function($){ 1108 1109 Beechnut.Modules.JoinCircle = function() { 1110 1111 /** 1112 * Initialize module on page load 1113 * @returns {Beechnut.Modules.JoinCircle} 1114 */ 1115 this.init = function() { 1116 1117 if(!$('.content-join-circle').length)return this; //some shall pass 1118 1119 $('.add-another-outer > a').click(function(e){ 1120 e.preventDefault(); 1121 $('.childs-birthdays .childs-birthday.is-not-shown').first().fadeIn('fast') 1122 .removeClass('is-not-shown').addClass('is-shown'); 1123 1124 if(!$('.childs-birthdays .childs-birthday.is-not-shown').length){ 1125 $(this).fadeOut('fast'); 1126 } 1127 }); 1128 1129 return this; 1130 }; 1131 1132 return this.init(); 1133 }; 1134 1135})(jQuery); 1136 1137(function($){ 1138 1139 Beechnut.Modules.RecipesAndBlog = function() { 1140 1141 /** 1142 * Initialize module on page load 1143 * @returns {Beechnut.Modules.RecipesAndBlog} 1144 */ 1145 this.init = function() { 1146 1147 if($('.content-recipes').length || $('.content-blog').length){ 1148 this.loadMoreAjax(); 1149 this.mobileRecipeNav(); 1150 } 1151 1152 if($('.content-recipe-detail').length || $('.content-blog-detail').length){ 1153 this.responsiveIframes(); 1154 } 1155 1156 return this; 1157 }; 1158 1159 /** 1160 * Wrap div with bootstrap class around all iframes in content of blog or 1161 * recipe detail pages. 1162 * @return {[type]} [description] 1163 */ 1164 this.responsiveIframes = function(){ 1165 $('.content-area iframe').unwrap().wrap("<div class='content-embed embed-responsive embed-responsive-16by9'></div>"); 1166 } 1167 1168 /** 1169 * Mobile dropdown click event. 1170 */ 1171 this.mobileRecipeNav = function(){ 1172 $('#dLabel').click(function(){ 1173 $('.navs-mobile .dropdown-options').fadeToggle('fast'); 1174 $('.navs-mobile .dropdown').toggleClass('is-active'); 1175 }); 1176 }; 1177 1178 /** 1179 * Logic for load more ajax. 1180 */ 1181 this.loadMoreAjax = function(){ 1182 $('.load-more > a').click(function(e){ 1183 e.preventDefault(); 1184 1185 var paged = $('.results .results-page').last().data('paged'); 1186 var tax = $('.results').data('tax'); 1187 var taxID = $('.results').data('tax-id'); 1188 var postType = $('.results').data('post-type'); 1189 1190 $.ajax({ 1191 type: 'POST', 1192 url: '/ajax/getRecipeCards', 1193 data: { 1194 'ajax-action' : 'get_recipe_cards_ajax', 1195 'recipes_paged' : paged+1, 1196 'recipe_tax' : tax, 1197 'recipe_tax_id' : taxID, 1198 'post_type' : postType, 1199 }, 1200 dataType: 'json', 1201 success: function(response){ 1202 // console.log('response'); 1203 // console.log(response); 1204 1205 $('.results .results-page').last().append(response); 1206 $('.results .results-page').last().fadeIn('fast'); 1207 // Get the total number of recipes that can show. 1208 var totalPossible = $('.results .results-page').first().data('total'); 1209 // Get the total number of recipes showing 1210 var total = $('.results .recipe-card').length; 1211 1212 if(total == totalPossible){ 1213 $('.load-more').addClass('hidden'); 1214 // $('.load-more').addClass('is-disabled'); 1215 } 1216 }, 1217 error: function(jqXhr) { 1218 // console.log(jqXhr.responseText); 1219 } 1220 }); 1221 1222 }); 1223 }; 1224 1225 return this.init(); 1226 }; 1227 1228})(jQuery); 1229 1230 1231jQuery(document).ready(function($) { 1232 var $menu_mobile = $('.mobile-sub-nav'); 1233 var $items = $menu_mobile.find('li'); 1234 var showCount = 6; 1235 1236 if ($items.length > showCount) { 1237 $items.slice(showCount).hide(); 1238 $menu_mobile.append(`<li class="load-more"><a href="#" style="color:green;">Load More 1239 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path fill="green" d="M310.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-192 192c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L242.7 256 73.4 86.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l192 192z"/></svg></a></li>`); 1240 } 1241 1242 $menu_mobile.on('click', '.load-more', function(e) { 1243 e.preventDefault(); 1244 var $hiddenItems = $items.slice(showCount); 1245 if ($hiddenItems.is(':hidden')) { 1246 $hiddenItems.show(); 1247 $(this).find('a').text('Show Less'); 1248 } else { 1249 $hiddenItems.hide(); 1250 $(this).find('a').text('Load More'); 1251 } 1252 }); 1253});
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.