PageSourceSearch

https://journalismcourses.org/wp-content/plugins/woo-donations/assets/js/wdgk-front-script.js?ver=4.3.1

js journalismcourses.org collected 2026-10-01 10:20:22 UTC 5,695 bytes, 141 lines download raw bytes

1var decimal_sep, thousand_sep;
2decimal_sep = wdgk_obj.options.decimal_sep;        // woo commerce decimal separator
3thousand_sep = wdgk_obj.options.thousand_sep;      // woo commerce thousand separator
4
5jQuery(document).ready(function ($) {
6    /** Not allow alphabats on keypress */
7    jQuery('.wdgk_donation').on('keydown', function (e) {
8        if (e.which == 13) {
9            jQuery(this).closest('.wdgk_donation_content').find(".wdgk_add_donation").trigger("click");
10        }
11
12        // No letters
13        if (e.which >= 65 && e.which <= 90) {
14            e.preventDefault();
15            return false;
16        }
17    });
18
19    jQuery('body').on("click", ".wdgk_add_donation", function () {
20
21        var note = "";
22        var price = "";
23        var decimal_price = "";
24        var price_elem = jQuery(this).closest('.wdgk_donation_content').find("input[name='donation-price']");
25        if (price_elem) {
26            updated_price = wdgk_updatedInputprice(price_elem.val());
27            price_elem.val(updated_price);
28            price = updated_price;
29            var replace_decimal_regex = new RegExp('\\' + decimal_sep, "g");
30            decimal_price = price.replace(replace_decimal_regex, '.');      // replace decimal sparator to dot
31        }
32
33        if (jQuery(this).closest('.wdgk_donation_content').find('.donation_note').val()) {
34            var note = jQuery(this).closest('.wdgk_donation_content').find('.donation_note').val();
35            var lines = [];
36            $.each(note.split(/\n/), function (i, line) {
37                if (line) {
38                    lines.push(jQuery.trim(line));
39                } else {
40                    lines.push("");
41                }
42            });
43            var note_text = JSON.stringify(lines);
44        }
45        var ajaxurl = jQuery('.wdgk_ajax_url').val();
46        var product_id = jQuery(this).attr('data-product-id');
47        var redirect_url = jQuery(this).attr('data-product-url');
48
49
50        if (decimal_price == "") {
51            jQuery(this).closest('.wdgk_donation_content').find(".wdgk_error_front").text("Please enter a value!!");
52            return false;
53        } else {
54            var pattern = new RegExp(/^[0-9.*]/);
55            if (!pattern.test(decimal_price) || decimal_price < 0.01) {
56                jQuery(this).closest('.wdgk_donation_content').find(".wdgk_error_front").text("Please enter valid value!!");
57                return false;
58            }
59        }
60
61        // update function for allow comma in donation price
62        if (isNumber(decimal_price)) {
63            jQuery(this).closest('.wdgk_donation_content').find(".wdgk_error_front").text("Please enter numeric value!!");
64            return false;
65        }
66
67        jQuery(this).closest('.wdgk_donation_content').find('.wdgk_loader').removeClass("wdgk_loader_img");
68        // set new cookie for display price with comma
69        setCookie('wdgk_product_display_price', price, 1);
70        // price = price.replace(/,/g, '');
71
72        setCookie('wdgk_product_price', decimal_price, 2);
73        setCookie('wdgk_donation_note', note_text, 3);
74
75        jQuery.ajax({
76            url: ajaxurl,
77            data: {
78                action: 'wdgk_donation_form',
79                product_id: product_id,
80                price: decimal_price,
81                note: note,
82                redirect_url: redirect_url
83            },
84            type: 'POST',
85            success: function (data) {
86                var redirect = jQuery.parseJSON(data);
87                if (redirect.error == "true") {
88                    jQuery(this).closest('.wdgk_donation_content').find(".wdgk_error_front").text("Please enter valid value!!");
89                    jQuery(this).closest('.wdgk_donation_content').find('.wdgk_loader').addClass("wdgk_loader_img");
90                    return false;
91                } else {
92                    document.location.href = redirect.url;
93                }
94            }
95        });
96    });
97
98
99
100});
101
102function setCookie(cname, cvalue, exdays) {
103    var d = new Date();
104    d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
105    var expires = "expires=" + d.toUTCString();
106    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
107}
108
109function getCookie(cname) {
110    var name = cname + "=";
111    var ca = document.cookie.split(";");
112    for (var i = 0; i < ca.length; i++) {
113        var c = ca[i];
114        while (c.charAt(0) == " ") {
115            c = c.substring(1);
116        }
117        if (c.indexOf(name) == 0) {
118            return c.substring(name.length, c.length);
119        }
120    }
121    return "";
122}
123// 
124function isNumber(price) {
125    var regex = /^[0-9.,\b]+$/;
126    if (!regex.test(price)) return false;
127}
128
129/* Returns filtered product price */
130function wdgk_updatedInputprice(input_val) {
131    let allow_number = new RegExp('[^0-9\\' + decimal_sep + ']', 'g');  // allow only number and decimal                "/[^\d.]/g"
132    let remove_ml_sep = new RegExp('\\' + decimal_sep + '+$');          // remove multiple decimal from last of string     "/\.+$/"
133    let remove_from_start_end = new RegExp('^\\' + decimal_sep + '+|\\' + decimal_sep + '+$', 'g');  // remove decimal from start and end of string  "/^,+|,+$/g"
134    var updated_price = input_val.replace(allow_number, "").replace(remove_ml_sep, "").replace(remove_from_start_end, "");
135
136    if (updated_price != '' && updated_price.includes(decimal_sep)) {
137        let new_val = updated_price.split(decimal_sep);
138        updated_price = new_val.shift() + decimal_sep + new_val.join('');
139    }
140    return updated_price;
141}

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.