PageSourceSearch

https://www.digitalegeletterdheid.nl/wp-content/plugins/mailplus-forms/public/js/form_additions.js

js digitalegeletterdheid.nl collected 2026-10-10 01:52:42 UTC 4,880 bytes, 126 lines download raw bytes

1(function ($) {
2    $(document).ready(function () {
3        let mpForms = $('form.mpForm')
4
5        if (mpForms.length) {
6            $.each(mpForms, function () {
7                refreshFormUniqueProperties($(this));
8            })
9        }
10    });
11
12    function refreshFormUniqueProperties(form) {
13        if (!$(form).length) {
14            return;
15        }
16
17        bindFormInitializationGuard(form);
18
19        let uniqId = $(form).data('uniq-id'),
20            abInfo = $(form).find('input[name="abInfo"]');
21
22        // Detecting the security question within the form, this is needed to place the new security question
23        // within the form.
24        let fieldDescriptionLabels = $(form).find('label.descriptionLabel'),
25            secretFieldGroupId = null,
26            isHTMLForm = form.find('ul > li.mpQuestionTable').length;
27
28        $.each(fieldDescriptionLabels, function () {
29
30            // Can match the following string: 1 + 2 =
31            if (/^(\d+\s[+]\s\d+)\s[=]/g.test($(this).text())) {
32                secretFieldGroupId = isHTMLForm ? $(this).closest('li').prop('id') :
33                    $(this).closest('table.mpQuestionTable').prop('id');
34
35                // Since we've found our match, break out of the each.
36                return false;
37            }
38        });
39
40        if (!uniqId) {
41            return;
42        }
43
44        let ajaxData = {
45            action: 'spotler_get_form',
46            enc_id: $('input[name="_form_enc_id_' + uniqId + '"]').val(),
47            form_id: $('input[name="_form_id_' + uniqId + '"]').val(),
48            account_id: $('input[name="_form_account_id_' + uniqId + '"]').val(),
49            nonce: $('input[name="_form_nonce_' + uniqId + '"]').val()
50        }
51
52        $.ajax(
53            {
54                url: spotlerFormAdditions.ajaxUrl,
55                data: ajaxData,
56                type: 'POST',
57                success: function (response) {
58                    if (typeof response.data == 'undefined' || !response.data.length)
59                        return;
60
61                    let newForm = $(response.data),
62                        newAbInfo = newForm.find('input[name="abInfo"]');
63
64                    if (newAbInfo.length) {
65                        abInfo.val(newAbInfo.val());
66                    }
67
68                    if (!secretFieldGroupId) {
69                        setFormInitialized(form);
70                        return;
71                    }
72
73                    let secretFieldGroup = isHTMLForm ? form.find('li#' + secretFieldGroupId) :
74                            form.find('table#' + secretFieldGroupId),
75                        newSecretFieldGroup = isHTMLForm ? newForm.find('li#' + secretFieldGroupId) :
76                            newForm.find('table#' + secretFieldGroupId);
77
78                    if (!secretFieldGroup.length || !newSecretFieldGroup.length)
79                        return;
80
81                    let newSecretFieldGroupLabel = newSecretFieldGroup.find('label.descriptionLabel').text()
82
83                    if (newSecretFieldGroupLabel === '')
84                        return;
85
86                    let secretFieldInput = isHTMLForm ? secretFieldGroup.find('div.mpFormField input') :
87                        secretFieldGroup.find('td.mpFormField input');
88
89                    setTimeout(function () {
90                        // Unfortunately I had to use eval here since the value of the new input field is not set
91                        // when received from the API. This is probably filled by the Javascript that's loaded initially when
92                        // the page loads.
93                        if (!secretFieldInput.length)
94                            return;
95
96                        secretFieldGroup.find('label.descriptionLabel').text(newSecretFieldGroupLabel);
97
98                        if (isHTMLForm) {
99                            secretFieldGroup.find('div.mpFormField input').val(eval(newSecretFieldGroupLabel.replace('=', '')));
100                        } else {
101                            secretFieldGroup.find('td.mpFormField input').val(eval(newSecretFieldGroupLabel.replace('=', '')));
102                        }
103
104                        setFormInitialized(form);
105                    }, 100);
106                }
107            }
108        )
109    }
110
111    function bindFormInitializationGuard(form) {
112        form.on('submit.spotlerInitialization', function (event) {
113            if ($(this).attr('data-spotler-initialized') === 'true') {
114                return true;
115            }
116
117            event.preventDefault();
118            return false;
119        });
120    }
121
122    function setFormInitialized(form) {
123        form.attr('data-spotler-initialized', 'true');
124        form.off('submit.spotlerInitialization');
125    }
126})(jQuery);

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.