PageSourceSearch

https://www.lightology.com/assets/js/core_form.js?v=20260421083637

js lightology.com collected 2026-09-24 19:45:41 UTC 14,583 bytes, 375 lines download raw bytes

1
2// Event handlers
3//  handle_download_catalog_requests_button_click(event)
4//  handle_standard_form_submit($this, offset, action)
5//  handle_submit_signup_footer_click(recaptcha_token)
6
7let form_height = 0;
8
9let standard_fieldsets = [
10    { // STANDARD_FIELDS_1
11        form_module_name: {},
12        form_module_term: {},
13        first_name: {label: 'First Name'},
14        last_name: {label: 'Last Name'},
15        email_address: {label: 'Email'},
16        company_name: {},
17        phone_number: {label: 'Phone'},
18        state_id: {label: 'State', select_dropdown: true},
19        user_comment: {textarea: true}
20    },
21    { // STANDARD_FIELDS_2
22        form_module_name: {},
23        form_module_term: {},
24        first_name: {label: 'First Name'},
25        last_name: {label: 'Last Name'},
26        email_address: {label: 'Email'},
27        company_name: {},
28        phone_number: {label: 'Phone'},
29        state_id: {label: 'State', select_dropdown: true}
30    },
31    { // STANDARD_FIELDS_3
32        form_module_name: {},
33        form_module_term: {},
34        first_name: {label: 'First Name'},
35        last_name: {label: 'Last Name'},
36        email_address: {label: 'Email'},
37        company_name: {},
38        street_address: {label: 'Street Address'},
39        city: {label: 'City'},
40        zip_code: {label: 'ZIP Code'},
41        state_name: {label: 'State or Province', select_dropdown: true}
42    },
43    { // STANDARD_FIELDS_4
44        form_module_name: {},
45        form_module_term: {},
46        first_name: {label: 'First Name'},
47        last_name: {label: 'Last Name'},
48        email_address: {label: 'Email'},
49        phone_number: {label: 'Phone'},
50        company_name: {},
51        state_id: {label: 'State', select_dropdown: true},
52        occupation: {label: 'Occupation', select_dropdown: true},
53        service_inquiry: {label: 'Service', select_dropdown: true},
54        user_comment: {textarea: true}
55    },
56    { // STANDARD_FIELDS_5
57        form_module_name: {},
58        form_module_term: {},
59        first_name: {label: 'First Name'},
60        last_name: {label: 'Last Name'},
61        email_address: {label: 'Email'},
62        phone_number: {label: 'Phone'},
63        state_id: {label: 'State', select_dropdown: true},
64        company_name: {},
65        room_qty: {label: 'Room Quantity'},
66        square_footage: {label: 'Square Footage'},
67        select_property: {label: 'Property', select_dropdown: true},
68        user_comment: {textarea: true}
69    },
70    { // STANDARD_FIELDS_6
71        form_module_name: {},
72        form_module_term: {},
73        first_name: {label: 'First Name'},
74        last_name: {label: 'Last Name'},
75        email_address: {label: 'Email'},
76        phone_number: {label: 'Phone'},
77        company_name: {},
78        state_id: {label: 'State', select_dropdown: true},
79        user_comment: {textarea: true},
80        smart_kit: { checkbox: true }
81    },
82    { // STANDARD_FIELDS_7
83        form_module_name: {},
84        form_module_term: {},
85        vendor_name: {},
86        first_name: {label: 'First Name'},
87        last_name: {label: 'Last Name'},
88        email_address: {label: 'Email'},
89        phone_number: {label: 'Phone'},
90        state_id: {label: 'State', select_dropdown: true},
91        contact_via: { checkbox: true },
92        user_comment: {textarea: true, label: 'Inquiry'}
93    },
94    {},
95    { // STANDARD_FIELDS_9
96        form_module_name: {},
97        form_module_term: {},
98        first_name: {label: 'First Name'},
99        last_name: {label: 'Last Name'},
100        email_address: {label: 'Email'},
101        company_name: {},
102        job_name: {},
103        phone_number: {label: 'Phone'},
104        street_address: {label: 'Street Address'},
105        city: {label: 'City'},
106        country_id: {},
107        zip_code: {label: 'ZIP Code'},
108        state_id: {label: 'State', select_dropdown: true},
109        user_comment: {textarea: true, label: 'list of products'}
110    },
111    { // STANDARD_FIELDS_10
112        form_module_name: {},
113        form_module_term: {},
114        first_name: {label: 'First Name'},
115        last_name: {label: 'Last Name'},
116        email_address: {label: 'Email'},
117        phone_number: {label: 'Phone'},
118        state_id: {label: 'State', select_dropdown: true},
119        user_comment: {textarea: true}
120    },
121];
122
123function handle_download_catalog_requests_button_click(event) {
124    event.preventDefault();
125    const download = $('input[name="download"]').val();
126    const min = parseInt($('#min').val());
127    const max = parseInt($('#max').val());
128    if (download >= min && download <= max) {
129        window.location = '/index.php?module=dispatcher&action=download_catalog_requests&download=' + download;
130        setTimeout(function() {
131            location.reload();
132        }, 10000)
133    }
134}
135
136function handle_standard_form_submit($this, offset, action)
137{
138    // Get the fields
139    if (offset < 0 || offset >= standard_fieldsets.length) {
140        return;
141    }
142    let fields = standard_fieldsets[offset];
143
144    // Clear any error messages
145    for (let field in fields) {
146        if (fields[field].hasOwnProperty('label')) {
147            $('#' + field + '_error').html('');
148        }
149    }
150    let $recaptcha_error = $('#recaptcha_error');
151    if ($recaptcha_error.length) {
152        $recaptcha_error.html('');
153    }
154
155    // Prepare the request URL
156    let module_name = get_module_name();
157    let url = '/index.php?module=' + module_name;
158    if (module_name === 'consultant_project_preview') {
159        url = '/index.php?module=catalog_order_form';
160    }
161    if (module_name === 'how_to') {
162        let sub_name = get_sub_name();
163        if (sub_name.length > 0) {
164            url += '&sub=' + sub_name;
165        }
166    }
167    if (module_name === 'vend') {
168        url = '/index.php?module=dispatcher';
169    }
170
171    // Submit the form data including recaptcha if it is present
172    let data = (action.length > 0) ? 'action=' + action : 'submit=true';
173    for (let field in fields) {
174        if (fields[field].hasOwnProperty('multiselect_checkbox')) {
175            let values = [];
176            $.each($('input[name="' + field + '"]:checked'), function () {
177                values.push($(this).val());
178            });
179            data += '&' + field + '=' + values.join('|');
180        } else if (fields[field].hasOwnProperty('checkbox')) {
181            data += '&' + field + '=' + $('input[name="' + field + '"]:checked').val();
182        } else if (fields[field].hasOwnProperty('select_dropdown')) {
183            let dropdown_val = $('select[name="' + field + '"] option:selected').val();
184            data += '&' + field + '=' + dropdown_val.replace('&', 'and');
185        } else if (fields[field].hasOwnProperty('textarea')) {
186            data += '&' + field + '=' + encodeURIComponent($('textarea[name="' + field + '"]').val());
187        } else {
188            data += '&' + field + '=' + encodeURIComponent($('input[name="' + field + '"]').val());
189        }
190    }
191    if ($recaptcha_error.length) {
192        let form_data = $this.closest('form').serializeArray();
193        data += '&g-recaptcha-response=' + form_data[form_data.length - 1].value;
194    }
195    $.ajax({
196        type: 'POST',
197        url: url,
198        data: data,
199        dataType: 'json',
200        success: function(data) {
201            if (data.hasOwnProperty('submit_errors')) {
202                let error_count = data.submit_errors.length;
203                if (error_count === 0) {
204                    // Hide recaptcha
205                    $('#recaptcha-placeholder').hide();
206
207                    // Hide the Submit button
208                    $('#submit_standard_form_1').hide();
209
210                    // Show the success message
211                    let $success = $('#success');
212                    if ($success.length > 0) {
213                        $success.addClass('isOpen');
214                    }
215                    let $postresult = $('#postresult');
216                    if ($postresult.length > 0) {
217                        $postresult[0].scrollIntoView();
218                        $postresult.show().text('Thank you! We received your request and we\'ll get back to you soon.');
219                    }
220                }
221                else {
222                    // Display the errors
223                    let height_adjustment = 0;
224                    let error_line_height = 24;
225                    for (let idx = 0; idx < error_count; idx++) {
226                        let error = data.submit_errors[idx];
227                        let message = 'Please solve the <span>captcha</span>';
228                        if (error !== 'recaptcha') {
229                            if (fields[error].hasOwnProperty('select_dropdown')) {
230                                message = 'Please select a valid <span>' + fields[error].label + '</span>';
231                            } else {
232                                message = 'Please enter a valid <span>' + fields[error].label + '</span>';
233                            }
234                        }
235                        $('#' + error + '_error').html(message);
236                        height_adjustment += error_line_height;
237                    }
238
239                    // Adjust the form height
240                    $('#static-display-form').css({'height': (form_height + height_adjustment) + 'px'});
241                    $('#form-single').css({'height': (form_height + height_adjustment) + 'px'});
242                }
243            }
244        },
245        error: function() { // jqXhr, textStatus, errorMessage
246            // This can be caused by an error on the PHP side
247            // alert('Error: ' + errorMessage);
248            // alert(jqXhr.responseText);
249        }
250    });
251}
252
253function handle_submit_signup_footer_click(recaptcha_token)
254{
255    const $signup_message = $('#email-signup-message');
256    $signup_message.html('');
257
258    const email = $('#email_address_footer').val();
259    const url = '/index.php?module=dispatcher';
260    const data = 'action=subscribe_newsletter&email=' + email + '&g-recaptcha-response=' + recaptcha_token;
261
262    $.ajax({
263        type: 'POST',
264        url: url,
265        data: data,
266        dataType: 'json',
267        success: function(data) {
268            if (data?.code === 0) {
269                $signup_message.html(data.message);
270            } else if (data?.code === 1) {
271                window.location.href = '/index.php?module=email_signup_form_confirmation';
272            }
273        },
274        error: function(jqXhr, textStatus, errorMessage) {
275            // alert('Error: ' + errorMessage);
276            // alert(jqXhr.responseText);
277        }
278    });
279}
280
281$(document).ready(function() {
282    // Set the initial form height based on the #form-single element data settings
283    let window_width = $(window).width();
284    let $form_single = $('#form-single');
285    let $static_display_form = $('#static-display-form');
286    form_height = $form_single.data('deskHeight');
287    if (window_width <= 1366) { // See assets/scss/global/_var.scss $desktop-1366-breakpoint
288        form_height = $form_single.data('mobileHeight');
289    }
290    $static_display_form.height(form_height);
291    $form_single.height(form_height);
292
293    $('body')
294        .on('click', '#submit-signup-footer', function () {
295            execute_recaptcha('subscribe_newsletter', 'invisible_footer')
296                .then((token) => handle_submit_signup_footer_click(token));
297        })
298
299        .on('click', '#submit_standard_form_1', function () {
300            handle_standard_form_submit($(this), 0, ''); // STANDARD_FIELDS_1
301        })
302
303        .on('click', '#submit_standard_form_2', function () {
304            handle_standard_form_submit($(this), 1, ''); // STANDARD_FIELDS_2
305        })
306
307        .on('click', '#submit_standard_form_3', function () {
308            handle_standard_form_submit($(this), 2, ''); // STANDARD_FIELDS_3
309        })
310
311        .on('click', '#submit_standard_form_4', function () {
312            handle_standard_form_submit($(this), 3, ''); // STANDARD_FIELDS_4
313        })
314
315        .on('click', '#submit_standard_form_5', function () {
316            handle_standard_form_submit($(this), 4, ''); // STANDARD_FIELDS_5
317        })
318
319        .on('click', '#submit_standard_form_6', function () {
320            handle_standard_form_submit($(this), 5, ''); // STANDARD_FIELDS_6
321        })
322
323        .on('click', '#submit_standard_form_7', function () {
324            handle_standard_form_submit($(this), 6, 'process_vendor_inquiry'); // STANDARD_FIELDS_7
325        })
326
327        .on('click', '#submit_standard_form_9', function () {
328            handle_standard_form_submit($(this), 8, ''); // STANDARD_FIELDS_9
329        })
330
331        .on('click', '#submit_standard_form_10', function () {
332            handle_standard_form_submit($(this), 9, ''); // STANDARD_FIELDS_10
333        })
334
335        // Keep tabbing within the form
336        .on('keydown', '#first_form_field', function(event) {
337            if (event.code === 'Tab' && event.shiftKey) {
338                let $submit_standard_form_1 = $('#submit_standard_form_1');
339                if ($submit_standard_form_1.length > 0) {
340                    $submit_standard_form_1.focus();
341                }
342                return false;
343            }
344        })
345        .on('keydown', '#submit_standard_form_1', function(event) {
346            if (event.code === 'Tab' && ! event.shiftKey) {
347                $('#first_form_field').focus();
348                return false;
349            }
350        })
351
352        // Prevent tabbing from showing the success div
353        .on('keydown', '#last_tab_before_form', function(event) {
354            if (event.code === 'Tab' && ! event.shiftKey) {
355                $('#first_form_field').focus();
356                return false;
357            }
358        })
359
360        // Event handlers for Catalog Requests admin tool
361        .on('click', '#download_catalog_requests_button', handle_download_catalog_requests_button_click)
362
363        .on('keydown', '#download', function (event) {
364            if (event.keyCode === 13) {
365                $('#download').blur();
366                handle_download_catalog_requests_button_click(event);
367            }
368        })
369
370        .on('keypress', '#download', function (event) {
371            if ( ! /^[0-9]$/.test(event.key)) {
372                event.preventDefault();
373            }
374        })
375});

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.