1(function () { 2 function format(digits) { 3 if (digits.length && (digits[0] === '7' || digits[0] === '8')) digits = digits.slice(1); 4 digits = digits.slice(0, 10); 5 var out = '+7'; 6 if (digits.length > 0) out += ' ' + digits.slice(0, 3); 7 if (digits.length > 3) out += ' ' + digits.slice(3, 6); 8 if (digits.length > 6) out += ' ' + digits.slice(6, 8); 9 if (digits.length > 8) out += ' ' + digits.slice(8, 10); 10 return out; 11 } 12 function attach(el) { 13 if (el.dataset.phoneMasked) return; 14 el.dataset.phoneMasked = '1'; 15 el.setAttribute('inputmode', 'tel'); 16 el.setAttribute('autocomplete', 'tel'); 17 if (!el.getAttribute('maxlength')) el.setAttribute('maxlength', '18'); 18 if (!el.placeholder) el.placeholder = '+7 ___ ___ __ __'; 19 el.addEventListener('focus', function () { if (!el.value) el.value = '+7 '; }); 20 el.addEventListener('input', function () { 21 var digits = el.value.replace(/\D/g, ''); 22 el.value = digits ? format(digits) : ''; 23 }); 24 el.addEventListener('blur', function () { if (el.value === '+7' || el.value === '+7 ') el.value = ''; }); 25 el.addEventListener('keydown', function (e) { 26 if (e.key === 'Backspace' && el.value.replace(/\D/g, '').replace(/^7/, '').length === 0) el.value = ''; 27 }); 28 el.addEventListener('paste', function (e) { 29 e.preventDefault(); 30 var text = (e.clipboardData || window.clipboardData).getData('text'); 31 el.value = format(text.replace(/\D/g, '')); 32 }); 33 } 34 function init() { document.querySelectorAll('input[type="tel"]').forEach(attach); } 35 if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init); 36 else init(); 37})();
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.