PageSourceSearch

https://halalincorp.co.uk/wp-content/plugins/exchange-rates/assets/js/public/common.js

js halalincorp.co.uk collected 2026-10-06 13:02:15 UTC 5,496 bytes, 143 lines download raw bytes

1jQuery(document).ready(function() {
2    function formatNumber(r, n, p, ts, dp) {
3        var t = [];
4
5        if (typeof p == 'undefined') p = 2;
6        if (typeof ts == 'undefined') ts = ',';
7        if (typeof dp == 'undefined') dp = '.';
8
9        n = Number((r * n).toFixed(p));
10        n = n.toString().split('.');
11
12        for (var iLen = n[0].length, i = iLen ? iLen % 3 || 3 : 0, j = 0; i <= iLen; i += 3) {
13            t.push(n[0].substring(j, i));
14            j = i;
15        }
16
17        return t.join(ts) + (n[1] ? dp + n[1] : '');
18    }
19    /* Caption - start */
20    jQuery('span.exchange-rates-caption-button, strong.exchange-rates-caption-button').on('click', function(event) {
21        if (jQuery('#' + jQuery(this).data('caption-id')).css('display') === 'none') {
22            jQuery(jQuery(this).find('svg')[0]).css('display', 'none');
23            jQuery(jQuery(this).find('svg')[1]).css('display', 'block');
24            jQuery('#' + jQuery(this).data('caption-id')).show();
25
26        } else {
27            jQuery(jQuery(this).find('svg')[0]).css('display', 'block');
28            jQuery(jQuery(this).find('svg')[1]).css('display', 'none')
29            jQuery('#' + jQuery(this).data('caption-id')).hide();
30        }
31    });
32    /* Caption - end */
33
34    /* Currency Table - start */
35    jQuery('.widget-exchange-rates-currency-table input').on('click', function(event) {
36        var amount = jQuery(this).val();
37        jQuery(this).data('amount', amount).val('');
38    }).on('blur', function(event) {
39        var amount = jQuery(this).data('amount');
40        jQuery(this).val(amount);
41    });
42
43    jQuery('.widget-exchange-rates-currency-table input').on('input', function(event) {
44        var amount = parseFloat(jQuery(this).val());
45        var settings = jQuery('.widget-exchange-rates-currency-table table');
46
47        amount = (amount > 0) ? amount : 1;
48
49        jQuery(this).data('amount', amount);
50        jQuery('.widget-exchange-rates-currency-table table tbody td[data-rate]').each(function(index, value) {
51            var rate = jQuery(value).data('rate');
52            var pre = jQuery(value).data('symbol');
53            var after = '';
54
55            if (settings.data('after')) {
56                after = pre;
57                pre = '';
58            }
59
60            var result = pre + formatNumber(rate, amount, settings.data('decimals'), settings.data('thousands-sep'), settings.data('decimal-point')) + after;
61            var img = jQuery(value).find('img').clone();
62            jQuery(value).html(result);
63            img.appendTo(value);
64        });
65    });
66    /* Currency Table - end */
67
68    /* Widget Currency Converter - start */
69    jQuery('.widget-exchange-rates-currency-converter').each(function(k, v) {
70        var el = jQuery(this).html('');
71        var rates = el.data('currencies');
72
73        jQuery('<b>').text(el.data('title')).appendTo(el);
74
75        var div = jQuery('<div>').attr('class', 'd-flex amount').appendTo(el);
76        var input = jQuery('<input>').attr('value', el.data('amount')).appendTo(div);
77        var swap = jQuery('<button>').attr('class', 'swap').html('<svg xmlns="http://www.w3.org/2000/svg">' +
78            '<path d="M8 13V5.825L5.425 8.4L4 7L9 2L14 7L12.575 8.4L10 5.825V13ZM15 22 10 17 11.425 15.6 14 18.175V11H16V18.175L18.575 15.6L20 17Z"/>' +
79            '</svg>').appendTo(div);
80
81        jQuery.each([el.data('from'), el.data('to')], function(_i, s) {
82            var sel = jQuery('<select>');
83            sel.appendTo(el);
84            jQuery.each(el.data('currencies'), function(code, data) {
85                var obj = {
86                    'value': code
87                }
88                if (code == s) {
89                    obj['selected'] = s;
90                }
91
92                sel.append(jQuery("<option>").attr(obj).text(el.data('code') ? code : code + ' - ' + data['name']));
93            });
94        });
95
96        jQuery(swap).on('click', function(e) {
97            var from = jQuery(el.find('select')[0]);
98            var to = jQuery(el.find('select')[1]);
99            var _from = from.find('option:selected').val()
100            var _to = to.find('option:selected').val()
101            from.val(_to).change();
102            to.val(_from).change();
103            input.trigger("input");
104        });
105
106        jQuery(input).on('input', function() {
107            var amount = jQuery(this).val();
108            var base_currency = el.data('base-currency');
109
110            var from = jQuery(el.find('select')[0]).find('option:selected').val();
111            var to = jQuery(el.find('select')[1]).find('option:selected').val();
112            var rate = rates[from]['rate'] * (1 / rates[to]['rate']);
113            var pre = (el.data('symbol')) ? rates[to]['symbol'] : '';
114            var after = '';
115
116            if (el.data('after')) {
117                after = pre;
118                pre = '';
119            }
120
121            result.html(
122                pre + formatNumber(
123                    rate,
124                    amount,
125                    el.data('decimals'),
126                    el.data('thousands-sep'),
127                    el.data('decimal-point')
128                ) + after
129            );
130        });
131
132        var result = jQuery('<div>').attr('class', 'result').text(0).appendTo(el);
133
134        jQuery.each(el.find('select'), function(h, o) {
135            jQuery(o).on('change', function(h, o) {
136                input.trigger("input");
137            })
138        });
139
140        input.trigger("input");
141    });
142    /* Widget Currency Converter - end */
143});

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.