| 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').attr('class') == 'shop_table woocommerce-checkout-review-order-table'; |
| 32 |
// Get the width of the correct select box |
| 33 |
parcel_row.find('.parcel-machine-select-box').each(function() { |
| 34 |
select_box_width = jQuery(this).width() > 1 ? jQuery(this).width() : select_box_width; |
| 35 |
}); |
| 36 |
|
| 37 |
// If it is not the default table class, the theme is customized and no changes will be made |
| 38 |
if (default_layout && content_width !== 'undefined' && checkout_width !== 'undefined') { |
| 39 |
// Keep the searchable selectbox within size limits |
| 40 |
if (content_width > checkout_width / 2){ |
| 41 |
jQuery('.parcel_machine_checkout > td').css('max-width', (content_width / 2 - 20) +'px'); |
| 42 |
} else { |
| 43 |
jQuery('.parcel_machine_checkout > td').css('max-width', (content_width - 20) +'px'); |
| 44 |
} |
| 45 |
// If the size of the selectbox is bigger than X pixels and less than 2 times as small as the content, add a cell before it |
| 46 |
if (select_box_width > 500 && content_width / select_box_width < 2) { |
| 47 |
// Unless there already exist 2 cells, add an empty one before select_box |
| 48 |
if (parcel_row.find('.padding_cell').length < 1) { |
| 49 |
parcel_row.prepend('<td class="padding_cell"></td>'); |
| 50 |
} |
| 51 |
|
| 52 |
// Loop through children and change colspan of select_box cell to 1 |
| 53 |
parcel_row.children().each(function() { |
| 54 |
if (typeof(jQuery(this).attr('colspan')) !== 'undefined') { |
| 55 |
jQuery(this).attr('colspan', 1); |
| 56 |
} |
| 57 |
}); |
| 58 |
} else if (content_width <= 500 && parcel_row.find('.padding_cell').length > 0) { |
| 59 |
// If the row is smaller than the min amount and there's a padding cell, remove it |
| 60 |
parcel_row.children().each(function() { |
| 61 |
// Change colspan back to 2 |
| 62 |
if (typeof(jQuery(this).attr('colspan')) !== 'undefined') { |
| 63 |
jQuery(this).attr('colspan', 2); |
| 64 |
} else { |
| 65 |
jQuery(this).remove(); |
| 66 |
} |
| 67 |
}); |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
}); |
| 72 |
|