// Check the textbox every 100 milliseconds. This seems to be pretty responsive. var addButtonInterval; var refreshed = true; $(window).load(function(){ $("html,body").trigger("scroll"); }); $(document).ready(function(){ $(function () { $('.popup').styleddropdown(); }); // ošetřujeme lazy loading obrázků $( 'article img').not('img.banner').not('img.lazyignoreme').each(function( index ) { var src = $( this ).attr('src'); $( this ).attr('data-original', src); $( this ).attr('src', '/ui/images/transparent.gif'); $( this ).removeClass( 'lazyload' ); $( this ).addClass( 'lazyload' ); }); $( 'img.lazyload' ).lazyload({ effect : "fadeIn" }); $(".fancybox").jqPhotoSwipe({ galleryOpen: function (gallery) { //with `gallery` object you can access all methods and properties described here http://photoswipe.com/documentation/api.html //console.log(gallery); //console.log(gallery.currItem); //console.log(gallery.getCurrentIndex()); //gallery.zoomTo(1, {x:gallery.viewportSize.x/2,y:gallery.viewportSize.y/2}, 500); //gallery.toggleDesktopZoom(); gallery.goTo(1); // hack for duplicit first image } }); $("a#zobrazit-polozky").unbind("click").click(function(){ if ($("#kosik-wrapper").is(":hidden")){ $("#kosik-wrapper").slideDown("slow", function(){ // Callback function - will occur when sliding is complete. // $("input#hledat").focus(); //setTimeout(function() { document.getElementById('hledat').focus(); }, 10); }); } else{ $("#kosik-wrapper").slideUp("slow"); } }); $(".dot-wrapper").dotdotdot({ ellipsis: "\u2026 ", /* The text to add as ellipsis. */ truncate: "word", /* How to truncate the text: By "node", "word" or "letter". */ keep: null, /* jQuery-selector for elements to keep after the ellipsis. */ watch: "window", /* Whether to update the ellipsis: true: Monitors the wrapper width and height. "window": Monitors the window width and height. */ tolerance: 0 /* Deviation for the measured wrapper height. */ }); // move H3 element (if it's first child) one level up $( "div.item-label div.content" ).each(function( index ) { var customMaxHeight = 12; //132 //var customH3RowHeight = 31; var $child = $(this).find('> :first-child'); if($child.is('h3')){ /*var childHeight = $child.height(); if(childHeight > customH3RowHeight){ }*/ $child.remove(); $(this).parent().prepend($child); } var realHeight = $(this).height() / parseFloat($(this).find(' > p').css("font-size"));// >>> in em units if(realHeight > customMaxHeight){ $(this).removeClass( "showContent" ).addClass( "hideContent" ); $(this).parent().append("
"); }else{ $(this).removeClass( "hideContent" ).addClass( "showContent" ); } }); // show more content >> PRODUCTS $(".show-more a").on("click", function() { var $this = $(this); var $content = $this.parent().prev("div.content"); var linkText = $this.text().toUpperCase(); if(linkText === "SHOW MORE"){ linkText = "Show less"; $content.switchClass("hideContent", "showContent", 400); } else { linkText = "Show more"; $content.switchClass("showContent", "hideContent", 400); }; $this.text(linkText); }); /* ***** pridavame do kosiku ***** */ $('#b-do-kosiku').click(function () { // window.alert("ok"); $('#form-do-kosiku').submit(); }); /* ***** prepocitavame kosik ***** */ $('#b-prepocitat-kosik').click(function() { $('#form-kosik').submit(); }); /* ***** osobni udaje ***** */ $('#b-udaje-pokracovat').click(function() { $('#form-osobni-udaje').submit(); }); /* ***** validate onlyNumerics ***** */ $("input:text.numeric").keyup(function(){ // value is present var tval=trim($(this).val()); if (tval=='') return true; reg=/^0*/; tval=tval.replace(reg,''); if (tval!='') val=parseInt(tval); else val=0; var min=parseInt($(this).attr('min')); var max=parseInt($(this).attr('max')); var msg=""; if(min!='' && max !=''){ msg='Zboží lze objednat v množství od '+ min + ' do ' + max + ' kusů.' ; } else{ if(min!=''){msg='Minimální počet možných objednaných kusů je '+ min +'.';} else{ if(max!=''){msg='Maximální počet možných objednavých kusů je '+ max +'.';} } } if(min!=''){ if (min>val) { alert(msg); $(this).val(min); //$(this).css('background',_alertColor); } } if (max!=''){ if (val>max) { alert(msg); $(this).val(max); //$(this).css('background',_alertColor); } } }); /* ***** setup image position ***** */ /*$('img.setmeup').each(function(){ $(this).load(function(){ // var maxWidth = $(this).width(); // Max width for the image //var maxHeight = $(this).height(); // Max height for the image var maxWidth = 205; // Max width for the image var maxHeight = 185; // Max height for the image var frameWidth = 217; // frame width var frameHeight = 186; // frame height $(this).css("width", "auto").css("height", "auto"); // Remove existing CSS $(this).removeAttr("width").removeAttr("height"); // Remove HTML attributes var width = $(this).width(); // Current image width var height = $(this).height(); // Current image height if(width > height) { // Check if the current width is larger than the max if(width > maxWidth){ var ratio = maxWidth / width; // get ratio for scaling image height = height * ratio; // Reset height to match scaled image width = maxWidth; if(height > maxHeight){ ratio_2 = maxHeight / height; height = maxHeight; width = width * ratio_2; }else{ } $(this).css("width", width); // Set new width $(this).css("height", height); // Scale height based on ratio } }else { // Check if current height is larger than max if(height > maxHeight){ var ratio = maxHeight / height; // get ratio for scaling image $(this).css("height", maxHeight); // Set new height $(this).css("width", width * ratio); // Scale width based on ratio width = width * ratio; // Reset width to match scaled image } } // margins if(width < maxWidth){ var left = Math.ceil((frameWidth - width) / 2); }else{ var left = 5; } $(this).css("left", left); if(height < maxHeight){ var top = Math.ceil((frameHeight - height) / 2); }else{ var top = 5; } $(this).css("top", top); console.log('mt: ' + top); }); });*/ $("input#refjmeno").focus(function(){ var hledat = $("input#refjmeno").val(); if(hledat == 'Jméno, město…' || hledat == 'Jan Novák'){ $("input#refjmeno").val(''); }else{ this.select(); } }); $("input#refemail").focus(function(){ var hledat = $("input#refemail").val(); if(hledat == '@'){ // $("input#refemail").val(''); }else{ this.select(); } }); $("textarea#reftext").focus(function(){ var hledat = $("textarea#reftext").val(); if(hledat == 'Text…' || hledat == 'Váš názor na toto zboží.'){ $("textarea#reftext").val(''); }else{ this.select(); } }); $("a#b-refodeslat").unbind("click").click(function(){ var f_refjmeno = $("#refjmeno").val(); var f_reftext = $("#reftext").val(); var f_refemail = $("#refemail").val(); $.ajax({ type: "POST", url: "/cs/reference/pridat-form", data: ({ jmeno:f_refjmeno, text: f_reftext, email: f_refemail }), success: function(msg){ $('div#ajax-msg-box-reference').html(msg); // nulujeme form if(msg == 'Děkujeme, vaše reference čeká na schválení editorem.
'){ $("#refjmeno").val("Jméno, město…"); $("#reftext").val("Text…"); $("#refemail").val("@"); } $("div#ajax-msg-box-reference:hidden").show("fast"); // $("html, body").animate({ scrollTop: 0 }, "slow"); }, error: function(msg){ $('div#ajax-msg-box-reference').html(msg); $("div#ajax-msg-box-reference:hidden").show("fast"); // $("html, body").animate({ scrollTop: 0 }, "slow"); } }); }); $("a#filtr-list-toggle").unbind("click").click(function(){ var filtryElement = $(".row.filtry"); if ( $(filtryElement).css('display') == 'none' ){ // element is hidden $(".row.filtry").show("fast"); $("a#filtr-list-toggle").toggleClass('active'); }else{ $(".row.filtry").hide("fast"); $("a#filtr-list-toggle").toggleClass('active'); } }); $("a#b-hododeslat").unbind("click").click(function(){ var f_refjmeno = $("#refjmeno").val(); var f_reftext = $("#reftext").val(); var f_refemail = $("#refemail").val(); var f_zbozi = $("#refzbozi").val(); $.ajax({ type: "POST", url: "/cs/zbozi/pridat-form", data: ({ jmeno:f_refjmeno, text: f_reftext, email: f_refemail, zbozi: f_zbozi }), success: function(msg){ $('div#ajax-msg-box-reference').html(msg); // nulujeme form if(msg == 'Děkujeme, vaše hodnocení/recenze čeká na schválení editorem.
'){ $("#refjmeno").val("Jan Novák"); $("#reftext").val("Váš názor na toto zboží."); $("#refemail").val("@"); } $("div#ajax-msg-box-reference:hidden").show("fast"); // $("html, body").animate({ scrollTop: 0 }, "slow"); }, error: function(msg){ $('div#ajax-msg-box-reference').html(msg); $("div#ajax-msg-box-reference:hidden").show("fast"); // $("html, body").animate({ scrollTop: 0 }, "slow"); } }); }); // defaultní stav při prvním příchodu do formuláře if($("#panelnafirmu").val() == 1){ $("div.b-checkbox.panelnafirmu").addClass('active'); $('tr.panel-na-firmu').each(function(){ $(this).show(); }); } if($("#panelnaosobu").val() == 1){ $("div.b-checkbox.panelnaosobu").addClass('active'); $('tr.panel-na-osobu').each(function(){ $(this).show(); }); } if($("#paneldorucovaciadresa").val() == 1 ){ $("div.b-checkbox.paneldorucovaciadresa").addClass('active'); $('tr.panel-dorucovaci-adresa').each(function(){ $(this).show(); }); } $("div.b-checkbox.panelnafirmu").unbind("click").click(function(){ var f_panelnafirmu = $("#panelnafirmu").val(); if(f_panelnafirmu == null || f_panelnafirmu == 0){ // checkbox / stav $("#panelnafirmu").val(1); $("div.b-checkbox.panelnafirmu").addClass('active'); $('tr.panel-na-firmu').each(function(){ $(this).show(); }); // "vypnout" panel-na-osobu $("#panelnaosobu").val(0); $("div.b-checkbox.panelnaosobu").removeClass('active'); $('tr.panel-na-osobu').each(function(){ $(this).hide(); }); }else{ $("#panelnafirmu").val(0); $("div.b-checkbox.panelnafirmu").removeClass('active'); $('tr.panel-na-firmu').each(function(){ $(this).hide(); }); } }); $("div.b-checkbox.panelnaosobu").unbind("click").click(function(){ var f_panelnaosobu = $("#panelnaosobu").val(); if(f_panelnaosobu == null || f_panelnaosobu == 0){ // checkbox / stav $("#panelnaosobu").val(1); $("div.b-checkbox.panelnaosobu").addClass('active'); $('tr.panel-na-osobu').each(function(){ $(this).show(); }); // "vypnout" panel-na-osobu $("#panelnafirmu").val(0); $("div.b-checkbox.panelnafirmu").removeClass('active'); $('tr.panel-na-firmu').each(function(){ $(this).hide(); }); }else{ $("#panelnaosobu").val(0); $("div.b-checkbox.panelnaosobu").removeClass('active'); $('tr.panel-na-osobu').each(function(){ $(this).hide(); }); } }); $("div.b-checkbox.paneldorucovaciadresa").unbind("click").click(function(){ var f_paneldorucovaciadresa = $("#paneldorucovaciadresa").val(); if(f_paneldorucovaciadresa == null || f_paneldorucovaciadresa == 0){ // checkbox / stav $("#paneldorucovaciadresa").val(1); $("div.b-checkbox.paneldorucovaciadresa").addClass('active'); $('tr.panel-dorucovaci-adresa').each(function(){ $(this).show(); }); }else{ $("#paneldorucovaciadresa").val(0); $("div.b-checkbox.paneldorucovaciadresa").removeClass('active'); $('tr.panel-dorucovaci-adresa').each(function(){ $(this).hide(); }); } }); // VOP & GDPR if($("#vop").val() == 1){ $("div.b-checkbox.vop").addClass('active'); } if($("#gdpr").val() == 1){ $("div.b-checkbox.gdpr").addClass('active'); } $("div.b-checkbox.vop").unbind("click").click(function(){ var f_vop = $("#vop").val(); if(f_vop == null || f_vop == 0){ // checkbox / stav $("#vop").val(1); $("div.b-checkbox.vop").addClass('active'); }else{ $("#vop").val(0); $("div.b-checkbox.vop").removeClass('active'); } }); $("div.b-checkbox.gdpr").unbind("click").click(function(){ var f_gdpr = $("#gdpr").val(); if(f_gdpr == null || f_gdpr == 0){ // checkbox / stav $("#gdpr").val(1); $("div.b-checkbox.gdpr").addClass('active'); }else{ $("#gdpr").val(0); $("div.b-checkbox.gdpr").removeClass('active'); } }); // handle promo cookie /*if ($.cookies.get('promo-no-2') !== 1) { window.setTimeout("callFancyBox();", 1200) $.cookies.set('promo-no-2', 1); // // $.cookie('promo-no-2', '1', { expires: 24 * 60 * 60 * 1000 }); } // jquery UI TABS init $( "#tabs" ).tabs();*/ // Check the textbox every 100 milliseconds. This seems to be pretty responsive. window.addButtonInterval = setInterval(watchParams, 100); }); function trim(data){ return data.replace(/^\s*/, "").replace(/\s*$/, ""); } function watchParams() { var kusu = $("#pocet_kusu").val(); // if we do not have "pocet_kusu" field available on the page if(kusu == undefined){ window.clearInterval(window.addButtonInterval); }else{ // convert "kusu" na var amount = kusu.replace(/\D/g, ''); } var fullfilled = false; var gotvariants = false; // check 5 popups var ps = new Array(); for(i = 1; i < 7; i++){ if($("#p" + i).length != 0) { gotvariants = true; if($("#p" + i).val() != '') { ps[i] = $("#p" + i).val(); fullfilled = true; }else{ fullfilled = false; $('#cena-box').addClass('disabled'); $('#cena-box').html('0 Kčs DPH'); window.refreshed = false; break; } } } //console.log(ps); if((gotvariants == true && fullfilled == true && window.refreshed == false)){ var zbozi_id = $('#zbozi_id').val(); //console.log('máme variandu: odesíláme dotaz pro zbozi ID: ' + zbozi_id); var query = ""; for (i = 1; i <= ps.length; i++){ //console.log(ps[i]); if(ps[i] != undefined) query = query + "`s" + i + "_vlastnost` = '" + ps[i] + "'"; if(i < ps.length - 1) query = query + " AND "; } // get variant from db $.ajax({ type: "POST", url: "/zbozi/ajaxgetvariant", data: ({id: zbozi_id, value: query}), dataType : 'json', success: function (msg) { var json = msg; //alert('success: ' + msg); //console.log(json); //console.log('Success.'); //console.log(msg); //setup UI $('#cena-box').html(number_format(Math.round(json[0].cena_nejnizsi, 0), 0, ',', ' ') + ' Kč s DPH'); $('#cena-box').removeClass('disabled'); //setup hidden parts $('#cena_bez_dph').val(json[0].v_cena_bez_dph); $('#sazba_dph').val(json[0].v_sazba_dph); $('#cena').val(json[0].cena_nejnizsi); $('#varianta_id').val(json[0].id); $('#varianta_p1').val(json[0].s1_jmeno + ';' + json[0].s1_vlastnost); $('#varianta_p2').val(json[0].s2_jmeno + ';' + json[0].s2_vlastnost); $('#varianta_p3').val(json[0].s3_jmeno + ';' + json[0].s3_vlastnost); $('#varianta_p4').val(json[0].s4_jmeno + ';' + json[0].s4_vlastnost); $('#varianta_p5').val(json[0].s5_jmeno + ';' + json[0].s5_vlastnost); // all refreshed window.refreshed = true; }, error: function (msg) { //alert('Při pokusu o aktualizaci došlo k chybě: ' + msg); //console.log('Při pokusu o aktualizaci došlo k chybě.'); //console.log(msg); $('#cena-box').html('0 Kčs DPH'); $('#cena-box').addClass('disabled'); window.refreshed = false; } }); } if((gotvariants == false || fullfilled == true) && amount > 0){ fullfilled = true; }else{ fullfilled = false; } //enable/disable button if(fullfilled){ if($('#pridat-box a').hasClass('disabled')){ $('#pridat-box a').removeClass('disabled'); /* ***** pridavame do kosiku ***** */ $( "#pridat-box a" ).on( "click", function( event ) { $('#form-do-kosiku').submit(); }); } }else{ $( "#pridat-box a" ).off( "click", function( event ) {}); $('#pridat-box a').addClass('disabled'); } } function number_format (number, decimals, dec_point, thousands_sep) { // Strip all characters but numerical ones. number = (number + '').replace(/[^0-9+\-Ee.]/g, ''); var n = !isFinite(+number) ? 0 : +number, prec = !isFinite(+decimals) ? 0 : Math.abs(decimals), sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep, dec = (typeof dec_point === 'undefined') ? '.' : dec_point, s = '', toFixedFix = function (n, prec) { var k = Math.pow(10, prec); return '' + Math.round(n * k) / k; }; // Fix for IE parseFloat(0.55).toFixed(0) = 0; s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.'); if (s[0].length > 3) { s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep); } if ((s[1] || '').length < prec) { s[1] = s[1] || ''; s[1] += new Array(prec - s[1].length + 1).join('0'); } return s.join(dec); } /*$(function () { window.scrollmeset = true; window.portwidth = $(window).width(); window.documentheight = $( document ).height(); window.footerboxtop = $( ".box-footer").offset().top; window.footerheight = $( "footer").outerHeight(); console.log(window.documentheight); console.log(window.footerboxtop); $(window).resize(function () { window.portwidth = $(window).width(); window.footerboxtop = $( ".box-footer").offset().top; window.footerheight = $( "footer").outerHeight(); window.boxInitialTop = $('.scrollme').offset().top; window.boxInitialLeft = $('.scrollme').offset().left; window.boxInitialWidth = $('.scrollme').width(); window.boxInitialHeight = $('.scrollme').height(); window.scrollmeset = false; if(window.portwidth < 750){ $('.scrollme').width('100%'); } }); $('.scrollme img.setmeupdetail').on('load', function () { if (window.scrollmeset == true) { window.boxInitialTop = $('.scrollme').offset().top; window.boxInitialLeft = $('.scrollme').offset().left; window.boxInitialWidth = $('.scrollme').width(); window.boxInitialHeight = $('.scrollme').height(); window.scrollmeset = false; } // console.log('top: ' + window.boxInitialTop); // console.log('left: ' + window.boxInitialLeft); // console.log('width: ' + window.boxInitialWidth); // console.log('height: ' + window.boxInitialHeight); }); $(window).scroll(function () { //console.log('scroll: ' . $ ( window ). scrollTop ()); window.boxTop = $('.scrollme').offset().top; window.boxHeight = $('.scrollme').height(); console.log('boxTop: ' + (window.boxTop)); console.log('footerheight: ' + (window.footerheight)); console.log('footerboxtop: ' + window.footerboxtop); console.log('boxHeight: ' + (window.boxHeight)); console.log('boxTop - boxHeight: ' + (window.boxTop - window.boxHeight)); console.log('footerheight + boxHeight: ' + (window.footerheight + window.boxHeight)); console.log('documentheight - (footerheight + boxHeight): ' + (window.documentheight - (window.footerheight + window.boxHeight))); log('boxInitialTop: ' + (window.boxInitialTop)); console.log('window.documentheight - footerheight: ' + (window.documentheight - footerheight)); console.log('doc-height: ' + window.documentheight); if ($(window).scrollTop() > window.boxInitialTop && window.portwidth > 750) { $('.scrollme').css({'position' : 'fixed'}); $('.scrollme').css({'top' : '0'}); $('.scrollme').css('left', window.boxInitialLeft + 'px'); $('.scrollme').height(window.boxInitialHeight); $('.scrollme').width(window.boxInitialWidth); if(window.boxTop > (window.footerboxtop)){ var var_up = -(window.boxTop - window.boxInitialTop); console.log('jsme pod: ' + var_up + 'top: ' + window.boxTop) $('.scrollme').css({'top' : var_up}); } }else { $('.scrollme').css({'position' : 'relative', 'top' : ''}); $('.scrollme').css('left', 'auto'); $('.scrollme').width('100%'); } }); });*/