var onisoftPromoRabatClass = function(options){ var vars = { cdebug : false, percent_prefix: '- ', } /* * Private method */ var cDebug = function(info) { if(vars.cdebug == true){ console.log(info); } }; /* * Constructor */ this.construct = function(options){ $.extend(vars , options); cDebug(vars); }; this.displayRabaty = function(){ cDebug('start - displayRabaty'); $('.product').each(function() { var product = $(this); if(product.find('div.price del').length > 0) { var price_del = parseFloat(product.find('div.price del').text().replace(/[^0-9.,]/g, "").replace(',','.')); var price_new = parseFloat(product.find('div.price em').text().replace(/[^0-9.,]/g, "").replace(',','.')); var count_precent = Math.round(100 - (price_new * 100 / price_del)); if(count_precent >= 2){ var label_percent = vars.percent_prefix + count_precent+'%'; html = $('
'); html.addClass('onisoftPromoRabatClass'); html.text(label_percent); product.find('.boximgsize, .img-wrap').append(html); } } }); if($('.shop_product').length > 0){ if($('.shop_product').find('div.basket div.price del').length > 0){ var price_del = parseFloat($('.shop_product').find('div.basket div.price del').text().replace(/[^0-9.,]/g, "").replace(',','.')); var price_new = parseFloat($('.shop_product').find('div.basket div.price em').text().replace(/[^0-9.,]/g, "").replace(',','.')); var count_precent = Math.round(100 - (price_new * 100 / price_del)); if(count_precent >= 2){ var label_percent = vars.percent_prefix + count_precent+'%'; html = $('
'); html.addClass('onisoftPromoRabatClass'); html.text(label_percent); $('.shop_product').find('.productimg .mainimg').append(html); } } } cDebug('end - displayRabaty'); } this.construct(options); }; $(function() { var osoftPRC = new onisoftPromoRabatClass({}); osoftPRC.displayRabaty(); });