!function(a){"use strict";function t(t,n){a(t).isotope({layoutMode:"packery",itemSelector:n,isOriginLeft:!a("body.rtl").length,resizable:!0,initLayout:!0})}function n(t,n,i,s){const o=t.dataset.counter;s=s||a(t).parents(".fusion-builder-live-element").length,window[`igRequest-${o}`]&&window[`igRequest-${o}`].abort();const r=t.dataset.limit,d=t.dataset.link_type,l=t.dataset.link_target,g=t.dataset.page||1,u=t.querySelector(".instagram-posts"),w=t.querySelector(".awb-instagram-load-more-btn"),c=t.querySelector(".awb-instagram-infinite-scroll-handle"),m=t.querySelector(".instagram-posts-loading-container"),p=a(t).hasClass("layout-masonry");i&&a(m).show(),n=n?`${window.fusionInstagramVars.api_url}awb/instagram/media/?limit=${r}&page=${g}&url=${encodeURIComponent(n)}`:`${window.fusionInstagramVars.api_url}awb/instagram/media/?limit=${r}`,s&&(!s||window.fusionInstagramItems)||!a(t).hasClass("loading")&&!i||(window[`igRequest-${o}`]=a.ajax({type:"POST",url:window.fusionInstagramVars.ajax_url,data:{action:"awb_instagram_get_data",nonce:window.fusionInstagramVars.nonce,url:n,args:{layout:a(t).hasClass("layout-masonry")?"masonry":"grid",link_type:d||"",link_target:l||""},counter:o},dataType:"json",success:function(n){let o=n.html;i?(o=a(o),a(u).append(o),p&&a(u).isotope("appended",o)):u.innerHTML=o,s&&!window.fusionInstagramItems&&(window.fusionInstagramItems=o),e(t,s),t.dataset.page=parseInt(g)+1,w&&(n.data&&n.data.paging&&n.data.paging.next?w.dataset.url=n.data.paging.next:delete w.dataset.url),c&&(n.data&&n.data.paging&&n.data.paging.next?c.dataset.url=n.data.paging.next:delete c.dataset.url),t.classList.remove("loading"),i&&a(m).hide()}})),s&&t.classList.remove("loading"),a(t).hasClass("loading")||i||e(t,s)}function e(n,e){const i=n.dataset.counter,s=n.dataset.link_type,o=n.querySelector(".instagram-posts"),r="awb-instagram-"+i,d=n.querySelector(".awb-instagram-infinite-scroll-handle"),l=a(n).hasClass("layout-masonry");a(d).hasClass("is-active")&&a(d).removeClass("is-active"),"lightbox"===s&&(window[r]?(window[r].destroy(),window[r]=a(n).find(`a[data-rel="${r}"]`).iLightBox(window.avadaLightBox.prepare_options(r,!1))):window[r]=a(n).find(`a[data-rel="${r}"]`).iLightBox(window.avadaLightBox.prepare_options(r,!1)),a(n).find(".instagram-post-children").length&&a(".instagram-post-children").each(function(){const t=a(this).find("a:first-child").data("rel");window[t]?(window[t].destroy(),window[t]=a(n).find(`a[data-rel="${t}"]`).iLightBox(window.avadaLightBox.prepare_options(t,!1))):window[t]=a(n).find(`a[data-rel="${t}"]`).iLightBox(window.avadaLightBox.prepare_options(t,!1))})),l&&window.imagesLoaded(o,function(){a(o).data("isotope")?e?(a(o).isotope("destroy"),t(o,".instagram-post")):a(o).isotope("layout"):t(o,".instagram-post")})}function i(t){const e=t.dataset.url,i=a(t).parents(".awb-instagram-element"),s=i.find(".instagram-posts-loading-container");e?n(i[0],e,!0):(s.show(),setTimeout(()=>{s.find(".fusion-loading-spinner").hide(),s.find(".fusion-loading-msg").html(window.fusionInstagramVars.no_more_posts_msg)},500),setTimeout(()=>{s.slideUp(),a(t).hide()},3500))}a(".awb-instagram-element").each(function(){const a=this.dataset.counter;window[`igRequest-${a}`]=null,n(this)}),a(".awb-instagram-load-more-btn").on("click",function(a){a.preventDefault(),i(this)});const s=new IntersectionObserver(t=>{t.forEach(t=>{t.isIntersecting&&!a(t.target).hasClass("is-active")&&(a(t.target).addClass("is-active"),i(t.target))})});document.querySelectorAll(".awb-instagram-infinite-scroll-handle").forEach(a=>{s.observe(a)}),a(window).on("load fusion-element-render-fusion_instagram",function(a,t){const e="object"==typeof t?t:document.querySelector(`[data-cid="${t}"] .awb-instagram-element`);e&&n(e,!1,!1,!0)})}(jQuery);