Blame view

frontend/web/js/front.js 8.55 KB
ae432de6   Alexey Boroda   first commit
1
  if ($.cookie("theme_csspath")) {
9870b2b4   Alexey Boroda   -In process
2
      $('link#theme-stylesheet').attr("href", $.cookie("theme_csspath"));
ae432de6   Alexey Boroda   first commit
3
4
  }
  if ($.cookie("theme_layout")) {
9870b2b4   Alexey Boroda   -In process
5
      $('body').addClass($.cookie("theme_layout"));
ae432de6   Alexey Boroda   first commit
6
7
  }
  
9870b2b4   Alexey Boroda   -In process
8
  $(function () {
ae432de6   Alexey Boroda   first commit
9
  
9870b2b4   Alexey Boroda   -In process
10
11
12
13
14
15
16
17
18
19
      sliderHomepage();
      sliders();
      fullScreenContainer();
      productDetailGallery(4000);
      menuSliding();
      productDetailSizes();
      utils();
      animations();
      counters();
      demo();
ae432de6   Alexey Boroda   first commit
20
  
9870b2b4   Alexey Boroda   -In process
21
  });
ae432de6   Alexey Boroda   first commit
22
23
24
25
26
27
  
  /* for demo purpose only - can be deleted */
  
  function demo() {
  
      if ($.cookie("theme_csspath")) {
9870b2b4   Alexey Boroda   -In process
28
  	$('link#theme-stylesheet').attr("href", $.cookie("theme_csspath"));
ae432de6   Alexey Boroda   first commit
29
30
      }
  
9870b2b4   Alexey Boroda   -In process
31
      $("#colour").change(function () {
ae432de6   Alexey Boroda   first commit
32
  
9870b2b4   Alexey Boroda   -In process
33
  	if ($(this).val() !== '') {
ae432de6   Alexey Boroda   first commit
34
  
9870b2b4   Alexey Boroda   -In process
35
  	    var theme_csspath = 'css/style.' + $(this).val() + '.css';
ae432de6   Alexey Boroda   first commit
36
  
9870b2b4   Alexey Boroda   -In process
37
  	    $('link#theme-stylesheet').attr("href", theme_csspath);
ae432de6   Alexey Boroda   first commit
38
  
9870b2b4   Alexey Boroda   -In process
39
40
  	    $.cookie("theme_csspath", theme_csspath, {expires: 365, path: '/'});
  	}
ae432de6   Alexey Boroda   first commit
41
  
9870b2b4   Alexey Boroda   -In process
42
43
44
45
  	return false;
      });
      
      $("#layout").change(function () {
ae432de6   Alexey Boroda   first commit
46
  
9870b2b4   Alexey Boroda   -In process
47
  	if ($(this).val() !== '') {
ae432de6   Alexey Boroda   first commit
48
  
9870b2b4   Alexey Boroda   -In process
49
              var theme_layout = $(this).val();
ae432de6   Alexey Boroda   first commit
50
  
9870b2b4   Alexey Boroda   -In process
51
52
53
54
              $('body').removeClass('wide');
              $('body').removeClass('boxed');
              
              $('body').addClass(theme_layout);
ae432de6   Alexey Boroda   first commit
55
  
9870b2b4   Alexey Boroda   -In process
56
57
  	    $.cookie("theme_layout", theme_layout, {expires: 365, path: '/'});
  	}
ae432de6   Alexey Boroda   first commit
58
  
9870b2b4   Alexey Boroda   -In process
59
60
  	return false;
      });    
ae432de6   Alexey Boroda   first commit
61
62
63
64
65
66
  }
  
  /* slider homepage */
  
  function sliderHomepage() {
      if ($('#slider').length) {
9870b2b4   Alexey Boroda   -In process
67
68
69
70
71
72
73
74
75
  	var owl = $("#slider");
  
  	$("#slider").owlCarousel({
  	    autoPlay: 3000,
  	    items: 4,
  	    itemsDesktopSmall: [900, 3],
  	    itemsTablet: [600, 3],
  	    itemsMobile: [500, 2]
  	});
ae432de6   Alexey Boroda   first commit
76
77
78
79
80
81
82
83
      }
  
  }
  /* sliders */
  
  function sliders() {
      if ($('.owl-carousel').length) {
  
9870b2b4   Alexey Boroda   -In process
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  	$(".customers").owlCarousel({
  	    items: 6,
  	    itemsDesktopSmall: [990, 4],
  	    itemsTablet: [768, 2],
  	    itemsMobile: [480, 1]
  	});
  
  	$(".testimonials").owlCarousel({
  	    items: 4,
  	    itemsDesktopSmall: [990, 3],
  	    itemsTablet: [768, 2],
  	    itemsMobile: [480, 1]
  	});
  
  	$('.project').owlCarousel({
  	    navigation: true, // Show next and prev buttons
  	    navigationText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
  	    slideSpeed: 300,
  	    paginationSpeed: 400,
  	    autoPlay: true,
  	    stopOnHover: true,
  	    singleItem: true,
  	    afterInit: '',
  	    lazyLoad: true
  	});
  
  	$('.homepage').owlCarousel({
  	    navigation: false, // Show next and prev buttons
  	    navigationText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],
  	    slideSpeed: 2000,
  	    paginationSpeed: 1000,
  	    autoPlay: true,
  	    stopOnHover: true,
  	    singleItem: true,
  	    lazyLoad: false,
  	    addClassActive: true,
  	    afterInit: function () {
  		//animationsSlider();
  	    },
  	    afterMove: function () {
  		//animationsSlider();
  	    }
  	});
ae432de6   Alexey Boroda   first commit
127
128
129
130
      }
  
  }
  
