Issue #4 resolved

Javascript not working with dynamic ajax loading for shoppingcart.js

csurieux
created an issue

Suggested correction (this editor is clumsy)

jQuery(function ($) { var setQuantityToZero = function(parentTag) { return function(button) { return button.parents(parentTag + ":first") .find("input.quantity").val(0) .parents("form"); }; }, miniLoad = function(form) { mini.load(form.attr("action"), form.serializeArray(), onload); return false; }, onload = function(text) { mini.parent().toggle(text.trim().length > 0); $(".minicart .delete").on("click", function () { $(this).trigger("nwazet.removefromcart"); return miniLoad(setQuantityToZero("li")($(this))); }); $(".minicart .update-button").on("click", function () { $(this).trigger("nwazet.addtocart"); return miniLoad($(this).parents("form")); }); $(this).trigger("nwazet.cartupdated"); }, mini = $(".minicart");

mini.load(mini.data("url"), onload)
    .parent().hide();

$(".shoppingcart .delete").on("click", function () {
    $(this).trigger("nwazet.removefromcart");
    setQuantityToZero("tr")($(this)).submit();
});

$(".addtocart-button").on("click", function () {
    $(this).trigger("nwazet.addtocart");
    return miniLoad($(this).parents("form"));
});

});

Comments (5)

  1. csurieux reporter

    In the mini shopping cart version, the delete and addtocart buttons where not working because the click event handler was set before the loading, I moved them after.

  2. Log in to comment