1(function () { 2 var PHONE_PREFIX = "+7 ("; 3 var PHONE_PREFIX_LEN = PHONE_PREFIX.length; 4 5 function isPhoneMaskTarget(input) { 6 if (!input || input.tagName !== "INPUT") return false; 7 return ( 8 input.type === "tel" || 9 input.getAttribute("type") === "phone" || 10 input.name === "phone" 11 ); 12 } 13 14 function normalizeDigits(value) { 15 var digits = (value || "").replace(/\D/g, ""); 16 if (digits.charAt(0) === "7" || digits.charAt(0) === "8") { 17 digits = digits.slice(1); 18 } 19 return digits.slice(0, 10); 20 } 21 22 function formatPhoneValue(digits) { 23 var result = PHONE_PREFIX + digits.slice(0, 3); 24 if (digits.length >= 3) result += ") "; 25 if (digits.length > 3) result += digits.slice(3, 6); 26 if (digits.length >= 6) result += "-"; 27 if (digits.length > 6) result += digits.slice(6, 8); 28 if (digits.length >= 8) result += "-"; 29 if (digits.length > 8) result += digits.slice(8, 10); 30 return result; 31 } 32 33 function removeDigitAt(value, index) { 34 if (index < 0) return value; 35 return value.slice(0, index) + value.slice(index + 1); 36 } 37 38 function placeCaretAfterPrefix(input) { 39 if (!input) return; 40 setTimeout(function () { 41 if ((input.selectionStart || 0) < PHONE_PREFIX_LEN) { 42 input.setSelectionRange(PHONE_PREFIX_LEN, PHONE_PREFIX_LEN); 43 } 44 }, 0); 45 } 46 47 function ensurePhoneInput(input) { 48 if (!input || input.dataset.phoneMaskApplied === "1") return; 49 input.dataset.phoneMaskApplied = "1"; 50 input.setAttribute("maxlength", "18"); 51 } 52 53 function syncOrderPhoneButton(input) { 54 if (!input || input.id !== "order-phone") return; 55 var button = document.getElementById("btn-order-header"); 56 if (!button) return; 57 button.disabled = normalizeDigits(input.value).length !== 10; 58 } 59 60 document.addEventListener("focusin", function (e) { 61 if (!isPhoneMaskTarget(e.target)) return; 62 var input = e.target; 63 ensurePhoneInput(input); 64 65 var digits = normalizeDigits(input.value); 66 input.value = formatPhoneValue(digits); 67 syncOrderPhoneButton(input); 68 placeCaretAfterPrefix(input); 69 }); 70 71 document.addEventListener("click", function (e) { 72 if (!isPhoneMaskTarget(e.target)) return; 73 placeCaretAfterPrefix(e.target); 74 }); 75 76 document.addEventListener("keydown", function (e) { 77 if (!isPhoneMaskTarget(e.target)) return; 78 79 var input = e.target; 80 var caretStart = input.selectionStart || 0; 81 var caretEnd = input.selectionEnd || 0; 82 var hasSelection = caretStart !== caretEnd; 83 var isDeleteKey = e.key === "Backspace" || e.key === "Delete"; 84 85 if (!isDeleteKey) return; 86 87 if (hasSelection) { 88 e.preventDefault(); 89 90 var selectedRangeStartsBeforePrefix = caretStart < PHONE_PREFIX_LEN; 91 var valueAfterDelete = input.value.slice(0, caretStart) + input.value.slice(caretEnd); 92 var digitsAfterDelete = normalizeDigits(valueAfterDelete); 93 94 input.value = formatPhoneValue(digitsAfterDelete); 95 syncOrderPhoneButton(input); 96 97 if (selectedRangeStartsBeforePrefix) { 98 input.setSelectionRange(PHONE_PREFIX_LEN, PHONE_PREFIX_LEN); 99 } 100 placeCaretAfterPrefix(input); 101 return; 102 } 103 104 if (e.key === "Backspace") { 105 if (caretStart <= PHONE_PREFIX_LEN) { 106 e.preventDefault(); 107 input.value = formatPhoneValue(normalizeDigits(input.value)); 108 syncOrderPhoneButton(input); 109 input.setSelectionRange(PHONE_PREFIX_LEN, PHONE_PREFIX_LEN); 110 return; 111 } 112 113 var prevChar = input.value.charAt(caretStart - 1); 114 if (/\d/.test(prevChar)) return; 115 116 var digits = normalizeDigits(input.value); 117 var digitsBeforeCaret = input.value.slice(0, caretStart).replace(/\D/g, "").length; 118 var typedDigitsBeforeCaret = Math.max(0, digitsBeforeCaret - 1); 119 var deleteIndex = typedDigitsBeforeCaret - 1; 120 121 if (deleteIndex < 0) { 122 e.preventDefault(); 123 input.value = PHONE_PREFIX; 124 syncOrderPhoneButton(input); 125 input.setSelectionRange(PHONE_PREFIX_LEN, PHONE_PREFIX_LEN); 126 return; 127 } 128 129 e.preventDefault(); 130 var newDigits = removeDigitAt(digits, deleteIndex); 131 input.value = formatPhoneValue(newDigits); 132 syncOrderPhoneButton(input); 133 placeCaretAfterPrefix(input); 134 return; 135 } 136 137 if (e.key === "Delete" && caretStart < PHONE_PREFIX_LEN) { 138 e.preventDefault(); 139 input.setSelectionRange(PHONE_PREFIX_LEN, PHONE_PREFIX_LEN); 140 } 141 }); 142 143 document.addEventListener("input", function (e) { 144 if (!isPhoneMaskTarget(e.target)) return; 145 var input = e.target; 146 ensurePhoneInput(input); 147 var digits = normalizeDigits(input.value); 148 input.value = formatPhoneValue(digits); 149 if (digits.length === 0 || digits.length === 10) { 150 input.classList.remove("phone-invalid"); 151 } else { 152 input.classList.add("phone-invalid"); 153 } 154 syncOrderPhoneButton(input); 155 placeCaretAfterPrefix(input); 156 }); 157 158 document.addEventListener( 159 "blur", 160 function (e) { 161 if (!isPhoneMaskTarget(e.target)) return; 162 var input = e.target; 163 var digits = normalizeDigits(input.value); 164 if (!digits.length) { 165 input.value = ""; 166 input.classList.remove("phone-invalid"); 167 syncOrderPhoneButton(input); 168 return; 169 } 170 if (digits.length < 10) { 171 input.classList.add("phone-invalid"); 172 } else { 173 input.classList.remove("phone-invalid"); 174 } 175 input.value = formatPhoneValue(digits); 176 syncOrderPhoneButton(input); 177 }, 178 true 179 ); 180 181 function initPhoneFields() { 182 document.querySelectorAll('input[type="tel"], input[type="phone"], input[name="phone"]').forEach(function (input) { 183 ensurePhoneInput(input); 184 if (input.value) { 185 input.value = formatPhoneValue(normalizeDigits(input.value)); 186 } 187 syncOrderPhoneButton(input); 188 }); 189 } 190 191 if (document.readyState === "loading") { 192 document.addEventListener("DOMContentLoaded", initPhoneFields); 193 } else { 194 initPhoneFields(); 195 } 196})(); 197 198function getPhoneDigits(phone) { 199 return String(phone || "").replace(/\D/g, ""); 200} 201 202function isCompletePhoneNumber(phone) { 203 const digits = getPhoneDigits(phone); 204 if (digits.length !== 11) { 205 return false;
206 } 207 208 return digits.startsWith("7") || digits.startsWith("8"); 209} 210 211function initPhoneInput() {} 212 213// ÐниÑиализаÑÐ¸Ñ Ð´Ð»Ñ ÑоÑÐ¼Ñ #main-screen-form 214if (document.querySelector("#main-screen-form") != undefined) { 215 document 216 .querySelector("#main-screen-form") 217 .addEventListener("submit", function (event) { 218 if (!this.checkValidity()) { 219 event.preventDefault(); // ÐÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ Ð¾ÑпÑÐ°Ð²ÐºÑ ÑоÑмÑ, еÑли она не пÑоÑла валидаÑÐ¸Ñ 220 alert("ÐожалÑйÑÑа, заполниÑе вÑе обÑзаÑелÑнÑе полÑ."); 221 } 222 }); 223 224} 225 226const NH_STREET_MANUAL_VALUE = "__manual__"; 227const NH_STREET_MANUAL_LABEL = "Ðе наÑли ÑлиÑÑ? УкажиÑе адÑÐµÑ Ð²ÑÑÑнÑÑ"; 228 229function getNhSelect2Defaults(placeholder) { 230 return { 231 placeholder: placeholder || "", 232 allowClear: false, 233 width: "100%", 234 minimumResultsForSearch: 0, 235 dropdownCssClass: "nh-select-dropdown", 236 dropdownParent: jQuery(document.body), 237 language: { 238 noResults: function () { 239 return "ÐиÑего не найдено"; 240 }, 241 searching: function () { 242 return "ÐоиÑкâ¦"; 243 }, 244 }, 245 }; 246} 247 248function nhStreetSelect2Matcher(params, data) { 249 if (data.id === NH_STREET_MANUAL_VALUE) { 250 return data; 251 } 252 253 if (jQuery.trim(params.term) === "") { 254 return data; 255 } 256 257 if (typeof data.text === "undefined") { 258 return null; 259 } 260 261 if (data.text.toUpperCase().indexOf(params.term.toUpperCase()) > -1) { 262 return data; 263 } 264 265 return null; 266} 267 268function getNhStreetSelect2Config() { 269 return Object.assign({}, getNhSelect2Defaults("УлиÑа"), { 270 minimumResultsForSearch: 0, 271 dropdownCssClass: "nh-select-dropdown nh-select-dropdown--street", 272 matcher: nhStreetSelect2Matcher, 273 language: { 274 noResults: function () { 275 return "ÐдÑÐµÑ Ð½Ðµ найден. ÐÑбеÑиÑе пÑÐ½ÐºÑ Â«" + NH_STREET_MANUAL_LABEL + "» в ÑпиÑке."; 276 }, 277 searching: function () { 278 return "ÐоиÑкâ¦"; 279 }, 280 }, 281 templateResult: function (data) { 282 if (!data.id) { 283 return data.text; 284 } 285 if (data.id === NH_STREET_MANUAL_VALUE) { 286 return jQuery( 287 '<span class="nh-connect__street-manual-label">' + data.text + "</span>" 288 ); 289 } 290 return data.text; 291 }, 292 }); 293} 294 295function getNhStreetSelect2Container() { 296 const $street = jQuery("#nh-check-street"); 297 if (!$street.length) { 298 return jQuery(); 299 } 300 return $street.next(".select2-container"); 301} 302 303function hideNhConnectManualAddress() { 304 const field = document.getElementById("nh-check-street-field"); 305 const input = document.getElementById("nh-check-address-manual"); 306 const hint = document.getElementById("nh-check-address-hint"); 307 const $street = jQuery("#nh-check-street"); 308 const $container = getNhStreetSelect2Container(); 309 310 if (field) { 311 field.classList.remove("is-manual"); 312 } 313 if (hint) { 314 hint.setAttribute("hidden", ""); 315 } 316 if (input) { 317 input.value = ""; 318 input.setAttribute("hidden", ""); 319 input.removeAttribute("required"); 320 } 321 if ($street.length) { 322 $street.show(); 323 } 324 if ($container.length) { 325 $container.show(); 326 } 327} 328 329function toggleNhConnectManualAddress(isManual) { 330 const field = document.getElementById("nh-check-street-field"); 331 const input = document.getElementById("nh-check-address-manual"); 332 const hint = document.getElementById("nh-check-address-hint"); 333 const $street = jQuery("#nh-check-street"); 334 const $container = getNhStreetSelect2Container(); 335 336 if (!field || !input) { 337 return; 338 } 339 340 if (isManual) { 341 field.classList.add("is-manual"); 342 if (hint) { 343 hint.removeAttribute("hidden"); 344 } 345 if ($street.data("select2")) { 346 $street.select2("close"); 347 } 348 if ($container.length) { 349 $container.hide(); 350 } 351 $street.hide(); 352 if (!input.value && window.__nhStreetSearchTerm) { 353 input.value = window.__nhStreetSearchTerm; 354 } 355 window.__nhStreetSearchTerm = ""; 356 input.removeAttribute("hidden"); 357 window.setTimeout(function () { 358 input.focus(); 359 if (input.value) { 360 input.setSelectionRange(input.value.length, input.value.length); 361 } 362 }, 0); 363 } else { 364 hideNhConnectManualAddress(); 365 } 366} 367 368function exitNhConnectManualStreet() { 369 const $street = jQuery("#nh-check-street"); 370 hideNhConnectManualAddress(); 371 if ($street.length) { 372 $street.val("").trigger("change"); 373 window.setTimeout(function () { 374 $street.select2("open"); 375 }, 0); 376 } 377} 378 379function isNhConnectManualStreet(streetId) {
380 return streetId === NH_STREET_MANUAL_VALUE; 381} 382 383function initNhPagePhoneInputs(root) { 384 const scope = root && root.querySelectorAll ? root : document; 385 scope.querySelectorAll('input[type="tel"]').forEach(function (phoneInput) { 386 initPhoneInput(phoneInput); 387 }); 388 389 const heroPhoneInput = document.getElementById("input__form-phone"); 390 if (heroPhoneInput) { 391 initPhoneInput(heroPhoneInput); 392 } 393} 394 395function initNhDealerSelect() { 396 if (typeof jQuery === "undefined" || !jQuery.fn.select2) { 397 return; 398 } 399 400 const $city = jQuery("#nh-dealer-city"); 401 if (!$city.length || $city.hasClass("select2-hidden-accessible")) { 402 return; 403 } 404 405 const placeholder = 406 $city.find('option[value=""]').first().text() || "ÐÐ°Ñ Ð³Ð¾Ñод"; 407 408 $city.select2(getNhSelect2Defaults(placeholder)); 409} 410 411function syncNhHeaderOffset() { 412 if (!document.body.classList.contains("nh-page")) { 413 return; 414 } 415 416 var header = document.querySelector("header.header--new-home"); 417 if (!header) { 418 return; 419 } 420 421 var bar = header.querySelector(".nh-header") || header; 422 var height = Math.ceil(bar.getBoundingClientRect().height); 423 if (height <= 0) { 424 return; 425 } 426 427 var value = height + "px"; 428 document.documentElement.style.setProperty("--nh-header-offset", value); 429 document.documentElement.style.setProperty("--nh-header-h", value); 430 document.body.style.setProperty("--nh-header-offset", value); 431 document.body.style.setProperty("--nh-header-h", value); 432} 433 434function initNhHeaderOffsetSync() { 435 if (!document.body.classList.contains("nh-page")) { 436 return; 437 } 438 439 if (document.documentElement.dataset.nhHeaderOffsetReady === "1") { 440 syncNhHeaderOffset(); 441 return; 442 } 443 444 document.documentElement.dataset.nhHeaderOffsetReady = "1"; 445 syncNhHeaderOffset(); 446 447 window.addEventListener("resize", syncNhHeaderOffset, { passive: true }); 448 window.addEventListener("orientationchange", function () { 449 window.setTimeout(syncNhHeaderOffset, 100); 450 }); 451 window.addEventListener("load", syncNhHeaderOffset); 452 453 if (typeof ResizeObserver === "function") { 454 var header = document.querySelector("header.header--new-home"); 455 if (header) { 456 var observer = new ResizeObserver(function () { 457 syncNhHeaderOffset(); 458 }); 459 observer.observe(header); 460 } 461 } 462} 463 464function initNhMobileOverflowFix() { 465 if (!document.body.classList.contains("nh-page")) { 466 return; 467 } 468 469 var resetHorizontalScroll = function () { 470 if (window.scrollX !== 0) { 471 window.scrollTo(0, window.scrollY); 472 } 473 474 if (document.documentElement.scrollLeft !== 0) { 475 document.documentElement.scrollLeft = 0; 476 } 477 478 if (document.body.scrollLeft !== 0) { 479 document.body.scrollLeft = 0; 480 } 481 }; 482 483 resetHorizontalScroll(); 484 window.addEventListener("scroll", resetHorizontalScroll, { passive: true }); 485 window.addEventListener("resize", resetHorizontalScroll); 486 window.addEventListener("orientationchange", resetHorizontalScroll); 487} 488 489function initNhPageFaqAccordion() { 490 if (!document.body.classList.contains("nh-page")) { 491 return; 492 } 493 494 function setFaqItemState(item, isOpen) { 495 var button = item.querySelector(".nh-faq__question"); 496 item.classList.toggle("is-open", isOpen); 497 if (button) { 498 button.setAttribute("aria-expanded", isOpen ? "true" : "false"); 499 } 500 } 501 502 document.querySelectorAll(".nh-faq__question").forEach(function (button) { 503 if (button.dataset.nhFaqBound === "1") { 504 return; 505 } 506 507 button.dataset.nhFaqBound = "1"; 508 button.addEventListener("click", function () { 509 var item = button.closest(".nh-faq__item"); 510 if (!item) { 511 return; 512 } 513 514 var isOpen = item.classList.contains("is-open"); 515 document.querySelectorAll(".nh-faq__item.is-open").forEach(function (openItem) { 516 setFaqItemState(openItem, false); 517 }); 518 519 if (!isOpen) { 520 setFaqItemState(item, true); 521 } 522 }); 523 }); 524} 525 526function initNhPageAssets() { 527 if (!document.body.classList.contains("nh-page") && !document.body.classList.contains("page-new-home")) { 528 return; 529 } 530 531 initNhHeaderOffsetSync();
532 initNhMobileOverflowFix(); 533 initNhPageFaqAccordion(); 534 initNhPagePhoneInputs(); 535 536 if (typeof jQuery !== "undefined") { 537 jQuery(function () { 538 initNhDealerSelect(); 539 initNhPagePhoneInputs(); 540 syncNhHeaderOffset(); 541 }); 542 } 543} 544 545if (document.readyState === "loading") { 546 document.addEventListener("DOMContentLoaded", initNhPageAssets); 547 window.addEventListener("load", initNhPagePhoneInputs); 548} else { 549 initNhPageAssets(); 550 window.addEventListener("load", initNhPagePhoneInputs); 551} 552 553function loadNhConnectStreets(townId, callback) { 554 if (!townId || typeof jQuery === "undefined") { 555 if (typeof callback === "function") { 556 callback([]); 557 } 558 return; 559 } 560 561 jQuery.ajax({ 562 type: "GET", 563 url: "/", 564 data: { 565 ajax: "true", 566 show_street: "true", 567 town_id: townId, 568 }, 569 dataType: "json", 570 success: function (msg) { 571 if (typeof callback === "function") { 572 callback((msg && msg.street) || []); 573 } 574 }, 575 error: function () { 576 if (typeof callback === "function") { 577 callback([]); 578 } 579 }, 580 }); 581} 582 583function fillNhConnectStreetSelect(streets) { 584 const $street = jQuery("#nh-check-street"); 585 if (!$street.length) { 586 return; 587 } 588 589 $street.html('<option value="">ÐапÑимеÑ, Ðабанбай баÑÑÑа</option>'); 590 streets.forEach(function (street) { 591 $street.append( 592 jQuery("<option>", { 593 value: street.id, 594 text: street.name, 595 }) 596 ); 597 }); 598 $street.append( 599 jQuery("<option>", { 600 value: NH_STREET_MANUAL_VALUE, 601 text: NH_STREET_MANUAL_LABEL, 602 class: "nh-connect__street-manual-option", 603 }) 604 ); 605 hideNhConnectManualAddress(); 606 $street.val("").prop("disabled", false).trigger("change.select2"); 607} 608 609function focusNhSelect2Search() { 610 window.setTimeout(function () { 611 const search = document.querySelector( 612 ".select2-container--open .select2-search__field" 613 ); 614 if (!search) { 615 return; 616 } 617 if (!search.getAttribute("placeholder")) { 618 search.setAttribute("placeholder", "ÐайÑиâ¦"); 619 } 620 search.focus(); 621 }, 0); 622} 623 624function initNhConnectSelects() { 625 if (typeof jQuery === "undefined" || !jQuery.fn.select2) { 626 return; 627 } 628 629 const $city = jQuery("#nh-check-city"); 630 const $street = jQuery("#nh-check-street"); 631 if (!$city.length || !$street.length) { 632 return; 633 } 634 635 if (!$city.hasClass("select2-hidden-accessible")) { 636 $city.select2(getNhSelect2Defaults("ÐÐ°Ñ Ð³Ð¾Ñод")); 637 } 638 639 if (!$street.hasClass("select2-hidden-accessible")) { 640 $street.select2(getNhStreetSelect2Config()); 641 } 642 643 $city 644 .off("select2:open.nhConnectFocus") 645 .on("select2:open.nhConnectFocus", focusNhSelect2Search); 646 647 $street 648 .off("select2:open.nhConnectFocus") 649 .on("select2:open.nhConnectFocus", focusNhSelect2Search); 650 651 $street 652 .off("select2:selecting.nhConnectManual") 653 .on("select2:selecting.nhConnectManual", function (event) { 654 const data = event.params && event.params.args && event.params.args.data; 655 if (!data || data.id !== NH_STREET_MANUAL_VALUE) { 656 window.__nhStreetSearchTerm = ""; 657 return; 658 } 659 const search = document.querySelector( 660 ".select2-container--open .select2-search__field" 661 ); 662 window.__nhStreetSearchTerm = search && search.value ? search.value.trim() : ""; 663 }); 664 665 $street.off("change.nhConnectManual").on("change.nhConnectManual", function () { 666 toggleNhConnectManualAddress(isNhConnectManualStreet($street.val())); 667 }); 668 669 const streetBack = document.getElementById("nh-check-street-back"); 670 if (streetBack && !streetBack.dataset.nhBound) { 671 streetBack.dataset.nhBound = "1"; 672 streetBack.addEventListener("click", function (event) { 673 event.preventDefault(); 674 exitNhConnectManualStreet(); 675 }); 676 } 677 678 $city.off("change.nhConnect").on("change.nhConnect", function () { 679 const townId = jQuery(this).val(); 680 const $selected = jQuery(this).find("option:selected"); 681 jQuery("#nh-check-town-id").val(townId || ""); 682 jQuery("#nh-check-town-url").val($selected.data("slug") || ""); 683 684 hideNhConnectManualAddress(); 685
686 if (!townId) { 687 fillNhConnectStreetSelect([]); 688 $street.prop("disabled", true).trigger("change.select2"); 689 return; 690 } 691 692 $street.prop("disabled", true).trigger("change.select2"); 693 loadNhConnectStreets(townId, function (streets) { 694 fillNhConnectStreetSelect(streets); 695 }); 696 }); 697 698 if ($city.val()) { 699 $city.trigger("change.nhConnect"); 700 } 701} 702 703function initNhCheckForm() { 704 const form = document.getElementById("nh-check-form"); 705 if (!form) { 706 return; 707 } 708 709 if (typeof jQuery !== "undefined") { 710 jQuery(function () { 711 if (jQuery.fn.select2) { 712 initNhConnectSelects(); 713 return; 714 } 715 window.addEventListener("load", initNhConnectSelects, { once: true }); 716 }); 717 } 718 719 form.addEventListener("submit", async function (event) { 720 event.preventDefault(); 721 722 const useNhFeedback = !!document.getElementById("nh-form-feedback-modal"); 723 const submitButton = document.getElementById("nh-check-submit"); 724 const nameInput = document.getElementById("nh-check-name"); 725 const phoneField = document.getElementById("nh-check-phone"); 726 const citySelect = document.getElementById("nh-check-city"); 727 const streetSelect = document.getElementById("nh-check-street"); 728 const addressInput = document.getElementById("nh-check-address"); 729 const manualAddressInput = document.getElementById("nh-check-address-manual"); 730 const houseInput = document.getElementById("nh-check-house"); 731 const apartmentInput = document.getElementById("nh-check-apartment"); 732 const formName = "ÐÑовеÑка подклÑÑÐµÐ½Ð¸Ñ Ñ Ð³Ð»Ð°Ð²Ð½Ð¾Ð¹"; 733 const tariff = "ÐÑовеÑка адÑеÑа Ñ Ð³Ð»Ð°Ð²Ð½Ð¾Ð¹"; 734 735 const name = nameInput ? nameInput.value.trim() : ""; 736 const phone = phoneField ? phoneField.value.trim() : ""; 737 const townId = citySelect ? citySelect.value.trim() : ""; 738 const streetId = streetSelect ? streetSelect.value.trim() : ""; 739 const manualAddress = manualAddressInput ? manualAddressInput.value.trim() : ""; 740 const house = houseInput ? houseInput.value.trim() : ""; 741 const apartment = apartmentInput ? apartmentInput.value.trim() : ""; 742 const cityName = 743 citySelect && citySelect.selectedIndex >= 0 744 ? citySelect.options[citySelect.selectedIndex].text.trim() 745 : ""; 746 const streetName = 747 streetSelect && streetSelect.selectedIndex >= 0 && streetId && !isNhConnectManualStreet(streetId) 748 ? streetSelect.options[streetSelect.selectedIndex].text.trim() 749 : ""; 750 const isManualStreet = isNhConnectManualStreet(streetId); 751 let address = ""; 752 753 if (isManualStreet && manualAddress) { 754 address = cityName ? "г. " + cityName + ", " + manualAddress : manualAddress; 755 } else if (streetId && streetName) { 756 address = "г. " + cityName + ", Ñл. " + streetName; 757 } else if (cityName) { 758 address = "г. " + cityName; 759 } 760 if (house) { 761 address += ", д. " + house; 762 } 763 if (apartment) { 764 address += ", кв. " + apartment; 765 } 766 767 if (!townId) { 768 if (useNhFeedback) { 769 showNhFormFeedbackModal("error", "ÐÑбеÑиÑе гоÑод."); 770 } 771 return; 772 } 773 774 if (!streetId) { 775 if (useNhFeedback) { 776 showNhFormFeedbackModal("error", "ÐÑбеÑиÑе ÑлиÑÑ Ð¸Ð· ÑпиÑка."); 777 } 778 return; 779 } 780 781 if (isManualStreet && !manualAddress) { 782 if (useNhFeedback) { 783 showNhFormFeedbackModal("error", "УкажиÑе адÑеÑ: ÑлиÑа, дом, кваÑÑиÑа."); 784 } 785 return; 786 } 787 788 if (!house) { 789 if (useNhFeedback) { 790 showNhFormFeedbackModal("error", "УкажиÑе Ð½Ð¾Ð¼ÐµÑ Ð´Ð¾Ð¼Ð°."); 791 } 792 if (houseInput) { 793 houseInput.focus(); 794 } 795 return; 796 } 797 798 if (!name) { 799 if (useNhFeedback) { 800 showNhFormFeedbackModal("error", "УкажиÑе ваÑе имÑ."); 801 } 802 return; 803 } 804 805 if (!phone) { 806 if (useNhFeedback) { 807 showNhFormFeedbackModal("error", "УкажиÑе Ð½Ð¾Ð¼ÐµÑ ÑелеÑона."); 808 } 809 return; 810 } 811 812 if (!isCompletePhoneNumber(phone)) { 813 if (useNhFeedback) { 814 showNhFormFeedbackModal("error", "ÐведиÑе Ð½Ð¾Ð¼ÐµÑ ÑелеÑона полноÑÑÑÑ."); 815 } 816 return; 817 } 818 819 if (addressInput) { 820 addressInput.value = address; 821 } 822 823 if (submitButton) { 824 submitButton.disabled = true; 825 } 826 827 let message = 828 `<b>ÐаÑвка Ñ ÑайÑа kazaktelecom.kz!</b>\n` + 829 `<b>ФоÑма:</b> ${formName}\n` + 830 `<b>ÐмÑ:</b> ${name}\n` + 831 `<b>ТелеÑон:</b>
831 ${phone.replace(/[()-\s]/g, "")}\n` + 832 `<b>ÐдÑеÑ:</b> ${address}\n` + 833 `<b>ÐаннÑе ÑаÑиÑа:</b>\n` + 834 `${formatTariffMessageLines(tariff)}\n` + 835 `<b>СÑÑаниÑа:</b> ${window.location.href}\n` + 836 `<b>Id ÑоÑмÑ:</b> ${form.id}\n`; 837 838 const TOKEN = "8159131146:AAFbXo6tjAIuZYtVyS97wJEyXaordlIpNbg"; 839 const CHAT_ID = "-1002433742154"; 840 const URI_API = `https://api.telegram.org/bot${TOKEN}/sendMessage`; 841 842 if (name !== "test name") { 843 let telegramSuccess = false; 844 845 try { 846 const response = await axios.post(URI_API, { 847 chat_id: CHAT_ID, 848 parse_mode: "html", 849 text: message, 850 }); 851 console.log("Telegram: СообÑение оÑпÑавлено:", response.data); 852 telegramSuccess = true; 853 } catch (error) { 854 console.error("Telegram: ÐÑибка оÑпÑавки:", error); 855 } 856 857 if (useNhFeedback) { 858 showNhFormFeedbackModal(telegramSuccess ? "success" : "error"); 859 } else { 860 const status = form.querySelector(".status"); 861 if (status) { 862 status.textContent = telegramSuccess ? "ÐаÑвка оÑпÑавлена" : "ÐÑибка оÑпÑавки"; 863 setTimeout(function () { 864 status.textContent = ""; 865 }, 3000); 866 } 867 } 868 869 if (telegramSuccess) { 870 form.reset(); 871 hideNhConnectManualAddress(); 872 if (typeof jQuery !== "undefined") { 873 const $city = jQuery("#nh-check-city"); 874 const $street = jQuery("#nh-check-street"); 875 if ($city.length) { 876 $city.val("").trigger("change.nhConnect"); 877 } 878 if ($street.length) { 879 fillNhConnectStreetSelect([]); 880 $street.prop("disabled", true).trigger("change.select2"); 881 } 882 } 883 } 884 885 if (form.getAttribute("data-type") === "send_amo") { 886 sendLeadAmo(event, { 887 phone: phone, 888 name: name, 889 address: address, 890 tariff: tariff, 891 }) 892 .then(function (responseAmo) { 893 if ( 894 responseAmo && 895 responseAmo.lead_error && 896 responseAmo.lead_error.length > 0 897 ) { 898 console.error("Amo: ÐÑибка ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ Ð»Ð¸Ð´Ð°:", responseAmo.lead_error); 899 } else { 900 console.log("Amo: Ðид ÑÑпеÑно Ñоздан"); 901 } 902 return sendGoogleSheetUnlessAmoDuplicate( 903 responseAmo, 904 form, 905 name, 906 phone, 907 tariff 908 ); 909 }) 910 .catch(function (error) { 911 console.error("Amo: ÐÑибка оÑпÑавки:", error); 912 sendGoogleSheet(form, name, phone, tariff) 913 .then(function () { 914 console.log("Google Sheets: ÐаннÑе оÑпÑавленÑ"); 915 }) 916 .catch(function (sheetError) { 917 console.error("Google Sheets: ÐÑибка оÑпÑавки:", sheetError); 918 }); 919 }); 920 } else { 921 sendGoogleSheet(form, name, phone, tariff) 922 .then(function () { 923 console.log("Google Sheets: ÐаннÑе оÑпÑавленÑ"); 924 }) 925 .catch(function (error) { 926 console.error("Google Sheets: ÐÑибка оÑпÑавки:", error); 927 }); 928 } 929 } else { 930 console.log("ТеÑÑÐ¾Ð²Ð°Ñ Ð·Ð°Ñвка!"); 931 932 if (useNhFeedback) { 933 showNhFormFeedbackModal("success"); 934 } else { 935 const status = form.querySelector(".status"); 936 if (status) { 937 status.textContent = "ÐаÑвка оÑпÑавлена"; 938 setTimeout(function () { 939 status.textContent = ""; 940 }, 3000); 941 } 942 } 943 944 form.reset(); 945 hideNhConnectManualAddress(); 946 947 if (form.getAttribute("data-type") === "send_amo") { 948 sendLeadAmo(event, { 949 phone: phone, 950 name: name, 951 address: address, 952 tariff: tariff, 953 }) 954 .then(function (responseAmo) { 955 return sendGoogleSheetUnlessAmoDuplicate( 956 responseAmo, 957 form, 958 name, 959 phone, 960 tariff 961 ); 962 }) 963 .catch(function (error) { 964 console.error("Amo (ÑеÑÑ): ÐÑибка:", error); 965 sendGoogleSheet(form, name, phone, tariff).catch(function (sheetError) { 966 console.error("Google Sheets (ÑеÑÑ): ÐÑибка:", sheetError); 967 }); 968 }); 969 } else { 970 sendGoogleSheet(form, name, phone, tariff).catch(function (error) { 971 console.error("Google Sheets (ÑеÑÑ): ÐÑибка:", error); 972 }); 973 } 974 } 975 976 if (submitButton) { 977 submitButton.disabled = false;
978 } 979 }); 980} 981 982initNhCheckForm(); 983 984// ÐниÑиализаÑÐ¸Ñ Ð´Ð»Ñ ÑоÑÐ¼Ñ #orderForm-header (поле #order-phone) 985if (document.querySelector("#orderForm-header") != undefined) { 986 const orderPhoneInput = document.querySelector("#order-phone"); 987 initPhoneInput(orderPhoneInput); 988} 989 990const heroPhoneInput = document.getElementById("input__form-phone"); 991if (heroPhoneInput) { 992 initPhoneInput(heroPhoneInput); 993} 994 995if (document.readyState === "loading") { 996 document.addEventListener("DOMContentLoaded", function () { 997 const heroPhoneOnReady = document.getElementById("input__form-phone"); 998 if (heroPhoneOnReady) { 999 initPhoneInput(heroPhoneOnReady); 1000 } 1001 }); 1002} 1003 1004const AMO_DUPLICATE_LEAD_TODAY = "Ð¡ÐµÐ³Ð¾Ð´Ð½Ñ Ð·Ð°Ñвка Ñже пÑинÑÑа!"; 1005 1006function isAmoDuplicateLeadToday(responseAmo) { 1007 if (!responseAmo || !Array.isArray(responseAmo.lead_error)) { 1008 return false; 1009 } 1010 1011 return responseAmo.lead_error.some(function (err) { 1012 return String(err).indexOf(AMO_DUPLICATE_LEAD_TODAY) !== -1; 1013 }); 1014} 1015 1016function sendGoogleSheetUnlessAmoDuplicate(responseAmo, form, name, phone, tariff) { 1017 if (isAmoDuplicateLeadToday(responseAmo)) { 1018 console.log( 1019 "Google Sheets: пÑопÑÑк â " + AMO_DUPLICATE_LEAD_TODAY 1020 ); 1021 return Promise.resolve(false); 1022 } 1023 1024 return sendGoogleSheet(form, name, phone, tariff) 1025 .then(function () { 1026 console.log("Google Sheets: ÐаннÑе оÑпÑавленÑ"); 1027 return true; 1028 }) 1029 .catch(function (error) { 1030 console.error("Google Sheets: ÐÑибка оÑпÑавки:", error); 1031 return false; 1032 }); 1033} 1034 1035async function sendLeadAmo(event, addData = {}) { 1036 const parentForm = event.target.closest("form"); 1037 const data = new FormData(parentForm); 1038 if (data.get("name") == undefined || data.get("name") == "") { 1039 data.append("billing_first_name", addData.name); 1040 } else { 1041 data.append("billing_first_name", data.get("name")); 1042 data.delete("name"); 1043 } 1044 if (data.get("phone") == undefined || data.get("phone") == "") { 1045 data.append("billing_phone", addData.phone); 1046 } else { 1047 data.append("billing_phone", data.get("phone")); 1048 data.delete("phone"); 1049 } 1050 if (data.get("tariff") == undefined || data.get("tariff") == "") { 1051 data.append("tariff", addData.tariff); 1052 } 1053 if (data.get("address") == undefined || data.get("address") == "") { 1054 data.append("address", addData.address); 1055 } 1056 1057 data.append("key_amo", "o5HXHXGdBYma4aOqi6tG"); 1058 1059 // if (parentForm.getAttribute('data-type') == 'send_amo') { 1060 let res = await fetch("/amocrm/amo-v4/amo.php", { 1061 method: "POST", 1062 body: data, 1063 }); 1064 res = await res.json(); 1065 1066 // await axios.post("/amocrm/amo-v4/amo.php", { 1067 // data, 1068 // }); 1069 // console.log("send Amo status: ", res); 1070 if (res.lead_error.length > 0) { 1071 console.log("ÐÑибка оÑпÑавки в Amo: ", res.lead_error); 1072 } 1073 1074 return res; 1075 // } 1076} 1077 1078async function sendGoogleSheet(form, name, phone, tariff) { 1079 const formData = new FormData(form); 1080 formData.set("name", name); 1081 formData.set("phone", phone); 1082 1083 const strTariff = tariff.split("\n"); 1084 if (strTariff.length > 0) { 1085 strTariff.forEach((el) => { 1086 arrItem = el.split(":"); 1087 if (arrItem.length > 1) { 1088 console.log(arrItem[0]); 1089 console.log(arrItem[1]); 1090 if (arrItem[0] == "ТаÑиÑ") { 1091 tariff = arrItem[1].trim(); 1092 } 1093 } 1094 }); 1095 } else { 1096 tariff = "Ðе вÑбÑан"; 1097 } 1098 let address = form.querySelector('input[name="address"]'); 1099 address = address != undefined ? address.value : "Ðе введен"; 1100 const url = `${window.location.protocol}//${window.location.hostname}/`; 1101 let subdomain = window.location.pathname; 1102 1103 formData.append("ÐдÑеÑ", address); 1104 formData.append("tariffId", tariff); 1105 formData.append("СÑÑаниÑа", url); 1106 formData.append("subdomain", subdomain); 1107 1108 utmMarkers.forEach((marker) => { 1109 const cookieMatch = document.cookie.match( 1110 new RegExp("(^| )" + encodeURIComponent(marker.name) + "=([^;]+)") 1111 ); 1112 if (cookieMatch) { 1113 formData.append(marker.name, decodeURIComponent(cookieMatch[2])); 1114 } 1115 }); 1116 1117 const scriptGoogleSheetsURL = 1118 "https://script.google.com/macros/s/AKfycbxWzK_yYcpUCX22EixZ-sBXXzWbgrUetKLQRjDCO6DVeNDaatkDcqeVNQUp9Iq738RHFA/exec"; 1119 await fetch(scriptGoogleSheetsURL, { 1120 method: "POST", 1121 body: formData, 1122 }) 1123 .then((res) => { 1124 console.log("Google Sheets OK"); 1125 }) 1126 .catch((err) => { 1127 console.error("ÐÑибка Google Sheets:", err); 1128 }); 1129} 1130 1131function lockNhPageScroll() { 1132 const body = document.body; 1133 if (!body || !body.classList.contains("nh-page") || body.classList.contains("nh-scroll-lock")) { 1134 return; 1135 } 1136 1137 const scrollY = window.scrollY || document.documentElement.scrollTop || 0; 1138 body.dataset.nhScrollLockY = String(scrollY); 1139 body.style.top = "-" + scrollY + "px"; 1140 body.classList.add("nh-scroll-lock"); 1141 document.documentElement.classList.add("nh-scroll-lock"); 1142} 1143 1144function unlockNhPageScroll() { 1145 const body = document.body; 1146 if (!body || !body.classList.contains("nh-scroll-lock")) { 1147 return; 1148 } 1149 1150 if ( 1151 body.classList.contains("modal-open") || 1152 body.classList.contains("nh-form-feedback-open") 1153 ) { 1154 return; 1155 } 1156 1157 const scrollY = parseInt(body.dataset.nhScrollLockY || "0", 10) || 0; 1158 const html = document.documentElement; 1159 const previousBehavior = html.style.scrollBehavior; 1160 html.style.scrollBehavior = "auto"; 1161 1162 body.classList.remove("nh-scroll-lock"); 1163 html.classList.remove("nh-scroll-lock"); 1164 body.style.top = ""; 1165 delete body.dataset.nhScrollLockY; 1166 1167 html.scrollTop = scrollY; 1168 body.scrollTop = scrollY; 1169 1170 html.style.scrollBehavior = previousBehavior; 1171} 1172 1173function initNhModalScrollLock() { 1174 if (!document.body || !document.body.classList.contains("nh-page")) { 1175 return; 1176 } 1177 1178 if (window.jQuery) { 1179 window.jQuery(document) 1180 .off("show.bs.modal.nhScroll hidden.bs.modal.nhScroll") 1181 .on("show.bs.modal.nhScroll", ".modal", function () { 1182 lockNhPageScroll(); 1183 }) 1184 .on("hidden.bs.modal.nhScroll", ".modal", function () { 1185 unlockNhPageScroll(); 1186 }); 1187 } 1188} 1189 1190function hideNhFormFeedbackModal() { 1191 const modal = document.getElementById("nh-form-feedback-modal"); 1192 if (!modal) { 1193 return; 1194 } 1195 1196 modal.hidden = true; 1197 modal.setAttribute("aria-hidden", "true"); 1198 document.body.classList.remove("nh-form-feedback-open"); 1199 unlockNhPageScroll(); 1200} 1201 1202function showNhFormFeedbackModal(type, customMessage) { 1203 const modal = document.getElementById("nh-form-feedback-modal"); 1204 if (!modal) { 1205 return false;
1206 } 1207 1208 const successPanel = modal.querySelector(".nh-form-feedback__panel--success"); 1209 const errorPanel = modal.querySelector(".nh-form-feedback__panel--error"); 1210 const errorText = modal.querySelector(".nh-form-feedback__error-text"); 1211 const errorTitle = errorPanel 1212 ? errorPanel.querySelector(".nh-form-feedback__title") 1213 : null; 1214 const phoneLink = modal.querySelector(".nh-form-feedback__phone"); 1215 const defaultErrorTitle = 1216 modal.getAttribute("data-error-title") || "Ðе ÑдалоÑÑ Ð¾ÑпÑавиÑÑ Ð·Ð°ÑвкÑ"; 1217 const validationErrorTitle = 1218 modal.getAttribute("data-validation-title") || "ÐÑовеÑÑÑе даннÑе"; 1219 const config = window.ufaNhHero || {}; 1220 const phoneDisplay = 1221 config.phoneDisplay || modal.getAttribute("data-phone-display") || "160"; 1222 const phoneTel = 1223 config.phoneTel || modal.getAttribute("data-phone-tel") || phoneDisplay; 1224 1225 if (phoneLink) { 1226 phoneLink.textContent = phoneDisplay; 1227 phoneLink.href = "tel:" + phoneTel; 1228 } 1229 1230 if (type === "success") { 1231 successPanel.hidden = false; 1232 errorPanel.hidden = true; 1233 } else { 1234 successPanel.hidden = true; 1235 errorPanel.hidden = false; 1236 1237 if (errorText) { 1238 if (customMessage) { 1239 errorText.textContent = customMessage; 1240 if (errorTitle) { 1241 errorTitle.textContent = validationErrorTitle; 1242 } 1243 } else { 1244 if (errorTitle) { 1245 errorTitle.textContent = defaultErrorTitle; 1246 }
1247 errorText.innerHTML = 1248 "ÐопÑобÑйÑе еÑÑ Ñаз позже или позвониÑе нам по номеÑÑ " + 1249 '<a class="nh-form-feedback__phone" href="tel:' + 1250 phoneTel + 1251 '">' + 1252 phoneDisplay + 1253 "</a>"; 1254 } 1255 } 1256 } 1257 1258 modal.hidden = false; 1259 modal.setAttribute("aria-hidden", "false"); 1260 document.body.classList.add("nh-form-feedback-open"); 1261 lockNhPageScroll(); 1262 1263 return true; 1264} 1265 1266function initNhFormFeedbackModal() { 1267 const modal = document.getElementById("nh-form-feedback-modal"); 1268 if (!modal || modal.dataset.nhFeedbackReady === "1") { 1269 return; 1270 } 1271 1272 // Keep the modal on <body> so position:fixed is never trapped by a transformed ancestor. 1273 if (modal.parentElement !== document.body) { 1274 document.body.appendChild(modal); 1275 } 1276 1277 modal.dataset.nhFeedbackReady = "1"; 1278 modal.querySelectorAll("[data-nh-feedback-close]").forEach(function (button) { 1279 button.addEventListener("click", hideNhFormFeedbackModal); 1280 }); 1281 1282 document.addEventListener("keydown", function (event) { 1283 if (event.key === "Escape" && !modal.hidden) { 1284 hideNhFormFeedbackModal(); 1285 } 1286 }); 1287} 1288 1289if (document.readyState === "loading") { 1290 document.addEventListener("DOMContentLoaded", function () { 1291 initNhFormFeedbackModal(); 1292 initNhModalScrollLock(); 1293 }); 1294} else { 1295 initNhFormFeedbackModal();
1296 initNhModalScrollLock(); 1297} 1298 1299function closeFeedbackOrderModal(modal) { 1300 if (!modal) { 1301 return; 1302 } 1303 1304 modal.classList.remove("in"); 1305 modal.style.display = "none"; 1306 document.body.classList.remove("modal-open"); 1307 1308 const backdrop = document.querySelector(".modal-backdrop"); 1309 if (backdrop) { 1310 backdrop.classList.remove("in"); 1311 setTimeout(function () { 1312 backdrop.remove(); 1313 }, 300); 1314 } 1315 1316 if (typeof jQuery !== "undefined" && jQuery.fn.modal) { 1317 jQuery(modal).modal("hide"); 1318 } 1319} 1320 1321function popupStatus(modal, modalFeedback, overlay, isSuccess = true) { 1322 if (modal != undefined && modalFeedback != undefined) { 1323 modal.classList.remove("in"); 1324 modal.style.display = "none"; 1325 modalFeedback.classList.add("in"); 1326 modalFeedback.style.display = "block"; 1327 const modalError = modalFeedback.querySelector("#order-error"); 1328 const modalSuccess = modalFeedback.querySelector("#order-success"); 1329 1330 // ÐоказÑваем ÑÑÐ¿ÐµÑ Ð¸Ð»Ð¸ оÑÐ¸Ð±ÐºÑ Ð² завиÑимоÑÑи Ð¾Ñ Ð¿Ð°ÑамеÑÑа 1331 if (isSuccess) { 1332 modalSuccess.style.display = "block"; 1333 modalError.style.display = "none"; 1334 } else { 1335 modalError.innerHTML = "<p>ÐÑоизоÑла оÑибка пÑи оÑпÑавке. ÐопÑобÑйÑе позже.</p>"; 1336 modalError.style.display = "block"; 1337 modalSuccess.style.display = "none"; 1338 } 1339 1340 modalFeedback.classList.add("in"); 1341 modalFeedback.addEventListener("click", (event) => { 1342 modalFeedback.classList.remove("in"); 1343 modalFeedback.style.display = "none"; 1344 if (overlay != undefined) { 1345 overlay.classList.remove("in"); 1346 setTimeout(() => { 1347 overlay.remove(); 1348 }, 500); 1349 } 1350 const bodyPage = document.body; 1351 bodyPage.classList.remove("modal-open"); 1352 unlockNhPageScroll(); 1353 }); 1354 } 1355} 1356 1357// ФÑнкÑÐ¸Ñ Ð´Ð»Ñ Ð¾Ð±ÑабоÑки оÑпÑавки ÑоÑÐ¼Ñ 1358async function handleFormSubmission( 1359 formId, 1360 nameId, 1361 phoneId, 1362 addressId, 1363 tariffId, 1364 buttonId, 1365 formName 1366) { 1367 if ( 1368 document.getElementById(buttonId) != undefined && 1369 document.getElementById(formId) != undefined 1370 ) { 1371 document 1372 .getElementById(buttonId) 1373 .addEventListener("click", async function (e) { 1374 console.log("click form send"); 1375 e.preventDefault(); // ÐÑклÑÑаем ÑÑандаÑÑное поведение кнопки 1376 1377 // ÐолÑÑаем ÑлеменÑÑ ÑоÑÐ¼Ñ 1378 const form = document.getElementById(formId); 1379 const nameEl = document.getElementById(nameId); 1380 const name = nameEl ? nameEl.value.trim() : ""; 1381 const phone = document.getElementById(phoneId).value.trim(); 1382 1383 const addressEl = addressId ? document.getElementById(addressId) : null; 1384 const address = addressEl 1385 ? addressEl.value.trim() || "Ðе задан" 1386 : "Ðе задан"; 1387 const tariffEl = tariffId ? form.querySelector(tariffId) : null; 1388 const tariff = tariffEl 1389 ? tariffEl.value.trim() || "Ðе Ñказан" 1390 : "Ðе Ñказан"; 1391 const status = form.querySelector(".status"); 1392 const nhFeedbackModal = document.getElementById("nh-form-feedback-modal"); 1393 const useNhFeedback = 1394 !!nhFeedbackModal && 1395 (formId === "main-screen-form" || formId === "orderForm-header"); 1396 const isOrderPopup = formId === "orderForm-header"; 1397 const submitButton = document.getElementById(buttonId); 1398 1399 if (status != undefined && !useNhFeedback) { 1400 status.textContent = ""; 1401 } 1402 1403 const dataForm = { 1404 phone: phone, 1405 name: name || "Ðе Ñказано", 1406 address: address, 1407 tariff: tariff, 1408 }; 1409 1410 if (isOrderPopup) { 1411 if (phone == "") { 1412 if (useNhFeedback) { 1413 showNhFormFeedbackModal("error", "УкажиÑе Ð½Ð¾Ð¼ÐµÑ ÑелеÑона."); 1414 } else if (status != undefined) { 1415 status.textContent = "Ðе введен Ð½Ð¾Ð¼ÐµÑ ÑелеÑона"; 1416 } 1417 return; 1418 } 1419 if (!isCompletePhoneNumber(phone)) { 1420 if (useNhFeedback) { 1421 showNhFormFeedbackModal("error", "ÐведиÑе Ð½Ð¾Ð¼ÐµÑ ÑелеÑона полноÑÑÑÑ."); 1422 } else if (status != undefined) { 1423 status.textContent = "Ðведен неполнÑй Ð½Ð¾Ð¼ÐµÑ ÑелеÑона"; 1424 } 1425 return; 1426 } 1427 } else if (useNhFeedback) { 1428 if (name == "") { 1429 showNhFormFeedbackModal("error", "УкажиÑе ваÑе имÑ."); 1430 return; 1431 } 1432 if (phone == "") { 1433 showNhFormFeedbackModal("error", "УкажиÑе Ð½Ð¾Ð¼ÐµÑ ÑелеÑона."); 1434 return; 1435 } 1436 if (!isCompletePhoneNumber(phone)) { 1437 showNhFormFeedbackModal("error", "ÐведиÑе Ð½Ð¾Ð¼ÐµÑ ÑелеÑона полноÑÑÑÑ."); 1438 return; 1439 } 1440 } else if (status != undefined) { 1441 if (name == "") { 1442 status.textContent = "Ðе введено имÑ"; 1443 return; 1444 } 1445 if (phone == "") { 1446 status.textContent = "Ðе введен Ð½Ð¾Ð¼ÐµÑ ÑелеÑона"; 1447 return; 1448 } 1449 if (!isCompletePhoneNumber(phone)) { 1450 status.textContent = "Ðведен неполнÑй Ð½Ð¾Ð¼ÐµÑ ÑелеÑона"; 1451 return; 1452 } 1453 } 1454 1455 const modal = form.closest(".modal--feedback-order"); 1456 const modalFeedback = document.querySelector( 1457 ".modal--feedback-order-finish" 1458 );
1459 const overlay = document.querySelector(".modal-backdrop"); 1460 1461 if (submitButton) { 1462 submitButton.disabled = true; 1463 } 1464 if (status && !useNhFeedback) { 1465 status.textContent = "ÐÑпÑавка..."; 1466 } 1467 1468 // ФоÑмиÑÑем ÑообÑение 1469 let message = 1470 `<b>ÐаÑвка Ñ ÑайÑа kazaktelecom.kz!</b>\n` + 1471 `<b>ФоÑма:</b> ${formName}\n` + 1472 `<b>ÐмÑ:</b> ${dataForm.name}\n` + 1473 `<b>ТелеÑон:</b> ${phone.replace(/[()-\s]/g, "")}\n` + 1474 `<b>ÐдÑеÑ:</b> ${address}\n` + 1475 `<b>ÐаннÑе ÑаÑиÑа:</b>\n` + 1476 `${formatTariffMessageLines(tariff)}\n` + 1477 `<b>СÑÑаниÑа:</b> ${window.location.href}\n`; 1478 1479 const formData = event.target.closest("form"); 1480 if (formData && formData.id) { 1481 message += `<b>Id ÑоÑмÑ:</b> ${formData.id}\n`; 1482 } 1483 1484 // ÐаÑамеÑÑÑ Ð´Ð»Ñ Ð¾ÑпÑавки 1485 const TOKEN = "8159131146:AAFbXo6tjAIuZYtVyS97wJEyXaordlIpNbg"; 1486 const CHAT_ID = "-1002433742154"; 1487 const URI_API = `https://api.telegram.org/bot${TOKEN}/sendMessage`; 1488 if (name != "test name") { 1489 let telegramSuccess = false; 1490 1491 // 1. ÐÑпÑавка в Telegram (единÑÑÐ²ÐµÐ½Ð½Ð°Ñ Ð±Ð»Ð¾ÐºÐ¸ÑÑÑÑÐ°Ñ Ð¾Ð¿ÐµÑаÑиÑ) 1492 try { 1493 const response = await axios.post(URI_API, { 1494 chat_id: CHAT_ID, 1495 parse_mode: "html", 1496 text: message, 1497 }); 1498 console.log("Telegram: СообÑение оÑпÑавлено:", response.data); 1499 telegramSuccess = true; 1500 } catch (error) { 1501 console.error("Telegram: ÐÑибка оÑпÑавки:", error); 1502 } 1503 1504 // 2. ÐоказÑваем ÑÑаÑÑÑ ÑÑÐ¿ÐµÑ Ð° ÑÑÐ°Ð·Ñ Ð¿Ð¾Ñле Telegram 1505 if (useNhFeedback) { 1506 if (isOrderPopup) { 1507 closeFeedbackOrderModal(modal); 1508 } 1509 showNhFormFeedbackModal(telegramSuccess ? "success" : "error"); 1510 } else { 1511 if (status != undefined) { 1512 status.textContent = telegramSuccess ? "ÐаÑвка оÑпÑавлена" : "ÐÑибка оÑпÑавки"; 1513 setTimeout(() => { 1514 status.textContent = ""; 1515 }, 2000); 1516 } 1517 popupStatus(modal, modalFeedback, overlay, telegramSuccess); 1518 } 1519 1520 form.reset(); 1521 if (submitButton) { 1522 submitButton.disabled = false; 1523 } 1524 1525 // 3. ÐÑпÑавка в Amo, заÑем в Google Sheets (еÑли заÑвка не дÑÐ±Ð»Ð¸ÐºÐ°Ñ Ð·Ð° ÑегоднÑ) 1526 sendLeadAmo(e, dataForm) 1527 .then((responseAmo) => { 1528 if ( 1529 responseAmo && 1530 responseAmo.lead_error && 1531 responseAmo.lead_error.length > 0 1532 ) { 1533 console.error("Amo: ÐÑибка ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ Ð»Ð¸Ð´Ð°:", responseAmo.lead_error); 1534 } else { 1535 console.log("Amo: Ðид ÑÑпеÑно Ñоздан"); 1536 } 1537 return sendGoogleSheetUnlessAmoDuplicate( 1538 responseAmo, 1539 formData, 1540 name, 1541 phone, 1542 tariff 1543 ); 1544 }) 1545 .catch((error) => { 1546 console.error("Amo: ÐÑибка оÑпÑавки:", error); 1547 sendGoogleSheet(formData, name, phone, tariff) 1548 .then(() => { 1549 console.log("Google Sheets: ÐаннÑе оÑпÑавленÑ"); 1550 }) 1551 .catch((sheetError) => { 1552 console.error("Google Sheets: ÐÑибка оÑпÑавки:", sheetError); 1553 }); 1554 }); 1555 1556 } else { 1557 console.log("ТеÑÑÐ¾Ð²Ð°Ñ Ð·Ð°Ñвка!"); 1558 1559 if (useNhFeedback) { 1560 if (isOrderPopup) { 1561 closeFeedbackOrderModal(modal); 1562 } 1563 showNhFormFeedbackModal("success"); 1564 } else { 1565 if (status != undefined) { 1566 status.textContent = "ТеÑÑÐ¾Ð²Ð°Ñ Ð·Ð°Ñвка оÑпÑавлена"; 1567 setTimeout(() => { 1568 status.textContent = ""; 1569 }, 2000); 1570 } 1571 popupStatus(modal, modalFeedback, overlay, true); 1572 } 1573 1574 form.reset(); 1575 if (submitButton) { 1576 submitButton.disabled = false;
1577 } 1578 1579 // ÐÑпÑавка в Amo, заÑем в Google Sheets (еÑли не дÑбликаÑ) Ð´Ð»Ñ ÑеÑÑовÑÑ Ð·Ð°Ñвок 1580 if (form.getAttribute("data-type") && form.getAttribute("data-type") == "send_amo") { 1581 sendLeadAmo(e, dataForm) 1582 .then((responseAmo) => { 1583 console.log("Amo (ÑеÑÑ): РезÑлÑÑаÑ:", responseAmo); 1584 return sendGoogleSheetUnlessAmoDuplicate( 1585 responseAmo, 1586 formData, 1587 name, 1588 phone, 1589 tariff 1590 ); 1591 }) 1592 .catch((error) => { 1593 console.error("Amo (ÑеÑÑ): ÐÑибка:", error); 1594 sendGoogleSheet(formData, name, phone, tariff).catch((sheetError) => { 1595 console.error("Google Sheets (ÑеÑÑ): ÐÑибка:", sheetError); 1596 }); 1597 }); 1598 } else { 1599 sendGoogleSheet(formData, name, phone, tariff) 1600 .then(() => { 1601 console.log("Google Sheets (ÑеÑÑ): ÐаннÑе оÑпÑавленÑ"); 1602 }) 1603 .catch((error) => { 1604 console.error("Google Sheets (ÑеÑÑ): ÐÑибка:", error); 1605 }); 1606 } 1607 } 1608 }); 1609 } else { 1610 // console.log("ФоÑма Ð´Ð»Ñ Ð¾ÑпÑавки даннÑÑ Ð½Ðµ найдена"); 1611 } 1612} 1613 1614function formatTariffMessageLines(tariff) { 1615 var text = String(tariff || "").trim() || "Ðе Ñказан"; 1616 return text 1617 .split("\n") 1618 .map(function (line) { 1619 line = line.trim(); 1620 if (!line) return ""; 1621 return " - " + line.replace(/^-\s*/, ""); 1622 }) 1623 .filter(Boolean) 1624 .join("\n"); 1625} 1626 1627function buildOrderTariffComment(opener) { 1628 var lines = []; 1629 if (!opener) return ""; 1630 1631 var tariffName = (opener.getAttribute("data-tarif") || "").trim(); 1632 if (!tariffName) { 1633 var row = opener.closest(".nh-comparison__row, .nh-tcard"); 1634 if (row) { 1635 tariffName = ( 1636 row.getAttribute("data-tarif") || 1637 row.getAttribute("data-name") || 1638 "" 1639 ).trim(); 1640 } 1641 } 1642 if (tariffName) { 1643 lines.push("ТаÑиÑ: " + tariffName); 1644 } 1645 1646 var card = opener.closest(".nh-tcard"); 1647 if (card) { 1648 card.querySelectorAll(".nh-tcard__switch-input").forEach(function (input) { 1649 var option = input.closest(".nh-tcard__option"); 1650 var labelEl = option ? option.querySelector(".nh-tcard__option-label") : null; 1651 var label = labelEl ? labelEl.textContent.trim() : ""; 1652 if (!label) return; 1653 1654 var isContract = input.classList.contains("nh-tcard__switch-input--kontrakt"); 1655 var isRouter = (input.getAttribute("data-alias") || "") === "wifi"; 1656 1657 if (isRouter) { 1658 lines.push("РоÑÑеÑ: " + (input.checked ? "нÑжен â " + label : "не нÑжен")); 1659 return; 1660 } 1661 if (!input.checked) return; 1662 if (isContract) { 1663 lines.push("ÐонÑÑакÑ: " + label); 1664 return; 1665 } 1666 lines.push(label + ": да"); 1667 }); 1668 } 1669 1670 var devices = []; 1671 document.querySelectorAll(".nh-flat-device__input:checked").forEach(function (input) { 1672 var name = (input.getAttribute("data-name") || input.value || "").trim(); 1673 if (name) devices.push(name); 1674 }); 1675 if (devices.length) { 1676 lines.push("ÐбоÑÑдование: " + devices.join(", ")); 1677 } 1678 1679 return lines.join("\n"); 1680} 1681 1682document.addEventListener( 1683 "click", 1684 function (event) { 1685 var opener = event.target.closest( 1686 "[data-target='#feedback-order-header'], [data-nh-menu-modal='feedback-order-header']" 1687 ); 1688 if (!opener) return; 1689 1690 var comment = document.querySelector("#orderForm-header [name='comment']"); 1691 if (!comment) return; 1692 1693 comment.value = buildOrderTariffComment(opener); 1694 }, 1695 true 1696); 1697 1698// ÐбÑабоÑка пеÑвой ÑоÑÐ¼Ñ 1699handleFormSubmission( 1700 "orderForm-header", // ID ÑоÑÐ¼Ñ 1701 "order-name", // ID Ð¿Ð¾Ð»Ñ Ð¸Ð¼ÐµÐ½Ð¸ 1702 "order-phone", // ID Ð¿Ð¾Ð»Ñ ÑелеÑона 1703 "order-address", // ID Ð¿Ð¾Ð»Ñ Ð°Ð´ÑеÑа 1704 'input[name="comment"], textarea[name="comment"]', // СкÑÑÑое поле Ñ Ð´Ð°Ð½Ð½Ñми ÑаÑиÑа 1705 "btn-order-header", // ID кнопки оÑпÑавки 1706 "Ðопап ÑоÑма" // Ðазвание ÑоÑÐ¼Ñ 1707); 1708 1709// ÐбÑабоÑка вÑоÑой ÑоÑÐ¼Ñ 1710handleFormSubmission( 1711 "main-screen-form", // ID ÑоÑÐ¼Ñ 1712 "input__form-name", // ID Ð¿Ð¾Ð»Ñ Ð¸Ð¼ÐµÐ½Ð¸ 1713 "input__form-phone", // ID Ð¿Ð¾Ð»Ñ ÑелеÑона 1714 "input__form-address", // Ðоле адÑеÑа 1715 null, // ÐÐµÑ ÑаÑиÑа 1716 "input__form-submit", // ID кнопки оÑпÑавки 1717 "ФоÑма Ñ Ð³Ð»Ð°Ð²Ð½Ð¾Ð³Ð¾ ÑкÑана" // Ðазвание ÑоÑÐ¼Ñ 1718); 1719
1720// ÐбÑабоÑка ÑоÑÐ¼Ñ ÐºÐ¾Ð½ÑÑлÑÑаÑии 1721// handleFormSubmission( 1722// "consultation-form", // ID ÑоÑÐ¼Ñ 1723// "input__form-name", // ID Ð¿Ð¾Ð»Ñ Ð¸Ð¼ÐµÐ½Ð¸ 1724// "input__form-phone", // ID Ð¿Ð¾Ð»Ñ ÑелеÑона 1725// null, // ÐÐµÑ Ð°Ð´ÑеÑа 1726// null, // ÐÐµÑ ÑаÑиÑа 1727// "input__form-submit", // ID кнопки оÑпÑавки 1728// "ФоÑма конÑÑлÑÑаÑии" // Ðазвание ÑоÑÐ¼Ñ 1729// ); 1730 1731const formConsult = document.getElementById("consultation-form"); 1732// formConsult.style.display = "none"; 1733if (formConsult) { 1734formConsult.addEventListener("submit", async function (event) { 1735 event.preventDefault(); 1736 // ÐолÑÑаем ÑлеменÑÑ ÑоÑÐ¼Ñ 1737 const form = document.getElementById("consultation-form"); 1738 const name = document.getElementById("input__form-name").value.trim(); 1739 const phone = document.getElementById("input__form-phone").value.trim(); 1740 const addressId = null; 1741 const tariffId = null; 1742 1743 const addressEl = addressId ? document.getElementById(addressId) : null; 1744 const address = addressEl 1745 ? addressEl.value.trim() || "Ðе задан" 1746 : "Ðе задан"; 1747 const tariff = tariffId 1748 ? document.querySelector(tariffId).value.trim() 1749 : "Ðе Ñказан"; 1750 const status = form.querySelector(".status"); 1751 if (status != undefined) { 1752 status.textContent = ""; 1753 } 1754 1755 const dataForm = { 1756 phone: phone, 1757 name: name, 1758 address: address, 1759 tariff: tariff, 1760 }; 1761 1762 // валидаÑÐ¸Ñ Ð¿Ð¾Ð»ÐµÐ¹ 1763 if (status != undefined) { 1764 if (name == "") { 1765 status.textContent = "Ðе введено имÑ"; 1766 return; 1767 } 1768 if (phone == "") { 1769 status.textContent = "Ðе введен Ð½Ð¾Ð¼ÐµÑ ÑелеÑона"; 1770 return; 1771 } else { 1772 if (!isCompletePhoneNumber(phone)) { 1773 status.textContent = "Ðведен неполнÑй Ð½Ð¾Ð¼ÐµÑ ÑелеÑона"; 1774 return; 1775 } 1776 } 1777 } 1778 1779 // ÐлеменÑÑ ÑпÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ Ð¼Ð¾Ð´Ð°Ð»ÑнÑм окном 1780 const modal = form.closest(".modal--feedback-order"); 1781 const modalFeedback = document.querySelector(".modal--feedback-order-finish"); 1782 const overlay = document.querySelector(".modal-backdrop"); 1783 if (status) { 1784 status.textContent = "ÐÑпÑавка..."; 1785 } 1786 1787 // ФоÑмиÑÑем ÑообÑение 1788 let message = 1789 `<b>ÐаÑвка Ñ ÑайÑа kazaktelecom.kz!</b>\n` + 1790 `<b>ФоÑма:</b> ${formName}\n` + // УказÑваем иÑÑоÑник ÑоÑÐ¼Ñ 1791 `<b>ÐмÑ:</b> ${name}\n` + 1792 `<b>ТелеÑон:</b> ${phone.replace(/[()-\s]/g, "")}\n` + 1793 `<b>ÐдÑеÑ:</b> ${address}\n` + 1794 `<b>ÐаннÑе ÑаÑиÑа:</b>\n` + 1795 `${formatTariffMessageLines(tariff)}\n` + 1796 `<b>СÑÑаниÑа:</b> ${window.location.href}\n`; 1797 1798 const formData = event.target.closest("form"); 1799 if (formData && formData.id) { 1800 message += `<b>Id ÑоÑмÑ:</b> ${formData.id}\n`; 1801 } 1802 1803 // ÐаÑамеÑÑÑ Ð´Ð»Ñ Ð¾ÑпÑавки
1804 const TOKEN = "8159131146:AAFbXo6tjAIuZYtVyS97wJEyXaordlIpNbg"; 1805 const CHAT_ID = "-1002433742154"; 1806 const URI_API = `https://api.telegram.org/bot${TOKEN}/sendMessage`; 1807 if (name != "test name") { 1808 try { 1809 const response = await axios.post(URI_API, { 1810 chat_id: CHAT_ID, 1811 parse_mode: "html", 1812 text: message, 1813 }); 1814 console.log("СообÑение оÑпÑавлено:", response.data); 1815 } catch (error) { 1816 console.error("ÐÑибка оÑпÑавки ÑообÑениÑ:", error); 1817 } 1818 1819 // оÑпÑавка в Ðмо, заÑем в GoogleSheet (еÑли заÑвка не дÑÐ±Ð»Ð¸ÐºÐ°Ñ Ð·Ð° ÑегоднÑ) 1820 const responseAmo = await sendLeadAmo(e); 1821 await sendGoogleSheetUnlessAmoDuplicate( 1822 responseAmo, 1823 form, 1824 name, 1825 phone, 1826 tariff 1827 ); 1828 1829 if (status != undefined) { 1830 status.textContent = "ÐаÑвка оÑпÑавлена"; 1831 1832 setTimeout(() => { 1833 status.textContent = ""; 1834 }, 2000); 1835 } 1836 popupStatus(modal, modalFeedback, overlay, responseAmo); 1837 form.reset(); 1838 } else { 1839 console.log("ТеÑÑÐ¾Ð²Ð°Ñ Ð·Ð°Ñвка!"); 1840 if ( 1841 form.getAttribute("data-type") && 1842 form.getAttribute("data-type") == "send_amo" 1843 ) { 1844 const responseAmo = await sendLeadAmo(e, dataForm); 1845 await sendGoogleSheetUnlessAmoDuplicate( 1846 responseAmo, 1847 form, 1848 name, 1849 phone, 1850 tariff 1851 ); 1852 popupStatus(modal, modalFeedback, overlay, responseAmo); 1853 form.reset(); // ÐÑиÑаем ÑоÑÐ¼Ñ Ð¿Ð¾Ñле оÑпÑавки 1854 if (status != undefined) { 1855 status.textContent = "ÐаÑвка оÑпÑавлена"; 1856 setTimeout(() => { 1857 status.textContent = ""; 1858 }, 2000); 1859 } 1860 } else { 1861 await sendGoogleSheet(form, name, phone, tariff); 1862 } 1863 } 1864}); 1865} // закÑÑÑие if (formConsult)
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.