1(function($){'use strict';var savedTerminalId=undefined;var retryTimer=null;var lastAjaxAttach=0;var AJAX_THROTTLE_MS=300;var observerDebounce=null;var terminalsCache={};var planCache={};function onTerminalSelect(data){var terminalId=data.id;var terminalName=data.text;if(terminalId&&terminalId!==savedTerminalId&&!isNaN(terminalId)){savedTerminalId=terminalId;$.post(woo_lithuaniapost.ajax_url,{action:'save_selected_lpexpress_terminal',terminal:terminalName,terminal_id:terminalId});}} 2function isTerminalPlanSync(methodValue){var instanceId=(methodValue.split(':')[1])||'';if(!instanceId)return false;if(Object.prototype.hasOwnProperty.call(planCache,instanceId)){return planCache[instanceId];} 3var isTerm=false;$.ajax({type:'POST',dataType:'json',async:false,url:woo_lithuaniapost.ajax_url,data:{action:'woo_lithuaniapost_check_plan',instance_id:instanceId},success:function(resp){isTerm=!!(resp&&resp.success&&resp.data==='TERMINAL');}});planCache[instanceId]=isTerm;return isTerm;} 4function fetchSavedTerminalSync(){var id=null;$.ajax({type:'POST',dataType:'json',async:false,url:woo_lithuaniapost.ajax_url,data:{action:'woo_lithuaniapost_get_saved_terminal'},success:function(resp){if(resp&&resp.success)id=resp.data||null;}});savedTerminalId=id;} 5function applySelect2($select){if($select.data('select2')){$select.off('select2:select').select2('destroy');} 6$select.select2({width:'resolve'});$select.on('select2:select',function(e){onTerminalSelect(e.params.data);});$select.closest('label.woo_lithuaniapost_lpexpress_terminal_label').css('display','block');} 7function fillSelect($select,data){$select.find('optgroup, option').not(':first').remove();$.each(data,function(city,terminals){var $group=$('<optgroup>').attr('label',city);$.each(terminals,function(id,name){$group.append(new Option(name,id));});$select.append($group);});if(savedTerminalId)$select.val(savedTerminalId);applySelect2($select);} 8function loadTerminals($select,countryCode){if(!countryCode||!$select||$select.length===0)return;if(terminalsCache[countryCode]){fillSelect($select,terminalsCache[countryCode]);return;} 9$.post(woo_lithuaniapost.ajax_url,{action:'get_terminals_by_country_code',s_country:countryCode}).done(function(resp){if(resp&&resp.success&&resp.data){terminalsCache[countryCode]=resp.data;fillSelect($select,resp.data);}});} 10function getCountry(){return $('#shipping-country').val()||$('#billing_country').val()||null;} 11function attachTerminalDropdown(){if(typeof savedTerminalId==='undefined')fetchSavedTerminalSync();if(typeof $.fn.select2==='undefined')return false;var $options=$('.wc-block-components-shipping-rates-control .wc-block-components-radio-control__option');if($options.length===0)return false;var $checked=$options.filter(function(){return $(this).find('input:checked').length>0||$(this).hasClass('wc-block-components-radio-control__option-checked');}).first();if($checked.length===0)return false;var methodValue=$checked.find('input').val()||'';if(methodValue.indexOf('woo_lithuaniapost_lpexpress_terminal')===-1||!isTerminalPlanSync(methodValue)){$options.find('.woo_lithuaniapost_lpexpress_terminal_label, .woo_lithuaniapost_shipping_method_terminal').remove();if(savedTerminalId!==null){savedTerminalId=null;$.post(woo_lithuaniapost.ajax_url,{action:'save_selected_lpexpress_terminal',terminal:null,terminal_id:null});} 12return false;} 13var $label=$checked.find('.woo_lithuaniapost_lpexpress_terminal_label');if($label.length===0){var tpl=woo_lithuaniapost.terminal_dropdown_template;if(!tpl)return false;var $newLabel=$('<div>').html(tpl).find('label.woo_lithuaniapost_lpexpress_terminal_label').first();if($newLabel.length===0)return false;$newLabel.find('select').find('optgroup, option').not(':first').remove();$newLabel.css('margin-top','10px');$checked.append($newLabel);$label=$checked.find('.woo_lithuaniapost_lpexpress_terminal_label');} 14var hiddenId=methodValue.replace(':','_');if($checked.find('#'+hiddenId+'.woo_lithuaniapost_shipping_method_terminal').length===0){$checked.append($('<input>',{type:'hidden',id:hiddenId,class:'woo_lithuaniapost_shipping_method_terminal'}));} 15if(savedTerminalId)$checked.find('#'+hiddenId).val(savedTerminalId);var $select=$label.find('select.woo_block_lithuaniapost_lpexpress_terminal_id');if($select.length>0&&$select.find('optgroup').length===0){loadTerminals($select,getCountry());}else if($select.find('optgroup').length>0){$label.css('display','block');} 16$options.not($checked).find('.woo_lithuaniapost_lpexpress_terminal_label, .woo_lithuaniapost_shipping_method_terminal').remove();return true;} 17function loopAttachTerminalDropdown(){if(retryTimer)clearTimeout(retr
17yTimer);retryTimer=null;if(!attachTerminalDropdown()){retryTimer=setTimeout(loopAttachTerminalDropdown,300);}} 18$(document).ready(function(){$(document).on('change','#shipping-country',function(){var country=$(this).val();if(!country)return;terminalsCache={};savedTerminalId=null;loadTerminals($('.woo_block_lithuaniapost_lpexpress_terminal_id'),country);});$(document).on('change','.wc-block-components-shipping-rates-control input[type="radio"]',function(){if(retryTimer)clearTimeout(retryTimer);retryTimer=setTimeout(loopAttachTerminalDropdown,150);});$(document).ajaxComplete(function(event,xhr,settings){var data=(settings&&settings.data)||'';if(typeof data==='string'&&(data.indexOf('action=save_selected_lpexpress_terminal')!==-1||data.indexOf('action=get_terminals_by_country_code')!==-1||data.indexOf('action=woo_lithuaniapost_get_saved_terminal')!==-1||data.indexOf('action=woo_lithuaniapost_check_plan')!==-1))return;var now=Date.now();if(now-lastAjaxAttach<AJAX_THROTTLE_MS)return;lastAjaxAttach=now;setTimeout(loopAttachTerminalDropdown,100);});if(typeof MutationObserver!=='undefined'){new MutationObserver(function(mutations){var found=mutations.some(function(m){return Array.prototype.some.call(m.addedNodes||[],function(node){return node.nodeType===1&&(node.classList.contains('wc-block-components-shipping-rates-control')||(node.querySelector&&node.querySelector('.wc-block-components-shipping-rates-control')));});});if(found){if(observerDebounce)clearTimeout(observerDebounce);observerDebounce=setTimeout(loopAttachTerminalDropdown,100);}}).observe(document.body||document.documentElement,{childList:true,subtree:true});} 19loopAttachTerminalDropdown();});})(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.