1import { Controller } from "@hotwired/stimulus"; 2import intlTelInput from 'intl-tel-input'; 3import Swal from 'sweetalert2'; 4import { trans } from 'translator'; 5 6export default class extends Controller { 7 static targets = ["phoneInput"]; 8 9 connect() { 10 this.element.addEventListener('keypress', (event) => { 11 if (event.key === 'Enter') { 12 this.control(); 13 event.preventDefault(); 14 } 15 } 16 ); 17 18 this.intlTelInputInstance = intlTelInput(this.phoneInputTarget, { 19 initialCountry: "auto", 20 geoIpLookup: this.geoIpLookup.bind(this), 21 utilsScript: "https://cdn.jsdelivr.net/npm/[email protected]/build/js/utils.js" 22 }); 23 } 24 25 geoIpLookup(callback) { 26 fetch('https://ipinfo.io/json') 27 .then((response) => response.json()) 28 .then((data) => callback(data.country)) 29 .catch(() => callback('fr')); 30 } 31 32 control() { 33 if (this.phoneInputTarget.value.trim()) { 34 if (this.intlTelInputInstance.isValidNumber()) { 35 this.phoneInputTarget.value = this.intlTelInputInstance.getNumber(); 36 this.element.closest('form').submit(); 37 } else { 38 let errorCode = this.intlTelInputInstance.getValidationError(); 39 const errorMap = [ 40 trans('sms_contact.show.intl_tel_input_invalid_number'), 41 trans('sms_contact.show.intl_tel_input_invalid_country_code'), 42 trans('sms_contact.show.intl_tel_input_too_short'), 43 trans('sms_contact.show.intl_tel_input_too_long'), 44 trans('sms_contact.show.intl_tel_input_invalid_number'), 45 trans('sms_contact.show.intl_tel_input_invalid_number') 46 ]; 47 48 const errorText = errorCode == -99 ? 'Erreur Internet' : errorMap[errorCode] 49 50 Swal.fire({ 51 title: errorText, 52 icon: "warning", 53 confirmButtonText: "OK" 54 }); 55 } 56 } 57 } 58}
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.