1(function ($) { 2 function validateSerialDevice(el, serial) { 3 var cart_id = el.data('cart-id'); 4 var cart_device = el.data('cart-device'); 5 var device_input = $('#cart_serial_' + cart_id + '_' + cart_device); 6 $.ajax( 7 { 8 type: 'POST', 9 url: cartSerial.ajaxurl, 10 data: { 11 action: 'serial_update_cart', 12 security: $('#woocommerce-cart-nonce').val(), 13 serial: serial, 14 device_index: cart_device, 15 cart_id: cart_id 16 }, 17 success: function (response) { 18 $('.cart').unblock(); 19 20 if (response.success === false) { 21 $('#serial_cart_item_devices').html('<tr><td>An unknown error occurred. Check the serial numbers, refresh the page, and try again. If the problem persists, contact Epiphan Video.</td></tr>') 22 } else { 23 var validated = response.data[cart_device] 24 displayNotice(cart_id, cart_device, device_input, validated); 25 } 26 } 27 } 28 ); 29 } 30 31 function displayNotice(cart_id, cart_device, device_input, validated) { 32 $('.cart').unblock(); 33 var $applyBtn = device_input.parents('.device-serial-form').find('.btn-primary'); 34 35 $applyBtn.attr('disabled', false); 36 $('#serial_notice_' + cart_id + '_' + cart_device) 37 .removeClass(['error', 'success']) 38 .addClass(validated.class) 39 .html(validated.message); 40 41 device_input 42 .removeClass(['error', 'success']) 43 .addClass(validated.class) 44 .attr('readonly', validated.valid); 45 46 if (validated.valid) { 47 $applyBtn.attr('disabled', true); 48 } 49 } 50 51 function deviceSerialListener() { 52 $('.device-serial-input').each(function () { 53 if ($(this).val()) { 54 validateSerialDevice($(this), $(this).val()); 55 } 56 }); 57 58 $('.device-serial-input').on('change paste', function (event) { 59 $('.cart').block({ 60 message: null, 61 overlayCSS: { 62 background: '#fff', 63 opacity: 0.6 64 } 65 }); 66 67 if (event.type === 'paste') { 68 var input = event.originalEvent.clipboardData.getData('text'); 69 } else { 70 var input = $(this).val(); 71 } 72 73 validateSerialDevice($(this), input); 74 }); 75 76 $('[data-cart-clear-device]').on('click', function (e) { 77 e.preventDefault(); 78 var device_input_id = $(this).data('cart-clear-device'); 79 $('#cart_serial_' + device_input_id).val('').trigger('change'); 80 }); 81 } 82 83 $(document).ready(deviceSerialListener); 84 $(document).on('updated_cart_totals', deviceSerialListener); 85})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.