Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<script type="text/javascript">
jQuery(document).bind('gform_post_render', function(e, formId, currentFormPage) {
var $form = jQuery('#gform_' + formId);
if ($form.data('configurator-init') === true) {
return;
}
$form.on('click', '.config-layer.image-choices-field .ginput_container_radio input', function (e) {
var $input = jQuery(this);
var $thisForm = $input.closest('form');
var $label = $input.next('label');
var $choice = $label.closest('.image-choices-choice');
var $field = $choice.closest('.gfield');
var $previewArea = $thisForm.find('.gform_body li.preview-area');
var layerRef = $field.data('layerRef');
var $layer = $previewArea.find('.'+layerRef);
var $img = $choice.find('span.image-choices-choice-image-wrap img:first').clone();
$img.attr('class', 'preview-item ' + $input.attr('id'));
$layer.empty().append($img);
});
$form.find('.gform_body .gfield.image-choices-field.config-layer').each(function(i, el){
var $field = jQuery(this);
if (!$field.find('.ginput_container_radio').length) {
return true;
}
var layerNum = i+1;
var layerRef = 'preview-layer-' + layerNum;
var fieldID = $field.attr('id');
var $previewArea = $field.closest('form').find('.gform_body li.preview-area');
$previewArea.append('<div class="preview-layer '+layerRef+' '+fieldID+'" style="z-index:'+layerNum+';"></div>');
$field.data('layerRef', layerRef);
});
$form.data('configurator-init', true);
});
jQuery(window).load(function(){
jQuery('.gfield.image-choices-field.config-layer .ginput_container_radio input:checked').each(function(i, el){
jQuery(this).trigger('click');
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.