PageSourceSearch

https://wabrum.com/js/addons/phone_mask.js

js wabrum.com collected 2026-10-08 11:50:24 UTC 2,203 bytes, 64 lines download raw bytes

1// Маска для туркменских номеров: +993XXXXXXXXX
2(function () {
3    'use strict';
4
5    function formatTM(raw) {
6        var d = raw.replace(/\D/g, '');
7        if (d.startsWith('993')) d = d.slice(3);
8        d = d.slice(0, 8);
9        return '+993' + d;
10    }
11
12    function attach(input) {
13        if (input.dataset.tmMask) return;
14        input.dataset.tmMask = '1';
15        input.removeAttribute('pattern');
16        input.setAttribute('type', 'tel');
17        input.setAttribute('placeholder', '+993XXXXXXXXX');
18        input.setAttribute('maxlength', '12');
19
20        input.addEventListener('focus', function () {
21            if (!this.value || this.value.trim() === '') {
22                this.value = '+993';
23            }
24        });
25
26        input.addEventListener('input', function () {
27            var formatted = formatTM(this.value);
28            this.value = formatted;
29            try { this.setSelectionRange(formatted.length, formatted.length); } catch(e) {}
30        });
31
32        input.addEventListener('blur', function () {
33            if (this.value.trim() === '+993') this.value = '';
34        });
35    }
36
37    function init() {
38        document.querySelectorAll('input[name*="phone"], input[id*="phone"], input[type="tel"]').forEach(attach);
39    }
40
41    if (document.readyState === 'loading') {
42        document.addEventListener('DOMContentLoaded', init);
43    } else {
44        init();
45    }
46
47    var observer = new MutationObserver(function (mutations) {
48        mutations.forEach(function (m) {
49            m.addedNodes.forEach(function (node) {
50                if (node.nodeType !== 1) return;
51                node.querySelectorAll('input[name*="phone"], input[id*="phone"], input[type="tel"]').forEach(attach);
52                if (node.matches && node.matches('input[name*="phone"], input[id*="phone"], input[type="tel"]')) attach(node);
53            });
54        });
55    });
56
57    if (document.body) {
58        observer.observe(document.body, { childList: true, subtree: true });
59    } else {
60        document.addEventListener('DOMContentLoaded', function () {
61            observer.observe(document.body, { childList: true, subtree: true });
62        });
63    }
64})();

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.