(function($) {
	"use strict";

	var ajaxurl = $(
		".elementor-widget-anggita-portfolio-ajax .rdn-port-val"
	).data("url");
	var page = 2;
	var portfolio_item = $(
		".elementor-widget-anggita-portfolio-ajax .rdn-port-val"
	).data("item");
	var port_column = $(
		".elementor-widget-anggita-portfolio-ajax .rdn-port-val"
	).data("col");
	var order_value = $(
		".elementor-widget-anggita-portfolio-ajax .rdn-port-val"
	).data("order");
	var security = $(
		".elementor-widget-anggita-portfolio-ajax .rdn-port-val"
	).data("nonce");
	var nomore = $(".elementor-widget-anggita-portfolio-ajax .rdn-port-val").data(
		"nomore"
	);

	$(".elementor-widget-anggita-portfolio-ajax .loadmore").on(
		"click",
		function() {
			$(".elementor-widget-anggita-portfolio-ajax .loadmore").hide();
			$(".elementor-widget-anggita-portfolio-ajax .port-load").show();
			$(".elementor-widget-anggita-portfolio-ajax .new-rcol").removeClass(
				"new-rcol"
			);
			var data = {
				action: "load_posts_by_ajax",
				page: page,
				portfolio_item: portfolio_item,
				port_column: port_column,
				order_value: order_value,
				security: security,
				nomore: nomore
			};

			var $grid = $(
				".elementor-widget-anggita-portfolio-ajax .c-iso"
			).isotope();

			$.post(ajaxurl, data, function(response) {
				$(".elementor-widget-anggita-portfolio-ajax .c-iso").append(response);
				$grid
					.append($(".new-rcol"))
					// add and lay out newly appended elements
					.isotope("appended", $(".new-rcol"));
				$(".elementor-widget-anggita-portfolio-ajax .new-rcol").removeClass(
					"new-rcol"
				);
				page++;
				$(".elementor-widget-anggita-portfolio-ajax .port-load").fadeOut(
					"fast"
				);
				setTimeout(function() {
					$(".elementor-widget-anggita-portfolio-ajax .loadmore").fadeIn();
				}, 400);
				if (
					$(".elementor-widget-anggita-portfolio-ajax .c-iso").find(".no-more")
						.length > 0
				) {
					$(".elementor-widget-anggita-portfolio-ajax .load-more").remove();
					$(".elementor-widget-anggita-portfolio-ajax .box-load").slideUp(
						"fast"
					);
					setTimeout(function() {
						$(".elementor-widget-anggita-portfolio-ajax .npsp").fadeOut();
						$(".elementor-widget-anggita-portfolio-ajax .npsp").remove();
						$(
							".elementor-widget-anggita-portfolio-ajax .portfolio-body"
						).isotope("layout");
					}, 2000);
				}
			});
		}
	);
})(jQuery);
