1/** 2 * ContentBerg Theme Utilities 3 * 4 * Copyright (c) 2023 ThemeSphere. 5 */ 6var Bunyad_Theme = (function($) { 7 "use strict"; 8 9 var has_touch = false, 10 responsive_menu = false, 11 search_active = false, 12 sticky_bar_active = false, 13 schemeKey = window.BunyadSchemeKey || 'bunyad-scheme'; 14 15 // module 16 var self = { 17 has_sticky_nav: false, 18 19 init: function() 20 { 21 // Fit videos to container 22 if ($.fn.fitVids) { 23 $('.featured-vid, .post-content').fitVids(); 24 } 25 26 // Back to top handler 27 $('.back-to-top').on('click', function() { 28 29 // Using both html, body until scrollingElement has more support 30 $('html, body').animate({scrollTop: 0}, 800); 31 return false; 32 }); 33 34 // Go back handler 35 $('.go-back').on('click', function() { 36 window.history.back(); 37 return false; 38 }); 39 40 /** 41 * Woocommerce 42 */ 43 $('.woocommerce-ordering .drop li a').on('click', function(e) { 44 var form = $(this).closest('form'); 45 46 form.find('[name=orderby]').val($(this).parent().data('value')); 47 form.submit(); 48 49 e.preventDefault(); 50 }); 51 52 $('.woocommerce .related > h2, .woocommerce .upsells > h2') 53 .addClass('section-head').wrapInner('<span class="title" />'); 54 55 // Post ticker 56 $('.posts-ticker ul').each(function() { 57 58 if (!$(this).find('li.active').length) { 59 $(this).find('li:first').addClass('active'); 60 } 61 62 var ticker = $(this); 63 64 window.setInterval(function() { 65 66 var active = ticker.find('li.active'); 67 active.fadeOut(function() { 68 69 var next = active.next(); 70 if (!next.length) { 71 next = ticker.find('li:first'); 72 } 73 74 next.addClass('active').fadeIn(); 75 active.removeClass('active'); 76 }); 77 78 }, 8000); 79 }); 80 81 /** 82 * Header Parallax - for style 7 83 */ 84 var header = $('.main-head.top-below .inner'), 85 bg = header.css('background-image'); 86 87 if ($(window).width() > 940 && (bg && bg != 'none')) { 88 var parallax = $('<div class="parallax" />').css('background-image', bg); 89 header.append(parallax); 90 header.css('background-image', 'none'); 91 92 var bottom = parallax.offset().top + parallax.outerHeight(), 93 top = parallax.offset().top; 94 95 $(window).on('scroll', function() { 96 97 var scroll = $(window).scrollTop(); 98 99 // Already scrolled enough 100 if (scroll > bottom) { 101 return; 102 } 103 104 var distance = scroll * 0.4; 105 106 requestAnimationFrame(function() { 107 parallax.css('transform', 'translate3d(0,' + distance + 'px, 0)'); 108 }); 109 }); 110 } 111 112 // VC Blocks fix 113 // $('.blocks .block, .blocks .wpb_content_element').last().addClass('last-block'); 114 115 // Twitter widget.js take-over fix. 116 $('.service.twitter, .post-share .twitter, .social-share .tsi-twitter').on('click', function(e) { 117 e.stopPropagation(); 118 }); 119 120 // Setup search 121 this.search(); 122 123 // Setup all sliders 124 this.sliders(); 125 126 // Setup header extras. 127 this.header(); 128 129 // Setup mobile & touch navigation 130 this.responsive_nav(); 131 132 // Setup mega menus 133 this.mega_menus(); 134 135 // Setup sticky top-bar 136 this.sticky_bar(); 137 138 // Sticky sidebar 139 this.sticky_sidebar(); 140 141 // Lightbox for images 142 this.lightbox(); 143 144 // Likes system 145 this.likes(); 146 147 // Single post functionality 148 this.single(); 149 150 // Lazyload setup 151 this.lazy_load(); 152 153 // Masonry layouts setup 154 this.masonry(); 155 156 // Pin buttons 157 this.pin_it(); 158 }, 159 160 header: function() 161 { 162 const toggleDarkMode = (scheme) => { 163 const prevScheme = (scheme == 'dark' ? 'light' : 'dark'); 164 165 // Set initial scheme. 166 const htmlClass = $('html').data('origClass'); 167 let initialScheme; 168 if (htmlClass) { 169 initialScheme = htmlClass.includes('s-dark') ? 'dark' : 'light'; 170 } 171 172 if ($('html').data('autoDark')) { 173 initialScheme = 'dark'; 174 } 175 176 if (scheme !== initialScheme) { 177 localStorage.setItem(schemeKey, scheme); 178 } 179 else { 180 localStorage.removeItem(schemeKey); 181 } 182 183 $('html') 184 .removeClass(`s-${prevScheme} site-s-${prevScheme}`) 185 .addClass(`s-${scheme} site-s-${scheme}`); 186 }; 187 188 $('.scheme-switcher .toggle').on('click', function() { 189 const ele = $(this); 190 let scheme = ele.hasClass('toggle-dark') ? 'dark' : 'light'; 191 192 toggleDarkMode(scheme); 193 194 return false;
195 }); 196 }, 197 198 /** 199 * Setup responsive and touch 200 */ 201 responsive_nav: function() 202 { 203 // detect touch capability dynamically 204 $(window).on('touchstart', function() { 205 has_touch = true; 206 $('body').addClass('touch'); 207 }); 208 209 this.init_responsive_nav(); 210 this.touch_nav(); 211 var that = this; 212 213 $(window).on('resize orientationchange', function() { 214 that.init_responsive_nav(); 215 }); 216 }, 217 218 /** 219 * Setup the responsive nav events and markup 220 */ 221 init_responsive_nav: function() { 222 223 if ($(window).width() > 940 || responsive_menu) { 224 return; 225 } 226 227 // Set responsive initialized 228 responsive_menu = true; 229 230 // Create off-canvas container 231 var menu_contain = $('.mobile-menu-container'); 232 233 // No items for mobile menu? Grab from others 234 if (!menu_contain.find('.mobile-menu').children().length) { 235 236 // Merge existing menus 237 var mobile_menu = menu_contain.find('.mobile-menu'), 238 main_menu = $('.navigation .menu'); 239 240 var menu = main_menu.children().clone(); 241 242 if (!main_menu.length) { 243 return; 244 } 245 246 // add category mega menu links 247 menu.find('.mega-menu .sub-cats').each(function() { 248 var container = $(this).closest('.menu-item'); 249 250 container.append($(this).find('.sub-nav')); 251 container.find('.sub-nav').replaceWith(function() { 252 return $('<ul />', {html: $(this).html()}); 253 }); 254 255 $(this).remove(); 256 257 }); 258 259 mobile_menu.append(menu); 260 } 261 262 $('body').addClass('nav-off-canvas'); 263 264 // Setup mobile menu click handlers 265 $('.mobile-menu li > a').each(function() { 266 267 if ($(this).parent().children('ul').length) { 268 $('<span class="chevron"><i class="tsi tsi-chevron-down"></i></span>').insertAfter($(this)); 269 } 270 }); 271 272 $('.mobile-menu li .chevron').on('click', function() { 273 $(this).closest('li').find('ul').first().parent().toggleClass('active item-active'); 274 return false; 275 }); 276 277 // Menu open handler 278 $('.top-bar .mobile-nav, .main-head .mobile-nav').on('click', function() { 279 $('.mobile-menu').addClass('active'); 280 $('body').toggleClass('off-canvas-active'); 281 $('html').toggleClass('hide-scroll'); 282 }); 283 284 // Off-canvas close 285 $('.off-canvas .close').on('click', function() { 286 $('body').toggleClass('off-canvas-active'); 287 }); 288 }, 289 290 /** 291 * Setup touch for touch devices 292 */ 293 touch_nav: function() { 294 295 var targets = $('.menu:not(.mobile-menu) a'), 296 open_class = 'item-active', 297 child_tag = 'ul, .mega-menu'; 298 299 targets.each(function() { 300 301 var $this = $(this), 302 $parent = $this.parent('li'), 303 $siblings = $parent.siblings().find('a'); 304 305 $this.on('click', function(e) { 306 307 if (!has_touch) { 308 return; 309 } 310 311 var $this = $(this); 312 e.stopPropagation(); 313 314 $siblings.parent('li').removeClass(open_class); 315 316 // has a child? open the menu on tap 317 if (!$this.parent().hasClass(open_class) && $this.next(child_tag).length > 0 && !$this.parents('.mega-menu.links').length) { 318 e.preventDefault(); 319 $this.parent().addClass(open_class); 320 } 321 }); 322 }); 323 324 // close all menus 325 $(document).on('click', function(e) { 326 if (!$(e.target).is('.menu') && !$(e.target).parents('.menu').length) { 327 targets.parent('li').removeClass(open_class); 328 } 329 }); 330 }, 331 332 /** 333 * Search setup 334 */ 335 search: function() 336 { 337 // Nav search overlay 338 $('.main-head.has-search-overlay .search-link').on('click', function() { 339 340 var overlay = $(this).parent().find('.search-box-overlay'); 341 342 search_active = true; 343 if (overlay.hasClass('active')) { 344 search_active = false; 345 } 346 347 overlay.toggleClass('active'); 348 349 return false; 350 }); 351 352 // Search bar for alt header 353 var search_active_alt = false; 354 $('.search-alt .top-bar .search-submit').on('click', function() { 355 if (!search_active_alt) { 356 $(this).closest('form').find('.search-field').addClass('active').focus(); 357 search_active_alt = true; 358 359 return false;
360 } 361 }); 362 363 // Hide search on outside clicks 364 $(document).on('click', function(e) { 365 if (search_active && !$(e.target).parents('.search-box-overlay').length) { 366 $('.main-head.has-search-overlay .search-link').click(); 367 } 368 369 // Hide alt header search 370 if (search_active_alt && !$(e.target).parents('.top-bar').length) { 371 search_active_alt = false; 372 373 $('.main-head.search-alt .search-submit') 374 .closest('form').find('.search-field').removeClass('active'); 375 } 376 }); 377 378 // Search modal 379 $('.main-head.has-search-modal .search-link').magnificPopup({ 380 items: { 381 src: '.search-modal-wrap', 382 type: 'inline' 383 }, 384 removalDelay: 400, 385 focus: 'input', 386 closeBtnInside: false, 387 closeOnBgClick: false, 388 mainClass: 'search-modal', 389 midClick: true, 390 fixedContentPos: true, 391 autoFocusLast: false 392 }); 393 }, 394 395 /** 396 * Mega Menus 397 */ 398 mega_menus: function() 399 { 400 // Bind events for mega menus 401 $('.navigation .mega-menu').each(function() { 402 403 var menu = $(this); 404 405 // Init mega menus 406 var default_mega_menu = function f() { 407 menu.find('.posts-wrap').last().addClass('active'); 408 return f; 409 }(); 410 411 // Mega-menu sub-cats handling 412 menu.find('.menu-item').on('mouseenter', function() { 413 414 var id = parseInt( $(this).attr('class').match(/menu-cat-(\d+)/)[1] || 0 ), 415 menu = $(this).parents('.mega-menu'), 416 view_all = $(this).hasClass('view-all'); 417 418 if (!view_all && !id) { 419 return; 420 } 421 422 // remove other actives 423 menu.find('.active, .current-menu-item').removeClass('active current-menu-item'); 424 425 // activate current 426 $(this).addClass('current-menu-item'); 427 var posts = menu.find('[data-id=' + id + ']').addClass('active'); 428 429 if (posts.find('.post-wrap').data('pages') < 2) { 430 posts.parent().find('.navigate').hide(); 431 } 432 else { 433 posts.parent().find('.navigate').show(); 434 } 435 436 return false; 437 }); 438 439 // Reset mega menu state on fresh hover 440 menu.parent().on('mouseenter', function() { 441 442 var menu = $(this).find('.mega-menu'); 443 444 // reset at beginning 445 menu.find('.active, .current-menu-item') 446 .removeClass('active current-menu-item'); 447 448 $(this)[0].offsetWidth; // reflow 449 default_mega_menu(); 450 }); 451 }); 452 453 /** 454 * Mega menu pagination 455 */ 456 let processing = false; 457 458 const postsLoaded = (posts, current, page) => { 459 processing = false; 460 current.removeClass('loading'); 461 462 current.find('.posts').hide(); 463 posts.show(); 464 current.data('page', page); 465 466 posts.addClass('fade-in-up'); 467 } 468 469 const menuNavigate = (type, ele) => { 470 471 if (processing) { 472 return false; 473 } 474 processing = true; 475 476 const current = $(ele).parents('.mega-menu').find('.posts-wrap.active'); 477 const thePage = current.data('page') || 1; 478 const nextPage = Math.max(1, type == 'prev' ? (thePage - 1) : (thePage + 1)); 479 const maxPage = current.data('pages'); 480 481 current.addClass('loading'); 482 483 current.parent().find('.show-prev') 484 .removeClass('enabled disabled') 485 .addClass(nextPage > 1 ? 'enabled' : 'disabled'); 486 487 current.parent().find('.show-next') 488 .removeClass('enabled disabled') 489 .addClass(nextPage !== maxPage ? 'enabled' : 'disabled'); 490 491 const havePosts = current.find('.posts-' + nextPage); 492 if (havePosts.length) { 493 havePosts.removeClass('fade-in-up'); 494 postsLoaded(havePosts, current, nextPage); 495 } else { 496 $.post( 497 Sphere_Plugin.ajaxurl, 498 { 499 action: 'bunyad_mega_menu', 500 id: current.data('id'), 501 page: nextPage, 502 posts: current.data('posts'), 503 submenu: current.data('submenu') 504 }, 505 data => { 506 const html = $(data); 507 const posts = html.find('.posts'); 508 509 if (posts.length) { 510 current.append(posts); 511 } 512 513 postsLoaded(posts, current, nextPage); 514 } 515 ); 516 } 517 518 return false; 519 } 520 521 $('.mega-menu .show-prev').on('click', e => menuNavigate('prev', e.target)); 522 $('.mega-menu .show-next').on('click', e => menuNavigate('next', e.target)); 523 }, 524 525 /** 526 * Setup sticky bar if enabled 527 */ 528 sticky_bar: function() 529 { 530 var nav, 531 top_bar = $('.top-bar-content'), 532 is_smart = false,
533 is_sticky = false, 534 is_static = false, 535 prev_scroll = 0, 536 cur_scroll = 0, 537 extra_top = 0, 538 nav_top, 539 hide_at, 540 head = $('.main-head'), 541 head_height; 542 543 544 // Set height for container 545 var set_size = function(skip_calc) { 546 547 // Don't reset if it's stuck 548 if (sticky_bar_active) { 549 return; 550 } 551 552 // Skip calculation if asked to and head height has been prev set 553 if (skip_calc && head_height) { 554 return; 555 } 556 557 // in raf to throttle resize events 558 requestAnimationFrame(function() { 559 var new_height = head.css('min-height', 0).height(); 560 head.css('min-height', new_height); 561 head_height = new_height; 562 }); 563 }; 564 565 $(window).on('load resize', set_size); 566 567 var init = function() { 568 569 // Reset vars - might be a re-init 570 is_static = false; 571 572 // Is smart? 573 var check_smart = function() { 574 575 // Enable smart at responsive 576 if ($(window).width() < 940) { 577 is_smart = true; 578 } 579 else { 580 is_smart = false;
581 } 582 583 if (nav && nav.data('sticky-bar') == 'smart') { 584 is_smart = true; 585 } 586 }; 587 588 if ($('.admin-bar').length) { 589 extra_top = $('#wpadminbar').height(); 590 } 591 592 // Target sticky based on header layout 593 if (head.is('.nav-below, .top-below')) { 594 595 // Top bar below or nav-below-logo types 596 nav = head.hasClass('nav-below') ? $('.navigation.below') : top_bar; 597 598 nav_top = nav.offset().top - extra_top; 599 hide_at = nav_top + 1; 600 } 601 // Compact has a sticky topbar configured below 602 else if (head.is('.simple') || (head.is('.compact') && $(window).width() >= 940)) { 603 604 // Top bar below or nav below logo types 605 nav = head.find('.inner').first(); 606 check_smart(); 607 608 nav_top = head.offset().top + (head.height()/2) - extra_top; 609 hide_at = nav_top + 200; 610 611 if (is_smart) { 612 613 // For performance 614 var parallax = $('.single-creative .featured'); 615 if (parallax.length) { 616 hide_at = nav_top; 617 nav_top += parallax.height(); 618 } 619 } 620 621 } 622 else if (top_bar.length) { 623 624 nav = top_bar; 625 check_smart(); 626 627 // static sticky via CSS unless it's smart sticky 628 if (!is_smart && top_bar.data('sticky-bar')) { 629 top_bar.addClass('sticky-bar'); 630 is_static = true; 631 } 632 633 // default 634 var pos_ele = $('.top-bar'); 635 636 nav_top = pos_ele.offset().top - extra_top, 637 hide_at = nav_top + 1; 638 } 639 640 check_smart(); 641 642 // Android fix on addr bar hide 643 if (is_smart && !sticky_bar_active) { 644 prev_scroll = 0; 645 } 646 }; 647 648 // Init and calculate defaults 649 init(); 650 651 if (!nav) { 652 return; 653 } 654 655 // not enabled? 656 if (!nav.data('sticky-bar')) { 657 return; 658 } 659 660 self.has_sticky_nav = true; 661 662 if (nav.find('.sticky-logo').length) { 663 nav.addClass('has-logo'); 664 } 665 666 // disable the sticky nav 667 var remove_sticky = function() { 668 669 // check before dom modification 670 if (is_sticky) { 671 672 sticky_bar_active = 0; 673 nav.removeClass('sticky-bar'); 674 set_size(true); 675 676 $(document).trigger('sticky-bar-hide'); 677 } 678 }; 679 680 // Check and apply sticky - separated writes 681 var sticky_writes = writeRaf(function() { 682 683 // make it sticky when viewport is scrolled beyond the navigation 684 if (cur_scroll > nav_top) { 685 686 // for smart sticky, test for scroll change 687 if (is_smart && (!prev_scroll || cur_scroll > prev_scroll)) { 688 remove_sticky(); 689 } 690 else { 691 sticky_bar_active = 1; 692 693 if (!is_smart || cur_scroll < prev_scroll-4) { 694 695 if (!nav.hasClass('sticky-bar')) { 696 nav.addClass('sticky-bar no-transition'); 697 698 setTimeout(function() { 699 nav.removeClass('no-transition'); 700 }, 100); 701 702 $(document).trigger('sticky-bar-show'); 703 } 704 } 705 } 706 707 prev_scroll = cur_scroll; 708 709 } else { 710 711 // hide at a certain point 712 if (cur_scroll <= hide_at) { 713 prev_scroll = 0; 714 remove_sticky(); 715 } 716 } 717 }); 718 719 // Make the nav sticky 720 var sticky = function() { 721 722 if (!nav.data('sticky-bar') || is_static) { 723 return; 724 } 725 726 cur_scroll = $(window).scrollTop(); 727 is_sticky = nav.hasClass('sticky-bar'); 728 729 sticky_writes(); 730 }; 731 732 sticky(); 733 734 $(window).on('scroll', function() { 735 sticky(); 736 }); 737 738 // Re-initialize on resize 739 $(window).on('resize orientationchange', function() { 740 init(); 741 sticky(); 742 }); 743 }, 744 745 /** 746 * Setup sticky sidebar 747 */ 748 sticky_sidebar: function() 749 { 750 751 // Sidebar class on the widget element? Move it up 752 $('.main .sidebar').each(function() { 753 if ($(this).hasClass('wpb_content_element')) { 754 var parent = $(this).closest('.wpb_column'), 755 classes = 'sidebar'; 756 757 if ($(this).hasClass('sticky-col')) { 758 classes += ' sticky-col'; 759 } 760
761 parent.addClass(classes); 762 $(this).removeClass(classes); 763 } 764 }); 765 766 var sticky = $('.main .sticky-col, .main .sidebar[data-sticky=1]'); 767 768 if (!sticky.length) { 769 return; 770 } 771 772 var add = 20; 773 if ($('.admin-bar').length) { 774 add += 32; 775 } 776 777 if (self.has_sticky_nav) { 778 add += 50; 779 } 780 781 sticky.each(function() { 782 783 var parent_col = $(this); 784 785 // Add wrapper class if missing 786 if (!parent_col.find('.theiaStickySidebar').length) { 787 parent_col.find('.wpb_wrapper').first().addClass('theiaStickySidebar'); 788 } 789 790 parent_col.theiaStickySidebar({ 791 minWidth: 940, 792 updateSidebarHeight: false, 793 additionalMarginTop: add 794 }); 795 }); 796 797 // for iframe loads in sidebar 798 $(window).on('load', function() { 799 setTimeout(function() { 800 $(window).trigger('resize.TSS'); 801 }, 2500); 802 }); 803 }, 804 805 /** 806 * Single post functionality 807 */ 808 single: function() 809 { 810 if (!$('body').hasClass('single-post')) { 811 return; 812 } 813 814 /** 815 * Social sharing 816 */ 817 // Single top social sharing view all buttons 818 $('.post-share-b .show-more').on('click', function() { 819 $(this).parent().addClass('all'); 820 return false; 821 }); 822 823 // Setup floating share 824 Bunyad_Share_Float.init(); 825 826 // Paralax for creative 827 var creative = $('.single-creative.js-parallax .featured'); 828 if (creative.length && $.fn.jarallax) { 829 830 var img = creative.find('.wp-post-image'), 831 src = img.prop('src'); 832 833 if (img.prop('currentSrc')) { 834 src = img.prop('currentSrc'); 835 } 836 837 if ($(window).width() < 940) { 838 creative.removeClass('parallax'); 839 return; 840 } 841 842 creative.addClass('parallax'); 843 creative.find('.image-link').jarallax({ 844 imgSrc: src, 845 speed: 0.4, 846 noIos: false 847 }); 848 } 849 850 $(window).on('resize', this.post_navigation); 851 this.post_navigation(); 852 853 }, 854 855 /** 856 * Post Naviation 857 */ 858 post_navigation: function() 859 { 860 var initialized = false, 861 post_nav = $('.post-nav'); 862 863 if (!post_nav.length || $(window).width() < 1300) { 864 post_nav.removeClass('post-nav-float').addClass('post-nav-inline'); 865 return; 866 } 867 868 // Already setup or shouldn't be init? 869 if (initialized) { 870 return; 871 } 872 873 initialized = true; 874 post_nav.addClass('post-nav-float'); 875 post_nav = post_nav.find('.post'); 876 877 if ($('.has-share-float').length) { 878 post_nav.addClass('ss-overlap'); 879 } 880 881 // Show when post-content is in viewport and hide when footer 882 // becomes visible in view. 883 var ele = $('.the-post .post-content'), 884 scroll, offset, win_height, show_at, hide_at; 885 886 var calc = function() { 887 offset = ele.offset(); 888 win_height = $(window).height(); 889 890 show_at = offset.top + (win_height / 2) + 56; 891 hide_at = $('.main-footer').offset().top + (win_height / 3); 892 }; 893 894 calc(); 895 self._wait_load(calc, {'ready': true}); 896 897 // Lazyload fires this 898 $(window).on('resize.TSS', calc); 899 900 // Show at certain scroll 901 $(window).on('scroll', function() { 902 903 if ($(window).width() < 940) { 904 return; 905 } 906 907 // Add viewport height to scrollTop 908 scroll = $(window).scrollTop() + win_height; 909 910 requestAnimationFrame(function() { 911 if (scroll > show_at && scroll < hide_at) { 912 913 if (!post_nav.hasClass('active')) { 914 post_nav.addClass('active'); 915 } 916 } 917 else { 918 post_nav.removeClass('active'); 919 } 920 }); 921 }); 922 }, 923 924 /** 925 * Util to wait for until async CSS has been applied - waits for async font load 926 * too by default. 927 */ 928 _wait_load: function(cb, options) { 929 930 options = $.extend({ 931 'fonts': true, 932 'ready': false 933 }, options); 934 935 var sel = options.fonts ? '.wf-loading, .ld' : '.ld'; 936 937 if ($('html').is(sel) || (options.ready && document.readyState !== 'complete')) { 938 setTimeout( 939 self._wait_load.bind(null, cb, options), 940 30 941 ); 942 } 943 else { 944 cb(); 945 } 946 }, 947 948 /** 949 * Setup sliders and carousels 950 */ 951 sliders: function() 952 { 953 /** 954 * Parallax extend 955 */ 956 if (window.jarallax) { 957 var Jarallax = window.jarallax.constructor; 958 var orig = Jarallax.prototype.onScroll; 959 Jarallax.prototype.onScroll = function(force) { 960 961 if (!force) { 962 var ele = $(this.options.elementInViewport); 963 if (ele && ele.data('active-only') && !ele.is('.slick-active, .active')) { 964 return; 965 } 966 } 967 968 orig.apply(this, arguments); 969 }; 970 } 971 972 // Enable parallax 973 var add_parallax = function(slider, parallax_one) { 974 975 var do_parallax = function() { 976 977 if ($(window).width() < 940) { 978 slider.removeClass('parallax'); 979 return; 980 } 981 982 slider.addClass('parallax'); 983 984 var slides = slider.find('.slick-slide'); 985 986 if (slider.parent().is('.grid-slider, .grid-b-slider')) { 987 slides = slider.find('.item-large, .item-small').find('.image-link'); 988 } 989 990 slides.each(function() { 991 992 var img = $(this).find('img'), 993 src = img.prop('src'); 994 995 if (img.prop('currentSrc')) { 996 src = img.prop('currentSrc'); 997 } 998 999 if (parallax_one) { 1000 $(this).data('active-only', true); 1001 } 1002 1003 $(this).jarallax({ 1004 //imgSrc: src, 1005 imgElement: '.wp-post-image', 1006 keepImg: true, 1007 speed: 0.6, 1008 elementInViewport: parallax_one ? $(this) : $(this).closest('.slick-slider'), 1009 noIos: false, 1010 onInit: function() { 1011 $(this.image.$item).removeClass('wp-post-image'); 1012 } 1013 }); 1014 }); 1015 }; 1016 1017 $(window).on('resize', do_parallax); 1018 do_parallax(); 1019 }; 1020 1021 /** 1022 * Slider setup object 1023 */ 1024 var setup = {}; 1025 1026 /** 1027 * Main featured post slider 1028 */ 1029 setup.main_slider = function(slider) { 1030 1031 slider.slick({ 1032 centerMode: true, 1033 variableWidth: true, 1034 slidesToShow: 1, 1035 slidesToScroll: 1, 1036 autoplay: slider.data('autoplay') ? true : false, 1037 autoplaySpeed: slider.data('speed'), 1038 arrows: true, 1039 prevArrow: '<a href="#" class="prev-arrow"><i class="tsi tsi-angle-left"></i></a>', 1040 nextArrow: '<a href="#" class="next-arrow"><i class="tsi tsi-angle-right"></i></a>', 1041 touchThreshold: 50, 1042 dots: false, 1043 infinite: true, 1044 responsive: [{ 1045 breakpoint: 940, 1046 settings: { 1047 slidesToShow: 1, 1048 centerMode: false, 1049 variableWidth: false 1050 } 1051 }] 1052 }); 1053 1054 // Arrow positions 1055 slider.on('setPosition', function() { 1056 1057 // not for responsive 1058 if ($(window).width() < 940) { 1059 return; 1060 } 1061 1062 var center = $(this).find('.slick-active.slick-center'), 1063 pos = center.offset(), 1064 right = pos.left + center.width(); 1065 1066 $(this).find('.prev-arrow').css('left', pos.left + 'px'); 1067 $(this).find('.next-arrow').css('left', right + 'px'); 1068 }); 1069 1070 slider.find('[data-slick-index=0]').addClass('active'); 1071 1072 // Force our active class by first removing it from clones 1073 slider.on('beforeChange', function(e, slick, prev, current) { 1074 1075 $(this).find('.active').removeClass('active'); 1076 var ele = $(this); 1077 1078 requestAnimationFrame(function() { 1079 ele.find('[data-slick-index=' + current + ']').addClass('active'); 1080 }, 1); 1081 }); 1082 1083 };
1083 // main slider 1084 1085 /** 1086 * Fashion Slider 1087 */ 1088 setup.fashion_slider = function(slider, vars) { 1089 1090 slider.on('init', function(e, slick) { 1091 self._wait_load(function() { 1092 $(slick.$slides[0]).addClass('active'); 1093 }); 1094 }); 1095 1096 slider.slick($.extend(vars, { 1097 arrows: true, 1098 infinite: true, 1099 cssEase: 'cubic-bezier(0.4, 0.03, 0, 0.83)', 1100 speed: 700 1101 })); 1102 1103 slider.on('beforeChange', function(e, slick, prev, current) { 1104 var ele = $(this); 1105 1106 requestAnimationFrame(function() { 1107 1108 ele.find('.active').removeClass('active'); 1109 ele.find('[data-slick-index=' + current + ']').addClass('active'); 1110 1111 }); 1112 1113 }); 1114 }; 1115 1116 /** 1117 * Carousel Slider 1118 */ 1119 setup.carousel_slider = function(slider, vars) { 1120 1121 slider.slick($.extend(vars, { 1122 arrows: true, 1123 slidesToShow: 3, 1124 slidesToScroll: 3, 1125 infinite: true, 1126 cssEase: 'ease-out', 1127 speed: 500, 1128 responsive: [ 1129 { 1130 breakpoint: 940, 1131 settings: {slidesToShow: 2, slidesToScroll: 2} 1132 }, 1133 { 1134 breakpoint: 600, 1135 settings: {slidesToShow: 1, slidesToScroll: 1} 1136 } 1137 ] 1138 })); 1139 }; 1140 1141 // Bold slider 1142 setup.bold_slider = function(slider, vars) { 1143 1144 slider.on('init', function(e, slick) { 1145 self._wait_load(function() { 1146 $(slick.$slides[0]).addClass('active'); 1147 }); 1148 }); 1149 1150 //var slick = instance.get(0).slick; 1151 slider.slick($.extend(vars, { 1152 arrows: true, 1153 infinite: true, 1154 cssEase: 'ease-in-out', 1155 speed: 500 1156 })); 1157 1158 var nav = slider.parent().find('.post-thumb'); 1159 1160 slider.on('beforeChange', function(e, slick, prev, current) { 1161 1162 // Current nav thumb to activate 1163 nav.eq(current).click(); 1164 1165 var ele = $(this); 1166 ele.find('.active').removeClass('active'); 1167 1168 requestAnimationFrame(function() { 1169 ele.find('[data-slick-index=' + current + ']').addClass('active'); 1170 }); 1171 1172 }); 1173 1174 // Sync slider with navigation 1175 nav.first().addClass('active'); 1176 nav.on('click', function() { 1177 var index = $(this).index(); 1178 1179 $(this) 1180 .addClass('active') 1181 .siblings().removeClass('active'); 1182 1183 slider.slick('slickGoTo', index); 1184 1185 return false; 1186 }); 1187 }; 1188 1189 1190 /* Initialize home sliders */ 1191 $('.common-slider .slides').each(function() { 1192 1193 var slider = $(this).one('init', function() { 1194 $(this).addClass('loaded'); 1195 }); 1196 1197 // Common setting 1198 var vars = { 1199 prevArrow: '<a href="#" class="prev-arrow"><i class="tsi tsi-angle-left"></i></a>', 1200 nextArrow: '<a href="#" class="next-arrow"><i class="tsi tsi-angle-right"></i></a>', 1201 autoplay: slider.data('autoplay') ? true : false, 1202 autoplaySpeed: slider.data('speed'), 1203 fade: slider.data('animation') == 'fade' ? true : false 1204 }; 1205 1206 var parallax = slider.data('parallax') || 0, 1207 parallax_one, 1208 slider_type = slider.data('slider'); 1209 1210 switch (slider_type) { 1211 1212 case 'carousel': 1213 setup.carousel_slider(slider, vars); 1214 break; 1215 1216 case 'bold': 1217 setup.bold_slider(slider, vars); 1218 parallax_one = 1; 1219 break; 1220 1221 default: 1222 1223 var fn = setup[slider_type + '_slider']; 1224 if (typeof fn === 'function') { 1225 fn(slider, vars); 1226 } 1227 else { 1228 setup.main_slider(slider); 1229 } 1230 1231 break; 1232 } 1233 1234 // Has Parallax effect? 1235 if (parallax) { 1236 1237 // One active slide only to parallax 1238 if (parallax_one) { 1239 slider.on('beforeChange', function(e, slick, prev, current) { 1240 $(this).find('.active').removeClass('active'); 1241 var slide = $(this).find('[data-slick-index=' + current + ']'); 1242 1243 slide.addClass('active'); 1244 slide.jarallax('onScroll'); 1245 }); 1246 } 1247 1248 add_parallax(slider, parallax_one); 1249 } 1250 1251 }); 1252 1253 this.post_gallery_slider(); 1254 $(document).on('ajax-pagination', this.post_gallery_slider); 1255 1256 /** 1257 * Widget: Posts slider 1258 */ 1259 $('.widget-slider .slides').each(function() { 1260 $(this).slick({ 1261 prevArrow: '<a href="#" class="prev-arrow"><i class="tsi tsi-angle-left"></i></a>', 1262 nextArrow: '<a href="#" class="next-arrow"><i class="tsi tsi-angle-right"></i></a>', 1263 autoplay: $(this).data('autoplay') ? true : false, 1264 autoplaySpeed: 6000, 1265 infinite: true 1266 }); 1267 }); 1268 1269 // Disable anchor jump on arrows 1270 $('.common-slider, .widget-slider').on('click', '.slick-arrow', function(e) { 1271 e.preventDefault(); 1272 }); 1273 }, 1274 1275 /** 1276 * Posts featured gallery slider 1277 */ 1278 post_gallery_slider: function(e) { 1279 1280 $('.gallery-slider:not(.slick-initialized)').each(function() { 1281 1282 var slider = $(this); 1283 1284 var init = function() { 1285 1286 var vars = { 1287 infinite: true, 1288 slidesToShow: 1, 1289 prevArrow: '<a href="#" class="prev-arrow"><i class="tsi tsi-angle-left"></i></a>', 1290 nextArrow: '<a href="#" class="next-arrow"><i class="tsi tsi-angle-right"></i></a>', 1291 slidesToScroll: 1, 1292 adaptiveHeight: true 1293 }; 1294 1295 var parent = slider.closest('.single-creative .featured'), 1296 parallax; 1297 1298 if (parent.length) { 1299 1300 parent.addClass('has-gallery'); 1301 slider.addClass('gallery-slider-lg'); 1302 1303 vars = $.extend(vars, { 1304 variableWidth: true, 1305 centerMode: true, 1306 adaptiveHeight: false, 1307 responsive: [{ 1308 breakpoint: 940, 1309 settings: {centerMode: false, variableWidth: false} 1310 }] 1311 }); 1312 1313 } 1314 1315 slider.slick(vars); 1316 !parallax || add_parallax(slider); 1317 }; 1318 1319 if (e) { 1320 slider.imagesLoaded(init); 1321 } 1322 else { 1323 init(); 1324 } 1325 1326 }); 1327 }, 1328 1329 /** 1330 * Setup Likes system 1331 */ 1332 likes: function() 1333 { 1334 if (typeof Sphere_Plugin == 'undefined') { 1335 return; 1336 } 1337 1338 $('.likes-count').on('click', function() { 1339 1340 var like = $(this); 1341 1342 if (like.hasClass('voted')) { 1343 return false;
1344 } 1345 1346 // Register the vote! 1347 $.post(Sphere_Plugin.ajaxurl, {action: 'sphere_likes', id: $(this).data('id')}, function(data) { 1348 1349 if (data === Object(data)) { 1350 like.addClass('voted animate').find('.number').html(data.count); 1351 } 1352 1353 }, 'json'); 1354 1355 return false; 1356 1357 }); 1358 }, 1359 1360 /** 1361 * Setup Lightbox 1362 */ 1363 lightbox: function() 1364 { 1365 // disabled on mobile screens 1366 if (!$.fn.magnificPopup || $(window).width() < 768 || !$('body').hasClass('has-lb')) { 1367 return; 1368 } 1369 1370 /** 1371 * Filter to handle valid images only. 1372 */ 1373 var filterImages = function() { 1374 1375 if (!$(this).attr('href')) { 1376 return false; 1377 } 1378 1379 return $(this).attr('href').match(/\.(jpe?g|webp|png|bmp|gif)($|\?.+?)/); 1380 }; 1381 1382 var mfp_init = { 1383 type: 'image', 1384 tLoading: '', 1385 mainClass: 'mfp-fade mfp-img-mobile', 1386 removalDelay: 300, 1387 callbacks: { 1388 afterClose: function() { 1389 if (this._lastFocusedEl) { 1390 $(this._lastFocusedEl).addClass('blur'); 1391 } 1392 } 1393 } 1394 }; 1395 1396 /** 1397 * Handle Galleries in post 1398 */ 1399 1400 var gal_selectors = '.gallery-slider, .post-content .gallery, .post-content .blocks-gallery-item, .post-content .tiled-gallery, .wp-block-gallery .wp-block-image, .tiled-gallery__gallery .tiled-gallery__item'; 1401 1402 // Filter to only tie valid images. 1403 $(gal_selectors) 1404 .find('a') 1405 .has('img') 1406 .filter(filterImages) 1407 .addClass('lightbox-gallery-img'); 1408 1409 // Add WooCommerce support 1410 $('.woocommerce a[data-rel^="prettyPhoto"], a.zoom').addClass('lightbox-gallery-img'); 1411 gal_selectors += ', .woocommerce .images'; 1412 1413 // attach the lightbox as gallery 1414 $(gal_selectors).magnificPopup($.extend({}, mfp_init, { 1415 delegate: '.lightbox-gallery-img', 1416 gallery: {enabled: true}, 1417 image: { 1418 titleSrc: function(item) { 1419 var image = item.el.find('img'), 1420 caption = item.el.find('.caption').html(); 1421 1422 return (caption || image.attr('title') || ' '); 1423 } 1424 } 1425 })); 1426 1427 // Non-gallery images in posts 1428 var selector = $('.post-content, .main .featured, .single-creative .featured') 1429 .find('a:not(.lightbox-gallery-img)').has('img'); 1430 1431 selector.add('.post-content, .main .featured, .lightbox-img') 1432 .filter(filterImages) 1433 .magnificPopup(mfp_init); 1434 }, 1435 1436 /** 1437 * Pinterest Pin It 1438 */ 1439 pin_it: function() 1440 { 1441 var button = $('body .pinit-btn'), 1442 the_button = button.prop('outerHTML'), 1443 index = 1; 1444 1445 // Only proceed if non-touch device and button exists 1446 if (has_touch || !the_button) { 1447 return; 1448 } 1449 1450 var show_on = button.data('show-on').split(','); 1451 1452 var get_image = function(ele) { 1453 if (!ele.is('img')) { 1454 ele = ele.find('img').first(); 1455 } 1456 1457 return ele; 1458 }; 1459 1460 var setup = function() { 1461 1462 var selectors = []; 1463 if (show_on.indexOf('single') !== -1) { 1464 selectors.push('.post-content img, .single-cover .featured, .single:not(.layout-creative) .featured .image-link'); 1465 } 1466 1467 if (show_on.indexOf('listing') !== -1) { 1468 selectors.push('.posts-container .post-header .image-link, .posts-container .post-thumb .image-link'); 1469 } 1470 1471 selectors = selectors.join(', '); 1472 1473 $(selectors) 1474 .on('mouseenter', function() { 1475 1476 var img = get_image($(this)), 1477 wrap = img.parent(); 1478 1479 if (img.hasClass('nopin') || img.width() < 200 || img.height < 200) { 1480 return; 1481 } 1482 1483 var pos = img.position(), 1484 media = img.prop('src'), 1485 url, desc, button; 1486 1487 // URL 1488 if ($('body').hasClass('single')) { 1489 url = window.location.href; 1490 } 1491 else { 1492 1493 if (wrap.hasClass('image-link')) { 1494 url = wrap.prop('href'); 1495 } 1496 else { 1497 url = img.closest('.post').find('.post-title-alt a, .post-title a').prop('href'); 1498 } 1499 1500 // featured img has post title 1501 desc = img.prop('title'); 1502 } 1503 1504 // desc = img.prop('alt') || img.prop('title'); 1505 1506 if (!url) { 1507 return; 1508 } 1509 1510 // Create if not already done 1511 if (!img.data('pinit-id')) {
1512 button = $(the_button).appendTo(wrap); 1513 1514 if (!desc) { 1515 desc = button.data('heading'); 1516 } 1517 1518 var url_format = button.prop('href') 1519 .replace('%media%', encodeURIComponent(media)) 1520 .replace('%url%', encodeURIComponent(url)) 1521 .replace('%desc%', encodeURIComponent(desc)); 1522 1523 button.prop('href', url_format); 1524 1525 button.on('click', function(e) { 1526 e.preventDefault(); 1527 e.stopPropagation(); 1528 1529 window.open($(this).prop('href'), '_blank'); 1530 }); 1531 1532 index++; 1533 img.attr('data-pinit-id', index); 1534 button.attr('data-pinit-id', index); 1535 } 1536 else { 1537 // Existing button 1538 button = wrap.find('a[data-pinit-id=' + img.data('pinit-id') +']'); 1539 } 1540 1541 button.addClass('show').css({ 1542 top: pos.top + parseInt(img.css('marginTop')) + parseInt(img.css('paddingTop')), 1543 left: pos.left + parseInt(img.css('marginLeft')) + parseInt(img.css('paddingLeft')) 1544 }); 1545 }) 1546 .on('mouseleave', function(e) { 1547 1548 var ele = get_image($(this)).parent(); 1549 1550 if ($(e.relatedTarget).hasClass('pinit-btn')) { 1551 return; 1552 } 1553 1554 ele.find('.pinit-btn').removeClass('show'); 1555 }); 1556 }; 1557 1558 setup(); 1559 $(document).on('ajax-pagination', setup); 1560 1561 }, 1562 1563 lazy_load: function() 1564 { 1565 var type = $('body').prop('className').match(/lazy-([^\s]+)/); 1566 if (!type || !window.lazySizes) { 1567 return; 1568 } 1569 type = type[1]; 1570 1571 // Debounced resize trigger 1572 var timer; 1573 var loaded = function() { 1574 clearTimeout(timer); 1575 timer = setTimeout(function() { 1576 $(window).trigger('resize.TSS'); 1577 }, 50); 1578 }; 1579 1580 $(document).on('lazyloaded', '.main', function(e) { 1581 loaded(); 1582 }); 1583 1584 // Only for "smart" type and large desktops 1585 if (type != 'smart' || $(window).width() < 1380) { 1586 return; 1587 } 1588 1589 // Deferred preload 1590 var is_loaded = false; 1591 var defer_load = function() { 1592 1593 if (is_loaded) { 1594 return; 1595 } 1596 1597 $('img.lazyload').each(function() { 1598 lazySizes.loader.unveil($(this).get(0)); 1599 }); 1600 1601 is_loaded = true; 1602 }; 1603 1604 // With delay or immediate on scroll (touch, mousemove other candidates) 1605 var events = 'scroll.ll'; 1606 $(window).on(events, function() { 1607 defer_load(); 1608 $(this).off(events); 1609 }); 1610 1611 self._wait_load(defer_load, {ready: true}); 1612 }, 1613 1614 /** 1615 * Setup masonry on archives 1616 */ 1617 masonry: function(reload, posts, grid) 1618 { 1619 1620 if ($.fn.masonry && $('.posts-dynamic').hasClass('masonry')) { 1621 var grid = grid || $('.posts-dynamic.masonry .posts-wrap'); 1622 1623 if (!grid.length) { 1624 return; 1625 } 1626 1627 grid.on('layoutComplete', function() { 1628 requestAnimationFrame(function() { 1629 $(window).trigger('resize.TSS'); 1630 }); 1631 }); 1632 1633 // Reload masonry? 1634 if (reload && posts) { 1635 1636 var posts = grid.find(posts).css({ opacity: 0 }); 1637 1638 grid.each(function() { 1639 1640 $(this).imagesLoaded(function() { 1641 posts.css({ opacity: 1 }); 1642 grid.masonry('appended', posts, true); 1643 }); 1644 }); 1645 } 1646 else { 1647 grid.each(function() { 1648 $(this).imagesLoaded(function() { 1649 grid.masonry(); 1650 }); 1651 }); 1652 } 1653 } 1654 } 1655 1656 }; // end module 1657 1658 // Utils 1659 function writeRaf(fn, options) { 1660 var running, 1661 args, 1662 that; 1663 1664 var run = function() { 1665 running = false; 1666 fn.apply(that, args); 1667 }; 1668 1669 if (!options) { 1670 options = {}; 1671 } 1672 1673 return function() { 1674 args = arguments; 1675 that = options.that || this; 1676 1677 if (!running) { 1678 running = true; 1679 requestAnimationFrame(run); 1680 } 1681 }; 1682 } 1683 1684 return self; 1685 1686})(jQuery); 1687 1688/** 1689 * Social Sharing float behavior 1690 */ 1691var Bunyad_Share_Float = (function($) { 1692 "use strict"; 1693 1694 /** 1695 * Check if element intersects 1696 */ 1697 var intersects = function(el1, el2) { 1698 var rect1 = el1.getBoundingClientRect(); 1699 var rect2 = el2.getBoundingClientRect(); 1700 1701 return !( 1702 rect1.top > rect2.bottom || 1703 rect1.right < rect2.left || 1704 rect1.bottom < rect2.top || 1705 rect1.left > rect2.right 1706 ); 1707 } 1708 1709 var start_at = 0; 1710 1711 return { 1712 init: function() { 1713 1714 if (!$('.post-share-float').length) { 1715 return; 1716 } 1717 1718 $(window).on('resize load resize.TSS', this.theInit.bind(this)); 1719 document.readyState !== 'complete' || this.theInit(); 1720 }, 1721 1722 theInit: function() { 1723 this.init_calc(); 1724 this.sticky(); 1725 this.visibility(); 1726 }, 1727 1728 /** 1729 * Pre-calc for performance 1730 */ 1731 init_calc: function() { 1732 1733 if (!$('body').hasClass('no-sidebar') && !$('.the-post-modern').length) { 1734 var featured = $('.the-post-header .featured, .single-creative .featured, .single-cover .featured, .single-magazine .featured'); 1735 if (featured.length) { 1736 start_at = featured.position().top; 1737 } 1738 else { 1739 var post_header = $('.the-post-header'); 1740 start_at = post_header.length ? post_header.position().top : 0; 1741 } 1742 } 1743 }, 1744 1745 /** 1746 * Setup sticky float 1747 */ 1748 sticky: function() { 1749 // Floating social sharing 1750 var add = 20; 1751 add += $('.admin-bar').length ? 32 : 0; 1752 add += Bunyad_Theme.has_sticky_nav ? 50 : 0; 1753 var width = $(window).width(); 1754 1755 $('.post-share-float').each(function() { 1756 1757 var post_foot = $('.the-post-foot').outerHeight(true) + 50; 1758 $(this).css('height', $('.the-post .post-content').height() + (width > 1500 ? post_foot : 0) + 'px'); 1759 1760 $(this).theiaStickySidebar({ 1761 minWidth: 768, 1762 updateSidebarHeight: false, 1763 defaultPosition: 'absolute', 1764 additionalMarginTop: add 1765 }); 1766 }); 1767 }, 1768 1769 /** 1770 * Determine when to show and hide 1771 */ 1772 visibility: function() { 1773 1774 if ($(window).width() < 768) { 1775 return false;
1776 } 1777 1778 var intersect_sels = [ 1779 '.the-post-modern .alignfull', 1780 '.the-post-modern .alignwide', 1781 '.the-post-modern .gallery:not(.aligncenter)', 1782 '.the-post-modern .wp-block-gallery:not(.aligncenter)', 1783 '.the-post-modern figure.alignnone', 1784 '.the-post-modern img.alignnone', 1785 ]; 1786 1787 var observe = [], 1788 share_ele = $('.post-share-float'); 1789 1790 $(intersect_sels.join(',')).each(function() { 1791 observe.push(this); 1792 }); 1793 1794 $(window).on('scroll', function() { 1795 var is_hidden = false, 1796 ele = share_ele.find('.theiaStickySidebar').get(0); 1797 1798 if ($(window).scrollTop() < start_at) { 1799 is_hidden = true; 1800 } 1801 else { 1802 1803 // Check if any of the observed elements intersect 1804 for (var i in observe) { 1805 if (intersects(ele, observe[i])) { 1806 is_hidden = true; 1807 break; 1808 } 1809 } 1810 } 1811 1812 (is_hidden 1813 ? share_ele.addClass('is-hidden') 1814 : share_ele.removeClass('is-hidden') 1815 ); 1816 }); 1817 } 1818 } 1819})(jQuery); 1820 1821 1822/** 1823 * Pagination handlers 1824 */ 1825var Bunyad_Pagination = (function($) { 1826 "use strict"; 1827 1828 // Blocks load more 1829 var processing = false, 1830 cache = []; 1831 1832 var self = { 1833 1834 init: function() { 1835 // AJAX pagination handlers 1836 $('.main').on('click', '.main-pagination .load-button, .block .main-pagination.number a', this.ajax_pagination); 1837 }, 1838 1839 /** 1840 * Initiate handling of AJAX pagination 1841 */ 1842 ajax_pagination: function(e) 1843 { 1844 if (processing) { 1845 return false; 1846 } 1847 1848 // Type of pagination 1849 var type = 'more'; 1850 if ($(this).closest('.main-pagination').hasClass('number')) { 1851 type = 'number'; 1852 } 1853 1854 var ele = $(this), 1855 block = ele.closest('.block'), 1856 post_id = ele.closest('.page-content, .post-content').data('id'), 1857 page = ele.data('page') + 1, 1858 is_block = true; 1859 1860 // Not a block, archives 1861 if (!block.length) { 1862 is_block = false; 1863 block = ele.closest('.main-content'); 1864 } 1865 1866 // AJAX params 1867 var params = { 1868 '_bunyad_act': 'block', 1869 'page_id': post_id, 1870 'paged': page, 1871 'block_id': block.data('id') 1872 }; 1873 1874 switch(type) { 1875 1876 // Type: Load More 1877 case 'more': 1878 ele.addClass('loading').find('.tsi').addClass('tsi-spin'); 1879 1880 // Processing method for load more 1881 var process = self.process_load_more; 1882 1883 break; 1884 1885 // Type: Numbered 1886 case 'number': 1887 block.find('.block-content').addClass('loading'); 1888 1889 // Change page number 1890 var permalink = ele.attr('href').match(/\/page\/(\d+)\//); 1891 if (permalink !== null) { 1892 params.paged = permalink[1]; 1893 } 1894 else { 1895 // Plain links 1896 var src = ele.attr('href').match(/(\?|&)paged?=(\d+)/); 1897 params.paged = src ? src[2] : 1; 1898 } 1899 1900 // Set height 1901 block.css('height', block.height()); 1902 1903 var process = function(data) { 1904 cache[params.paged] = data; 1905 var content = $(data), 1906 block_content = block.find('.block-content'); 1907 1908 block_content.removeClass('fade-in-down-lg') 1909 .html($(data).find('.block-content').html()); 1910 1911 block.css('height', 'auto'); 1912 block_content.addClass('fade-in-down-lg').removeClass('loading'); 1913 1914 // position correctly 1915 $('html, body').animate({scrollTop: block.offset().top - 50}, 200); 1916 1917 $(document).trigger('ajax-pagination'); 1918 }; 1919 1920 // In cache? 1921 if (cache[params.paged]) { 1922 processing = false; 1923 process(cache[params.paged]); 1924 1925 return false; 1926 } 1927 1928 break; 1929 } 1930 1931 // Process block 1932 if (is_block) { 1933 1934 // Home blocks AJAX 1935 var ajax_url = Bunyad.custom_ajax_url; 1936 ajax_url += (ajax_url.indexOf('?') !== -1 ? '&' : '?'); 1937 1938 processing = $.get(ajax_url + $.param(params), function(data) { 1939 process(data, block, ele); 1940 }) 1941 .always(function() { 1942 // All done 1943 processing = false; 1944 }); 1945 } 1946 else { 1947 1948 // Archives AJAX 1949 var ajax_url = $(this).attr('href'); 1950 processing = $.get(ajax_url, function(data) { 1951 data = $(data).find('.main-content').get(0); 1952 process(data, block, ele); 1953 }) 1954 .always(function() { 1955 // All done 1956 processing = false;
1957 }); 1958 } 1959 1960 return false; 1961 }, 1962 1963 /** 1964 * Load More Ajax callback method 1965 */ 1966 process_load_more: function(data, block, ele) 1967 { 1968 var content = $(data), 1969 wrap = block.find('.posts-container'), 1970 posts; 1971 1972 if (content.find('.posts-container').hasClass('mixed')) { 1973 posts = content.find('.posts-dynamic').children().addClass('fade-in-up-lg'); 1974 wrap.append(posts); 1975 } 1976 else { 1977 // Directly below or in a .posts-wrap wrapper? 1978 // WARNING: Always have .posts-wrap to prevent unexpected bugs 1979 var container = block.find('.posts-wrap').length ? '.posts-wrap' : '.posts-container'; 1980 1981 posts = content.find(container).children().addClass('fade-in-up-lg'); 1982 block.find(container).append(posts); 1983 } 1984 1985 // Masonry reload 1986 if (wrap.hasClass('masonry')) { 1987 //posts.removeClass('fade-in-up-lg'); 1988 Bunyad_Theme.masonry(true, posts, wrap.find('.posts-wrap')); 1989 } 1990 1991 $(document).trigger('ajax-pagination'); 1992 1993 block.find('.main-pagination') 1994 .replaceWith(content.find('.main-pagination')); 1995 1996 ele.removeClass('loading') 1997 .find('.tsi').removeClass('tsi-spin'); 1998 } 1999 }; 2000 2001 return self; 2002 2003})(jQuery); 2004 2005// load when ready 2006jQuery(function($) { 2007 "use strict"; 2008 2009 // Init 2010 var init = function() { 2011 Bunyad_Theme.init(); 2012 Bunyad_Pagination.init(); 2013 }; 2014 2015 init(); 2016}); 2017 2018/** 2019 * Plus/minus polyfill for numbers - used in WooCommerce 2020 * 2021 * Author Bryce Adams 2022 */ 2023jQuery( function( $ ) { 2024 2025 // Quantity buttons 2026 $( 'div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)' ) 2027 .addClass( 'buttons_added' ) 2028 .append( '<div class="vertical-buttons"><input type="button" value="+" class="plus" /><input type="button" value="-" class="minus" /></div>' ); 2029 2030 $( document ).on( 'click', '.plus, .minus', function() { 2031 2032 // Get values 2033 var $qty = $( this ).closest( '.quantity' ).find( '.qty' ), 2034 currentVal = parseFloat( $qty.val() ), 2035 max = parseFloat( $qty.attr( 'max' ) ), 2036 min = parseFloat( $qty.attr( 'min' ) ), 2037 step = $qty.attr( 'step' ); 2038 2039 // Format values 2040 if ( ! currentVal || currentVal === '' || currentVal === 'NaN' ) currentVal = 0; 2041 if ( max === '' || max === 'NaN' ) max = ''; 2042 if ( min === '' || min === 'NaN' ) min = 0; 2043 if ( step === 'any' || step === '' || step === undefined || parseFloat( step ) === 'NaN' ) step = 1; 2044 2045 // Change the value 2046 if ( $( this ).is( '.plus' ) ) { 2047 2048 if ( max && ( max == currentVal || currentVal > max ) ) { 2049 $qty.val( max ); 2050 } else { 2051 $qty.val( currentVal + parseFloat( step ) ); 2052 } 2053 2054 } else { 2055 2056 if ( min && ( min == currentVal || currentVal < min ) ) { 2057 $qty.val( min ); 2058 } else if ( currentVal > 0 ) { 2059 $qty.val( currentVal - parseFloat( step ) ); 2060 } 2061 2062 } 2063 2064 // Trigger change event 2065 $qty.trigger( 'change' ); 2066 2067 }); 2068 2069});
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.