/* CORE */ function init_frontend(){ // } /* PROJECT */ function fix_plist() { } $(function(){ jQuery.expr[':'].Contains = function(a, i, m) { return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0; }; $("#winner_search_input").on('keyup', function() { var item = $(".lottery_winners td:Contains(" + this.value + ")"); if (typeof item.html() != 'undefined'){ $(".lottery_winners tr").hide(); $(item).parent().show(); } else { $(".lottery_winners tr").show(); } }); // sarasai // $(document).on('click', 'div.list-collapse > .title, div.list-collapse-mobile > .title', function(e){ // e.preventDefault(); // var $list = $(this).parent(); // $list.toggleClass('open'); // }); calcIframeHeight(); $(document).on('click', 'div.list-collapse > .title', function(e){ e.preventDefault(); var $list = $(this).parent(); $list.toggleClass('open'); }); $(document).on('click', 'div.list-collapse-mobile > .title', function(e){ if ($(window).width()<992) { e.preventDefault(); var $list = $(this).parent(); $list.toggleClass('open'); } }); $(document).on('click', 'div.list-dropdown > .title', function(){ var $list = $(this).parent(); // jeigu click'as ivyko 100ms po hoverio, reikia uzdaryti drop-down'a if ($list.is('.hover') && ($list.data('hovertime') < (new Date()).getTime() - 100)) { $list.removeClass('hover'); } else { $list.addClass('hover'); } }); var timeout = false; $(document).on('mouseenter', 'div.list-dropdown', function(){ //$(this).addClass('hover'). var el = $(this); timeout = setTimeout(function(){ el.addClass('hover').data('hovertime', (new Date()).getTime()); }, 500); }); $(document).on('mouseleave', 'div.list-dropdown', function(){ clearTimeout(timeout); var hovertime = $(this).data('hovertime'); var hover_delay = $(this).data('hover-delay') ? $(this).data('hover-delay') : 0; var $dropdown = $(this); setTimeout(function(){ // patikrinam, ar siuo metu dropdown'as tikrai neturetu buti rodomas if ($dropdown.data('hovertime') == hovertime) { $dropdown.removeClass('hover'); } }, hover_delay); }); // $(document).on('click', "a[data-promoclick]", function(e){ // var promo_name = $(this).data('promoclick'); // var promo_id = $(this).data('promoid'); // var promo_type = $(this).data('promotype'); // promo_click(promo_id, promo_name, promo_type); // }); $(document).on('click', "a[data-productclick]", function(e){ var info = $(this).data('productclick'); product_click(info); }); $(document).on('click', "[data-action='add2favorite']", function(e){ e.preventDefault(); $('#ajax_loader').show(); e.preventDefault(); var el = $(this); var id = el.data('id'); $.ajax({ url: '?display=content_types/products/add2favorite', type: 'POST', dataType: 'json', data: { item_id:id }, success: function(json){ $('#ajax_loader').hide(); if (typeof json.action !== 'undefined') { if (json.action == 'added') { el.find('i').removeClass('ico-heart').addClass('ico-heart-filled'); } else { el.find('i').removeClass('ico-heart-filled').addClass('ico-heart'); } } else if (typeof json.html !== 'undefined') { $('body').append(json.html); $.fancybox.open($('#cart_added'), { 'padding': 15, 'afterShow': function () { $(".fancybox-inner").css({'overflow-x': 'hidden'}).css({'overflow-y': 'hidden'}); } }); $('#cart_added a.btn-default').click(function (e) { e.preventDefault(); $.fancybox.close(); }); } } }); }); }); function promo_click(promo_id, promo_name, promo_type) { if (typeof (ga) !== "undefined") { ga('ec:addPromo', { 'id': promo_id, 'name': promo_name, 'position': promo_type }); ga('ec:setAction', 'promo_click'); ga('send', 'event', 'Internal Promotions', 'click', promo_name); } } function product_click(info) { if (typeof dataLayer == 'object') { dataLayer.push({ 'event': 'productClick', 'ecommerce': { 'click': { 'actionField': {'list': info.list}, 'products': [{ 'id': info.id, 'name': info.name, 'category': info.category, 'brand': info.brand, 'variant': info.variant, 'price': info.price, 'quantity': 1, 'metric1': info.old_price, }] } } }); } // if (typeof (ga) !== "undefined") { // ga('ec:addProduct', { // 'id': info.id, // 'name': info.name, // 'brand': info.brand, // 'position': info.position // }); // // ga("ec:setAction", "click", { "list": info.list }); // ga("send", "event", info.list, "click", ""); // } } function htmlspecialchars_decode (string, quote_style) { // Convert special HTML entities back to characters // // version: 1009.2513 // discuss at: http://phpjs.org/functions/htmlspecialchars_decode // + original by: Mirek Slugen // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + bugfixed by: Mateusz "loonquawl" Zalega // + input by: ReverseSyntax // + input by: Slawomir Kaniecki // + input by: Scott Cariss // + input by: Francois // + bugfixed by: Onno Marsman // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + bugfixed by: Brett Zamir (http://brett-zamir.me) // + input by: Ratheous // + input by: Mailfaker (http://www.weedem.fr/) // + reimplemented by: Brett Zamir (http://brett-zamir.me) // + bugfixed by: Brett Zamir (http://brett-zamir.me) // * example 1: htmlspecialchars_decode("
this -> "
", 'ENT_NOQUOTES'); // * returns 1: 'this -> "
' // * example 2: htmlspecialchars_decode("""); // * returns 2: '"' var optTemp = 0, i = 0, noquotes= false; if (typeof quote_style === 'undefined') { quote_style = 2; } string = string.toString().replace(/</g, '<').replace(/>/g, '>'); var OPTS = { 'ENT_NOQUOTES': 0, 'ENT_HTML_QUOTE_SINGLE' : 1, 'ENT_HTML_QUOTE_DOUBLE' : 2, 'ENT_COMPAT': 2, 'ENT_QUOTES': 3, 'ENT_IGNORE' : 4 }; if (quote_style === 0) { noquotes = true; } if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags quote_style = [].concat(quote_style); for (i=0; i < quote_style.length; i++) { // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4 if (OPTS[quote_style[i]] === 0) { noquotes = true; } else if (OPTS[quote_style[i]]) { optTemp = optTemp | OPTS[quote_style[i]]; } } quote_style = optTemp; } if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) { string = string.replace(/*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should // string = string.replace(/'|*27;/g, "'"); // This would also be useful here, but not a part of PHP } if (!noquotes) { string = string.replace(/"/g, '"'); } // Put this in last place to avoid escape being double-decoded string = string.replace(/&/g, '&'); return string; } (function($) { $.fn.extend({ limit_characters: function(limit, elem) { $(this).on("keyup focus", function() { setCount(this, elem); }); function setCount(src, elem) { var chars = src.value.length; if (chars > limit) { src.value = src.value.substr(0, limit); chars = limit; } elem.html( limit - chars ); } setCount($(this)[0], elem); } }); })(jQuery); jQuery.fn.maxLength = function(max){ this.each(function(){ //Get the type of the matched element var type = this.tagName.toLowerCase(); //If the type property exists, save it in lower case var inputType = this.type? this.type.toLowerCase() : null; //Check if is a input type=text OR type=password if(type == "input" && inputType == "text" || inputType == "password"){ //Apply the standard maxLength this.maxLength = max; } //Check if the element is a textarea else if(type == "textarea"){ //Add the key press event this.onkeypress = function(e){ //Get the event object (for IE) var ob = e || event; //Get the code of key pressed var keyCode = ob.keyCode; //Check if it has a selected text var hasSelection = document.selection? document.selection.createRange().text.length > 0 : this.selectionStart != this.selectionEnd; //return false if can't write more return !(this.value.length >= max && (keyCode > 50 || keyCode == 32 || keyCode == 0 || keyCode == 13) && !ob.ctrlKey && !ob.altKey && !hasSelection); }; //Add the key up event this.onkeyup = function(){ //If the keypress fail and allow write more text that required, this event will remove it if(this.value.length > max){ this.value = this.value.substring(0,max); } }; } }); }; function add_shadows() { } $(function(){ $('input.clear_on_focus, textarea.clear_on_focus').focus(function(){ if (!$(this).data('cleared')) { $(this).data('cleared', true); $(this).data('cleared_value', this.value); this.value = ''; } }).blur(function(){ if (this.value.match(/^\s*$/)) { if ($(this).data('cleared_value')) { this.value = $(this).data('cleared_value'); $(this).data('cleared', false); } } }); $("a.rules").fancybox({ maxWidth: '800' }); $('a.fancybox').fancybox({ openEffect: 'none', closeEffect: 'none', nextEffect: 'none', prevEffect: 'none', helpers: { title: {type:'inside'} } }); $('a.fancybox2').fancybox({ openEffect: 'none', closeEffect: 'none', nextEffect: 'none', prevEffect: 'none', helpers: { title: {type:'inside'} } }); $('.bxslider').bxSlider({ mode: 'fade', speed: 1000, adaptiveHeight: true, auto: true, nextSelector: '.slider-next', prevSelector: '.slider-prev', nextText: 'next', prevText: 'back', pause: 5000 }); // add_shadows(); // fix_plist(); $(":not(#autocomplete)").click(function(){ $('#autocomplete').hide(); }); init_simple_slider(); $(window).resize(function() { init_simple_slider(); }); }); /* $(window).load(function(){ add_shadows(); var maxleft = $('#head_row2 div.width_wrapper').offset().left+$('#head_row2 div.width_wrapper').width(); $("#catalog_menu .submenu").each(function(){ var submenu = $(this); var tds = submenu.find('.submenu_inner table tr td'); tds.addClass('classe'); tds.each(function(){ tdw = $(this).actual( 'outerWidth', { clone : true } ); $(this).css('width', tdw); }); var width = submenu.find('table').actual( 'outerWidth', { clone : true } ); submenu.css('width',width); var level1 = submenu.closest('li.level1'); var left = level1.offset().left; var rel_left = left - $('#head_row2 div.width_wrapper').offset().left; diff = (left+width)-maxleft; if (diff > 0) { //submenu.css('right', '0px' ); submenu.css('left', '-'+diff+'px' ); } else { submenu.css('left', '0px' ); } }); $("#catalog_menu ul.level1 li.level1").hover(function(){ var submenu = $(this).find('.submenu'); if (submenu.length) { submenu.show(); $(this).find('a.level1').addClass('hover'); $(this).addClass('hover'); } }, function(){ var submenu = $(this).find('.submenu'); submenu.hide(); $(this).removeClass('hover'); $(this).find('a.level1').removeClass('hover'); }); }); function fix_plist() { $('div.plist a.prod_el:first').addClass('first'); $('div.plist a.prod_el:nth-child(4n)').addClass('fourth'); var buf = [], max_height = max_height2 = 0; $('div.plist a.prod_el').each(function(i){ buf.push(this); if ( max_height < $(this).height() ){ max_height = $(this).height(); } if (max_height > max_height2) max_height2 = max_height; if ( ((i+1)%4 == 0) || (i+1 == $('div.plist a.prod_el').length) ){ $.each(buf, function(index, item){ $(item).css({minHeight:(max_height+10)+'px'}); }); max_height = 0; buf = []; } }); //$("#cart_added .plist a.prod_el").css({minHeight:max_height2+'px'}); //$("#cart_added .rps").css({height:(max_height2+55)+'px'}); //$("#cart_added .plist").css({height:(max_height2+30)+'px'}); //$.fancybox.resize; //$('#similar_products a.prod_el:nth-child(4n)').addClass('fourth'); var buf = [], max_height = 0; $('#similar_products a.prod_el').each(function(i){ buf.push(this); if ( max_height < $(this).height() ){ max_height = $(this).height(); } }); $('#similar_products a.prod_el').css({minHeight:(max_height+10)+'px'}); //$('#similar_products').css({height:(max_height+30)+'px'}); } $(function(){ //fix_plist(); //$(".newsletter-fancy").fancybox(); $(".newsletter-fancybox").click(function(e) { e.preventDefault(); var url = $(this).attr('href'); var id = $(this).attr('id').replace('newsletter-',''); $.fancybox({ href : '?display=content_types/pages/newsletter.tpl&source='+id, type : 'ajax' }); }); }); $(window).load(function(){ fix_plist(); }); */ /* Jquery Actual */ ;(function(a){a.fn.extend({actual:function(b,l){if(!this[b]){throw'$.actual => The jQuery method "'+b+'" you called does not exist';}var e={absolute:false,clone:false,includeMargin:undefined};var i=a.extend(e,l);var d=this;var g,j;if(i.clone===true){g=function(){var m={position:"absolute",top:-1000};d=d.filter(":first").clone().css(m).appendTo("body");};j=function(){d.remove();};}else{var f=[];var c,h;g=function(){c=d.parents().andSelf().filter(":hidden");h={visibility:"hidden",display:"block"};if(i.absolute===true){h.position="absolute";}c.each(function(){var m=a(this);f.push(m.attr("style"));m.css(h);});};j=function(){c.each(function(m){var o=a(this);var n=f[m];if(n===undefined){o.removeAttr("style");}else{o.attr("style",n);}});};}g();var k=/(outer)/g.test(b)?d[b](i.includeMargin):d[b]();j();return k;}});})(jQuery); /* Accordion */ $(function(){ $('div.accordion_item:not(:first-child)').find('.accordion_content').hide(); $('div.accordion_item:not(:first-child)').find('.accordion_title').addClass('collapsed'); $('div.accordion_title').click(function(){ var $title = $(this); var $content = $title.next(); var $container = $(this).parents('div.accordion_container'); if ($title.is('.collapsed')) { $('div.accordion_title', $container).addClass('collapsed'); $('div.accordion_content', $container).slideUp('fast'); $title.removeClass('collapsed'); $content.slideDown('fast'); } else { $title.addClass('collapsed'); $content.slideUp('fast'); } }); hover_cart(); }) function hover_cart(){ $("#cart_info").hover(function(){ $(".overview_container:not(.empty)").stop( true, true ).fadeIn('fast'); },function(){ $(".overview_container:not(.empty)").stop( true, true ).fadeOut('fast'); }); } function init(){ $(document).on('click',"#back_step1",function(event){ event.preventDefault(); $("#step2").hide(); $("#step1").fadeIn('fast'); }); $(document).on('click',"#for_step2",function(event){ event.preventDefault(); $("#step1").hide(); $("#step2").fadeIn('fast'); }); } $(document).ready(function() { if(jQuery().inputmask) { $('input[data-inputmask]').inputmask(); } $('.product_element .color').click(function (e) { e.preventDefault(); var url = $(this).parent().parent().attr('href') + '?item=' + $(this).data('variant-color'); window.location.href = url; //alert(url); }); init_color_select(); $(window).resize(function() { init_color_select(); }); init_styled_input() }); function init_color_select() { var neededHeight = $("#products_cart_add #expand").outerWidth() - 44; //you can also use static value var totalChildLenght = 0; if (window.innerWidth > 991) { $("#products_cart_add #expand").find("ul").children("li:not('.opener')").each(function () { $(this).show(); totalChildLenght += $(this).outerWidth() + 10; //add up to the total height if (totalChildLenght > neededHeight) { //compare if the height limit was exceeded $("#products_cart_add #expand").find("ul li.opener").show() $(this).hide(); // if it did, hide the current element $(this).nextAll("li:not('.opener')").hide(); //hide all other list also return false; // break the loop to stop the further iteration } }); } else { $("#products_cart_add #expand").find("ul").children("li:not('.opener')").each(function () { $(this).show(); }); } if (totalChildLenght < neededHeight) { $("#products_cart_add #expand").find("ul li.opener").hide(); } } function init_simple_slider() { $('.simple_slider').each(function() { var slider_main_container = $(this); if (slider_main_container.hasClass('mobile_only')) { // simple_slider(true); if (window.innerWidth < 992) { slider_main_container.find('.ss_container').height(slider_main_container.find('ul').outerHeight()); var slider_width = slider_main_container.outerWidth(); //you can also use static value var slider_content_width = slider_main_container.find('ul').outerWidth() - 10; var slider_step_in_px = -4; if (slider_content_width < slider_width) { $('.ss_nav > span', slider_main_container).hide(); } else { slider_main_container.find("ul").data('left', 3); slider_main_container.find("ul").css('left', '3px'); $('.ss_nav > span', slider_main_container).each(function() { if ($(this).hasClass('left')) { $(this).hide(); } else { $(this).show(); } }); } slider_main_container.find("ul").children("li:not('.opener')").each(function () { let el_width = $(this).outerWidth() + 13; if ((slider_step_in_px + el_width) < slider_width) { slider_step_in_px += el_width; } else { return false; } }); var slides = $('#slider ul').children().length; var slideWidth = $('#slider').width(); var min = 3; var max = -(slider_content_width - slider_step_in_px); slider_main_container.find('ul').draggable({ axis: 'x', drag: function (event, ui) { if (ui.position.left > min) { ui.position.left = min; slider_main_container.find('ul').data('left', min); } if (ui.position.left < max) { ui.position.left = max; slider_main_container.find('ul').data('left', slider_content_width - slider_step_in_px); } if (ui.position.left < 3) { slider_main_container.find('.ss_nav > span.left').show(); } else { slider_main_container.find('.ss_nav > span.left').hide(); } if (ui.position.left > max) { slider_main_container.find('.ss_nav > span.right').show(); } else { slider_main_container.find('.ss_nav > span.right').hide(); } } }); $('.ss_nav > span', slider_main_container).unbind('click').on('click', function() { let max_left = slider_content_width - slider_step_in_px; var cur_pos = slider_main_container.find("ul").data('left'); var left = $(this).hasClass('left'); var left_px = 3; if (typeof cur_pos == 'undefined') { cur_pos = 3 } if (left) { // i kaire if ((cur_pos - slider_step_in_px) <= 3) { cur_pos = 3; $(this).parent().find('span.left').hide(); } else { cur_pos -= slider_step_in_px; } if ((cur_pos + slider_step_in_px) < slider_content_width) { $(this).parent().find('span.right').show(); } } else { // i desine if (cur_pos < max_left) { if ((cur_pos + slider_step_in_px) > max_left) { cur_pos = max_left; } else { cur_pos += slider_step_in_px; } } if ((cur_pos + slider_step_in_px + 10) >= slider_content_width) { $(this).parent().find('span.right').hide(); } if (cur_pos > 3) { //display left $(this).parent().find('span.left').show(); } } slider_main_container.find("ul").data('left', cur_pos); if (cur_pos == 3) { left_px = cur_pos+'px'; } else { left_px = '-'+cur_pos+'px'; } slider_main_container.find("ul").css('left', left_px); }); } } else { // simple_slider(false); } }); } function init_styled_input() { $('.param.styled').each(function(){ if ($.trim($(this).find('input').val()) !== '') { $(this).addClass('filled'); } }); $(document).on('focus', '.param.styled', function(e) { $(this).addClass('filled').addClass('focus'); }); $(document).on('blur', '.param.styled', function(e) { if ($(this).find('input').length) { if ($.trim($(this).find('input').val()) === '') { $(this).removeClass('filled'); } } else if ($(this).find('textarea').length) { if ($.trim($(this).find('textarea').val()) === '') { $(this).removeClass('filled'); } } $(this).removeClass('focus'); }); $('.param.styled input').on('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(e) { if (e.originalEvent.animationName == 'onAutoFillStart') { $(this).closest('.param.styled').addClass('filled'); } }); } function show_fancybox_from_iframe(url) { if (typeof $.fancybox == 'object') { $.fancybox.open({ src: url, }); } else if (typeof $.fancybox == 'function') { $.fancybox.open({ href: url, type: "iframe", // other API options openEffect: 'fade', closeEffect: 'fade', padding: 0, maxWidth : 1600, maxHeight : 900, fitToView : true, autoSize : false, helpers: { overlay: { opacity: 0.9, css: {'background': '#1e1e1e'} } }, beforeShow: function(){ this.width = $(window).width(); this.height = $(window).width()/1.7777; } }); } } function calcIframeHeight(){ $('iframe.fullheight, .fullheight iframe').on('load', function() { this.style.height = this.contentWindow.document.body.scrollHeight + 'px'; }); $(window).on('resize', function(){ $('iframe.fullheight, .fullheight iframe').each(function() { this.style.height = this.contentWindow.document.body.scrollHeight + 'px'; }); }); }