1(function ($) { 2 'use strict'; 3 4 var options = { 5 mobileBreakPoint: 768 6 }; 7 8 var main = { 9 init: function () { 10 11 this.eventHandlers = {}; 12 13 this.burgerMenuBtn = '.burger-button'; 14 this.mobileMenu = '.header .main-nav'; 15 16 this.header = '.header'; 17 this.scrollableWrap = '.scrollable-wrap'; 18 19 this.bindEvents(); 20 this.initTopBar(); 21 this.initScrollBar(); 22 this.initSticky(); 23 this.addTargetBlankExternalLinks(); 24 }, 25 26 bindEvents: function () { 27 var self = this; 28 29 this.eventHandlers.burgerBtnHandler = self.burgerBtnHandler.bind(this); 30 this.eventHandlers.toggleMobileSubMenu = self.toggleMobileSubMenu.bind(this); 31 32 window.addEventListener('resize', self.setViewPortHeight.bind(this), {passive: true}); 33 34 $(document.body).on('click', this.burgerMenuBtn, this.eventHandlers.burgerBtnHandler); 35 $(self.mobileMenu).on('click', '.arrow', this.eventHandlers.toggleMobileSubMenu); 36 }, 37 38 burgerBtnHandler: function (e) { 39 this.mobileMenuToggleHandler(!e.currentTarget.classList.contains('btn-open')); 40 }, 41 42 mobileMenuToggleHandler: function (state) { 43 var self = this; 44 45 if (state) { 46 document.body.classList.add('mobile-menu-opened'); 47 document.querySelector(this.burgerMenuBtn).classList.add('btn-open'); 48 document.querySelector(this.mobileMenu).classList.add('show'); 49 50 setTimeout(function () { 51 document.querySelector(self.mobileMenu).classList.add('fade-in'); 52 }, 100); 53 } else { 54 document.querySelector(this.burgerMenuBtn).classList.remove('btn-open'); 55 56 document.querySelector(this.mobileMenu).classList.remove('fade-in'); 57 58 setTimeout(function () { 59 document.querySelector(self.mobileMenu).classList.remove('show'); 60 document.body.classList.remove('mobile-menu-opened'); 61 }, 600); 62 } 63 }, 64 65 toggleMobileSubMenu: function (e) { 66 $(e.target).closest('.menu-item').find('.sub-menu').stop().slideToggle(); 67 }, 68 69 initSticky: function () { 70 var container = '.has-sticky'; 71 var self = this; 72 73 if ($('.sticky').length === 0) return; 74 75 self.sticky = new StickySidebar('.sticky', { 76 topSpacing: $(self.header).outerHeight(), 77 containerSelector: container, 78 innerWrapperSelector: '.sticky-inner', 79 minWidth: 768 80 }); 81 82 $(document.body).bind('ajax_load_more_posts_loaded', function () { 83 self.sticky.updateSticky(); 84 }); 85 }, 86 87 initScrollBar() { 88 var self = this; 89 90 if ($(self.scrollableWrap).length > 0) { 91 $(self.scrollableWrap).each(function () { 92 $(this).scrollBar(); 93 }); 94 } 95 }, 96 97 setViewPortHeight: function () { 98 // We execute the same script as before 99 let vh = window.innerHeight * 0.01; 100 document.documentElement.style.setProperty('--vh', `${vh}px`); 101 }, 102 103 initTopBar: function () { 104 var self = this; 105 106 self.topbar = '.header-top-bar'; 107 108 if (Cookies.get('disableTopBar') !== '1') { 109 document.documentElement.classList.add('top-bar-active'); 110 111 $(self.topbar).on('click', '.btn-close', function () { 112 Cookies.set('disableTopBar', '1', {expires: 30}) 113 document.documentElement.classList.remove('top-bar-active'); 114 }); 115 } 116 }, 117 118 addTargetBlankExternalLinks: function () { 119 var a = new RegExp('/' + window.location.host + '/'); 120 121 $(document.body).on('click', 'a', function () { 122 if (this.href && !a.test(this.href)) { 123 this.target = '_blank'; 124 } 125 }); 126 }, 127 }; 128 129 var homePage = { 130 init: function () { 131 this.homeSlider = '.slick-home'; 132 133 this.initSlick(); 134 }, 135 136 initSlick: function () { 137 var self = this; 138 139 if (!document.querySelector(self.homeSlider)) { 140 return; 141 } 142 143 $(self.homeSlider).slick({ 144 autoplay: true, 145 infinite: true, 146 autoplaySpeed: 5000, 147 }); 148 }, 149 }; 150 151 var galleriesPage = { 152 153 init: function () { 154 var self = this; 155 156 }, 157 158 bindEvents: function () { 159 } 160 }; 161 162 var gallerySinglePage = { 163 164 init: function () { 165 this.galleryFancybox = '[data-fancybox="gallery"]'; 166 167 this.initFancybox(); 168 }, 169 170 initFancybox: function () { 171 var $galleryFancybox = $(this.galleryFancybox); 172 173 if ($galleryFancybox.length === 0) { 174 return; 175 } 176 177 $galleryFancybox.fancybox({ 178 caption: function (instance, item) { 179 var count = $(this).closest('.gallery').find('.gallery-item').length; 180 return ( 181 `${item.index + 1} / ${count}` 182 ); 183 }, 184 lang: "dk", 185 i18n: { 186 dk: { 187 NEXT: "NÃSTE", 188 PREV: "FORRIGE", 189 } 190 }, 191 baseTpl: 192 '<div class="fancybox-container" role="dialog" tabindex="-1">' + 193 '<div class="fancybox-bg"></div>' + 194 '<div class="fancybox-inner">' + 195 '<div class="fancybox-infobar"><span data-fancybox-index></span> / <span data-fancybox-count></span></div>' + 196 '<div class="fancybox-toolbar">{{buttons}}</div>' + 197 '<div class="fancybox-stage"></div>' + 198 '<div class="fancybox-caption"><div class="fancybox-caption__body"></div>{{arrows}}</div>' + 199 '</div>' + 200 '</div>', 201 btnTpl: { 202 arrowLeft: 203 '<button data-fancybox-prev class="fancybox-button fancybox-button--arrow_left" title="{{PREV}}">{{PREV}}</button>', 204 arrowRight: 205 '<button data-fancybox-next class="fancybox-button fancybox-button--arrow_right" title="{{NEXT}}">{{NEXT}}</button>', 206 } 207 }); 208 }, 209 }; 210 211 var filter = { 212 213 init: function (wrapper) { 214 var self = this; 215 216 self.$wrapper = $(wrapper); 217 218 if (self.$wrapper.length === 0) { 219 return; 220 } 221 222 self.historyKey = wrapper; 223 self.actionUrl = self.$wrapper.find('form[action]').attr('action'); 224 225 self.contentPosts = self.$wrapper.data('content-posts'); 226 self.contentFilter = self.$wrapper.data('content-filter'); 227 228 self.termsCheckBox = 'input[type="checkbox"].term'; 229 self.taxonomyTermsValue = '.taxonomy-terms-value'; 230 self.searchValue = '.filter-search input.search-value'; 231 self.searchButton = '.filter-search button.btn-search'; 232 233 history.replaceState(self.historyKey, null, null); 234 self.bindEvents(); 235 236 self.searchPopup.init('#sidebar-search-content'); 237 }, 238 239 bindEvents: function () { 240 var self = this; 241 242 self.$wrapper.on('submit', '.filter-body form', function () { 243 self.filterAction($(this).serialize(), true); 244 245 return false;
246 }); 247 248 self.$wrapper.on('change', self.termsCheckBox, function () { 249 self.onChangeCheckBox($(this)); 250 }); 251 252 self.$wrapper.on('click', '.btn-reset-filter', function (e) { 253 e.preventDefault(); 254 self.filterAction('', true); 255 }); 256 257 self.$wrapper.on('click', '.btn-show-all', function (e) { 258 e.preventDefault(); 259 260 var $wrapper = $(this).closest('.taxonomy-filter'); 261 262 if (!this.classList.contains('less')) { 263 this.classList.add('less'); 264 $wrapper.find('.term-label.hidden').addClass('shown'); 265 this.innerText = this.dataset.showLess; 266 } else { 267 this.classList.remove('less'); 268 $wrapper.find('.term-label.hidden').removeClass('shown'); 269 this.innerText = this.dataset.showAll; 270 } 271 }); 272 273 $(self.contentPosts).on('change', '.filter-selected-terms input.term', function (e) { 274 e.preventDefault(); 275 276 var termValue = this.value, 277 urlParams = new URLSearchParams(window.location.search), 278 buildActionUrl = [], values, newValues = []; 279 280 for (const key of urlParams.keys()) { 281 values = urlParams.get(key).split(','); 282 newValues = []; 283 284 for (const value of values) { 285 if (termValue !== value) { 286 newValues.push(value) 287 } 288 } 289 290 if (newValues.length > 0) { 291 buildActionUrl.push(key + '=' + newValues.join(',')); 292 } 293 } 294 295 self.filterAction(buildActionUrl.join('&'), true); 296 }); 297 298 window.addEventListener('popstate', self.filterHistoryHandler); 299 300 $.fn.scrollBar.init('.filter-selected-terms'); 301 }, 302 303 onChangeCheckBox: function ($this) { 304 var self = this, 305 $form = $this.closest('form'), 306 $taxonomy = $this.closest('.filter-terms'), 307 $taxonomyTermsValue = $taxonomy.find(self.taxonomyTermsValue), 308 values = this.prepareValues($taxonomy); 309 310 if (values.length === 0) { 311 $taxonomyTermsValue.prop('disabled', true); 312 } else { 313 $taxonomyTermsValue.prop('disabled', false); 314 } 315 316 self.propSearch(); 317 318 $taxonomyTermsValue.val(values.join(',')); 319 $form.trigger('submit'); 320 }, 321 322 filterAction: function (actionData, pushState) { 323 var self = this, 324 historyUrl = self.actionUrl, 325 visibility = []; 326 327 $(self.contentFilter).find('.filter-terms').each(function () { 328 if ($(this).find('.btn-show-all').hasClass('less')) { 329 visibility.push($(this).attr('id')); 330 } 331 }); 332 333 $.get(self.actionUrl + '?_ajax=1', actionData).done(function (response) { 334 var $response = $('<div>' + response + '</div>'), 335 title = $response.find('#wp_title').text(); 336 337 $(self.contentPosts).html($(response).find(self.contentPosts).html()); 338 $(self.contentFilter).html($(response).find(self.contentFilter).html()); 339 $('.total-posts').html($(response).find('.total-posts').html()); 340 341 visibility.forEach(function (taxonomy) { 342 var $taxonomyFilter = $('#' + taxonomy), 343 $showButton = $taxonomyFilter.find('.btn-show-all'); 344 345 $taxonomyFilter.find('.taxonomy-filter .term-label.hidden').addClass('shown'); 346 347 if ($showButton.length) { 348 $showButton.get(0).classList.add('less'); 349 $showButton.get(0).innerText = $showButton.get(0).dataset.showLess; 350 } 351 }); 352 353 grid.resizeGrid($(self.contentPosts).find('.grid')); 354 355 if (actionData !== '' && actionData !== 'paged=1') { 356 historyUrl = '?' + actionData; 357 } 358 359 console.log(historyUrl); 360 361 if (pushState === true) { 362 history.pushState(self.historyKey, title, removeURLParameter(historyUrl, 'paged')); 363 document.title = title; 364 } 365 366 self.propSearch(false); 367 }); 368 }, 369 370 filterHistoryHandler: function (e) { 371 var self = filter; 372 373 if (e.state === self.historyKey) { 374 self.filterAction(document.location.search.replace('?', ''), false); 375 } else { 376 e.preventDefault(); 377 return false;
378 } 379 }, 380 381 prepareValues: function ($taxonomy) { 382 var self = this; 383 384 let values = []; 385 386 $taxonomy.find(self.termsCheckBox + ':checked').filter(function () { 387 values.push(this.value); 388 }); 389 390 return values; 391 }, 392 393 getQueryParameters: function (str) { 394 var self = this; 395 396 return (str || document.location.search).replace(/(^\?)/, '').split("&").map(function (n) { 397 return n = n.split("="), this[n[0]] = n[1], this 398 }.bind({}))[0]; 399 }, 400 401 propSearch: function (state) { 402 var self = this; 403 404 if (document.querySelector(self.searchValue) === null) { 405 return; 406 } 407 408 if (state !== undefined) { 409 document.querySelector(self.searchValue).disabled = state; 410 return; 411 } 412 413 if (document.querySelector(self.searchValue).value === '') { 414 document.querySelector(self.searchValue).disabled = true; 415 } else { 416 document.querySelector(self.searchValue).disabled = false; 417 } 418 }, 419 420 searchPopup: { 421 init: function (searchInput) { 422 var self = this; 423 424 if (document.querySelector(searchInput) === null) { 425 return; 426 } 427 428 self.keyPressTimer = 0; 429 self.searchInput = searchInput; 430 self.resultCache = []; 431 self.ajaxAction = document.querySelector(searchInput).dataset.ajaxAction; 432 433 self._filterBody = document.querySelector('.filter-body'); 434 self._searchResultProducts = document.querySelector('.search-body'); 435 436 self.bindEvents(); 437 }, 438 439 bindEvents: function () { 440 var self = this; 441 442 document.querySelector(self.searchInput).closest('form') 443 .addEventListener('submit', function (e) { 444 e.preventDefault(); 445 }); 446 447 $(document.body).on('input', self.searchInput, function (e) { 448 e.preventDefault(); 449 450 var keyword = this.value; 451 452 clearTimeout(self.keyPressTimer); 453 454 self.keyPressTimer = setTimeout(function () { 455 self.sendRequest(keyword); 456 }, 400); 457 }); 458 }, 459 460 sendRequest: function (keyword) { 461 var self = this; 462 463 if (keyword.length < 3) { 464 self.showResult(false); 465 return; 466 } 467 468 if (self.resultCache[keyword]) { 469 self.showResult(self.resultCache[keyword]); 470 return; 471 } 472 473 $.ajax({ 474 url: theme_params.ajax_url, 475 method: "POST", 476 dataType: 'json', 477 data: { 478 action: 'theme_ajax', 479 ajax_action: self.ajaxAction, 480 keyword: keyword 481 }, 482 beforeSend: function () { 483 self._searchResultProducts.classList.add('loading'); 484 }, 485 complete: function () { 486 self._searchResultProducts.classList.remove('loading'); 487 }, 488 success: function (response) { 489 self.resultCache[keyword] = response.data; 490 self.showResult(response.data); 491 }, 492 }); 493 }, 494 495 showResult: function (data) { 496 var self = this; 497 498 self._searchResultProducts.innerHTML = ''; 499 500 if (false === data) { 501 self._filterBody.style.display = 'block'; 502 self._searchResultProducts.style.display = 'none'; 503 return; 504 } 505 506 self._filterBody.style.display = 'none'; 507 self._searchResultProducts.style.display = 'block'; 508 509 var regExp = new RegExp(data.keyword, "gi"); 510 511 if (data.found_products !== 0) {
512 data.products.forEach(function (product) { 513 product.title = product.title.replace(regExp, function (match) { 514 return `<mark>${match}</mark>`; 515 }); 516 517 const markup = ` 518 <div class="search-post"> 519 <a href="${product.url}"> 520 <div class="post-title"> 521 ${product.title} 522 </div> 523 </a> 524 </div>`; 525 526 self._searchResultProducts.insertAdjacentHTML('afterbegin', markup); 527 }); 528 } else { 529 const markup = `<p class="nothing-found">${data.message}</p>`; 530 531 self._searchResultProducts.insertAdjacentHTML('afterbegin', markup); 532 } 533 } 534 } 535 536 }; 537 538 var search = { 539 init: function () { 540 var self = this; 541 542 self.searchInput = '#site-search-content'; 543 544 if (document.querySelector(self.searchInput) === null) { 545 return; 546 } 547 548 self.keyPressTimer = 0; 549 self.resultCache = []; 550 551 self._trendingBody = document.querySelector('#search-sidebar .trending-body'); 552 self._searchResult = document.querySelector('#search-sidebar .search-body'); 553 self._showMoreResults = document.querySelector('#search-sidebar .show-more-results'); 554 555 self.bindEvents(); 556 }, 557 558 bindEvents: function () { 559 var self = this; 560 561 $(document.body).on('input', self.searchInput, function (e) { 562 e.preventDefault(); 563 564 var keyword = this.value; 565 566 clearTimeout(self.keyPressTimer); 567 568 self.keyPressTimer = setTimeout(function () { 569 self.sendRequest(keyword); 570 }, 400); 571 }); 572 573 $(document.body).on('click', '.load-more-search .load-more-button', function (e) { 574 e.preventDefault(); 575 576 self.loadMore(this, this.dataset.paged, this.dataset.post_type, this.dataset.search_term); 577 }); 578 }, 579 580 sendRequest: function (keyword) { 581 var self = this; 582 583 if (keyword.length < 3) { 584 self.showResult(false); 585 return; 586 } 587 588 if (self.resultCache[keyword]) { 589 self.showResult(self.resultCache[keyword]); 590 return; 591 } 592 593 $.ajax({ 594 url: theme_params.ajax_url, 595 method: "POST", 596 dataType: 'json', 597 data: { 598 action: 'theme_ajax', 599 ajax_action: 'site_search', 600 keyword: keyword 601 }, 602 beforeSend: function () { 603 self._searchResult.classList.add('loading'); 604 }, 605 complete: function () { 606 self._searchResult.classList.remove('loading'); 607 }, 608 success: function (response) { 609 self.resultCache[keyword] = response.data; 610 self.showResult(response.data); 611 }, 612 }); 613 }, 614 615 showResult: function (data) { 616 var self = this, 617 resultHtml = ''; 618 619 self._searchResult.innerHTML = ''; 620 621 if (false === data) { 622 self._trendingBody.style.display = 'block'; 623 self._searchResult.style.display = 'none'; 624 self._showMoreResults.style.visibility = 'hidden'; 625 return; 626 } 627 628 self._trendingBody.style.display = 'none'; 629 self._searchResult.style.display = 'block'; 630 self._showMoreResults.style.visibility = 'hidden'; 631 632 if (data.count_posts !== 0) { 633 resultHtml += self.getPostsLayout(data.central_banks, theme_params.labels.central_banks_title, data.keyword); 634 resultHtml += self.getPostsLayout(data.posts, theme_params.labels.news_title, data.keyword); 635 resultHtml += self.getPostsLayout(data.research, theme_params.labels.research_title, data.keyword); 636 637 self._searchResult.insertAdjacentHTML('afterbegin', resultHtml); 638 self._showMoreResults.style.visibility = 'visible'; 639 } else { 640 const markup = `<p class="nothing-found">${data.message}</p>`; 641 642 self._searchResult.insertAdjacentHTML('afterbegin', markup); 643 } 644 }, 645 646 getPostsLayout: function (posts, title, keyword) { 647 var markup = '', 648 regExp = new RegExp(keyword, "gi"); 649 650 if (posts.length > 0) { 651 652 markup += `<div class="search-post">`; 653 markup += `<span class="title-search-label">${title}</span>`;
654 markup += `<ul>`; 655 656 posts.forEach(function (post) { 657 post.title = post.title.replace(regExp, function (match) { 658 return `<mark>${match}</mark>`; 659 }); 660 661 markup += ` 662 <li> 663 <a href="${post.url}"> 664 <div class="post-title"> 665 ${post.title} 666 </div> 667 </a> 668 </li>`; 669 }); 670 671 markup += `</ul></div>`; 672 } 673 674 return markup; 675 }, 676 677 loadMore: function (_button, paged, post_type, keyword) { 678 679 $.ajax({ 680 url: theme_params.ajax_url, 681 method: "POST", 682 dataType: 'json', 683 data: { 684 action: 'theme_ajax', 685 ajax_action: 'search_load_more', 686 keyword: keyword, 687 paged: paged, 688 post_type: post_type 689 }, 690 beforeSend: function () { 691 //self._searchResult.classList.add('loading'); 692 }, 693 complete: function () { 694 //self._searchResult.classList.remove('loading'); 695 }, 696 success: function (response) { 697 //console.log(response.data); 698 699 if (response.data.post_count > 0) { 700 var loopPosts = _button.closest('.search-result').querySelector('.loop-posts'); 701 702 loopPosts.insertAdjacentHTML('beforeend', response.data.posts_html); 703 704 grid.resizeGrid($(loopPosts)); 705 706 if (response.data.next_paged !== '') { 707 _button.dataset.paged = response.data.next_paged; 708 } else { 709 _button.parentNode.remove(); 710 } 711 } else { 712 _button.parentNode.remove(); 713 } 714 }, 715 }); 716 717 } 718 719 }; 720 721 var loadMore = { 722 723 init: function () { 724 var self = this; 725 726 self.posts = '.loop-posts'; 727 self.pagination = '.posts-wrapper .load-more-pagination'; 728 729 $(document.body).on('click', '.load-more-pagination .load-more-button', function (e) { 730 e.preventDefault(); 731 self.loadPosts(this); 732 }); 733 734 }, 735 736 loadPosts: function (_button) { 737 var self = loadMore, 738 loadMoreUrl = _button.getAttribute('href'), 739 $posts = $(self.posts), 740 $pagination = $(self.pagination); 741 742 if (loadMoreUrl === '#') { 743 return; 744 } 745 746 if ($pagination.hasClass('loading')) { 747 return; 748 } 749 750 $.ajax({ 751 method: "GET", 752 url: updateQueryStringParameter(loadMoreUrl, '_ajax', 1), 753 beforeSend: function () { 754 $pagination.addClass('loading'); 755 }, 756 complete: function () { 757 $pagination.removeClass('loading'); 758 } 759 }).done(function (response) { 760 761 var $parsedPosts = $(response).find(self.posts).children(); 762 763 $pagination.html($(response).find(self.pagination).html()); 764 765 $.each($parsedPosts, function (key, _post) { 766 $posts.append(_post); 767 }); 768 769 $pagination = $(self.pagination); 770 771 $(document.body).trigger('ajax_load_more_posts_loaded', $pagination); 772 }); 773 }, 774 775 }; 776 777 var magazineLoadMore = { 778 init: function () { 779 this.loadMoreBtn = '.magazine-load-more-button'; 780 this.wrapper = '.magazine-row'; 781 782 $(document.body).on('click', this.loadMoreBtn, this.loadMagazine.bind(this)); 783 }, 784 785 loadMagazine: function (e) { 786 var self = this, 787 paged = parseInt(e.currentTarget.dataset.paged); 788 789 e.preventDefault(); 790 791 $.ajax({ 792 url: theme_params.ajax_url, 793 method: "POST", 794 dataType: 'json', 795 data: { 796 action: 'theme_ajax', 797 ajax_action: 'magazine_load_more', 798 paged: paged, 799 mobileLayout: (window.innerWidth < options.mobileBreakPoint ? 1 : 0) 800 }, 801 beforeSend: function () { 802 //self._searchResult.classList.add('loading'); 803 }, 804 complete: function () { 805 //self._searchResult.classList.remove('loading'); 806 }, 807 success: function (response) { 808 if (response.data.magazine_html) { 809 $(self.wrapper).removeClass('first-load'); 810 $(self.wrapper).append(response.data.magazine_html); 811 } 812 813 if (response.data.paged === 0) { 814 $(self.loadMoreBtn).parent().remove() 815 } else { 816 e.currentTarget.dataset.paged = paged + 1; 817 } 818 }, 819 }); 820 } 821 }; 822 823 var shareButton = { 824 init: function () { 825 var self = this; 826 827 self.windowArgs = 'toolbar=no,scrollbars=yes,resizable=yes,width=700,height=700' 828 829 $('.entry-share .share-buttons').on('click', 'a.btn-share', self.shareButtonHandler); 830 $('.entry-container').on('click', 'a.btn-share-pinterest', self.sharePinterestButtonHandler); 831 832 self.addPinterestBtn(); 833 }, 834 835 shareButtonHandler: function (e) { 836 var self = shareButton, url, 837 _this = this, 838 _share = _this.parentNode; 839 840 e.preventDefault(); 841 842 switch (_this.dataset.type) { 843 case 'facebook': 844 url = 'https://www.facebook.com/sharer/?u=' + encodeURIComponent(_share.dataset.permalink); 845 window.open(url, '_blank', self.windowArgs); 846 break; 847 case 'pinterest': 848 url = 'https://pinterest.com/pin/create/bookmarklet/?is_video=false&media=' + encodeURIComponent(_share.dataset.thumbnail) + '&url=' + encodeURIComponent(_share.dataset.permalink) + '&description=' + encodeURIComponent(_share.dataset.title); 849 window.open(url, '_blank', self.windowArgs); 850 break; 851 case 'twitter': 852 url = 'https://twitter.com/intent/tweet?text=' + encodeURIComponent(_share.dataset.title) + '&url=' + encodeURIComponent(_share.dataset.permalink); 853 window.open(url, '_blank', self.windowArgs); 854 break; 855 case 'linkedin': 856 var imgUrl = $('.woocommerce-product-gallery__image img').attr('src'); 857 url = 'https://www.linkedin.com/shareArticle/?mini=true&title=' + encodeURIComponent(_share.dataset.title) + '&url=' + encodeURIComponent(_share.dataset.permalink); 858 window.open(url, '_blank', self.windowArgs); 859 break; 860 case 'email': 861 url = 'mailto:?subject=' + encodeURIComponent(_share.dataset.title) + '&body=' + encodeURIComponent('Your message...\n\n\n Read more: ' + _share.dataset.permalink); 862 window.open(url, '_blank'); 863 break; 864 case 'print': 865 window.print(); 866 break; 867 } 868 }, 869 870 sharePinterestButtonHandler: function (e) { 871 var self = shareButton; 872 873 e.preventDefault(); 874 window.open(this.href, '_blank', self.windowArgs); 875 }, 876 877 addPinterestBtn: function () { 878 if (!document.body.classList.contains('single-post')) { 879 return; 880 } 881 882 var _post = document.querySelector('article#post-item'), 883 images = document.querySelectorAll('.entry-content img'); 884
885 images.forEach(function (image, key) { 886 var url, button; 887 888 //console.log(image.getBoundingClientRect()) 889 890 if (image.className.indexOf('wp') === -1) { 891 return; 892 } 893 894 if (image.dataset.pinterest === 'false') { 895 return; 896 } 897 898 url = 'https://pinterest.com/pin/create/bookmarklet/?is_video=false'; 899 url += '&url=' + _post.dataset.permalink; 900 url += '&media=' + image.src; 901 url += '&description=' + _post.dataset.title; 902 903 button = '<a href="' + url + '" class="btn-share btn-share-pinterest" data-type="pinterest"><i class="fab fa-pinterest"></i></a>'; 904 905 image.insertAdjacentHTML('afterend', button); 906 }); 907 } 908 }; 909 910 var mailchimpEmbed = { 911 912 init: function () { 913 var self = this; 914 915 self.mailchimp = 'form#mc-embedded-subscribe-form'; 916 self.fnames = []; 917 self.ftypes = []; 918 919 self.fnames[1] = "FNAME"; 920 self.ftypes[1] = "text"; 921 self.fnames[0] = "EMAIL"; 922 self.ftypes[0] = "email"; 923 924 $(document.body).on('submit', self.mailchimp, self.submitHandler); 925 926 }, 927 928 submitHandler: function (e) { 929 var self = mailchimpEmbed, 930 $form = $(this), 931 errors = 0; 932 933 e.preventDefault(); 934 935 $('#mce-success-response').hide(); 936 $('#mce-error-response').hide(); 937 938 $form.find('.mc-field-group.invalid').removeClass('invalid'); 939 $form.find('.mce_inline_error').remove(); 940 941 self.fnames.forEach(function (name) { 942 var $input = $form.find('[name="' + name + '"]'); 943 944 if (self.validateInput($input)) { 945 $input.closest('.mc-field-group').addClass('invalid'); 946 errors++; 947 } 948 }); 949 950 if (errors > 0) { 951 return; 952 } 953 954 $.ajax({ 955 url: self.getAjaxSubmitUrl($form), 956 type: 'GET', 957 dataType: 'json', 958 contentType: "application/json; charset=utf-8", 959 data: $form.serializeArray(), 960 success: function (response) { 961 self.onSuccessCallback(response, $form) 962 } 963 }); 964 }, 965 966 getAjaxSubmitUrl: function ($form) { 967 var url = $form.attr("action"); 968 url = url.replace("/post?u=", "/post-json?u="); 969 url += "&c=?"; 970 return url; 971 }, 972 973 onSuccessCallback: function (resp, $form) { 974 var self = mailchimpEmbed; 975 976 // On successful form submission, display a success message and reset the form 977 if (resp.result === "success") { 978 $('#mce-' + resp.result + '-response').show(); 979 $('#mce-' + resp.result + '-response').html(resp.msg); 980 $('#mc-embedded-subscribe-form').each(function () { 981 this.reset(); 982 }); 983 984 // If the form has errors, display them, inline if possible, or appended to #mce-error-response 985 } else { 986 if (resp.msg === "captcha") { 987 var url = $("form#mc-embedded-subscribe-form").attr("action"); 988 var parameters = $.param(resp.params); 989 url = url.split("?")[0]; 990 url += "?"; 991 url += parameters; 992 window.open(url); 993 } 994 995 // Example errors - Note: You only get one back at a time even if you submit several that are bad. 996 // Error structure - number indicates the index of the merge field that was invali
996d, then details 997 // Object {result: "error", msg: "6 - Please enter the date"} 998 // Object {result: "error", msg: "4 - Please enter a value"} 999 // Object {result: "error", msg: "9 - Please enter a complete address"} 1000 1001 // Try to parse the error into a field index and a message. 1002 // On failure, just put the dump thing into in the msg variable. 1003 var index = -1; 1004 var msg; 1005 try { 1006 var parts = resp.msg.split(' - ', 2); 1007 if (parts[1] == undefined) { 1008 msg = resp.msg; 1009 } else { 1010 const i = parseInt(parts[0]); 1011 if (i.toString() == parts[0]) { 1012 index = parts[0]; 1013 msg = parts[1]; 1014 } else { 1015 index = -1; 1016 msg = resp.msg; 1017 } 1018 } 1019 } catch (e) { 1020 index = -1; 1021 msg = resp.msg; 1022 } 1023 1024 try { 1025 // If index is -1 if means we don't have data on specifically which field was invalid. 1026 // Just lump the error message into the generic response div. 1027 if (index === -1) { 1028 $('#mce-' + resp.result + '-response').show(); 1029 $('#mce-' + resp.result + '-response').html(msg); 1030 1031 } else { 1032 var fieldName = $("input[name*='" + self.fnames[index] + "']").attr('name'); // Make sure this exists (they haven't deleted the fnames array lookup) 1033 var data = {}; 1034 data[fieldName] = msg; 1035 1036 $.each(data, function (name, message) { 1037 $form.find('[name="' + name + '"]').closest('.mc-field-group').addClass('invalid'); 1038 $form.find('[name="' + name + '"]').closest('.mc-field-group').append('<div class="mce_inline_error">' + message + '</div>'); 1039 }); 1040 } 1041 } catch (e) { 1042 $('#mce-' + resp.result + '-response').show(); 1043 $('#mce-' + resp.result + '-response').html(msg); 1044 } 1045 } 1046 }, 1047 1048 validateInput: function ($input) { 1049 var self = this; 1050 1051 if ($input.attr('aria-required') !== 'true') { 1052 return false; 1053 } 1054 1055 if ($input.val() === '') { 1056 return true; 1057 } 1058 1059 if ($input.attr('type') === 'email' && !self.validateEmail($input.val())) { 1060 return true; 1061 } 1062 1063 return false; 1064 }, 1065 1066 validateEmail: function (email) { 1067 const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 1068 return re.test(String(email).toLowerCase()); 1069 } 1070 1071 }; 1072 1073 $(document).ready(function () { 1074 main.init(); 1075 homePage.init();
1076 loadMore.init(); 1077 galleriesPage.init(); 1078 gallerySinglePage.init(); 1079 magazineLoadMore.init(); 1080 }); 1081 1082 $(document.body).CustomResize({ 1083 resize: function () { 1084 1085 }, 1086 timeout: 200 1087 }); 1088 1089}(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.