// 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(){ //$("a[rel^='prettyPhoto']").prettyPhoto({theme:'light_rounded',social_tools:false, deeplinking: false, overlay_gallery: false}); /*$("a.inline").fancybox({ 'hideOnContentClick': true });*/ $(function () { $('.popup').styleddropdown(); }); $(".fancybox").fancybox({ prevEffect : 'none', nextEffect : 'none', closeBtn : true, /*hideOnContentClick: true,*/ helpers: { title : { type : 'inside' }, /*buttons : {}*/ } }); // ošetřujeme lazy loading obrázků $( 'article img').not('img.banner').not('img.setmeup').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"*/ }); /* *** CAMERA arrows on window.resize *** */ handleCameraArrowsPosition(); $(window).on('resize', handleCameraArrowsPosition); function handleCameraArrowsPosition() { setTimeout(function () { var margin = 60; var win = $(this); //this = window var viewPort = $('#camera_both'); var wWin = win.width(); var wPort = viewPort.width(); // fix for max arrows distance var wWinCustom = 960 + (4 * margin); if(wWin >= wWinCustom){ wWin = wWinCustom; } //window.alert('wWidth: ' + win.width() + ', wHeight: ' + win.height() + ', pWidth: ' + viewPort.width() + ', pHeight: ' + viewPort.height()); if(wWin < 750){ var margin = 10; }else if(wWin < 1000){ var margin = 30; } var pos = (wPort - wWin) / 2 + margin; $('#camera_prev').css({'left':pos}); $('#camera_next').css({'right':pos}); }, 100); }; $("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"); } }); // kraceni pro jednotlive stranky if ($(".shortplease.dsc3").length){ $(".shortplease.dsc3").ThreeDots({ max_rows: 3 }); } if ($(".shortplease.dsc4").length){ $(".shortplease.dsc4").ThreeDots({ max_rows: 4 }); } if ($(".shortplease.dsc5").length){ $(".shortplease.dsc5").ThreeDots({ max_rows: 5 }); } if ($(".shortplease.dsc7").length){ $(".shortplease.dsc7").ThreeDots({ max_rows: 7 }); } if ($(".shortplease.title1").length){ $(".shortplease.title1").ThreeDots({ max_rows: 1 }); } if ($(".shortplease.title2").length){ $(".shortplease.title2").ThreeDots({ max_rows: 2 }); } // 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("
Show more
"); }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); }); $("input#hledat").click(function(){ var hledat = $("input#hledat").val(); if(hledat == "hledat"){ $("input#hledat").val(''); $("input#hledat").css("color","#000000"); } }); $("input#hledat").focus(function(){ var hledat = $("input#hledat").val(); if(hledat == "hledat"){ $("input#hledat").val(''); $("input#hledat").css("color","#000000"); }else{ $("input#hledat").css("color","#000000"); } }); $("input#hledat").blur(function(){ var hledat = $("input#hledat").val(); if(hledat == ""){ $("input#hledat").val('hledat'); $("input#hledat").css("color","#ababab"); }else{ $("input#hledat").css("color","#000000"); } }); // prevent default form submit $("#search-form-id").submit(function(e){ return false; }); $("input#hledat").keypress(function(event){ var keycode = (event.keyCode ? event.keyCode : event.which); if(keycode == '13'){ var hledat = $("input#hledat").val(); if(hledat != "" && hledat != "hledat"){ var url = getURL() + "/zbozi/hledat/"; var query = encodeURI($("input#hledat").val()); url = url + query window.location = url; }else{ alert('Zadejte výraz pro vyhledávání.'); } } }); $("a#b-hledat").click(function(){ var hledat = $("input#hledat").val(); if(hledat != "" && hledat != "hledat"){ var url = getURL() + "/zbozi/hledat/"; var query = encodeURI($("input#hledat").val()); url = url + query; window.location = url; }else{ alert('Zadejte výraz pro vyhledávání.'); } }); /* ***** pridavame do kosiku ***** */ $('#b-do-kosiku').click(function () { var varval = $("input:radio[name='varianty']").val(); if($("input:radio[name='varianty']").is(":checked") || varval == undefined) { // window.alert("ok"); $('#form-do-kosiku').submit(); }else{ window.alert('Nejdříve zvolte variantu zboží.'); } }); /* ***** 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); }); });*/ $('img.setmeupdetail').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 = 283; // Max width for the image var maxHeight = 188; // Max height for the image var frameWidth = 290; // frame width var frameHeight = 196; // 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); }); }); $('img.setmeupdetailnahledy').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 = 81; // Max width for the image var maxHeight = 54; // Max height for the image var frameWidth = 85; // frame width var frameHeight = 58; // 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 = (frameWidth - width) / 2; }else{ var left = 2; } $(this).css("left", left); if(height < maxHeight){ var top = (frameHeight - height) / 2; }else{ var top = 2; } $(this).css("top", 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 tabJump(){ //get href ID as a number var thisID = Number($(this).attr('href').replace(/#tabs-/, '')) - 1; // this should trigger the new tab based on this href id. $("#tabs").tabs("select" , "#tabs-" + thisID); } function callFancyBox() { $('#promo-link').trigger('click'); } function setSearchInputColor(){ var hledat = $("input#hledat").val(); if(hledat == "hledat"){ $("input#hledat").css("color","#ababab"); } } function productCenaSliderChange(event, value, url){ var rozsah = "/rozsah/"; var hodnota = value; hodnota = hodnota.replace(" - ", "-"); hodnota = hodnota.replace(" Kč", ""); var url = window.location.protocol + "//" + window.location.host + url + rozsah + hodnota; //console.log(url); window.location = url; } function getURL() { var url = window.location.protocol + "//" + window.location.host; return url; } function zboziRazeni(url, sort) { var sort_field = $("select#sort-field").val(); var razeni = '/razeni/' + sort_field + '_' + sort; var url = window.location.protocol + "//" + window.location.host + url + razeni; //console.log(url); window.location = url; } function zboziPolozek(url) { var items_field = $("select#items-field").val(); var polozek = '/polozek/' + items_field; //console.log(url); var url = window.location.protocol + "//" + window.location.host + url + polozek; //console.log(url); window.location = url; } 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() { $('input[type=checkbox].setfilter').each(function() { console.log("X"); var span = $('').click(doCheck).mousedown(doDown).mouseup(doUp); if ($(this).is(':checked')) { span.addClass('checked'); } $(this).wrap(span).hide(); }); function doCheck() { if ($(this).hasClass('checked')) { $(this).removeClass('checked'); $(this).children().prop("checked", false); //console.log('unchecking'); } else { $(this).addClass('checked'); $(this).children().prop("checked", true); //console.log('checking'); } // Dispatch it. $(this).children().trigger('change'); //$(this).children().not('.no-trigger').trigger('change'); } function doDown() { $(this).addClass('clicked'); } function doUp() { $(this).removeClass('clicked'); } });