1var mepr_populate_states = function(obj) { (function($) { 2 var country = obj.val(); 3 var form = obj.closest('.mepr-form'); 4 5 if(form == undefined) { return; } 6 7 // Clean out all the options before re-populating 8 form.find('.mepr-states-dropdown option').remove(); 9 10 var states_dropdown = form.find('.mepr-states-dropdown'); 11 var states_text = form.find('.mepr-states-text'); 12 13 // Ensure we've found a dropdown & text element 14 if (states_dropdown.length <= 0 || states_text.length <= 0) { return; } 15 16 // Grab fieldname and value 17 var fieldname = states_dropdown.data('fieldname'); 18 var value = states_dropdown.data('value').toString(); 19 20 if(fieldname == undefined || value == undefined) { return; } 21 22 // Clean up trailing whitespace 23 fieldname = fieldname.replace(/^\s+/,''); 24 fieldname = fieldname.replace(/\s+$/,''); 25 value = value.replace(/^\s+/,''); 26 value = value.replace(/\s+$/,''); 27 28 var required = !!obj.attr('required'); 29 30 if (MeprI18n.states[country] !== undefined) { 31 states_dropdown.attr('name', fieldname); 32 states_dropdown.show(); 33 states_text.removeAttr('name'); 34 states_text.hide(); 35 if (required) { 36 states_text.removeAttr('required'); 37 states_dropdown.attr('required',''); 38 } 39 40 states_dropdown.append('<option value="">' + MeprI18n.please_select_state + '</option>'); 41 42 for (var st in MeprI18n.states[country]) { 43 var selected = (value===st ? ' selected="selected"' : ''); 44 states_dropdown.append('<option value="' + st + '" ' + selected + '>' + MeprI18n.states[country][st] + '</option>'); 45 } 46 } 47 else { 48 states_dropdown.removeAttr('name'); 49 states_dropdown.hide(); 50 states_text.attr('name', fieldname); 51 states_text.show(); 52 if (required) { 53 states_dropdown.removeAttr('required'); 54 states_text.attr('required',''); 55 } 56 } 57})(jQuery)}; 58 59var mepr_set_locate_inputs = function(country, state) { (function($) { 60 if(country !== '' && state !== '') { 61 // If the states are created for this country 62 // but the state is goofy then just blank it out 63 if(MeprI18n.states[country]!==undefined && 64 MeprI18n.states[country][state]===undefined) { 65 state = ''; 66 } 67 } 68 69 // Set the correct values for the country or state dropdowns 70 if ($('.mepr-form .mepr-countries-dropdown').length > 0) { 71 $.each($('.mepr-form .mepr-countries-dropdown'), function(i, obj) { 72 if($(obj).val()===undefined || $(obj).val()==='') { 73 $(obj).val(country); 74 } 75 76 mepr_populate_states($(obj)); 77 }); 78 } 79 80 // Set the states up properly where appropriate 81 if ($('.mepr-form .mepr-states-dropdown').length > 0) { 82 $.each($('.mepr-form .mepr-states-dropdown'), function(i, obj) { 83 84 if($(obj).data('value')===undefined || $(obj).data('value')==='') { 85 var options = $(obj).find('option'); 86 87 $.each(options, function(i, option) { 88 if(state===option.value) { 89 $(obj).attr('data-value',state); 90 $(option).attr('selected','selected'); 91 return false; 92 } 93 }); 94 } 95 96 }); 97 } 98 99 if ($('.mepr-form .mepr-geo-country').length > 0) { 100 $.each($('.mepr-form .mepr-geo-country'), function(i, obj) { 101 $(obj).val(country); 102 }); 103 } 104 105 $('.mepr-form .mepr-countries-dropdown').trigger('mepr-geolocated'); 106})(jQuery)}; 107 108var mepr_ssl_geoip_services = { 109 // The services 110 caseproof: { 111 url: 'https://cspf-locate.herokuapp.com?callback=?', 112 cindex: 'country_code', 113 sindex: 'region_code', 114 used: false, 115 type: 'jsonp', 116 }, 117 //telize: { //TELIZE SHUT DOWN IN 2015 118 // url: 'https://www.telize.com/geoip', 119 // cindex: 'country_code', 120 // sindex: 'region_code', 121 // used: false, 122 // type: 'json', 123 //}, 124 //geoplugin: { 125 // url: 'http://www.geoplugin.net/json.gp?jsoncallback=?', 126 // cindex: 'geoplugin_countryCode', 127 // sindex: 'geoplugin_regionCode', 128 // used: false, 129 // type: 'jsonp', 130 //}, 131 //'ip-api': { 132 // url: 'http://ip-api.com/json/?callback=?', 133 // cindex: 'countryCode', 134 // sindex: 'region', 135 // used: false, 136 // type: 'jsonp', 137 //}, 138 //freegeoip: { //Dead - needs to use https://ipstack.com/ now 139 // url: 'https://freegeoip.net/json/', 140 // cindex: 'country_code',
141 // sindex: 'region_code', 142 // used: false, 143 // type: 'json', 144 //} 145}; 146 147var mepr_locate = function(source_key) { (function($) { 148 if(source_key==undefined) { 149 source_key = 'caseproof'; // default 150 } 151 152 source = mepr_ssl_geoip_services[source_key]; 153 154 // If we've already used this source then assume we're out of choices 155 if(source.used===true) { 156 return mepr_set_locate_inputs('',''); 157 } 158 159 $.ajax({ 160 url: source.url, 161 method: 'GET', 162 timeout: 5000, // 5 seconds ... too much? too little? 163 dataType: source.type, 164 }) 165 .done (function(data) { 166 var state = ((data[source.sindex]!==undefined) ? data[source.sindex] : ''); 167 var country = ((data[source.cindex]!==undefined) ? data[source.cindex] : ''); 168 169 mepr_set_locate_inputs(country, state); 170 }) 171 .fail (function() { 172 mepr_ssl_geoip_services[source_key].used=true; 173 174 for (var k in mepr_ssl_geoip_services) { 175 var next_source = mepr_ssl_geoip_services[k]; 176 177 if(next_source.used===false) { 178 return mepr_locate(k); 179 } 180 } 181 182 mepr_set_locate_inputs('',''); 183 }); 184 185 return false; 186})(jQuery)}; 187 188jQuery(document).ready(function($){ 189 $.each($('.mepr-form .mepr-countries-dropdown'), function(i, obj) { 190 mepr_populate_states($(obj)); 191 $(obj).on('change', function(e) { 192 mepr_populate_states($(obj)); 193 }); 194 }); 195});
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.