Advertisement
Guest User

JS сценарий модуля

a guest
Dec 29th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(".js_shop_depend_param, .shop_form .depend_param").change(function() {
  2.     select_param_price($(this).parents('form'));
  3. });
  4. $(".js_shop_form, .shop_form").each(function() {
  5.     empty_param_price($(this));
  6.     select_param_price($(this));
  7. });
  8. $("input[action=buy]").click(function() {
  9.     $(this).parents('form').find('input[name=action]').val('buy');
  10.     $(this).parents('form').submit();
  11. });
  12. $("input[action=wish]").click(function() {
  13.     $(this).parents('form').find('input[name=action]').val('wish');
  14.     $(this).parents('form').submit();
  15. });
  16. $("input[action=wait]").click(function() {
  17.     $(this).parents('form').find('input[name=action]').val('wait');
  18.     $(this).parents('form').submit();
  19. });
  20. $("input[action=one_click]").click(function() {
  21.     $('form[one_click=true]').removeAttr('one_click');
  22.     $(this).parents('form').attr('one_click', 'true');
  23.     $(this).parents('.js_shop').find('.js_cart_one_click, .cart_one_click').show();
  24.    
  25. });
  26. $(".js_cart_one_click_form, .cart_one_click_form").on('click', ":button", function(){
  27.     var self = $(this).parents(".js_cart_one_click_form, .cart_one_click_form");
  28.     $('.js_shop_form_param input, .js_shop_form_param select, .shop_form_param input, .shop_form_param select, input[name=count]', 'form[one_click=true]').each(function(){
  29.         $("input[name="+$(this).attr('name')+"]", self).remove();
  30.         self.prepend('<input type="hidden" name="'+$(this).attr('name')+'" value="'+$(this).val()+'">');
  31.     });
  32.     self.submit();
  33. });
  34.  
  35. $('.js_shop_wishlist, .shop-like').click(function() {
  36.     var form = $(this).parents('.js_shop, .shop').find('.js_shop_form, .shop_form').first();
  37.     form.find('input[name=action]').val('wish')
  38.     form.submit(); 
  39. });
  40.  
  41. $('.js_shop_add_compare, .shop_compare_button').click(function() {
  42.     $(this).parents('form').submit();
  43. });
  44.  
  45. function select_param_price(th)
  46. {
  47.     var param_code = '';
  48.     $(".js_shop_depend_param, .depend_param", th).each(function(){
  49.         param_code = param_code + '[' + $(this).attr('name') + '=' + $(this).val() + ']';
  50.     });
  51.     if($('.js_shop_param_price, .shop_param_price', th).length)
  52.     {
  53.         $('.js_shop_param_price, .shop_param_price', th).hide();
  54.         if($('.js_shop_param_price' + param_code + ', .shop_param_price' + param_code, th).length)
  55.         {
  56.             $('.js_shop_param_price' + param_code + ', .shop_param_price'+param_code, th).show();
  57.             var image_id = $('.js_shop_param_price' + param_code + ', .shop_param_price' + param_code, th).attr('image_id');
  58.             if(image_id)
  59.             {
  60.                 th.parents('.js_shop, .shop').find('.js_shop_img, .shop-item-big-images a, .shop-photo img').each(function(){
  61.                     if($(this).attr('image_id') == image_id)
  62.                     {
  63.                         $(this).show();
  64.                     }
  65.                     else
  66.                     {
  67.                         if($('.js_shop_param_price[image_id='+$(this).attr('image_id')+'], .shop_param_price[image_id='+$(this).attr('image_id')+']', th).length)
  68.                         {
  69.                             $(this).hide();
  70.                         }
  71.                     }
  72.                 });
  73.             }
  74.             if($('.js_shop_param_price' + param_code + ', .shop_param_price'+param_code, th).find('.js_shop_no_buy, .shop_no_buy').length)
  75.             {
  76.                 $('.js_show_waitlist, .shop_waitlist', th).show();
  77.                 $('.js_shop_buy, .to-cart', th).hide();
  78.                 $('.js_shop_one_click, .shop_one_click', th).hide();
  79.             }
  80.             else
  81.             {
  82.                 if($('.js_shop_no_buy_good, .shop_no_buy_good', th).length)
  83.                 {
  84.                     $('.js_shop_waitlist, .shop_waitlist', th).show();
  85.                 }
  86.                 else
  87.                 {
  88.                     $('.js_shop_waitlist, .shop_waitlist', th).hide();
  89.                 }
  90.                 $('.js_shop_buy, .to-cart', th).show();
  91.                 $('.js_shop_one_click, .shop_one_click', th).show();
  92.             }
  93.         }
  94.         else
  95.         {
  96.             th.parents('.js_shop, .shop').find('.js_shop_img, .shop_img img, .shop_all_img img').each(function(){
  97.                 if($('.js_shop_param_price[image_id='+$(this).attr('image_id')+'], .shop_param_price[image_id='+$(this).attr('image_id')+']', th).length)
  98.                 {
  99.                     $(this).hide();
  100.                 }
  101.             });
  102.             $('.js_shop_buy, .to-cart', th).hide();
  103.             $('.js_shop_one_click, .shop_one_click', th).hide();
  104.             $('.js_shop_waitlist, .shop_waitlist', th).hide();
  105.         }
  106.     }
  107. }
  108.  
  109. function empty_param_price(th)
  110. {
  111.     var param_code = '';
  112.     $(".js_shop_depend_param", th).each(function(){
  113.         param_code = param_code + '['+$(this).attr('name')+'='+$(this).val()+']';
  114.     });
  115.     if($('.js_shop_param_price', th).length)
  116.     {
  117.         if($('.js_shop_param_price' + param_code, th).length)
  118.         {
  119.             if($('.js_shop_param_price' + param_code +' .js_shop_no_buy', th).length)
  120.             {
  121.                 var shop_depend_param = $(".js_shop_depend_param", th).first();
  122.                 if(get_selected(shop_depend_param).next('option').length)
  123.                 {
  124.                     get_selected(shop_depend_param).next('option').attr('selected', 'selected');
  125.                     empty_param_price(th);
  126.                 }
  127.             }
  128.         }
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement