Created
April 20, 2015 19:36
-
-
Save marshallm/72a7361dfd63e52884e8 to your computer and use it in GitHub Desktop.
jquery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tolerance:"touch", | |
drop:function (event, ui) { | |
var basket = $(this), | |
move = ui.draggable, | |
itemId = basket.find("ul li[data-id='" + move.attr("data-id") + "']"); | |
// To increase the value by +1 if the same item is already in the basket | |
if (itemId.html() != null) { | |
itemId.find("input").val(parseInt(itemId.find("input").val()) + 1); | |
} | |
else { | |
// Add the dragged item to the basket | |
addBasket(basket, move); | |
// Updating the quantity by +1" rather than adding it to the basket | |
move.find("input").val(parseInt(move.find("input").val()) + 1); | |
} | |
} | |
}); | |
// This function runs onc ean item is added to the basket | |
function addBasket(basket, move) { | |
basket.find("ul").append('<li data-id="' + move.attr("data-id") + '">' | |
+ '<span class="name">' + move.find("h4").html() + '</span>' | |
+ '<input class="count" value="1" type="text">' | |
+ '<input class="price" value="1" type="text">' | |
+ '<button class="delete">✕</button>'); | |
} | |
// The function that is triggered once delete button is pressed | |
$(".basket ul li button.delete").live("click", function () { | |
$(this).closest("li").remove(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment