1(function ($) { 2 "use strict"; 3 4 function StateSelect(element, states, countryselect){ 5 6 var body = $('body'), 7 is2019 = body.hasClass('template_2019'), 8 self = this, 9 state_input = $(element), 10 country_select = countryselect || $("select[name='country']").last(), 11 cs_class = (country_select.attr('class') || '') + '__state_select'; 12 13 if(!country_select.length){ 14 return; 15 } 16 17 $('.' + cs_class).hide(); 18 19 self.state_select = $('<select class="form-control"></select>'); 20 self.state_select.addClass((country_select.attr('class') || '') + '__state_select'); 21 self.status = false; 22 self.last_country = null; 23 24 state_input.addClass("__state_input"); 25 26 self.state_select.on('init change', function () { 27 state_input.val(self.state_select.val()); 28 }); 29 30 country_select.on("init change", function () { 31 var country_value = country_select.val(), 32 state_parent = state_input.parent(), 33 state_value = state_input.val(), 34 html = ""; 35 36 if (is2019) { 37 var label = $(state_input).closest('.form-label-group').find('label'); 38 } 39 40 if(self.last_country === country_value){ 41 return; 42 } 43 44 self.last_country = country_value; 45 if (country_value && states.hasOwnProperty(country_value) ) { 46 if(Array.isArray(states[country_value])) { 47 var key, length = states[country_value].length; 48 49 for (key=0; key < length; key++) { 50 if (states[country_value][key] === state_value) { 51 html += '<option selected="selected">' 52 + states[country_value][key] 53 + "</option>"; 54 } else{ 55 html += "<option>" + states[country_value][key] + "</option>" 56 } 57 } 58 } else { 59 for (var key of Object.keys(states[country_value])) { 60 if (key === state_value) { 61 html += '<option selected="selected" value="' 62 + key 63 +'">' 64 + states[country_value][key] 65 + "</option>"; 66 } else{ 67 html += '<option value="' 68 + key 69 +'">'+ states[country_value][key] + '</option>' 70 } 71 } 72 } 73 74 self.state_select.html(html); 75 self.state_select.css({ 76 'minWidth': Math.min(country_select.outerWidth(), state_input.outerWidth()) 77 }); 78 state_parent.append(self.state_select); 79 self.state_select.trigger('init'); 80 81 state_input.hide(); 82 state_input.trigger('showSelect', [self]); 83 self.status = true; 84 if (is2019) { 85 label.insertAfter(self.state_select).show(); 86 } 87 } else if(self.status) { 88 self.status = false; 89 state_input.show(); 90 self.state_select.detach(); 91 state_input.trigger('hideSelect', [self]); 92 if (is2019) { 93 label.insertAfter(state_input).show(); 94 } 95 } 96 }).trigger('init'); 97 state_input.trigger('initSelect', [self]); 98 } 99 100 $.fn.stateProvinceSelect = function (states, countryselect){ 101 states = $.extend({}, $.fn.stateProvinceSelect.states || {}, states); 102 return this.each(function () { 103 if (!$.data(this, "stateprovinceselect")) { 104 $.data(this, "stateprovinceselect" , new StateSelect(this, states, countryselect)); 105 } 106 }); 107 }; 108})(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.