Blame view

frontend/web/js/script.js 6.76 KB
fe7b6960   Yarik   Basket
1
  var artbox_basket = new ArtboxBasket();
d09f430f   Administrator   big commti
2
3
4
5
6
7
8
9
10
11
12
13
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
  
  /*order basket form js logic*/
  
  var recountPrice = function(container,new_value){
    var new_price = +$(container).find('.price span').html() * new_value;
    $(container).find('.cost span').html(new_price);
    var total_price = 0;
    $('#orderFrom').find('#cost span').each(function(){
      total_price += +$(this).html();
    });
  
    var total = $('#total span').html(total_price);
  };
  
  $(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*/
  
fe7b6960   Yarik   Basket
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  $(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);
  });
d09f430f   Administrator   big commti
84
  
fe7b6960   Yarik   Basket
85
86
87
88
89
90
91
92
93
  $(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');
  });
d09f430f   Administrator   big commti
94
95
  
  
fe7b6960   Yarik   Basket
96
97
98
99
100
101
102
103
  $(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');
a46c643b   Yarik   Link on top baske...
104
  });
d09f430f   Administrator   big commti
105
106
107
  
  
  $(document).on('click', '#top-cart-info', function() {
a46c643b   Yarik   Link on top baske...
108
    if(artbox_basket.count > 0) {
d09f430f   Administrator   big commti
109
      location.href='/order'
a46c643b   Yarik   Link on top baske...
110
111
    }
  });
d09f430f   Administrator   big commti
112
  
a46c643b   Yarik   Link on top baske...
113
114
115
116
  $(document).on('click', '#buyForm .cart_remove', function() {
    var container = $(this).parents('tr');
    var id = $(container).data('id');
    artbox_basket.set(id, 0);
d09f430f   Administrator   big commti
117
118
  });
  
7f87d6f9   Yarik   Modals.
119
120
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
169
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
227
228
229
230
231
  /* Category filter open submenu */
  $(document).on('click', '.properties_block', function(e) {
    var active = $(this).hasClass('opened');
    if(active) {
      $(this).removeClass('opened').addClass('closed');
      $(this).find('.chechboxes').hide();
    } else {
      $(this).removeClass('closed').addClass('opened');
      $(this).find('.chechboxes').show();
    }
  });
  /* 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) {
    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',
        top: 0,
        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);
      }
    })
  });
  /* End ajax form submit */