window.addEvent('domready', function() { /*************** Filtres checkbox ********************/ // 1 - Mise à jour du compteur function testResult() { var type1 = 31 ; var type2 = 24 ; var type3 = 11 ; var type4 = 7 ; var type5 = 0 ; var type6 = 0 ; var type7 = 6 ; var type8 = 0 ; var type9 = 2 ; var total = 0 ; if ( $("type1chk").checked ) total += type1 ; if ( $("type2chk").checked ) total += type2 ; if ( $("type3chk").checked ) total += type3 ; if ( $("type4chk").checked ) total += type4 ; if ( $("type7chk").checked ) total += type7 ; if ( $("type9chk").checked ) total += type9 ; return total ; } // 2 - Appel à la fonction testResult() pour chaque checkbox $("type1chk").addEvent("click", function(){ $("chiffre").innerHTML = testResult() ; }); $("type2chk").addEvent("click", function(){ $("chiffre").innerHTML = testResult() ; }); $("type3chk").addEvent("click", function(){ $("chiffre").innerHTML = testResult() ; }); $("type4chk").addEvent("click", function(){ $("chiffre").innerHTML = testResult() ; }); $("type7chk").addEvent("click", function(){ $("chiffre").innerHTML = testResult() ; }); $("type9chk").addEvent("click", function(){ $("chiffre").innerHTML = testResult() ; }); // 3 - Création des sliders // Type 1 $$("div.type1").each(function(element, i) { var mySwitch = $("type1chk") ; var mySlider = new Fx.Slide(element, {duration:1000, mode:"vertical", wait:false}); mySwitch.addEvent("click", function() { $("chiffre").innerHTML = testResult() ; if ( mySwitch.checked ) { // Coché mySlider.slideIn(); } else { // Décoché mySlider.slideOut(); } }); }); // Type 2 $$("div.type2").each(function(element, i) { var mySwitch = $("type2chk") ; var mySlider = new Fx.Slide(element, {duration:1000, mode:"vertical", wait:false}); mySwitch.addEvent("click", function() { $("chiffre").innerHTML = testResult() ; if ( mySwitch.checked ) { // Coché mySlider.slideIn(); } else { // Décoché mySlider.slideOut(); } }); }); // Type 3 $$("div.type3").each(function(element, i) { var mySwitch = $("type3chk") ; var mySlider = new Fx.Slide(element, {duration:1000, mode:"vertical", wait:false}); mySwitch.addEvent("click", function() { $("chiffre").innerHTML = testResult() ; if ( mySwitch.checked ) { // Coché mySlider.slideIn(); } else { // Décoché mySlider.slideOut(); } }); }); // Type 4 $$("div.type4").each(function(element, i) { var mySwitch = $("type4chk") ; var mySlider = new Fx.Slide(element, {duration:1000, mode:"vertical", wait:false}); mySwitch.addEvent("click", function() { $("chiffre").innerHTML = testResult() ; if ( mySwitch.checked ) { // Coché mySlider.slideIn(); } else { // Décoché mySlider.slideOut(); } }); }); // Type 7 $$("div.type7").each(function(element, i) { var mySwitch = $("type7chk") ; var mySlider = new Fx.Slide(element, {duration:1000, mode:"vertical", wait:false}); mySwitch.addEvent("click", function() { $("chiffre").innerHTML = testResult() ; if ( mySwitch.checked ) { // Coché mySlider.slideIn(); } else { // Décoché mySlider.slideOut(); } }); }); // Type 9 $$("div.type9").each(function(element, i) { var mySwitch = $("type9chk") ; var mySlider = new Fx.Slide(element, {duration:1000, mode:"vertical", wait:false}); mySwitch.addEvent("click", function() { $("chiffre").innerHTML = testResult() ; if ( mySwitch.checked ) { // Coché mySlider.slideIn(); } else { // Décoché mySlider.slideOut(); } }); }); /*************** fin Filtres checkbox ********************/ });