Last active
June 5, 2024 17:01
-
-
Save alfredo-wpmudev/d750f02f147b0dff9ace7cf70685b4e0 to your computer and use it in GitHub Desktop.
Forminator SPH and CYL Logic and conditionals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Forminator Lens SPH and CYL logic conditions | |
Version: 0.1 | |
Description: Forminator Lens SPH and CYL logic conditions | |
Author: Alfredo Galano Loyola | |
License: GPLv2 or later | |
License URI: https://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
defined('ABSPATH') || exit; | |
function frm_lens_sph_cyl_logic() | |
{ | |
?> | |
<script type="text/javascript"> | |
var sphR = 0; | |
var sphL = 0; | |
var cylR = 0; | |
var cylL = 0; | |
function checkSPH(value) { | |
if (value >= 4 || value <= -8) { | |
return true; | |
} else { | |
return false | |
} | |
} | |
function checkSPH_CR39(value) { | |
if (value >= 4 || value <= -6) { | |
return true; | |
} else { | |
return false | |
} | |
} | |
function checkCYL(value) { | |
if (value >= 2 || value <= -2) { | |
return true; | |
} else { | |
return false | |
} | |
} | |
function areLensAvailable(sphR, sphL, cylR, cylL) { | |
if (checkSPH(sphR) || checkSPH(sphL) || checkCYL(cylR) || checkCYL(cylL)) { | |
alert("Really sorry. Lens with those metrics are not available."); | |
jQuery('.forminator-button-next').hide(); | |
} else { | |
jQuery('.forminator-button-next').show(); | |
} | |
} | |
function areCR39Available(sphR, sphL, cylR, cylL) { | |
if (checkSPH_CR39(sphR) || checkSPH_CR39(sphL)) { | |
handleRadioOptions("hide"); | |
} else { | |
handleRadioOptions("show"); | |
} | |
} | |
function handleRadioOptions(action) { | |
jQuery('.forminator-radio-label').each(function(index) { | |
if (jQuery(this).text().includes("CR39")) { | |
if (action == "hide") { | |
jQuery(this).parent().hide(); | |
if (jQuery(this).parent().children(':first-child').is(':checked')) { | |
jQuery(this).parent().children(':first-child').prop('checked', false); | |
} | |
} else { | |
jQuery(this).parent().show(); | |
} | |
} | |
}); | |
} | |
jQuery(document).ready(function() { | |
if (jQuery('#forminator-module-1049823').length) { | |
setTimeout(() => { | |
jQuery("#select-1 select").on("change", function() { | |
sphR = jQuery(this).val(); | |
areLensAvailable(sphR, sphL, cylR, cylL); | |
areCR39Available(sphR, sphL, cylR, cylL); | |
}); | |
jQuery("#select-5 select").on("change", function() { | |
sphL = jQuery(this).val(); | |
areLensAvailable(sphR, sphL, cylR, cylL); | |
areCR39Available(sphR, sphL, cylR, cylL); | |
}); | |
jQuery("#select-2 select").on("change", function() { | |
cylR = jQuery(this).val(); | |
areLensAvailable(sphR, sphL, cylR, cylL); | |
areCR39Available(sphR, sphL, cylR, cylL); | |
}); | |
jQuery("#select-6 select").on("change", function() { | |
cylL = jQuery(this).val(); | |
areLensAvailable(sphR, sphL, cylR, cylL); | |
areCR39Available(sphR, sphL, cylR, cylL); | |
}); | |
console.log("Time is gold"); | |
}, 1500); | |
} | |
}); | |
</script> | |
<?php | |
} | |
add_action('wp_footer', 'frm_lens_sph_cyl_logic'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment