PageSourceSearch

https://www.artthema.com/lib/g/2.0/scripts/artlogic_modules/galler…=57db970&g=86fa599520a8e2968eb1fac1f53a968f

js artthema.com collected 2026-10-02 13:39:00 UTC 16,480 bytes, 369 lines download raw bytes

1import effects from './effects.js';
2
3var mailing_list_form = {
4
5    _send_url: '/mailing-list/signup/',
6    _error_messages: '',
7
8    init: function() {
9        var self = this;
10        $('#mailing_list_form, .mailing_list_form')
11            .off()
12            .each(function() {
13                $('.field', this)
14                    .each(function() {
15                        $(this).val($(this).attr('data-default-value'));
16                    })
17                    .focus(function() {
18                        if ($(this).val() == $(this).attr('data-default-value')) {
19                            $(this).addClass('active').val('');
20                        }
21                    })
22                    .blur(function() {
23                        if ($(this).val() == '') {
24                            $(this).removeClass('active').val($(this).attr('data-default-value'));
25                        }
26                    })
27                ;
28                $('.submit_button', this).click(function() {
29                    $(this).closest('form').submit();
30                    return false;
31                });
32                $('input, textarea', this).keypress(function(event) {
33                    if (event.which == 13) {
34                        $(this).closest('form').submit();
35                        return false;
36                    }
37                });
38            })
39            .submit(function(e){
40                e.preventDefault();
41                $('.submit_button', this).closest('.button').addClass('loading');
42                if ($("#mailing_list_form, #artlogic_mailinglist_signup_form").hasClass("submit_disabled")) {
43                    return false;
44                } else {
45                    $("#mailing_list_form, #artlogic_mailinglist_signup_form").addClass("submit_disabled");
46                }
47                self._submit_form($(this).closest('form'));
48            })
49        ;
50    },
51
52    _form_data: function(instance) {
53
54        var data = {}
55        $('input, textarea, select', instance).each(function() {
56            if ($(this).val() != $(this).attr('data-default-value')) {
57                if($(this).attr('type')=='checkbox'){
58                    if ($(this).prop('checked')) {
59                        (data[$(this).attr('name')]) ? data[$(this).attr('name')] += ','+$(this).val() :  data[$(this).attr('name')] = $(this).val();
60                    }
61                } else {
62                    data[$(this).attr('name')] = $(this).val();
63                }
64            } else {
65                data[$(this).attr('name')] = '';
66            }
67        });
68        return data;
69    },
70
71    _clear_form_data: function(instance) {
72        //:not([type="hidden"] added new by DC - prevent hidden fields from being cleared as they ofter contain static campaign data etc
73        $('input:not([type="checkbox"], [type="hidden"], [type="submit"]), textarea', instance).each(function() {
74            $(this).val($(this).attr('data-default-value'));
75        });
76        $('input[type="checkbox"]', instance).each(function() {
77            if ($(this).attr('data-autoset') && typeof $(this).attr('data-autoset') != 'undefined') {
78                // Dont reset this as it was auto set as checked
79            } else {
80                $(this).prop('checked', false);
81            }
82        });
83        $('.error', instance).text('').hide();
84    },
85
86    _mandatory_fields: function(instance) {
87        var self = this,
88            flag = true;
89        $('input[type!="hidden"], textarea', instance).each(function(i) {
90            var currentInput = $('input[type!="hidden"], textarea', instance).eq(i);
91            if (currentInput.attr('required') && (currentInput.val() == '' || currentInput.val() == currentInput.attr('data-default-value'))) {
92                currentInput.addClass('required-field');
93                currentInput.attr('aria-invalid', "true");
94                currentInput.attr('aria-errormessage', "error");
95                flag = false;
96            } else {
97                currentInput.removeClass('required-field');
98                currentInput.removeAttr('aria-invalid');
99                currentInput.removeAttr('aria-errormessage');
100            }
101        });
102        if (!flag) {
103            var error_message = $(instance).attr('data-field-error') && typeof $(instance).attr('data-field-error') != 'undefined' ? $(instance).attr('data-field-error') : 'Please fill in all required fields.';
104            self._set_error(error_message);
105            return false;
106        }
107        if ($('input[name="terms_accepted"]', instance).length && !$('input[name="terms_accepted"]', instance).is(':checked')) {
108            var error_message = $(instance).attr('data-terms-error') && typeof $(instance).attr('data-terms-error') != 'undefined' ? $(instance).attr('data-terms-error') : 'Please agree to the terms and conditions.';
109            self._set_error(error_message);
110            return false;
111        }
112        return flag;
113    },
114
115    _email_is_valid: function(instance) {
116        var self = this,
117            flag = false,
118            email = self._form_data(instance)['email'],
119            $emailfield = $("input#email", instance).first();
120        
121        if (!self._form_data(instance)['email']) {
122            flag = false;
123        } else if (email.indexOf('@') > -1 && email.split('@')[1].indexOf('.') > -1 && email.indexOf(' ') == -1) {
124            flag = true;
125        }
126        
127        /* Set error message */
128        if (!flag) {
129            $emailfield.attr('aria-invalid', "true");
130            $emailfield.attr('aria-errormessage', "error");
131            self._set_error('Please enter a valid email address.');
132            return false
133        }
134        $emailfield.removeAttr('aria-invalid');
135        $emailfield.removeAttr('aria-errormessage');
136        return flag;
137
138
139    },
140
141    _emails_match: function(instance) {
142
143        // We are NOT matching the emails on this form
144        return true;
145
146        var self = window.galleries.mailing_list_form,
147            flag = false;
148
149        self._form_data(instance)['email2'] == self._form_data(instance)['email'] ? flag = true : flag = false;
150
151        /* Set error message */
152        if (!flag) {
153            self._set_error('Your email addresses do not match.');
154        }
155        return flag;
156    },
157
158    _email_not_exists: function(instance) {
159        
160        // Depricated function - not currently used
161        
162        var self = window.galleries.mailing_list_form,
163            flag = false;
164
165        $.ajax({
166            url: '/mailing-list/artlogicmailings/email_exists/',
167            type: "POST",
168            dataType: 'json',
169            data: {'email': self._form_data(instance)['email']},
170            success: function(data){
171                flag = data['exists'] ? flag = false : flag = true;
172            },
173            error: function(jqXHR,textStatus,errorThrown){
174                console.log(errorThrown);
175            },
176            async: false
177        });
178
179        /* Set error message */
180        if (!flag) {
181            self._set_error('Your email address already exists on our mailing list.');
182        }
183        return flag;
184    },
185
186    _run_captcha: function(instance) {
187        let is_visible = instance.hasClass('contact_form_captcha_visible')
188        
189        if (is_visible) {
190            window.galleries.mailing_list_form._send_form(instance);
191        } else {
192            window.recaptcha_success_callback_instance = instance;
193            window.recaptcha_success_callback = function(instance) {
194                window.galleries.mailing_list_form._send_form(instance);
195            };
196            try {
197                grecaptcha.execute();
198            } catch(error_message) {
199                this._set_error('<h2>Sorry</h2>An error with captcha occurred, please refresh this page and try again. If you continue to have problems please contact us for support.')
200            }
201        }
202    },
203
204    _set_error: function(error) {
205        this._error_messages = error;
206    },
207
208    _display_error: function(instance) {
209        $('.submit_button', instance).closest('.button').removeClass('loading');
210        
211        var self = this;
212        var error_messages_str = '' + self._error_messages + ''
213        var error_heading = $(instance).attr('data-field-error-heading') && typeof $(instance).attr('data-field-error-heading') != 'undefined' ? '<h2>' + $(instance).attr('data-field-error-heading') + '</h2>' : '';
214        if (error_heading && typeof error_heading != 'undefined') {
215            error_messages_str = '' + error_heading + '' + error_messages_str;
216        }
217        if ($(instance).hasClass('popup_error')) {
218            h.alert(error_messages_str);
219        } else {
220            var error_element = $('.error', instance);
221            if (!error_element.length) {
222                // Fall back to error container outside the mailing list form
223                error_element = $('.error');
224            }
225            
226            $(error_element).html(error_messages_str);
227            window.galleries.effects.pulsate($(error_element));
228            $(error_element).focus();
229        }
230        
231        //var error_heading = $(instance).attr('data-field-error-heading') && typeof $(instance).attr('data-field-error-heading') != 'undefined' ? '<h2>' + $(instance).attr('data-field-error-heading') + '</h2>' : '';
232        //h.alert(error_heading + error_messages_str);
233    },
234
235    _submit_form: function(instance) {
236        var self = this
237        if (self._mandatory_fields(instance) && self._email_is_valid(instance) && self._emails_match(instance)) {
238            // ensure that captcha is enabled on this exact form, not enabled globally
239            if ($(instance).closest('form').hasClass('contact_form_captcha_enabled') && typeof grecaptcha != 'undefined') {
240                // captcha callback runs the actual submission form
241                self._run_captcha(instance)
242            }else {
243                self._send_form(instance)
244            }
245        } else {
246            self._display_error(instance);
247            $("#mailing_list_form, #artlogic_mailinglist_signup_form").removeClass("submit_disabled");
248        }
249    },
250
251    _send_form: function(instance) {
252        var self = this;
253        
254        if (self._mandatory_fields(instance) && self._email_is_valid(instance) && self._emails_match(instance)) {
255            $.ajax({
256                url: self._send_url,
257                type: "POST",
258                dataType: 'json',
259                data: self._form_data(instance),
260                success: function(data) {
261                    
262                    $('.submit_button', instance).closest('.button').removeClass('loading');
263                    
264                    if (data.success) {
265                        self._after_submit(instance);
266
267                        if (window.gtag) {
268                            gtag('event', 'mailing_list_submit', {
269                                'success': true,
270                            });
271                        }
272                        
273                        if (window.ga) {
274                            // Track in Analytics
275                            ga('send', {
276                                'hitType': 'event',
277                                'eventCategory': 'Mailing list submit success',
278                                'eventAction': window.location.pathname,
279                                'eventLabel': $(document).attr('title')
280                            });
281                            // Track in second Analytics account
282                            ga('tracker2.send', {
283                                'hitType': 'event',
284                                'eventCategory': 'Mailing list submit success',
285                                'eventAction': window.location.pathname,
286                                'eventLabel': $(document).attr('title')
287                            });
288                            ga('artlogic_tracker.send', {
289                                'hitType': 'event',
290                                'eventCategory': 'Mailing list submit success',
291                                'eventAction': window.location.pathname,
292                                'eventLabel': $(document).attr('title')
293                            });
294                        }
295                        
296                        if (data.already_exists) {
297                            var thanks_message_heading = $(instance).attr('data-field-exists-heading') && typeof $(instance).attr('data-field-exists-heading') != 'undefined' ? $(instance).attr('data-field-exists-heading') : 'Thank you';
298                            var thanks_message_content = $(instance).attr('data-field-exists-content') && typeof $(instance).attr('data-field-exists-content') != 'undefined' ? $(instance).attr('data-field-exists-content') : 'You are already on our mailing list';
299                        } else {
300                            var thanks_message_heading = $(instance).attr('data-field-thanks-heading') && typeof $(instance).attr('data-field-thanks-heading') != 'undefined' ? $(instance).attr('data-field-thanks-heading') : 'Thank you';
301                            var thanks_message_content = $(instance).attr('data-field-thanks-content') && typeof $(instance).attr('data-field-thanks-content') != 'undefined' ? $(instance).attr('data-field-thanks-content') : 'You have been added to our mailing list';
302                        }
303                        h.alert('<h2>' + thanks_message_heading + '</h2> ' + thanks_message_content + '.');
304                        self._clear_form_data(instance);
305                        
306                        if ($('body').hasClass('mailing_list_popup_active')) {
307                            window.galleries.mailinglist_signup_form_popup.close();
308                        }
309                        
310                    } else {
311
312                        if (window.gtag) {
313                            gtag('event', 'mailing_list_submit', {
314                                'success': false,
315                            });
316                        }
317                        
318                        if (window.ga) {
319                            // Track in Analytics
320                            ga('send', {
321                                'hitType': 'event',
322                                'eventCategory': 'Mailing list submit error',
323                                'eventAction': window.location.pathname,
324                                'eventLabel': $(document).attr('title')
325                            });
326                            // Track in second Analytics account
327                            ga('tracker2.send', {
328                                'hitType': 'event',
329                                'eventCategory': 'Mailing list submit error',
330                                'eventAction': window.location.pathname,
331                                'eventLabel': $(document).attr('title')
332                            });
333                            ga('artlogic_tracker.send', {
334                                'hitType': 'event',
335                                'eventCategory': 'Mailing list submit error',
336                                'eventAction': window.location.pathname,
337                                'eventLabel': $(document).attr('title')
338                            });
339                        }
340                        
341                        self._set_error('There was a problem adding you to the mailing list, please check the form and try again.');
342                        if (data.error_message) {
343                            self._set_error(data.error_message);
344                        }
345                        self._display_error(instance);
346                    }
347                    $("#mailing_list_form, #artlogic_mailinglist_signup_form").removeClass("submit_disabled");
348                    if (typeof grecaptcha != 'undefined') {
349                        grecaptcha.reset();
350                    }
351                }
352            });
353        } else {
354            self._display_error(instance);
355            if (typeof grecaptcha != 'undefined') {
356                grecaptcha.reset();
357            }
358            $("#mailing_list_form, #artlogic_mailinglist_signup_form").removeClass("submit_disabled");
359        }
360    },
361    
362    _after_submit: function(instance) {
363        
364    }
365}
366
367window.galleries = window.galleries || {};
368window.galleries.mailing_list_form = mailing_list_form
369export default mailing_list_form

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.