9870b2b4   Alexey Boroda   -In process
131
132
  
  
ae432de6   Alexey Boroda   first commit
133
134
135
136
  /* menu sliding */
  
  function menuSliding() {
  
9870b2b4   Alexey Boroda   -In process
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
  
      $('.dropdown').on('show.bs.dropdown', function (e) {
  
  	if ($(window).width() > 750) {
  	    $(this).find('.dropdown-menu').first().stop(true, true).slideDown();
  
  	}
  	else {
  	    $(this).find('.dropdown-menu').first().stop(true, true).show();
  	}
      }
  
      );
      $('.dropdown').on('hide.bs.dropdown', function (e) {
  	if ($(window).width() > 750) {
  	    $(this).find('.dropdown-menu').first().stop(true, true).slideUp();
  	}
  	else {
  	    $(this).find('.dropdown-menu').first().stop(true, true).hide();
  	}
      });
ae432de6   Alexey Boroda   first commit
158
159
160
161
162
163
164
  
  }
  
  /* animations */
  
  function animations() {
      delayTime = 0;
9870b2b4   Alexey Boroda   -In process
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
      $('[data-animate]').css({opacity: '0'});
      $('[data-animate]').waypoint(function (direction) {
  	delayTime += 150;
  	$(this).delay(delayTime).queue(function (next) {
  	    $(this).toggleClass('animated');
  	    $(this).toggleClass($(this).data('animate'));
  	    delayTime = 0;
  	    next();
  	    //$(this).removeClass('animated');
  	    //$(this).toggleClass($(this).data('animate'));
  	});
      },
  	    {
  		offset: '90%',
  		triggerOnce: true
  	    });
  
      $('[data-animate-hover]').hover(function () {
  	$(this).css({opacity: 1});
  	$(this).addClass('animated');
  	$(this).removeClass($(this).data('animate'));
  	$(this).addClass($(this).data('animate-hover'));
      }, function () {
  	$(this).removeClass('animated');
  	$(this).removeClass($(this).data('animate-hover'));
      });
ae432de6   Alexey Boroda   first commit
191
192
193
194
195
196
197
  
  }
  
  function animationsSlider() {
  
      var delayTimeSlider = 400;
  
9870b2b4   Alexey Boroda   -In process
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
      $('.owl-item:not(.active) [data-animate-always]').each(function () {
  
  	$(this).removeClass('animated');
  	$(this).removeClass($(this).data('animate-always'));
  	$(this).stop(true, true, true).css({opacity: 0});
  
      });
  
      $('.owl-item.active [data-animate-always]').each(function () {
  	delayTimeSlider += 500;
  
  	$(this).delay(delayTimeSlider).queue(function (next) {
  	    $(this).addClass('animated');
  	    $(this).addClass($(this).data('animate-always'));
  
  	    console.log($(this).data('animate-always'));
  
  	});
      });
  
  
ae432de6   Alexey Boroda   first commit
219
220
221
222
223
224
225
  
  }
  
  /* counters */
  
  function counters() {
  
9870b2b4   Alexey Boroda   -In process
226
227
228
229
      $('.counter').counterUp({
  	delay: 10,
  	time: 1000
      });
ae432de6   Alexey Boroda   first commit
230
231
232
  
  }
  
9870b2b4   Alexey Boroda   -In process
233
  
ae432de6   Alexey Boroda   first commit
234
235
236
237
  /* picture zoom */
  
  function pictureZoom() {
  
9870b2b4   Alexey Boroda   -In process
238
239
240
241
      $('.product .image, .post .image, .photostream div').each(function () {
  	var imgHeight = $(this).find('img').height();
  	$(this).height(imgHeight);
      });
ae432de6   Alexey Boroda   first commit
242
243
244
245
246
247
  }
  
  /* full screen intro */
  
  function fullScreenContainer() {
  
9870b2b4   Alexey Boroda   -In process
248
      var screenWidth = $(window).width() + "px";
ae432de6   Alexey Boroda   first commit
249
  
9870b2b4   Alexey Boroda   -In process
250
251
252
253
254
      if ($(window).height() > 500) {
  	var screenHeight = $(window).height() + "px";
      }
      else {
  	var screenHeight = "500px";
ae432de6   Alexey Boroda   first commit
255
256
      }
  
9870b2b4   Alexey Boroda   -In process
257
258
259
260
261
  
      $("#intro, #intro .item").css({
  	width: screenWidth,
  	height: screenHeight
      });
ae432de6   Alexey Boroda   first commit
262
263
264
265
266
  }
  function utils() {
  
      /* tooltips */
  
9870b2b4   Alexey Boroda   -In process
267
      $('[data-toggle="tooltip"]').tooltip();
ae432de6   Alexey Boroda   first commit
268
269
270
  
      /* click on the box activates the radio */
  
9870b2b4   Alexey Boroda   -In process
271
272
273
274
      $('#checkout').on('click', '.box.shipping-method, .box.payment-method', function (e) {
  	var radio = $(this).find(':radio');
  	radio.prop('checked', true);
      });
ae432de6   Alexey Boroda   first commit
275
276
      /* click on the box activates the link in it */
  
9870b2b4   Alexey Boroda   -In process
277
      $('.box.clickable').on('click', function (e) {
ae432de6   Alexey Boroda   first commit
278
  
9870b2b4   Alexey Boroda   -In process
279
280
  	window.location = $(this).find('a').attr('href');
      });
ae432de6   Alexey Boroda   first commit
281
282
      /* external links in new window*/
  
9870b2b4   Alexey Boroda   -In process
283
284
285
286
287
      $('.external').on('click', function (e) {
  
  	e.preventDefault();
  	window.open($(this).attr("href"));
      });
ae432de6   Alexey Boroda   first commit
288
289
      /* animated scrolling */
  
9870b2b4   Alexey Boroda   -In process
290
      $('.scroll-to, .scroll-to-top').click(function (event) {
ae432de6   Alexey Boroda   first commit
291
  
9870b2b4   Alexey Boroda   -In process
292
293
294
  	var full_url = this.href;
  	var parts = full_url.split("#");
  	if (parts.length > 1) {
ae432de6   Alexey Boroda   first commit
295
  
9870b2b4   Alexey Boroda   -In process
296
297
298
299
  	    scrollTo(full_url);
  	    event.preventDefault();
  	}
      });
ae432de6   Alexey Boroda   first commit
300
      function scrollTo(full_url) {
9870b2b4   Alexey Boroda   -In process
301
302
303
304
305
306
307
308
309
310
311
  	var parts = full_url.split("#");
  	var trgt = parts[1];
  	var target_offset = $("#" + trgt).offset();
  	var target_top = target_offset.top - 100;
  	if (target_top < 0) {
  	    target_top = 0;
  	}
  
  	$('html, body').animate({
  	    scrollTop: target_top
  	}, 1000);
ae432de6   Alexey Boroda   first commit
312
313
314
315
316
317
      }
  }
  
  /* product detail gallery */
  
  function productDetailGallery(confDetailSwitch) {
9870b2b4   Alexey Boroda   -In process
318
      $('.thumb:first').addClass('active');
ae432de6   Alexey Boroda   first commit
319
      timer = setInterval(autoSwitch, confDetailSwitch);
9870b2b4   Alexey Boroda   -In process
320
321
322
323
324
325
326
327
328
329
330
331
332
      $(".thumb").click(function (e) {
  
  	switchImage($(this));
  	clearInterval(timer);
  	timer = setInterval(autoSwitch, confDetailSwitch);
  	e.preventDefault();
      }
      );
      $('#mainImage').hover(function () {
  	clearInterval(timer);
      }, function () {
  	timer = setInterval(autoSwitch, confDetailSwitch);
      });
ae432de6   Alexey Boroda   first commit
333
      function autoSwitch() {
9870b2b4   Alexey Boroda   -In process
334
335
336
337
338
  	var nextThumb = $('.thumb.active').closest('div').next('div').find('.thumb');
  	if (nextThumb.length == 0) {
  	    nextThumb = $('.thumb:first');
  	}
  	switchImage(nextThumb);
ae432de6   Alexey Boroda   first commit
339
340
341
342
      }
  
      function switchImage(thumb) {
  
9870b2b4   Alexey Boroda   -In process
343
344
345
346
  	$('.thumb').removeClass('active');
  	var bigUrl = thumb.attr('href');
  	thumb.addClass('active');
  	$('#mainImage img').attr('src', bigUrl);
ae432de6   Alexey Boroda   first commit
347
348
349
350
351
352
      }
  }
  
  /* product detail sizes */
  
  function productDetailSizes() {
9870b2b4   Alexey Boroda   -In process
353
354
355
356
357
358
359
      $('.sizes a').click(function (e) {
  	e.preventDefault();
  	$('.sizes a').removeClass('active');
  	$('.size-input').prop('checked', false);
  	$(this).addClass('active');
  	$(this).next('input').prop('checked', true);
      });
ae432de6   Alexey Boroda   first commit
360
361
  }
  
9870b2b4   Alexey Boroda   -In process
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
  
  $.fn.alignElementsSameHeight = function () {
      $('.same-height-row').each(function () {
  
  	var maxHeight = 0;
  	var children = $(this).find('.same-height');
  	children.height('auto');
  	if ($(window).width() > 768) {
  	    children.each(function () {
  		if ($(this).innerHeight() > maxHeight) {
  		    maxHeight = $(this).innerHeight();
  		}
  	    });
  	    children.innerHeight(maxHeight);
  	}
  
  	maxHeight = 0;
  	children = $(this).find('.same-height-always');
  	children.height('auto');
  	children.each(function () {
  	    if ($(this).height() > maxHeight) {
  		maxHeight = $(this).innerHeight();
  	    }
  	});
  	children.innerHeight(maxHeight);
  
      });
ae432de6   Alexey Boroda   first commit
389
390
  }
  
9870b2b4   Alexey Boroda   -In process
391
  $(window).load(function () {
ae432de6   Alexey Boroda   first commit
392
  
9870b2b4   Alexey Boroda   -In process
393
      windowWidth = $(window).width();
ae432de6   Alexey Boroda   first commit
394
  
9870b2b4   Alexey Boroda   -In process
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
      $(this).alignElementsSameHeight();
      pictureZoom();
  });
  $(window).resize(function () {
  
      newWindowWidth = $(window).width();
  
      if (windowWidth !== newWindowWidth) {
  	setTimeout(function () {
  	    $(this).alignElementsSameHeight();
  	    fullScreenContainer();
  	    pictureZoom();
  	}, 205);
  	windowWidth = newWindowWidth;
      }
  
  });