forAny(':is([data-lipotype-name="cohort-comparison"], [data-lipotype-name="correlation-analysis"]) label:first-child input[type="checkbox"]', element=> {
let sibling=element.closest('label').nextElementSibling.querySelector('input[type="checkbox"]');
sibling.disabled='disabled';
element.addEventListener('click', _=> {
if(element.checked){
sibling.removeAttribute('disabled');
}else{
sibling.checked=false;
sibling.disabled='disabled';
}});
});
forAny('.lipotype-quantity-wrapper', quantityWrapper=> {
let sibling=document.querySelector('.lipotype-wpcpo-total-wrapper');
if(sibling){
sibling.parentNode.insertBefore(quantityWrapper, sibling);
}});
forAny('.wp-block-query:has(#lipotype-shop-fallback-tile):has(ul.wp-block-post-template):not(:has(.wp-block-query-pagination-previous))', element=> {
let tile=element.querySelector('#lipotype-shop-fallback-tile');
tile.classList.add('follow-inner-link', 'helper-stretch-height');
let item=document.createElement('li');
item.classList.add('wp-block-post', 'product');
item.append(tile);
element.querySelector('ul.wp-block-post-template:not(.append-contact)')?.prepend(item);
element.querySelector('ul.wp-block-post-template.append-contact')?.append(item);
});
onAny('.lipotype-woocommerce-variation-checkboxes input[type="checkbox"]', 'change', checkbox=> {
let select=document.getElementById(checkbox.name);
let value=checkbox.checked ? checkbox.value:select.value=select.options[1].value;
jQuery(select).val(value).trigger('change');
});
let lipotype_open_headers=new Set();
forAny('.tom-select', element=> {
let options={
plugins: {
remove_button: {
title: 'Remove this item', label: '<input type="checkbox" checked/>'
}, checkbox_options: {},
}, persist: false, maxOptions: null
};
element.tomselect=new TomSelect(element, {...options});
});
forAny('.lipid-filter:is(select,input)', element=> {
let options={
plugins: {
remove_button: {
title: 'Remove this item', label: '<input type="checkbox" checked/>'
}, checkbox_options: {},
}, persist: false, render: {
'item': (data, escape)=> {
return '<div data-parent="">' + escape(data.name) + '</div>';
},
optgroup: function (data){
let optgroup=document.createElement('div');
optgroup.className='optgroup';
let parentName=data.group.name_parent;
optgroup.dataset.parent=parentName;
if(data.group.show_parent){
let open=lipotype_open_headers.has(parentName) ? '':'is-closed';
optgroup.innerHTML=`<div class="optgroup-header parent ${open}" title="${parentName}" onclick="lipotype_filter_toggle_open(this); return false;"><span>${parentName}</span><span class="toggle">▶</span></div>`
}
optgroup.appendChild(data.options);
let last_parent=false;
optgroup.querySelectorAll('.option').forEach(option=> {
let parentName=lipotype_lipid_filter_settings.parents[option.dataset.value];
if(last_parent!==parentName){
let parentElement=document.createElement('div');
parentElement.classList.add('optgroup-header', 'category');
if(!lipotype_open_headers.has(parentName)){
parentElement.classList.add('is-closed');
}
parentElement.onclick=function (){
lipotype_filter_toggle_open(parentElement, true);
return false;
};
parentElement.innerHTML=`<span>${parentName}</span><span class="toggle">▶</spanspan>`;
optgroup.insertBefore(parentElement, option);
}
last_parent=parentName;
});
return optgroup;
},
optgroup_header: function (data, escape){
let title=escape(data.name);
let open=lipotype_open_headers.has(title) ? '':'is-closed';
return `<div class="optgroup-header parent ${open}" title="${title}" onclick="lipotype_filter_toggle_open(this,false); return false;"><span>${title}</span><span class="toggle">▶</span></div>`;
}},
maxOptions: null,
};
element.tomselect=new TomSelect(element, {...options, ...window.lipotype_lipid_filter_settings});
});
function lipotype_filter_toggle_open(element, category=false){
let title=element.title;
let isOpen = !element.classList.toggle('is-closed');
if(isOpen){
lipotype_open_headers.add(title);
}else{
lipotype_open_headers.delete(title);
}
if(category){
let nextSibling=element.nextElementSibling;
while (nextSibling){
if(nextSibling.classList.contains('option')){
nextSibling.classList.remove('hidden');
nextSibling.classList.remove('show');
if(isOpen){
nextSibling.classList.add('show')
}else{
nextSibling.classList.add('hidden')
}
nextSibling=nextSibling.nextElementSibling;
continue;
}
nextSibling=false;
}}
if(event){
event.stopPropagation();
event.stopImmediatePropagation();
}}
jQuery(document).on('wpcpo_update_total', function (event, total){
});
let other_type_details_field=document.getElementById('billing_organization_type_other_details_field');
let other_type_field=document.getElementById('billing_organization_type');
if(other_type_details_field){
let other_type_default=other_type_details_field.value;
if(other_type_default===''){
other_type_default='Please describe your organization.';
other_type_details_field.value=other_type_default;
}
function lipotype_toggle_organization_type(){
if(other_type_field.value==='Other'){
other_type_details_field.value=other_type_details_field;
other_type_details_field.classList.remove('lipotype-hidden');
}else{
other_type_details_field.classList.add('lipotype-hidden');
other_type_details_field.value=other_type_default;
}}
other_type_field.addEventListener('change', lipotype_toggle_organization_type);
lipotype_toggle_organization_type();
}
wpcpo_update_total=function ($total){
let qty=parseFloat($total.closest('form.cart').find('.quantity .qty').val()),
price=parseFloat($total.attr('data-price')),
type=$total.data('type'), name=$total.data('product-name'), total=price * qty,
fields=$total.closest('.wpcpo-wrapper').find('.wpcpo-option-field').get(), html='',
qty_string=wpcpo_vars.is_rtl ? wpcpo_vars.quantity_symbol + qty:qty + wpcpo_vars.quantity_symbol;
html +='<ul>';
html +=`<li>
<div class="wpcpo-col1"><span>${qty_string}</span> ${name}</div>
<div class="wpcpo-col2 right-align"><strong><span class="amount">${wpcpo_format_price(price * qty)}</span></strong><br /><small class="nowrap">${wpcpo_format_price(price)} per Sample</small></div>
</li>`;
for (let field of fields){
let $field=jQuery(field), enable_price=$field.data('enable-price'),
$price_label=$field.closest('.wpcpo-option').find('.label-price-' + $field.attr('id')),
value=$field.val();
if($field.is(':checkbox')||$field.is(':radio')){
if($field.prop('checked')){
value=$field.data('label');
}else{
value='';
}}
if($field.is('select')){
value=$field.find('option:selected').data('label');
}
if(enable_price===1&&value!==''){
let field_price=wpcpo_get_field_price($field, price, qty);
if(!isNaN(field_price)){
if(field_price){
total +=field_price;
$price_label.html(`(+${wpcpo_format_price(field_price)})`);
html +=`<li><div class="wpcpo-col1"><span>${$field.data('title')}:</span> ${value}</div><div class="wpcpo-col2"><strong><span class="amount">${wpcpo_format_price(field_price)}</span></strong></div></li>`;
}else{
html +=`<li class="wpcpo-free"><div class="wpcpo-col1"><span>${$field.data('title')}:</span> ${value}</div><div class="wpcpo-col2"><strong><span class="amount">${wpcpo_format_price(field_price)}</span></strong></div></li>`;
}}
}else{
$price_label.html('');
}}
html +=`<li class="wpcpo-subtotal">${wpcpo_vars.i18n_subtotal}<span class="amount">${wpcpo_format_price(total)}</span></li>`;
html +='</ul>';
$total.html(html);
jQuery(document).trigger('wpcpo_update_total', [$total]);
};
function lipotype_quantity_plus(button){
let input=button.parentNode.querySelector('input');
input.stepUp();
input.dispatchEvent(new Event('change', {bubbles: true,}));
}
function lipotype_quantity_minus(button){
let input=button.parentNode.querySelector('input');
input.stepDown();
input.dispatchEvent(new Event('change', {bubbles: true,}));
}
whenVisible('#checkbox-lipotype-billing_organization_type', lipotype_improve_checkout);
whenVisible('input.qty', input=> input.dispatchEvent(new Event('change', {bubbles: true,})));
setTimeout(lipotype_improve_checkout, 500);
function lipotype_improve_checkout(){
let oldCheckbox=document.getElementById('checkbox-lipotype-billing_organization_type');
let newTemplate=document.getElementById('lipotype-billing-organization-type-template');
if(!oldCheckbox||!newTemplate){
setTimeout(lipotype_improve_checkout, 500);
return;
}
let parent=oldCheckbox.parentElement;
newTemplate.classList.remove('hidden', 'lipotype-hidden');
parent.appendChild(newTemplate);
};