| 1 |
jQuery(function(){ |
| 2 |
|
| 3 |
jQuery(document).on('updated_checkout', function() { |
| 4 |
|
| 5 |
jQuery(".parcel_machine_checkout").css('display', 'none'); |
| 6 |
|
| 7 |
jQuery('.shipping_method:checked, .shipping_method[type=hidden]').each(function() { |
| 8 |
var method = jQuery(this).val(), display; |
| 9 |
if (method.indexOf(':') > -1) { |
| 10 |
var tmp = method.split(':'); |
| 11 |
method = tmp[0]; |
| 12 |
} |
| 13 |
jQuery(".parcel_machine_checkout_"+method).not(':first').remove(); |
| 14 |
jQuery(".parcel_machine_checkout_"+method).css('display', 'table-row'); |
| 15 |
}); |
| 16 |
|
| 17 |
adjust_select_box_width(); |
| 18 |
}); |
| 19 |
|
| 20 |
jQuery(window).resize(function() { |
| 21 |
adjust_select_box_width(); |
| 22 |
}); |
| 23 |
|
| 24 |
function adjust_select_box_width() { |
| 25 |
// Get widths of the content, parcel_machine_checkout row |
| 26 |
var select_box_width; |
| 27 |
var content_width = jQuery('.woocommerce-checkout-review-order').width(); |
| 28 |
var checkout_width = jQuery('.woocommerce-checkout').width(); |
| 29 |
var parcel_row = jQuery('.parcel_machine_checkout'); |
| 30 |
// Get the parent table class |
| 31 |
var default_layout = jQuery(parcel_row).closest('table').hasClass('shop_table') && |
| 32 |
jQuery(parcel_row).closest('table').hasClass('woocommerce-checkout-review-order-table'); |
| 33 |
// Get the width of the correct select box |
| 34 |
parcel_row.find('.parcel-machine-select-box').each(function() { |
| 35 |
select_box_width = jQuery(this).width() > 1 ? jQuery(this).width() : select_box_width; |
| 36 |
}); |
| 37 |
|
| 38 |
// If it is not the default table class, the theme is customized and no changes will be made |
| 39 |
if (default_layout && content_width !== 'undefined' && checkout_width !== 'undefined') { |
| 40 |
// Keep the searchable selectbox within size limits |
| 41 |
if (content_width > checkout_width / 2){ |
| 42 |
jQuery('.parcel_machine_checkout > td').css('max-width', (content_width / 2 - 20) +'px'); |
| 43 |
} else { |
| 44 |
jQuery('.parcel_machine_checkout > td').css('max-width', (content_width - 20) +'px'); |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
}); |
| 49 |
|