PageSourceSearch

https://leinert.com/wp-content/plugins/coinsnap-bitcoin-donation/assets/js/shared.js?ver=1.5.9

js leinert.com collected 2026-10-02 22:09:00 UTC 3,500 bytes, 113 lines download raw bytes

1/**
2 * Coinsnap Bitcoin Donation - Shared Utilities
3 */
4
5const addNumSeparators = (amount) => {
6    var tmp = removeThousandSeparator(amount);
7    var val = Number(tmp).toLocaleString("en-GB");
8    return (tmp === '') ? '' : val;
9};
10
11const getThousandSeparator = () => {
12    return (1000).toLocaleString("en-GB").replace(/\d/g, '')[0];
13};
14
15const removeThousandSeparator = (amount) => {
16    const sep = getThousandSeparator();
17    return amount?.replace(new RegExp(`\\${sep}`, 'g'), '');
18};
19
20const cleanDonationAmount = (amount) => {
21    return parseFloat(removeThousandSeparator(String(amount)));
22};
23
24const formatNumericInput = (target) => {
25    var tmp = removeThousandSeparator(target.value);
26    var original = tmp;
27    tmp = parseFloat(tmp);
28    original = original.replace(tmp, "");
29    var val = Number(tmp).toLocaleString("en-GB");
30    if (isNaN(tmp) || tmp === '') {
31        target.value = '';
32    } else {
33        target.value = `${val}${original}`;
34    }
35};
36
37const unformatNumericInput = (target) => {
38    var val = removeThousandSeparator(target.value);
39    target.value = val;
40};
41
42const NumericInput = (inputFieldName) => {
43    const inp = document.getElementById(inputFieldName);
44    if (inp) {
45        const sep = (getThousandSeparator() === ".") ? "," : ".";
46        var numericKeys = `0123456789${sep}`;
47
48        inp.addEventListener('keypress', function (e) {
49            var event = e || window.event;
50            if (event.charCode === 0) return;
51            if (`${inp.value}`.includes(sep) && event.key === sep) {
52                event.preventDefault();
53                return;
54            }
55            if (-1 === numericKeys.indexOf(event.key)) {
56                event.preventDefault();
57                return;
58            }
59        });
60
61        inp.addEventListener('blur', function (e) {
62            formatNumericInput(e.target);
63        });
64
65        inp.addEventListener('focus', function (e) {
66            unformatNumericInput(e.target);
67        });
68        unformatNumericInput(inp);
69        formatNumericInput(inp);
70    }
71};
72
73const addErrorDonationField = (field, message) => {
74    field.classList.add('error');
75    if (message !== '') {
76        if (jQuery(field).next('.donation-field-error').length) {
77            jQuery(field).next('.donation-field-error').text(message);
78        } else {
79            jQuery('<span>').addClass('donation-field-error').text(message).insertAfter(jQuery(field));
80        }
81    }
82    removeDonationBorderOnFocus(field, field);
83};
84
85const removeDonationBorderOnFocus = (field1, field2) => {
86    field1.addEventListener('focus', function () {
87        field2.classList.remove('error');
88        jQuery(field1).next('.donation-field-error').remove();
89        jQuery(field2).next('.donation-field-error').remove();
90    });
91};
92
93const hideDonationElementById = (id, prefix, sufix) => {
94    prefix = prefix || '';
95    sufix = sufix || '';
96    var el = document.getElementById(`${prefix}${id}${sufix}`);
97    if (el) el.style.display = 'none';
98};
99
100const showDonationElementById = (id, display, prefix, sufix) => {
101    prefix = prefix || '';
102    sufix = sufix || '';
103    var el = document.getElementById(`${prefix}${id}${sufix}`);
104    if (el) el.style.display = display;
105};
106
107const hideDonationElementsById = (ids, prefix, sufix) => {
108    ids.forEach(id => hideDonationElementById(id, prefix, sufix));
109};
110
111const showDonationElementsById = (ids, display, prefix, sufix) => {
112    ids.forEach(id => showDonationElementById(id, display, prefix, sufix));
113};

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.