2017-08-18 143 views
0

我有一个使用带有AJAX过滤器的灯箱产品的woocommerce站点。 要访问灯箱,当您将鼠标悬停在产品上时,会出现一个快速浏览按钮。AJAX加载后加载javascript

当我加载AJAX过滤器时,灯箱快速查看按钮不再可点击。 我需要在AJAX加载后将代码添加到按钮。 以下是主题使用的功能。

85: function(t, e) { 
      "use strict"; 
      Flatsome.behavior("quick-view", { 
       attach: function(t) { 
        jQuery(".quick-view", t).each(function(t, e) { 
         jQuery(e).hasClass("quick-view-added") || (jQuery(e).click(function(t) { 
          if ("" != jQuery(this).attr("data-prod")) { 
           jQuery(this).parent().parent().addClass("processing"); 
           var e = jQuery(this).attr("data-prod"), 
            i = { 
             action: "flatsome_quickview", 
             product: e 
            }; 
           jQuery.post(flatsomeVars.ajaxurl, i, function(t) { 
            jQuery(".processing").removeClass("processing"), jQuery.magnificPopup.open({ 
             removalDelay: 300, 
             closeBtnInside: !0, 
             autoFocusLast: !1, 
             items: { 
              src: '<div class="product-lightbox lightbox-content">' + t + "</div>", 
              type: "inline" 
             } 
            }), setTimeout(function() { 
             jQuery(".product-lightbox").imagesLoaded(function() { 
              jQuery(".product-lightbox .slider").flickity({ 
               cellAlign: "left", 
               wrapAround: !0, 
               autoPlay: !1, 
               prevNextButtons: !0, 
               adaptiveHeight: !0, 
               imagesLoaded: !0, 
               dragThreshold: 15 
              }) 
             }) 
            }, 300), jQuery(".product-lightbox form").hasClass("variations_form") && jQuery(".product-lightbox form.variations_form").wc_variation_form(), jQuery(".product-lightbox form.variations_form").on("show_variation", function(t, e) { 
             e.image.src ? (jQuery(".product-lightbox .product-gallery-slider .slide.first img").attr("src", e.image.src).attr("srcset", ""), jQuery(".product-lightbox .product-gallery-slider .slide.first a").attr("href", e.image_link), jQuery(".product-lightbox .product-gallery-slider").flickity("select", 0)) : e.image_src && (jQuery(".product-lightbox .product-gallery-slider .slide.first img").attr("src", e.image_src).attr("srcset", ""), jQuery(".product-lightbox .product-gallery-slider .slide.first a").attr("href", e.image_link), jQuery(".product-lightbox .product-gallery-slider").flickity("select", 0)) 
            }), jQuery(".product-lightbox .quantity").addQty() 
           }), t.preventDefault() 
          } 
         }), jQuery(e).addClass("quick-view-added")) 
        }) 
       } 
      }) 
     } 

回答

1

如果你可以编辑主题,代码直接写入成功回调:

jQuery.post(flatsomeVars.ajaxurl, i, function(t) { 
    // Code you want to run 
    // Other code. i.e. jQuery(".processing").removeClass ... etc. 
}); 

或定义的函数,并调用它的成功()回调里面。

var myFunction = function() { 
    // Code to run after success 
} 
jQuery.post(flatsomeVars.ajaxurl, i, function(t) { 
    myFunction(); 
    // Other code 
}); 
+0

正是我所需要的,问题是我真的不知道我必须运行什么代码,在它上面工作! – Joe