Guest User

Untitled

a guest
Apr 25th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. $(document).ready(function(){
  2. $('#form_container').click(function(event){
  3. var $tgt = $(event.target)
  4. if ($tgt.is('button')) {
  5. var id = $tgt.attr("id")
  6. var classes = $tgt.attr("class")
  7. if (classes.match(/delete/)) {
  8. 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>');
  9. $.ajax({
  10. type: "POST",
  11. data: {_method: "delete"},
  12. url: '/cart_items/' + id,
  13. dataType: "script",
  14. beforeSend: function(xhr){ confirm("Are you sure?");},
  15. success: function(data, status) {
  16. $newForm.insertAfter('#form_container').fadeIn('slow', function() {
  17. $('#' + id).remove()
  18. })
  19. }
  20. })
  21. return false
  22. }
  23. if (classes.match(/create/)) {
  24. 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>');
  25. $.ajax({
  26. type: "POST",
  27. data: {id: id},
  28. url: "/cart_items",
  29. dataType: "script",
  30. success: function(data, status) {
  31. $newForm.insertAfter('#form_container').fadeIn('slow', function() {
  32. $('#' + id).remove()
  33. })
  34. }
  35. })
  36. return false
  37. }
  38. }
  39. })
  40. })
Add Comment
Please, Sign In to add comment