var _____WB$wombat$assign$function_____=function(name){return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name))||self[name];};if(!self.__WB_pmw){self.__WB_pmw=function(obj){this.__WB_source=obj;return this;}}{
let window = _____WB$wombat$assign$function_____("window");
let self = _____WB$wombat$assign$function_____("self");
let document = _____WB$wombat$assign$function_____("document");
let location = _____WB$wombat$assign$function_____("location");
let top = _____WB$wombat$assign$function_____("top");
let parent = _____WB$wombat$assign$function_____("parent");
let frames = _____WB$wombat$assign$function_____("frames");
let opens = _____WB$wombat$assign$function_____("opens");
jQuery(function ($) { // use jQuery code inside this to avoid "$ is not defined" error

	var infinite_loadmore_started = false;
	var infinite_page_end = false;
	function post_load_more(e) {
		e.preventDefault();
		var button;
		var is_loadmore = 'on';
		if ($(e.target).hasClass('dmach-loadmore')) {
			button = $(e.target);
		} else {
			button = $('.divi-filter-archive-loop.main-loop').closest('.filtered-posts-cont');
			is_loadmore = 'off';
		}
		var $module_featured_posts = button.parent().find('.divi-filter-archive-loop'),
			layoutid = $module_featured_posts.attr("data-layoutid"),
			posttype = $module_featured_posts.attr("data-posttype"),
			noresults = $module_featured_posts.attr("data-noresults"),
			sortorder = $module_featured_posts.attr("data-sortorder"),
			sortasc = $module_featured_posts.attr("data-sortasc"),
			gridstyle = $module_featured_posts.attr("data-gridstyle"),
			columnscount = $module_featured_posts.attr("data-columnscount"),
			postnumber = $module_featured_posts.attr("data-postnumber"),
			loadmoretext = $module_featured_posts.attr("data-btntext"),
			loadmoretextloading = $module_featured_posts.attr("data-btntext_loading"),
			resultcount = $module_featured_posts.attr("data-resultcount"),
			countposition = $module_featured_posts.attr("data-countposition"),
			shortcode_name = $module_featured_posts.attr("data-shortcode_name"),
			module_current_page = parseInt($module_featured_posts.attr("data-current-page")),
			module_max_page = parseInt($module_featured_posts.attr("data-max-page")),
			post_var = $module_featured_posts.attr("data-filter-var"),
			loadmore_icon = $module_featured_posts.find(".divi-loadmore").attr("data-icon"),
			has_map = $module_featured_posts.attr("data-has-map"),
			hide_marker_label = $module_featured_posts.attr("data-hide-marker-label"),
			map_selector = $module_featured_posts.attr("data-map-selector"),
			marker_layout = $module_featured_posts.attr("data-map-marker-layout"),
			map_all_posts = $module_featured_posts.attr("data-map-all-posts"),
			map_cluster = $module_featured_posts.attr("data-map-cluster"),
			link_wholegrid = $module_featured_posts.attr("data-link_wholegrid"),
			link_wholegrid_external = $module_featured_posts.attr("data-wholegrid-external"),
			link_wholegrid_external_acf = $module_featured_posts.attr("data-wholegrid-external_acf"),
            result_count_single_text = $module_featured_posts.attr("data-result-count-single-text"),
            result_count_all_text = $module_featured_posts.attr("data-result-count-all-text"),
            result_count_pagination_text = $module_featured_posts.attr("data-result-count-pagination-text");
        
        if ( $module_featured_posts.attr("data-loop-var") ) {
            var loop_var = JSON.stringify(JSON.parse($module_featured_posts.attr("data-loop-var")));
        }

		var data = {
			'action': 'divi_filter_loadmore_ajax_handler',
			'security': loadmore_ajax_object.security,
			'query': post_var,
			'page': module_current_page,
			'layoutid': layoutid,
			'posttype': posttype,
			'noresults': noresults,
			'sortorder': sortorder,
			'sortasc': sortasc,
			'gridstyle': gridstyle,
			'columnscount': columnscount,
			'resultcount': resultcount,
			'countposition': countposition,
			'shortcode_name': shortcode_name,
			'postnumber': postnumber,
			'loadmoretext': loadmoretext,
			'loadmore_icon': loadmore_icon,
			'link_wholegrid': link_wholegrid,
			'link_wholegrid_external': link_wholegrid_external,
			'link_wholegrid_external_acf': link_wholegrid_external_acf,
			'is_loadmore': is_loadmore,
			'has_map': has_map,
			'map_all_posts': map_all_posts,
			'map_selector': map_selector,
			'marker_layout': marker_layout,
            'result_count_single_text':result_count_single_text,
            'result_count_all_text':result_count_all_text,
            'result_count_pagination_text':result_count_pagination_text,
            'loop_var': loop_var
		};
        
        if ( $module_featured_posts.attr('data-groupping-taxonomy') ) {
            data.groupping_taxonomy = $module_featured_posts.attr('data-groupping-taxonomy');
            data.last_grouping_term_id = $module_featured_posts.find('.groupping-term-title').last().attr('data-term_id');
        }

		if (layoutid == 'none') {
			data.show_rating = $module_featured_posts.attr('data-show_rating');
			data.show_price = $module_featured_posts.attr('data-show_price');
			data.show_excerpt = $module_featured_posts.attr('data-show_excerpt');
			data.show_add_to_cart = $module_featured_posts.attr('data-show_add_to_cart');
		}

		$.ajax({ // you can also use $.post here
			url: loadmore_ajax_object.ajax_url, // AJAX handler
			data: data,
			type: 'POST',
			beforeSend: function (xhr) {
                $module_featured_posts.closest('.filtered-posts-cont').addClass('infinite-loading');
				if (is_loadmore == 'on') {
					button.text(loadmoretextloading); // change the button text, you can also add a preloader image	
				} else {
					var anim_chosen = jQuery('.filtered-posts-cont').attr('data-ajaxload-anim');
					button.parent().append('<div class="loadmore-ajax-loading ' + anim_chosen + '"><div class="lines"><div class="line"></div><div class="line"></div><div class="line"></div></div><div class="spinner donut-cont"><div class="donut"></div></div><div class="spinner donutmulti-cont"><div class="donut multi"></div></div><div class="spinner ripple-cont"><div class="ripple"></div></div></div>');
				}

				$module_featured_posts.closest('.filtered-posts-cont').find('.filtered-posts-loading').prepend('<div class="ajax-loading"><div class="lines"><div class="line"></div><div class="line"></div><div class="line"></div></div><div class="spinner donut-cont"><div class="donut"></div></div><div class="spinner donutmulti-cont"><div class="donut multi"></div></div><div class="spinner ripple-cont"><div class="ripple"></div></div></div>');
			},
			success: function (data) {

                $module_featured_posts.closest('.filtered-posts-cont').removeClass('infinite-loading');
				infinite_loadmore_started = false;
				if (data) {
					var new_posts = $(data.posts);
					if (button.hasClass('dmach-loadmore')) {
						button.text(loadmoretext.replace(/\\/g, ''));
					} else {
						button.parent().find('.loading').remove();
						button.parent().find('.loadmore-ajax-loading').remove();
					}

					if (button.parent().find('.loop-grid').length > 0) {
						button.parent().find('.loop-grid').eq(0).append(new_posts); // insert new posts	
					} else if (button.parent().find('ul.products').length > 0) {
						button.parent().find('ul.products').eq(0).append(new_posts);
					}

					button.parent().find('.divi-filter-archive-loop').append(data.css_output);

					$module_featured_posts.closest('.filtered-posts-cont').find('.filtered-posts-loading').find('.ajax-loading').remove();

					var filter_post_container = button.parent();

					if (filter_post_container.find('.divi-filter-result-count').length > 0) {
						filter_post_container.find('.divi-filter-result-count').remove();
					}

					if (data.bc_result_count && button.parent().find('.woocommerce-result-count').length > 0) {
						button.parent().find('.woocommerce-result-count').html(data.bc_result_count);
					}

					//button.parent().find('.divi-filter-archive-loop').append(data.after_post);

					if (button.hasClass('dmach-loadmore')) {
						button.remove();
					}


					if (data.after_post) {
						var afterPost = $('<textarea />').html(data.after_post).text();
						filter_post_container.append(afterPost.replace(/\\/g, ''));
					}

					jQuery(".single_add_to_cart_button").addClass("ajax_add_to_cart");

					if ("undefined" != typeof ajax_disabled_products_class) {
						$("." + ajax_disabled_products_class + " .single_add_to_cart_button").removeClass("ajax_add_to_cart");
					}

					$module_featured_posts.attr("data-current-page", module_current_page + 1);

					if (typeof resizeAllGridItems == 'function') {
						var totalImgs = new_posts.find('img').length;
						new_posts.find('img').one('load', function () {
							totalImgs--;
							if (totalImgs <= 0) {
								resizeAllGridItems();
							}
						}).each(function () {
							if (this.complete) {
								jQuery(this).trigger('load');
							}
						});

					}
					//show_filter_counts();
					if (typeof get_post_popup == 'function') {
						get_post_popup();
					}
					// same_height_cards();

					if ($module_featured_posts.find(".grid-col").find(".gallery_vars").length > 0) {
						var gallery_vars = $module_featured_posts.find(".grid-col").find(".gallery_vars").attr("data-gallery_vars");
						var gallery_type = $module_featured_posts.find(".grid-col").find(".gallery_vars").attr("data-gallery_type");
						gallery_vars = gallery_vars.replace(/,\s*$/, "");
						gallery_vars = gallery_vars.replace(/,/g, ", ");
						gallery_vars = gallery_vars.replace(/'/g, '"');
						gallery_vars = '{' + gallery_vars + '}';

						gallery_vars = JSON.parse(gallery_vars);

						jQuery('.et_pb_de_mach_acf_slider_containter').each(function (i, obj) {
							if (jQuery(this).hasClass('slick-initialized')) {
								jQuery(this).slick('unslick');
							}
							jQuery(this).slick(gallery_vars);
						});

						if (gallery_type == 'gallery') {
							var gallery_nav_vars = $module_featured_posts.find(".grid-col").find(".gallery_vars").attr("data-gallery_nav");
							gallery_nav_vars = gallery_nav_vars.replace(/,\s*$/, "");
							gallery_nav_vars = gallery_nav_vars.replace(/,/g, ", ");
							gallery_nav_vars = gallery_nav_vars.replace(/'/g, '"');
							gallery_nav_vars = '{' + gallery_nav_vars + '}';

							gallery_nav_vars = JSON.parse(gallery_nav_vars);
							gallery_nav_vars.asNavFor = '.et_pb_de_mach_acf_slider_containter';
							gallery_nav_vars.focusOnSelect = true;
							jQuery('.et_pb_de_mach_acf_slider_containter_nav').each(function (i, obj) {
								if (jQuery(this).hasClass('slick-initialized')) {
									jQuery(this).slick('unslick');
								}
								jQuery(this).slick(gallery_nav_vars);
							});
						}

					}

					if (data.map_data && jQuery(map_selector).length > 0 && map_all_posts == 'off') {
						jQuery(map_selector).each(function () {

				            var _this = jQuery(this);
				            var map_obj = jQuery(this).data('map');

				            for (let i = 0; i < markers.length; i++) {
				              markers[i].setMap(null);
				            }
				            markers = [];
				            
				            if (map_cluster != 'on') {
				              jQuery.each(data.map_data, function (ind, map) {
				                locations.push({ lat: map.lat, lng: map.lng });
				                if ( typeof hide_marker_label !== "undefined" && hide_marker_label == "on" ) {
				                  labels.push(map.title.charAt(0));  
				                } else {
				                  labels.push("");
				                }
				                i_windows.push(map.infoview);
				              });

				              if (typeof map_obj != 'undefined') {
				                markers = locations.map((location, i) => {
				                  var marker = new google.maps.Marker({
				                    position: location,
				                    label: labels[i],
				                    map: map_obj
				                  });

				                  var i_window = new google.maps.InfoWindow({
				                    content: i_windows[i]
				                  });

				                  google.maps.event.addListener(map_obj, "click", (function () {
				                    i_window.close()
				                  }
				                  ));

				                  google.maps.event.addListener(marker, "click", (function () {
				                    i_window.open(map_obj, marker);
				                  }
				                  ));

				                  return marker;
				                });
				              }
				            } else {
				              /* Marker Clusterer */
				              jQuery.each(data.map_data, function (ind, map) {
				                locations.push({ lat: map.lat, lng: map.lng });
				                if ( typeof hide_marker_label !== "undefined" && hide_marker_label == "on" ) {
				                  labels.push(map.title.charAt(0));  
				                } else {
				                  labels.push("");
				                }
				                i_windows.push(map.infoview);
				              });

				              if (typeof map_obj != 'undefined') {
				                markers = locations.map((location, i) => {
				                  var marker = new google.maps.Marker({
				                    position: location,
				                    label: labels[i],
				                  });

				                  var i_window = new google.maps.InfoWindow({
				                    content: i_windows[i]
				                  });

				                  google.maps.event.addListener(map_obj, "click", (function () {
				                    i_window.close()
				                  }
				                  ));

				                  google.maps.event.addListener(marker, "click", (function () {
				                    i_window.open(map_obj, marker);
				                  }
				                  ));

				                  return marker;
				                });

				                const markerClusterer = new MarkerClusterer(map_obj, markers, { imagePath: clusterer_obj.imgPath });
				              }
				            }
				          });
					}

					if( gridstyle == 'masonry' ){
						// for each .divi-filter-archive-loop.masonry
						// for each .divi-filter-archive-loop.masonry
						jQuery('.grid-layout-masonry').each(function () {
							var masonry_data = jQuery(this).find('.divi-filter-archive-loop.masonry');
							
							var gutter_row_column = parseInt(masonry_data.attr('data-masonry-row-column'), 10) || 0,
								gutter_row_gap = parseInt(masonry_data.attr('data-masonry-row-gap'), 10) || 0,
								columns_desktop = parseInt(masonry_data.attr('data-masonry-columns-desktop'), 10) || 3,
								columns_tablet = parseInt(masonry_data.attr('data-masonry-columns-tablet'), 10) || 2,
								columns_mobile = parseInt(masonry_data.attr('data-masonry-columns-mobile'), 10) || 1;
							
							var macyInstance = Macy({
							container: '.masonry .divi-filter-loop-container .grid-posts.loop-grid',
							trueOrder: false,
							waitForImages: true,
							margin: {
								x: gutter_row_column,
								y: gutter_row_gap
							},
							columns: columns_desktop,
							breakAt: {
								1200: columns_desktop,
								980: columns_tablet,
								767: columns_mobile
							}
							});

							macyInstance.runOnImageLoad(function () {
							macyInstance.recalculate(true);
							}, true);

							// Ensure recalculation when new items are loaded via AJAX
							jQuery(document).off('ajaxComplete').on('ajaxComplete', function () {
							macyInstance.recalculate(true);
							});
						});	
					}

					if (gridstyle == 'masonry' && typeof resizeAllGridItems == 'function' ) {

						var masonry_ajax_buffer = $module_featured_posts.attr('data-masonry_ajax_buffer');
						resizeAllGridItems();
						var totalImgs = jQuery('.divi-filter-archive-loop.main-loop').children().eq(0).find('img').length;
						jQuery('.divi-filter-archive-loop.main-loop').children().eq(0).find('img').one("load", function () {
							totalImgs--;
							if (totalImgs == 0) {
								resizeAllGridItems();
							}
						}).each(function () {
							if (this.complete) {
								jQuery(this).trigger('load'); // For jQuery >= 3.0 
							}
						});


						setTimeout(
							function () {
								resizeAllGridItems();
							}, masonry_ajax_buffer);							
					}

					if (jQuery.fn.fitVids) {
						jQuery('#main-content').fitVids({
							customSelector: "iframe[src^='http://www.hulu.com'], iframe[src^='http://www.dailymotion.com'], iframe[src^='http://www.funnyordie.com'], iframe[src^='https://embed-ssl.ted.com'], iframe[src^='http://embed.revision3.com'], iframe[src^='https://flickr.com'], iframe[src^='http://blip.tv'], iframe[src^='http://www.collegehumor.com']"
						});
					}

					if ( $module_featured_posts.find('.et_post_gallery').length > 0 ) {
						$module_featured_posts.find('.et_post_gallery').each((function() {
	                        jQuery(this).magnificPopup({
	                            delegate: ".et_pb_gallery_image a",
	                            type: "image",
	                            removalDelay: 500,
	                            gallery: {
	                                enabled: !0,
	                                navigateByImgClick: !0
	                            },
	                            mainClass: "mfp-fade",
	                            zoom: {
	                                enabled: window.et_pb_custom && !window.et_pb_custom.is_builder_plugin_used,
	                                duration: 500,
	                                opener: function(t) {
	                                    return t.find("img")
	                                }
	                            },
	                            autoFocusLast: !1
	                        })
	                    }
	                    ));
	                    $module_featured_posts.find('.et_post_gallery').find("a").off("click");
					}
              
                    jQuery('.variations_form').each(function() {
                      jQuery(this).wc_variation_form();
                      jQuery(this).trigger('check_variations');
                    });

					jQuery.event.trigger({
						type: "divi_filter_completed"
					});

					if (data.posts == '') {
						infinite_page_end = true;
					}
				} else {
					if (button.hasClass('dmach-loadmore')) {
						button.remove(); // if no data, remove the button as well
					}
				}
			}
		});
	}
	$(document).on('click keydown', '.dmach-loadmore', function (e) {
		post_load_more(e);
	});

	if ($('.divi-filter-archive-loop.main-loop').data('loadmore') == 'infinite') {
		$(window).scroll(function (e) {
			var main_loop = $('.divi-filter-archive-loop.main-loop');
			var offset = main_loop.offset();
			if (parseInt(main_loop.attr('data-current-page')) < parseInt(main_loop.attr('data-max-page'))) {
				if ($(window).scrollTop() > (offset.top + main_loop.outerHeight(true) - $(window).height()) && !infinite_loadmore_started && !infinite_page_end) {
					infinite_loadmore_started = true;
					post_load_more(e);
				}
			}
		});
	}
});
}