telephony: автоформат +380, тип линии SIP/АТС и звонок через Asterisk AMI.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,10 +1,27 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
if (window.__acorePhoneFormatLoaded) {
|
||||
return;
|
||||
}
|
||||
window.__acorePhoneFormatLoaded = true;
|
||||
|
||||
function isPhoneField(input) {
|
||||
if (!input || input.tagName !== 'INPUT' || input.type !== 'text') {
|
||||
if (!input || input.tagName !== 'INPUT') {
|
||||
return false;
|
||||
}
|
||||
if (input.type && input.type !== 'text' && input.type !== 'tel') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((input.className || '').split(/\s+/).indexOf('js-phone') !== -1) {
|
||||
return true;
|
||||
}
|
||||
if ((input.getAttribute('inputmode') || '') === 'tel') {
|
||||
return true;
|
||||
}
|
||||
if ((input.getAttribute('autocomplete') || '') === 'tel') {
|
||||
return true;
|
||||
}
|
||||
|
||||
var name = (input.name || '').toLowerCase();
|
||||
var id = (input.id || '').toLowerCase();
|
||||
@@ -54,7 +71,7 @@
|
||||
return '';
|
||||
}
|
||||
|
||||
var local = uaDigits.slice(3); // 9 digits after country code
|
||||
var local = uaDigits.slice(3);
|
||||
var p1 = local.slice(0, 2);
|
||||
var p2 = local.slice(2, 5);
|
||||
var p3 = local.slice(5, 7);
|
||||
@@ -85,12 +102,19 @@
|
||||
if (!current) {
|
||||
return;
|
||||
}
|
||||
input.value = toPretty(current);
|
||||
var pretty = toPretty(current);
|
||||
if (pretty === current) {
|
||||
return;
|
||||
}
|
||||
input.value = pretty;
|
||||
}
|
||||
|
||||
function normalizePhoneInputs(scope) {
|
||||
var root = scope || document;
|
||||
var inputs = root.querySelectorAll('input[type="text"]');
|
||||
if (!root.querySelectorAll) {
|
||||
return;
|
||||
}
|
||||
var inputs = root.querySelectorAll('input[type="text"], input[type="tel"], input.js-phone');
|
||||
|
||||
for (var i = 0; i < inputs.length; i += 1) {
|
||||
if (!isPhoneField(inputs[i])) {
|
||||
@@ -122,20 +146,44 @@
|
||||
return;
|
||||
}
|
||||
|
||||
var inputs = form.querySelectorAll('input[type="text"]');
|
||||
var inputs = form.querySelectorAll('input[type="text"], input[type="tel"], input.js-phone');
|
||||
for (var i = 0; i < inputs.length; i += 1) {
|
||||
if (!isPhoneField(inputs[i])) {
|
||||
if (!isPhoneField(inputs[i]) || !inputs[i].value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!inputs[i].value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
inputs[i].value = toCanonical(inputs[i].value);
|
||||
}
|
||||
}, true);
|
||||
|
||||
document.addEventListener('htmx:configRequest', function (event) {
|
||||
var params = event.detail && event.detail.parameters;
|
||||
if (!params) {
|
||||
return;
|
||||
}
|
||||
var source = event.detail.elt;
|
||||
var form = source && source.closest ? source.closest('form') : null;
|
||||
if (!form) {
|
||||
return;
|
||||
}
|
||||
var inputs = form.querySelectorAll('input[type="text"], input[type="tel"], input.js-phone');
|
||||
for (var i = 0; i < inputs.length; i += 1) {
|
||||
if (!isPhoneField(inputs[i]) || !inputs[i].name || !inputs[i].value) {
|
||||
continue;
|
||||
}
|
||||
var canonical = toCanonical(inputs[i].value);
|
||||
if (typeof params.set === 'function') {
|
||||
params.set(inputs[i].name, canonical);
|
||||
} else {
|
||||
params[inputs[i].name] = canonical;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('htmx:afterSwap', function (event) {
|
||||
var target = event.detail && event.detail.target;
|
||||
normalizePhoneInputs(target || document);
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
normalizePhoneInputs(document);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user