/*------------------------------------- Template name: One Listing Version: 1.0 Author Name: wpWax --------------------------------------- JS INDEX ======================================= #. Preloader #. Search Popup #. Tiny Slider #. Mobile Menu #. Magnific Popup #. Counter Up #. Click to Copy #. Average Rating Cont #. Author Dropdown Activation #. Listing With map #. Search Home category Icon #. Responsive Menu Trigger #. Bootstrap Tooltip #. Contact Info ---------------------------------------*/ "use strict"; (function ($) { var theme = { /* Preloader */ preloader: function () { if ($('#theme-preloader') !== null) { $('#theme-preloader').fadeOut('slow', function () { // $(this).remove(); }); } }, /* Search Popup */ // searchPopup: function () { // const searchTrigger = document.querySelector('.theme-menu-action-box__search--trigger'); // // const seachPopup = document.querySelector('#theme-search-popup'); // const btnClose = document.querySelector('.theme-popup-close'); // const shade = document.querySelector('.theme-shade'); // function triggerSearchPopup(e) { // e.preventDefault(); // if (seachPopup) { // seachPopup.classList.add("theme-popup-open"); // shade.classList.add("theme-show"); // } // } // function closeSearchPopup(e) { // e.preventDefault(); // seachPopup.classList.remove("theme-popup-open"); // shade.classList.remove("theme-show"); // } // if (searchTrigger) { // searchTrigger.addEventListener('click', triggerSearchPopup); // } // if (btnClose) { // btnClose.addEventListener('click', closeSearchPopup); // } // if (shade) { // shade.addEventListener('click', closeSearchPopup); // } // }, /* Tiny Slider */ tinyslider: function () { if (typeof tns != 'undefined') { $("#theme-testimonial-slider").each(function () { var options = $(this).data('options'); options.container = this; tns(options); }); const listingSlider = document.querySelectorAll('#theme-single-listing-slider'); listingSlider.forEach(function (el) { let totalItem = el.dataset.items; var slider = tns({ "container": '#theme-single-listing-slider', "items": totalItem, "slideBy": 1, "autoplay": false, "loop": false, "controls": true, "gutter": 6, "speed": 1000, "mouseDrag": true, "controlsText": [best_listing_localize_data.SliderIconLeft, best_listing_localize_data.SliderIconRight], "nav": false, "responsive": { "1199": { "items": totalItem, }, "992": { "items": 3, }, "768": { "items": 2 }, "0": { "items": 1 } }, }); }); } }, /* Mobile Menu */ mobileMenu(dropDownTrigger, dropDown) { $('body').on('click', '.theme-responsive-menu a', function (e) { if ($(this).parent().hasClass('menu-item-has-children')) { e.preventDefault(); } if ($(this).closest('.theme-responsive-menu-trigger').length !== 0) { $(this).parent().toggleClass('theme-submenu-open'); $(this).siblings(dropDown) .slideToggle().parent().siblings('.sub-menu') .children(dropDown).slideUp().siblings(dropDownTrigger).parent().removeClass('theme-submenu-open'); } }); $('body').on('click', '.theme-mobile-menu-trigger', function () { $('.theme-responsive-menu-trigger .theme-main-navigation-inner').addClass('theme-offcanvas-active'); $('.theme-mobile-menu-overlay').addClass('theme-mobile-menu-triggered'); }); $('body').on('click', '.theme-mobile-menu-close, .theme-mobile-menu-overlay', function (e) { e.preventDefault(); $('.theme-responsive-menu-trigger .theme-main-navigation-inner').removeClass('theme-offcanvas-active'); $('.theme-mobile-menu-overlay').removeClass('theme-mobile-menu-triggered'); }); }, /* Responsive Menu Trigger */ responsiveMenuTrigger: function () { const menuArea = document.querySelector('.theme-header-menu-area'); const navCollapse = best_listing_localize_data.resmenuWidth; const windowWidth = window.innerWidth; if (navCollapse >= windowWidth) { document.querySelector('html').classList.add('theme-responsive-menu-trigger'); menuArea && menuArea.classList.add('theme-responsive-menu'); } else { document.querySelector('html').classList.remove('theme-responsive-menu-trigger'); menuArea && menuArea.classList.remove('theme-responsive-menu'); } }, /* Magnific Popup */ magnificPopup: function () { const seeAllButton = document.querySelector('.btn-listing-see-all'); if (seeAllButton) { seeAllButton.addEventListener('click', function (e) { e.preventDefault(); $('.theme-single-listing-slider__item').magnificPopup('open'); }); } if ($('.theme-single-listing-slider__item').length !== 0) { $('.theme-single-listing-slider__item').magnificPopup({ delegate: 'a', type: 'image', gallery: { enabled: true }, mainClass: 'mfp-zoom-in', }); } }, /* Counter up */ counterUpPlugin: function () { $(".theme-counter__count").each(function () { var options = $(this).data('options'); $(this).counterUp(options); }); }, /* Click Copy */ clickToCopy: function () { $('#copyBtn').on('click', function (e) { e.preventDefault(); let copyText = document.getElementById('copyUrl').value; // Create Virtual Dom let textArea = document.createElement("textarea"); textArea.value = copyText; $(this).append(textArea); textArea.select(); try { document.execCommand("copy"); $(this).addClass('copied'); } catch (err) { alert('Sorry!! Please refresh Your Page to copy again') } textArea.remove(); }); }, /* Average Rating Count */ avgRatings: function () { const ratingWrapper = document.querySelectorAll('.ratings'); ratingWrapper.forEach((elm, ind) => { const dataRating = elm.getAttribute('data-rating'); const dataRatingFloat = parseFloat(dataRating); switch (dataRatingFloat) { case 1: elm.classList.add('one'); break; case 2: elm.classList.add('two'); break; case 3: elm.classList.add('three'); break; case 4: elm.classList.add('four'); break; case 5: elm.classList.add('five'); break; default: elm.classList.add('none'); } function fractionClass(v1, v2, classOne, classTwo) { if (dataRatingFloat > v1 && dataRatingFloat < v2) { elm.classList.add(classOne, classTwo); } } fractionClass(1, 2, 'one', 'one-n-half'); fractionClass(2, 3, 'two', 'two-n-half'); fractionClass(3, 4, 'three', 'three-n-half'); fractionClass(4, 5, 'four', 'four-n-half'); }); }, /* Author Drodown Activation */ authorDropdownActive: function () { const authorTrigger = document.querySelector('.theme-header-action__author--info'); const shade = document.querySelector('.theme-white-shade'); const authorDropdown = document.querySelector('.theme-header-author-navigation'); function authorDropdownActive() { authorDropdown.classList.toggle('theme-show'); shade.classList.toggle('theme-show'); } function removeDropdown() { authorDropdown.classList.remove('theme-show'); shade.classList.remove('theme-show'); } if (authorTrigger) { authorTrigger.addEventListener('click', authorDropdownActive); } if (shade) { shade.addEventListener('click', removeDropdown); shade.classList.remove('.theme-white-shade'); } }, /* Listing With Map */ listingsWithMap: function (param) { $('body').on('submit', '#directorist-search-area-form', function (e) { var form = $(this); $.post( best_listing_localize_data.ajaxurl, { action: 'best_listing_map_header_title', post_id: $('.directorist-listing-map-title').data('post-id'), form: form.serialize(), }, function (data) { $('.directorist-listing-map-title').html(data); } ); }); }, /* Search Home Category Icon */ categoriesWithIcon: function () { // getOptionIcon function getOptionIcon(optionID) { return best_listing_localize_data.category_icons[optionID]; } function getOptionColor(optionID) { return best_listing_localize_data.category_colors[optionID]; } // convertToSelect2 function convertToSelect2(field) { if (!field) { return; } if (!field.elm) { return; } if (!field.elm.length) { return; } const default_args = { allowClear: true, dropdownCssClass: "theme-home-search-category", width: '100%', templateResult: function (data) { // We only really care if there is an element to pull classes from if (!data.element) { return data.text; } var $element = $(data.element); var icon = getOptionIcon(data.id); var color = getOptionColor(data.id); if (icon) { var content = `${icon} ${data.text}`; } else { var content = best_listing_localize_data.mapMarker + data.text; } var $wrapper = $('' + content + ''); $wrapper.addClass($element[0].className); return $wrapper; } }; var args = (field.args && typeof field.args === 'object') ? Object.assign(default_args, field.args) : default_args; var options = field.elm.find('option'); var placeholder = (options.length) ? options[0].innerHTML : ''; if (placeholder.length) { args.placeholder = placeholder; } field.elm.select2(args); } // Init Select 2 if ($('.cat_with_icon').length > 0) { convertToSelect2({ elm: $('.cat_with_icon') }); } if ($('#directorist-search-area-form select').length > 0) { convertToSelect2({ elm: $('#directorist-search-area-form select') }); } }, /* listing slider */ listingSlider: function () { const thumbList = document.querySelectorAll('.directorist-listing-single__thumb-slider'); thumbList.forEach(function (el) { let totalItem = el.dataset.items; var slider = tns({ "container": el, "items": totalItem, "slideBy": 1, "autoplay": false, "loop": false, "controls": true, "gutter": 0, "speed": 1000, "mouseDrag": true, "controlsText": [best_listing_localize_data.SliderIconLeft, best_listing_localize_data.SliderIconRight], "nav": true, }); }); }, /* Search Dropdown */ searchDropDown: function () { $("body").on("click", ".directorist-filter-btn", function () { $(this).closest(".directorist-filter-btn").toggleClass("active"); }); $("body").on("click", ".theme-search-dropdown .theme-search-dropdown__label", function () { $(this).closest(".theme-search-dropdown").toggleClass("active"); }); $('body').on('click', function (e) { if (!$(e.target).closest('.theme-search-dropdown').length) { $(".theme-search-dropdown").removeClass("active"); } }); }, directory_type: function() { var deviceType = $("body").attr("data-elementor-device-mode"); if (deviceType == 'mobile') { "search_listing_types directorist-listing-type-selection__link--current" var element = document.querySelectorAll(".directorist-listing-type-selection__link--current"); element.forEach( function( item ) { item.scrollIntoView({behavior: "smooth" ,inline: "center"}); }); } }, /* Search Dropdown */ updateArchiveListings: function () { $('.directorist-thumb-listing-author').closest('.directorist-listing-single').addClass('directorist-listing-has-thumb-active'); $("body").on('click', '.directorist-type-nav__list li', function () { $(".directorist-type-nav__list li.current").removeClass("current"); $(this).addClass("current"); }); $("body").on('click', '.elementor-widget-wpwaxtheme-all-listings .directorist-type-nav li a', function () { $('.directorist-archive-grid-view').addClass('theme-tab-listing-loader'); window.setTimeout(function () { $('.directorist-archive-grid-view').removeClass('theme-tab-listing-loader'); $('.directorist-archive-grid-view').prop('disabled', true); }, 2500); }); $('.elementor-page .elementor-widget-wpwaxtheme-all-listings .directorist-archive-contents .directorist-type-nav a.directorist-type-nav__link').click(function (e) { e.preventDefault(); let href = $(e.target).attr('href'); if (undefined === href) { return; } let start = href.indexOf("="); let type = href.slice(start + 1); let parentDiv = e.target.closest('.directorist-archive-contents'); let atts = $(parentDiv).data('atts'); $.post( best_listing_localize_data.ajaxurl, { action: 'best_listing_archive_listings', type: type, atts: atts, }, function (data) { if (data) { let gridFound = $(parentDiv).find('.directorist-archive-grid-view'); if (gridFound) { $(gridFound).remove() } let listFound2 = $(parentDiv).find('.directorist-archive-list-view'); if (listFound2) { $(listFound2).remove() } $(parentDiv).append(data); } } ); }); }, /* Contact Button */ contactButton: function () { if ($('#best-listing-contact-owner-form') !== null) { $('body').on('submit', '#best-listing-contact-owner-form', function (e) { e.preventDefault(); $('#directorist-contact-message-display').append('
'); // Post via AJAX const data = { action: 'atbdp_public_send_contact_email', post_id: $('#best-listing-post-id').val(), name: $('#atbdp-contact-name').val(), email: $('#atbdp-contact-email').val(), listing_email: $('#atbdp-listing-email').val(), message: $('#atbdp-contact-message').val(), directorist_nonce: atbdp_public_data.directorist_nonce, }; $.post( best_listing_localize_data.ajaxurl, data, function (response) { if (response.error == 1) { $('#directorist-contact-message-display') .addClass('text-danger') .html(response.message); } else { $('#atbdp-contact-message').val(''); $('#directorist-contact-message-display') .addClass('text-success') .html(response.message); } }, 'json' ); }); } }, /* Navigation submenu level fix */ navMenuFix: function(){ function addMultipleEventListener(element, events, handler) { events.forEach(e => element.addEventListener(e, handler)) } const li = document.querySelectorAll('.menu-main-menu-container li.menu-item-has-children'); for(const el of li){ addMultipleEventListener(el, ['mouseenter', 'touchstart'], (e)=>{ if(window.innerWidth - e.clientX <= 300){ el.querySelector('.sub-menu').classList.add('open-left'); el.closest('.sub-menu') ? el.closest('.sub-menu').classList.add('open-left') : ''; } }); el.addEventListener('keyup', (e)=>{ if(e.keyCode === 9){ el.addEventListener('focusin', ()=>{ el.querySelector('.sub-menu').classList.add('open-left'); el.closest('.sub-menu') ? el.closest('.sub-menu').classList.add('open-left') : ''; }); } }) } }, focusTrap: function(){ var capture = $( ".theme-responsive-menu-trigger .theme-main-navigation-inner" ) .attr( "tabindex", "-1" ) .focus() .keydown( function handleKeydown( event ) { if ( event.key.toLowerCase() !== "tab" ) { return; } var tabbable = $() .add( capture.find( "button, input, select, textarea" ) ) .add( capture.find( "[href]" ) ) .add( capture.find( "[tabindex]:not([tabindex='-1'])" ) ) ; var target = $( event.target ); if ( event.shiftKey ) { if ( target.is( capture ) || target.is( tabbable.first() ) ) { event.preventDefault(); tabbable.last().focus(); } } else { if ( target.is( tabbable.last() ) ) { event.preventDefault(); tabbable.first().focus(); } } } ); }, } theme.responsiveMenuTrigger(); /* Window Resize */ $(window).resize(function () { theme.responsiveMenuTrigger(); theme.focusTrap(); }); /* Content Ready Scripts */ function content_ready_scripts() { theme.mobileMenu('.menu-item a', '.sub-menu'); theme.clickToCopy(); theme.counterUpPlugin(); theme.avgRatings(); theme.authorDropdownActive(); theme.listingsWithMap(); theme.categoriesWithIcon(); theme.searchDropDown(); theme.updateArchiveListings(); theme.contactButton(); theme.navMenuFix(); theme.focusTrap(); theme.responsiveMenuTrigger(); } /* Content Load Scripts */ function content_load_scripts() { theme.preloader(); theme.tinyslider(); theme.listingSlider(); theme.magnificPopup(); theme.categoriesWithIcon(); theme.searchDropDown(); theme.directory_type(); } window.addEventListener('directorist-reload-listings-map-archive', function () { theme.searchDropDown(); theme.categoriesWithIcon(); theme.listingSlider(); }); window.addEventListener('directorist-search-form-nav-tab-reloaded', function () { theme.searchDropDown(); theme.categoriesWithIcon(); }); /* Load Scripts after Change Directory Type*/ function initSetup() { theme.categoriesWithIcon(); theme.searchDropDown(); theme.directory_type(); } $(document).ready(function () { content_ready_scripts(); }); $(window).on('load', function () { content_load_scripts(); }); $(window).on('load', initSetup); $(window).on('directorist-search-form-nav-tab-reloaded', initSetup); /* Elementor Edit Mode */ $(window).on('elementor/frontend/init', function () { setTimeout(() => { if (elementorFrontend.isEditMode()) { //elementorFrontend.hooks.addAction('frontend/element_ready/widget', function() { content_ready_scripts() theme.tinyslider(); theme.categoriesWithIcon(); //}); } }, 6000); }); // Bootstrap Tooltip Initialize var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')) var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { return new bootstrap.Tooltip(tooltipTriggerEl) }); })(jQuery);