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