PageSourceSearch

https://www.paris-prix.com/modules/faqs/views/js/faqs_form.js

js paris-prix.com collected 2026-09-29 23:03:08 UTC 13,713 bytes, 366 lines download raw bytes

1var close_notification_button_id = "#mpm_faqs_notification_close_button";
2var reset_trigger = "#mpm_faqs_notification_reset_button";
3
4var faqsForm = {
5    overlay: {
6        id: "#mpm_faqs_form_overlay"
7    },
8    container: {
9        id: "#mpm_faqs_form_container"
10    },
11    close_button: {
12        id: "#mpm_faqs_form_close_button"
13    },
14    submit_button: {
15        id: "#mpm_faqs_form_submit_button"
16    },
17    input_fields: {
18        name_customer: {
19            form_group_id: "#name_customer_form_group"
20        },
21        email_customer: {
22            form_group_id: "#email_customer_form_group"
23        },
24        category_question: {
25            form_group_id: "#category_question_form_group"
26        },
27        question_customer: {
28            form_group_id: "#question_customer_form_group"
29        },
30        captcha_res: {
31            form_group_id: "#captcha_res_form_group"
32        },
33        focused_input_id: "mpm-faqs-focused-input",
34        invalid_input_id: "mpm-faqs-validation-error",
35        invalid_input_message_block_id: "mpm-faqs-form-validation-message"
36    },
37    consent_checkbox: "#mpm_faqs_form_container #consent_checkbox",
38    recaptcha_block: "#mpm_faqs_form_container .g-recaptcha",
39    open: function() {
40        var basePath = $('input[name="basePath"]').val();
41        var overlay = this.overlay.id;
42        var container = this.container.id;
43        var id_shop = $('input[name="id_shop"]').val();
44        var id_lang = $('input[name="id_lang"]').val();
45        var id_product = $('input[name="id_product"]').val();
46        
47        $.ajax({
48            type: "POST",
49            url: basePath + 'index.php?rand=' + new Date().getTime(),
50            dataType: 'json',
51            async: true,
52            cache: false,
53            data: {
54                ajax: true,
55                token: "",
56                controller: 'AjaxForm',
57                fc: 'module',
58                module: 'faqs',
59                action: 'showForm',
60                id_shop: id_shop,
61                id_lang: id_lang,
62            },
63            success: function (json) {
64                if (json['form']) {
65                    $("body").prepend(json['form']);
66                    faqsForm.scroll(1);
67                    stylizeSelect();
68                    $(overlay).fadeIn(300);
69                    $(container).fadeIn(300);
70                }
71            },
72        });
73    },
74    close: function () {
75        var overlay = this.overlay.id;
76        var container = this.container.id;
77        $(overlay).fadeOut(300);
78        $(container).fadeOut(300);
79        
80        setTimeout(function(){
81            $(overlay).remove();
82            $(container).remove();
83        }, 700);
84    },
85    send: function () {
86        if ($(faqsForm.consent_checkbox).length && !$(faqsForm.consent_checkbox).is(":checked")) {
87            return false;
88        }
89        
90        var basePath = $('input[name="basePath"]').val();
91        var thisObject = $(this);
92        
93        if (thisObject.data("requestRunning")) {
94            return;
95        }
96        
97        thisObject.data("requestRunning", true);
98        
99        $.ajax({
100            type: "POST",
101            url: basePath + 'index.php?rand=' + new Date().getTime(),
102            dataType: 'json',
103            async: true,
104            cache: false,
105            data: {
106                ajax: true,
107                token: "",
108                controller: 'AjaxForm',
109                fc: 'module',
110                module: 'faqs',
111                action: 'send',
112                id_shop: $('input[name="id_shop"]').val(),
113                id_lang: $('input[name="id_lang"]').val(),
114                id_product: $('input[name="id_product"]').val(),
115                name: $('input[name="name_customer"]').val(),
116                email: $('input[name="email_customer"]').val(),
117                captcha: $('input[name="captcha_res"]').val(),
118                category: $('select[name="category_question"]').val(),
119                question: $('textarea[name="question_customer"]').val(),
120            },
121            success: function (json) {
122                if (json['error_field']) {
123                    var form_input_names = ["name_customer", "email_customer", "question_customer", "captcha_res"];
124                    var error_field = json["error_field"];
125                    var error_message = json["error_message"];
126                    
127                    if (form_input_names.indexOf(error_field) !== -1) {
128                        faqsForm.input_fields.validationError(error_field, error_message);
129                    }
130                } else if (json['form']) {
131                    $(faqsForm.container.id).replaceWith(json['form']);
132                    $(faqsForm.container.id).fadeIn(300);
133                    faqsForm.scroll(1);
134                }
135            },
136            complete: function() {
137                thisObject.data("requestRunning", false);
138            }
139        });
140    },
141    scroll: function (show) {
142        if ($(this.container.id).length > 0) {
143            $(this.container.id).css('margin-top', '0px');
144            
145            var top = $(document).scrollTop();
146            var height_window = $(window).outerHeight();
147            var height_form = $(this.container.id).outerHeight();
148            var margin = (height_window - height_form) / 2;
149            var form_offset = $(this.container.id).offset().top;
150            
151            if (show && margin < 11) {
152                margin = 11;
153            }
154            
155            if (margin > 10) {
156                var margin_top = margin + top;
157                $(this.container.id).css('top', margin_top + 'px');
158            }
159            else {
160                if (direction >= 0) {
161                    if (top < form_offset) {
162                        $(this.container.id).css({top: (top + 10)});
163                    }
164                }
165                if (direction < 0) {
166                    if (top > (height_form + 10 - height_window)) {
167                        $(this.container.id).css({top: (top - (height_form - he
167ight_window + 10))});
168                    }
169                }
170            }
171        }
172    },
173    reset: function () {
174        this.close();
175        this.open();
176    },
177    getConsentForProcessingData: function() {
178        var validated = true;
179        
180        if ($(faqsForm.consent_checkbox).length && !$(faqsForm.recaptcha_block).length) {
181            validated = $(faqsForm.consent_checkbox).is(":checked");
182        } else if ($(faqsForm.recaptcha_block).length && !$(faqsForm.consent_checkbox).length) {
183            validated = grecaptcha.getResponse() != 0;
184        } else if ($(faqsForm.recaptcha_block).length && $(faqsForm.consent_checkbox).length) {
185            validated = $(faqsForm.consent_checkbox).is(":checked") && grecaptcha.getResponse() != 0;
186        }
187        
188        if (validated) {
189            $(faqsForm.submit_button.id).attr("disabled", false);
190            $(faqsForm.submit_button.id).removeClass("disabled-submit-btn");
191        } else {
192            $(faqsForm.submit_button.id).attr("disabled", true);
193            $(faqsForm.submit_button.id).addClass("disabled-submit-btn");
194        }
195    }
196};
197
198faqsForm.input_fields.focus = function (input_field_name) {
199    $(faqsForm.container.id + " .form-group").removeClass(this.focused_input_id);
200    $(this[input_field_name].form_group_id).addClass(this.focused_input_id);
201};
202
203faqsForm.input_fields.blur = function (input_field_name, eventRelatedTargetId) {
204    if (eventRelatedTargetId == "mpm_faqs_form_submit_button") {
205        $(faqsForm.submit_button.id).trigger("click");
206    }
207    
208    $(this[input_field_name].form_group_id).removeClass(this.focused_input_id + " " +  this.invalid_input_id);
209};
210
211faqsForm.input_fields.validationError = function (error_field_name, error_message) {
212    $(faqsForm.container.id + " .form-group").removeClass(this.focused_input_id + " " + this.invalid_input_id);
213    
214    $(this[error_field_name].form_group_id + " .form-control").focus();
215    $(this[error_field_name].form_group_id).removeClass(this.focused_input_id).addClass(this.invalid_input_id);
216    $(this[error_field_name].form_group_id + " ." + this.invalid_input_message_block_id).text(error_message);
217};
218
219faqsForm.closeTriggers = [faqsForm.close_button.id, faqsForm.overlay.id, close_notification_button_id];
220
221
222$(document).ready(function() {
223    
224    $(document).on("focus", faqsForm.container.id + " .form-control", function(e) {
225        e.preventDefault();
226        faqsForm.input_fields.focus($(this).attr("name"));
227    });
228    
229    $(document).on("blur", faqsForm.container.id + " .form-control", function(e) {
230        e.preventDefault();
231        var eventRelatedTargetId = "";
232        
233        if (e.relatedTarget && e.relatedTarget.id) {
234            eventRelatedTargetId = e.relatedTarget.id;
235        }
236        
237        faqsForm.input_fields.blur($(this).attr("name"), eventRelatedTargetId);
238    });
239    
240    $(document).keydown(function(e) {
241        var key = e.keyCode;
242        
243        if (key === 13 && e.target.localName !== "textarea") {
244            $(faqsForm.submit_button.id).trigger("click");
245        } else if (key === 27) {
246            $(faqsForm.close_button.id).trigger("click");
247        }
248    });
249    
250    $(document).on('click', faqsForm.closeTriggers.join(", "), function() {
251        faqsForm.close()
252    });
253    
254    $(document).on('click', '.button-ask-question', function() {
255        faqsForm.open()
256    });
257    
258    $(document).on('click', faqsForm.submit_button.id, function(e) {
259        e.preventDefault();
260        faqsForm.send()
261    });
262    
263    $(document).on("click", reset_trigger, function() {
264        faqsForm.reset()
265    });
266    
267    $(document).scroll(function() {
268        faqsForm.scroll(0)
269    });
270    
271    
272    $(document).on("click", "#module-faqs-display", function() {
273        if($('#mpm_faqs_select_wrapper .content').find('.list').is(':visible')) {
274            $('#mpm_faqs_select_wrapper .content').find('.list').hide();
275            $('#mpm_faqs_select_wrapper .content').css({"border-radius" : "0 3px 3px 0"});
276            $("#category_question_form_group .input-group-addon").css({"border-radius":"3px 0 0 3px"});
277            
278            $(faqsForm.container.id + " .form-group").removeClass("mpm-faqs-focused-input");
279        }
280    });
281    
282    $(document).on('click','#mpm_faqs_select_wrapper .content', function(e) {
283        e.stopPropagation();
284        if( $(e.target).parent().hasClass('list') ){
285            return false;
286        }
287        
288        if($(this).find('.list').is(':visible')) {
289            $(this).find('.list').hide();
290            $(this).css({"border-radius" : "0 3px 3px 0"});
291            $("#category_question_form_group .input-group-addon").css({"border-radius":"3px 0 0 3px"});
292            
293            $(faqsForm.container.id + " .form-group").removeClass("mpm-faqs-focused-input");
294        } else {
295            $(this).find('.list').show();
296            $(this).css({"border-radius" : "0 3px 0 0"});
297            $("#category_question_form_group .input-group-addon").css({"border-radius":"3px 0 0 0"});
298            
299            $(faqsForm.container.id + " .form-group").removeClass("mpm-faqs-focused-input");
300            $("#category_question_form_group").addClass("mpm-faqs-focused-input");
301        }
302    });
303    
304    $(document).on("click","#mpm_faqs_select_wrapper .content .list span", function(e) {
305        var chosen_option_val = $(this).data("value");
306        
307        if (chosen_option_val != "0") {
308            $("#mpm_faqs_select_wrapper .content").css({"color": "#232323"});
309        } else {
310            $("#mpm_faqs_select_wrapper .content").css({"color": "#c1c2d1"});
311        }
312    });
313    
314    $(document).on('click','#mpm_faqs_select_wrapper .content .list span', function() {
315        var parent = $(this).parents('#mpm_faqs_select_wrapper');
316        
317        parent.find('select').val($(this).attr('data-value'));
318        parent.find('.selected').html($(this).text());
319        parent.find('select').change();
320        parent.find('.list').hide();
321        
322        $("#category_question_form_group .input-group-addon").css({"border-radius":"3px 0 0 3px"});
323    });
324    
325    $(document).on('change','#mpm_faqs_select_wrapper select', function() {
326        var selected = $(this).parent().find('.selected');
327        var currentText = $.trim(selected.text());
328        var selectedText = $.trim($(this).find('option[value='+$(this).val()+']').text());
329        
330        if( selectedText !== currentText ){
331            selected.html(selectedText);
332        }
333    });
334    
335    faqsForm.getConsentForProcessingData();
336    $(document).on("click change", faqsForm.consent_checkbox, function() {
337        faqsForm.getConsentForProcessingData();
338    });
339});
340
341function stylizeSelect() {
342    $.each($('#mpm_faqs_select_wrapper'), function (value) {
343        if( $(this).find('.content').length > 0 ){
344            return;
345        }
346        
347        $(this).css('max-width', ($(this).find('select').width() + 35) + 'px');
348        var current_value = $(this).find('select').val();
349        var span = $('<span class="content"><span class="list"></span></span>');
350        var selected = '';
351        $.each($(this).find('select option'), function (key, value) {
352            if( $(this).attr('value') == current_value){
353                selected = '<span class="selected">'+$(this).text()+'</span>';
354            }
355            span.find('.list').append('<span data-value="'+$(this).attr('value')+'">'+$(this).text()+'</span>');
356        });
357        
358        span.prepend(selected);
359        
360        $(this).append(span);
361    });
362}
363
364function checkIfRecaptchaIsVerified() {
365    faqsForm.getConsentForProcessingData();
366}

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.