Advertisement
abushyk

realia:favorites_add_rem

Feb 15th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).on('click','a.fav-add',function(e){
  2.         var o=$(this);
  3.         var id=o.attr('alt');
  4.         if(id){
  5.             $.ajax({
  6.                 url: estate_folder + "/js/ajax.php?action=add_to_favorites",
  7.                 data: 'id='+id,
  8.                 type: "POST",
  9.                 dataType: "json",
  10.                 success: function(json){
  11.                     if(json.response.body=='OK'){
  12.                         var favcount=$('#favorites_count');
  13.                         if(favcount.length>0){
  14.                             favcount.text(new Number($('#favorites_count').text())+1);
  15.                         }
  16.                         o.removeClass('fav-add').addClass('fav-rem');
  17.                     }
  18.                 },
  19.                 error: function(xhr, ajaxOptions, thrownError){
  20.                    
  21.                 }
  22.             });
  23.         }
  24.         e.preventDefaults();
  25.     });
  26.    
  27.     $(document).on('click','a.fav-rem',function(e){
  28.         var o=$(this);
  29.         var id=o.attr('alt');
  30.         if(id){
  31.             $.ajax({
  32.                 url: estate_folder + "/js/ajax.php?action=remove_from_favorites",
  33.                 data: 'id='+id,
  34.                 type: "POST",
  35.                 dataType: "json",
  36.                 success: function(json){
  37.                     if(json.response.body=='OK'){
  38.                         var favcount=$('#favorites_count');
  39.                         if(favcount.length>0){
  40.                             favcount.text(new Number($('#favorites_count').text())-1);
  41.                         }
  42.                         o.removeClass('fav-rem').addClass('fav-add');
  43.                     }
  44.                 },
  45.                 error: function(xhr, ajaxOptions, thrownError){
  46.                    
  47.                 }
  48.             });
  49.         }
  50.         e.preventDefaults();
  51.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement