Blame view

frontend/web/js/script.js 7.31 KB
bff65579   Виталий   test commit
1
2
3
4
5
6
  var artbox_basket = new ArtboxBasket();
  
  /*order basket form js logic*/
  
  var recountPrice = function(container,new_value){
    var new_price = +$(container).find('.price span').html() * new_value;
83ecdaba   Administrator   big commti
7
    $(container).find('.cost span').html(new_price.toFixed(2));
bff65579   Виталий   test commit
8
    var total_price = 0;
83ecdaba   Administrator   big commti
9
    $('#ordersFrom').find('#cost span').each(function(){
bff65579   Виталий   test commit
10
11
12
      total_price += +$(this).html();
    });
  
83ecdaba   Administrator   big commti
13
    var total = $('#total span').html(total_price.toFixed(2));
bff65579   Виталий   test commit
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  };
  
  $(document).on('click', '#ordersFrom .count_choise .plus', function(e) {
    e.preventDefault();
    var container = $(this).parents('.order_item');
    var input = $(container).find('.prod_count');
    var value = $(input).val();
    var new_value = parseInt(value) + 1;
    $(input).val(new_value);
    $(input).trigger('change');
    recountPrice(container,new_value);
  
  });
  
  $(document).on('click', '#ordersFrom .count_choise .minus', function(e) {
    e.preventDefault();
    var container = $(this).parents('.order_item');
    var input = $(container).find('.prod_count');
    var value = $(input).val();
    if(value > 1 ){
      var new_value = parseInt(value) - 1;
      $(input).val(new_value);
      $(input).trigger('change');
      recountPrice(container,new_value);
    }
  
  });
  
  $(document).on('change', '#ordersFrom .prod_count', function(e) {
    e.preventDefault();
    var container = $(this).parents('.order_item');
    var new_value = $(this).val();
    recountPrice(container,new_value);
    var product_variant_id = container.data('id');
    var value = $(this).val();
    if(value < 0) {
      value = 0;
    }
    artbox_basket.set(product_variant_id, value);
  });
  
  
  
  $(document).on('click', '#ordersFrom .cart_remove', function(e) {
    e.preventDefault();
    var container = $(this).parents('.order_item');
  
    var id = $(container).data('id');
    container.remove();
    artbox_basket.set(id, 0);
  });
  
  
  /*end order basket form js logic*/
  
  $(document).on('click', '.buy_button', function(e) {
    e.preventDefault();
    var product_variant_id = $(this).data('id');
    var count = 1;
    artbox_basket.add(product_variant_id, count);
  });
  $(document).on('change', '#buyForm .prod_count', function(e) {
    e.preventDefault();
    var product_variant_id = $(this).parents('tr').data('id');
    var value = $(this).val();
    if(value < 0) {
      value = 0;
    }
    artbox_basket.set(product_variant_id, value);
  });
  
  $(document).on('click', '#buyForm .count_choise .minus', function(e) {
    e.preventDefault();
    var container = $(this).parents('tr');
    var input = $(container).find('.prod_count');
    var value = $(input).val();
    var new_value = parseInt(value) - 1;
    $(input).val(new_value);
    $(input).trigger('change');
  });
  
  
  $(document).on('click', '#buyForm .count_choise .plus', function(e) {
    e.preventDefault();
    var container = $(this).parents('tr');
    var input = $(container).find('.prod_count');
    var value = $(input).val();
    var new_value = parseInt(value) + 1;
    $(input).val(new_value);
    $(input).trigger('change');
  });
  
bff65579   Виталий   test commit
106
107
108
109
110
111
112
  $(document).on('click', '#buyForm .cart_remove', function() {
    var container = $(this).parents('tr');
    var id = $(container).data('id');
    artbox_basket.set(id, 0);
  });
  
  /* Category filter open submenu */
118c6c59   Виталий   test commit
113
114
  $(document).on('click', '.block_title', function(e) {
    var active = $(this).parent().hasClass('opened');
bff65579   Виталий   test commit
115
    if(active) {
118c6c59   Виталий   test commit
116
117
      $(this).parent().removeClass('opened').addClass('closed');
      $(this).parent().find('.chechboxes').hide();
bff65579   Виталий   test commit
118
    } else {
118c6c59   Виталий   test commit
119
120
      $(this).parent().removeClass('closed').addClass('opened');
      $(this).parent().find('.chechboxes').show();
bff65579   Виталий   test commit
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
    }
  });
  /* End Category filter open submenu */
  /* Cart resize on scroll */
  $('.img_part').height($('.info').height());
  $(document).on('scroll', window, function(e)
  {
    currentScroll = $(window).scrollTop();
    if (currentScroll > 0) {
      $('#top-cart-content').addClass('small-cart');
    } else {
      $('#top-cart-content').removeClass('small-cart');
    }
  });
  /* End cart resize on scroll */
  /* Catalog product scroll watcher */
  $(document).on('scroll', window, function(e) {
      if(($('.detail_main_tabs').length)>0) {
          checkFixed(e);
          checkSelector(e);
      }
  
  });
  function checkFixed(e) {
    var img_part = $('.img_part');
    var position = $(img_part).find('.position');
    var position_height = $(position).height();
    var info = $('.info');
    var info_position = $(info).position();
    var info_height = $(info).height();
    var info_top = info_position.top;
    var info_bottom = info_top + info_height;
    var currentScroll = $(window).scrollTop();
    if(info_bottom - currentScroll > 0 && info_bottom - currentScroll < position_height) {
      $(position).removeClass('fixed').css({
        position: 'absolute',
        bottom: 0,
        top: 'auto',
      });
    } else if(currentScroll > info_top && currentScroll < info_bottom) {
      $(position).addClass('fixed').css({
        position: 'fixed',
        top: '100px',
        bottom: 'auto'
      });
    } else {
      $(position).removeClass('fixed').css({
        position: 'relative',
f2f358f5   Yarik   JS fix
169
        top: '50px',
bff65579   Виталий   test commit
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
        bottom: 'auto'
      });
    }
  }
  function checkSelector(e) {
    var tab_content = $('#characteristics');
    var tab_content_top = $(tab_content).position().top - 100;
    var comments_block = $('#reviews');
    var comments_block_top = $(comments_block).position().top - 100;
    var collection = $('#collection');
    var collection_top = $(collection).position().top - 100;
    var currentScroll = $(window).scrollTop();
    var detail_main_tabs = $('.detail_main_tabs');
    var active;
    if(currentScroll > tab_content_top && currentScroll < collection_top) {
      active = 'characteristics';
    } else if(currentScroll > comments_block_top) {
      active = 'reviews';
    } else if(currentScroll > collection_top && currentScroll < comments_block_top) {
      active = 'collection';
    }
    $(detail_main_tabs).find('li.selected').removeClass('selected');
    $(detail_main_tabs).find('[data-target='+active+']').addClass('selected');
  }
  $(window).scroll(function(e) {
    // checkFixed(e);
    // checkSelector(e);
  });
  /* End catalog product scroll watcher */
  /* Animated links */
  $(document).on('click', '.detail_main_tabs a', function(e) {
    e.preventDefault();
    var hash = $(this).attr('href').replace(/^.*?(#|$)/,'');
    var target = $('#'+hash);
    var target_top = $(target).position().top - 50;
    var body = $('html, body');
    body.stop().animate({scrollTop:target_top}, 500, 'swing', function() {});
  });
  /* End animated links */
  /* Ajax form submit */
  $(document).on('submit', '#feedback-form', function(e) {
    e.preventDefault();
    $.post('/ajax/feedback', $(this).serialize(), function(data) {
      $('#myCallback').find('.modal-body').html(data.result);
    });
  });
  $(document).on('submit', '#quickbuy-form', function(e) {
    e.preventDefault();
    var container = $(this).parents('.fast_order_form');
    $.post('/order/quick', $(this).serialize(), function(data) {
      if(!data.error) {
        $(container).html(data.result);
      } else {
        $(container).html(data.error);
      }
    })
  });
0fc3bf10   Yarik   Quickbuy modal
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
  $(document).on('submit', '#quickbuy-modal', function(e)
  {
    e.preventDefault();
    var form = $('#buyForm');
    $.post('/order/quick-basket', $(this).serialize(), function(data)
    {
      if(!data.error) {
        $(form).find('.modal-body').html(data.result);
      } else {
        $(form).find('.modal-body').html(data.error);
      }
    }).fail(function(jqXHR, textStatus, errorThrown) {
      $(form).find('.modal-body').html(JSON.parse(jqXHR.responseText).message);
    });
    $(form).find('.modal-title').remove();
    $(form).find('.modal-footer').remove();
  });
bff65579   Виталий   test commit
244
  /* End ajax form submit */