Advertisement
Einav_Chazen

Untitled

Jan 24th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function isp_add_to_cart(event, product_id) {
  2.     $jquery.ajax({
  3.         url: "/cart/?add-to-cart=" + product_id + "&quantity=1",
  4.         type: "POST",
  5.         beforeSend: function(result) {
  6.             $("#btn_" + product_id).css("background-image", "url(https://storagehub.vmware.com/static/images/vmware/loading.gif)");
  7.             $("#btn_" + product_id).css("background-size", "25px");
  8.             if ($jquery(window).width() > 480) {
  9.                 $jquery('.header-wrapper .cart-button b').html("<img src='https://storagehub.vmware.com/static/images/vmware/loading.gif' style='width: 15px; height: 15px;'>");
  10.             } else {
  11.                 $jquery('#mobile-header .cart-button b').html("<img src='https://storagehub.vmware.com/static/images/vmware/loading.gif' style='width: 15px; height: 15px;'>");
  12.             }
  13.         },
  14.         success: function(result) {
  15.             $("#btn_" + product_id).css("background-image", "url(https://www.vivamart.no/wp-content/themes/onesocial-child/images/cart-hover.png)");
  16.             $("#btn_" + product_id).css("background-size", "50px");
  17.             if ($jquery(window).width() > 480) {
  18.                 $jquery('.header-wrapper .cart-button b').load(document.URL +  '.header-wrapper .header-total', function() {
  19.                     var seen = {};
  20.                     $jquery('.header-wrapper .header-total').each(function() {
  21.                         var txt = $jquery(this).text();
  22.                         if (seen[txt]) { $jquery(this).remove(); }
  23.                         else { seen[txt] = true; }
  24.                     });
  25.                 });
  26.             } else {
  27.                 $jquery('#mobile-header .cart-button b').load(document.URL +  '#mobile-header .header-total', function() {
  28.                     var seen = {};
  29.                     $jquery('#mobile-header .header-total').each(function() {
  30.                         var txt = $jquery(this).text();
  31.                         if (seen[txt]) { $jquery(this).remove(); }
  32.                         else { seen[txt] = true; }
  33.                     });
  34.                 });
  35.             }
  36.         },
  37.         error: function(result) {
  38.             console.log("error");
  39.         }
  40.     });
  41.  
  42.     event.preventDefault();
  43.     event.stopPropagation();
  44.     event.stopImmediatePropagation();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement