Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function(){
- $('#form_container').click(function(event){
- var $tgt = $(event.target)
- if ($tgt.is('button')) {
- var id = $tgt.attr("id")
- var classes = $tgt.attr("class")
- if (classes.match(/delete/)) {
- var $newForm = $('<form method="post" action="/cart_items" id="' + id + '" class="create"><input type="hidden" name="id" value="' + id + '" /><button id="' + id + '" type="submit" class="button positive"><img src="/stylesheets/lib/img/icons/tick.png" alt=""/> Add</button></form>');
- $.ajax({
- type: "POST",
- data: {_method: "delete"},
- url: '/cart_items/' + id,
- dataType: "script",
- beforeSend: function(xhr){ confirm("Are you sure?");},
- success: function(data, status) {
- $newForm.insertAfter('#form_container').fadeIn('slow', function() {
- $('#' + id).remove()
- })
- }
- })
- return false
- }
- if (classes.match(/create/)) {
- var $newForm = $('<form method="post" action="/cart_items/' + id + '" id="' + id + '" class="delete"><input type="hidden" name="_method" value="delete" /><button type="submit" id="' + id + '" class="button remove"><img src="/stylesheets/lib/img/icons/tick.png" alt=""/> Remove</button></form>');
- $.ajax({
- type: "POST",
- data: {id: id},
- url: "/cart_items",
- dataType: "script",
- success: function(data, status) {
- $newForm.insertAfter('#form_container').fadeIn('slow', function() {
- $('#' + id).remove()
- })
- }
- })
- return false
- }
- }
- })
- })
Add Comment
Please, Sign In to add comment