Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var __isp_options = {
  2.     isp_dropdown_callback: function(jquery_li_element, item) {
  3.         var product_id = jquery_li_element.attr('isp_id');
  4.         var product_sku = item.sku;
  5.         if (!item.id || item.category || !item.product_url) { return jquery_li_element; }
  6.         var addtocart_html = "<form style='position: absolute; right: 0; top: 50%; transform: translateY(-50%); z-index: 2147483647;' name='form_" + product_id + "' id='form_" + product_id + "' class='isp_add_to_cart_form' enctype='multipart/form data' method='post'>";
  7.         addtocart_html += "<input name='product_id' type='hidden' value=" + product_id + ">";
  8.         addtocart_html += "<input name='action' type='hidden' value='add'>";
  9.         addtocart_html += "<input name='product_sku' type='hidden' value=" + product_sku + ">";
  10.         addtocart_html += "<input type='hidden' id='quantity_" + product_id + "' name='qty[]' value='1' min='1' autocomplete='off' type='number'>";
  11.         addtocart_html += "<input style='background-color: #f95113; padding: 0; width: 60px; height: 60px; background-image: url(https://www.vivamart.no/wp-content/themes/onesocial-child/images/cart-hover.png); background-size: 50px; background-position: center; background-repeat: no-repeat;' id='btn_" + product_id + "' onclick='isp_add_to_cart(event, " + product_id + ")' type='submit' value='' class='isp_add_to_cart_btn'>";
  12.         addtocart_html += "</form>";
  13.         return jquery_li_element.prepend(addtocart_html);
  14.     }
  15. }
  16.  
  17. function isp_add_to_cart(event, product_id) {
  18.     $jquery.ajax({
  19.         url: "/cart/?add-to-cart=" + product_id + "&quantity=1",
  20.         type: "POST",
  21.         beforeSend: function(result) {
  22.             $("#btn_" + product_id).css("background-image", "url(https://storagehub.vmware.com/static/images/vmware/loading.gif)");
  23.             $("#btn_" + product_id).css("background-size", "25px");
  24.             if ($jquery_isp(window).width() > 480) {
  25.                 $jquery_isp('.header-wrapper .cart-button b').html("<img src='https://storagehub.vmware.com/static/images/vmware/loading.gif' style='width: 15px; height: 15px;'>");
  26.             } else {
  27.                 $jquery_isp('#mobile-header .cart-button b').html("<img src='https://storagehub.vmware.com/static/images/vmware/loading.gif' style='width: 15px; height: 15px;'>");
  28.             }
  29.         },
  30.         success: function(result) {
  31.             $("#btn_" + product_id).css("background-image", "url(https://www.vivamart.no/wp-content/themes/onesocial-child/images/cart-hover.png)");
  32.             $("#btn_" + product_id).css("background-size", "50px");
  33.             if ($jquery_isp(window).width() > 480) {
  34.                 $jquery_isp('.header-wrapper .cart-button b').load(document.URL +  '.header-wrapper .header-total', function() {
  35.                     var seen = {};
  36.                     $jquery_isp('.header-wrapper .header-total').each(function() {
  37.                         var txt = $jquery_isp(this).text();
  38.                         if (seen[txt]) { $jquery_isp(this).remove(); }
  39.                         else { seen[txt] = true; }
  40.                     });
  41.                 });
  42.             } else {
  43.                 $jquery_isp('#mobile-header .cart-button b').load(document.URL +  '#mobile-header .header-total', function() {
  44.                     var seen = {};
  45.                     $jquery_isp('#mobile-header .header-total').each(function() {
  46.                         var txt = $jquery_isp(this).text();
  47.                         if (seen[txt]) { $jquery_isp(this).remove(); }
  48.                         else { seen[txt] = true; }
  49.                     });
  50.                 });
  51.             }
  52.         },
  53.         error: function(result) {
  54.             console.log("error");
  55.         }
  56.     });
  57.  
  58.     event.preventDefault();
  59.     event.stopPropagation();
  60.     event.stopImmediatePropagation();
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement