// JavaScript Document var h_hght = 120; // высота шапки var h_mrg = 0; $(function(){ $(window).scroll(function(){ var top = $(this).scrollTop(); var elem = $('#top_nav'); if (top+h_mrg>h_hght) { $("#top_nav").addClass("sticky") } else { $("#top_nav").removeClass("sticky") } }); }); // JavaScript Document /*-----block_product_min_height-----*/ var flag_call_timestart_once= 0; var rtime; var timeout = false; var delta = 2000; function timestart() { rtime = new Date(); if (timeout === false) { timeout = true; setTimeout(timeend, delta); } } function timeend() { if (new Date() - rtime < delta) { setTimeout(timeend, delta); } else { timeout = false; // To do initPage(); } } /* x_equal_h */ var x_equal_h_obj= {}; var x_hash= "#content>.cpt_maincontent >.catalog>.cpt_product_lists>ul.product_list>li.block_product"; var x_numcol= 0; function row_eq_h(x_hash, x_slice_1, x_slice_2){ var max_heigt= 0; var element_height = 0; console.log('$("%s").slice( %s, %s)',x_hash, x_slice_1, x_slice_2); var items = $(x_hash).slice( x_slice_1, x_slice_2); var flag_row_skip= false; items.each(function(index, element) { /*Находим самую высокую картинку*/ element_img= $(element).find("img"); /**/ element_img.addClass("x"+x_slice_1); flag_isImageLoaded= false; element_img.each(function() { if(this.complete) flag_isImageLoaded= true; }); // console.log('[flag_isImageLoaded]=>%s)',flag_isImageLoaded); if(!flag_isImageLoaded)flag_row_skip=true; element_height= $(element).height(); if(element_height>max_heigt)max_heigt= element_height; }); console.log('[flag_row_skip]=>%s)',flag_row_skip); if(!flag_row_skip){ items.each(function(index, element) { /*Прописываем отступы чтобы выровнять высоту*/ max_vs_el_diferense= max_heigt-$(element).height(); margin_top_btm= Math.round(max_vs_el_diferense/2); if(margin_top_btm>0)$(element).find("img").css("margin",""+margin_top_btm+"px 0px") if((max_vs_el_diferense%2)==1){ if(margin_top_btm>0)$(element).find("img").css("margin",""+(margin_top_btm-1)+"px 0px "+margin_top_btm+"px") } }); x_equal_h_obj[x_slice_1]= 1; return true; }else{ x_equal_h_obj[x_slice_1]= 0; } } var flag_call_timestart_once= 0; var rtime; var timeout = false; var timestart_delta = 1000; var timestart_delta_increment = 1000; function x_timestart() { rtime = new Date(); if (timeout === false) { timeout = true; setTimeout(x_timeend, timestart_delta); } } function x_timeend() { if (new Date() - rtime < timestart_delta) { setTimeout(x_timeend, timestart_delta); } else { timeout = false; // To do x_recursion_eq_rows(); } } function x_recursion_eq_rows(){ for (var i in x_equal_h_obj) { if(x_equal_h_obj[i]==0)row_eq_h(x_hash, i, parseInt(i)+x_numcol); } var flag_has_0= false; for (var i in x_equal_h_obj) { if(x_equal_h_obj[i]==0)flag_has_0= true; } if(flag_has_0){ timestart_delta= timestart_delta+timestart_delta_increment; x_timestart(); } } function x_equal_h(){ var x_length= $(x_hash).length; if(!x_length)return; var _offsetTop= $(x_hash).eq(0).position().top; $(x_hash).each(function(index){ /*вычисляем количиствао колонок*/ if( _offsetTop!=parseInt($(this).position().top)){ return false; } x_numcol++; }) i=0; while (i < x_length) { row_eq_h(x_hash, i, i+x_numcol); i=i+x_numcol; } x_timestart(); console.log(JSON.stringify(x_equal_h_obj)); } /* ~x_equal_h */ function initPage(){ x_equal_h(); // Прибавление кол-ва товара. Лимит 999. Измените 999 на необходимое число $(document).on("click", ".inc_product", function () { var current = $(this).prev(".select_input").val(); if (current >= 999) { var current = 999; } $(this).prev(".select_input").val(parseInt(current) + 1); return false; }); // Вычитание кол-ва товара. Лимит 1 $(document).on("click", ".dec_product", function () { var current = $(this).next(".select_input").val(); if (current == 1) { var current = 2; } $(this).next(".select_input").val(parseInt(current) - 1); return false; }); } $(document).ready(function(){ initPage(); })