//манипуляции с ответом апи /* v1.4.49 - api_response */ function api_response(response) { //console.log('2'); if (response.data) { response.data.forEach(function (item) { //вставка if (item.method == 'append') { $(item.selector).append(item.content); } else if (item.method == 'prepend') { $(item.selector).prepend(); } else if (item.method == 'html') { $(item.selector).html(item.content); } else if (item.method == 'text') { $(item.selector).text(item.content); } else if (item.method == 'replaceWith') { $(item.selector).replaceWith(item.content); } //прокрутка else if (item.method == 'scrollTop') { var div = $(item.selector); div.scrollTop(div.prop('scrollHeight')); } else if (item.method == 'scroll') { //скрол $('html, body').animate({ scrollTop: $(item.selector).offset().top }, 1000); } //показать/скрыть else if (item.method == 'show') { $(item.selector).show(); } else if (item.method == 'hide') { $(item.selector).hide(); } else if (item.method == 'remove') { $(item.selector).remove(); } //атрибуты else if (item.method == 'prop') { $(item.selector).prop(item.prop, item.content); } else if (item.method == 'removeAttr') { $(item.selector).removeAttr(item.content); } else if (item.method == 'addClass') { $(item.selector).addClass(item.prop, item.content); } else if (item.method == 'removeClass') { $(item.selector).removeClass(item.content); } //алерт else if (item.method == 'alert') { alert(item.content); } //переадресация else if (item.method == 'location') { window.location.href = item.content; } //обновление else if (item.method == 'reload') { window.location.reload(); } //окно, тут заменить на свое окно если не бутстрап else if (item.method == 'modal') { $(item.selector).modal(); } //выполнение любого скрипта else if (item.method == 'script') { $('body').append(item.content); } else { alert(item.method); } }); } //todo код с ошибкой, сделать в всплывающем окне if (response.error_text) { alert(response.error_text); } else { if (response._error) alert(response._error); } } $(document).ready(function () { //валидация форм if ($.isFunction($.fn.validate)) { $('form.validate').each(function () { $(this).validate({ //настройка стилей валидации //.form-group обертка для всех полей errorPlacement: function (error, element) { error.appendTo(element.closest(".form-group")); }, highlight: function (element, errorClass, validClass) { //console.log('highlight'); $(element).addClass(errorClass); $(element).closest('.form-group').addClass(errorClass); }, unhighlight: function (element, errorClass, validClass) { //console.log('unhighlight'); $(element).removeClass(errorClass); $(element).closest('.form-group').removeClass(errorClass); } }) }); } //очитска урл от путстых значений $('form.form_clear').submit(function () { $(this).find('select,input').each(function () { if ($(this).val() == '' || $(this).val() == '0-0') $(this).removeAttr('name'); }); }); //отправка формы аджаксом - v1.2.22 $(document).on('submit', 'form.ajax', function () { var form = $(this), formData = new FormData($(this).get(0)), //путь куда отправляется форма action = $(this).data('action'), //окно которое открывается при успехе //window_success = $(this).data('window_success'), //блок куда показывать ошибки сгенерированные на пхп //message_box = $('.message_box',this), valid = true; //обработку делаем только если указан data-action, иначе форма ведет себя как обычная if (action) { //валидация if ($(this).hasClass('validate')) { //jquery_validate.js if ($.isFunction($.fn.validate)) { valid = false; if ($(this).valid()) { valid = true; } } } //делаем отправку только если форма валидная if (valid) { $.ajax({ url: action, type: $(form).attr('method'), dataType: 'json', contentType: false, processData: false, data: formData, cache: false, beforeSend: function () { $(form).find('button[type=submit]').addClass('disabled'); }, success: function (json, textStatus) { //очистка формы if (json.success) { $('input:not([type=submit]):not([name=captcha]):not([type=hidden]),textarea,select', form).prop('value', null); } api_response(json); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); }, complete: function (XMLHttpRequest, textStatus) { setTimeout(function () { $(form).find('button[type=submit]').removeClass('disabled'); }, 1000); } }); } return false; } }); //аналоги form.ajax не для форм (ссылки, кнопки и т.д.) $(document).on('click', '[data-api*="/"]', function (e) { e.preventDefault(); var $data = $(this).data(), $url = $data.api, $btn = $(this); //если уже нажали и небыло ответа аджакса то ничего не делать if (!$btn.hasClass('js_wait')) { $btn.addClass('js_wait'); //удаляем датаатрибут чтобы не дублировать в запросе delete $data.api; $.ajax({ method: "GET", type: 'JSON', url: $url, data: $data, cache: false }).done(function ($response) { api_response($response); }).fail(function () { alert("error"); }).always(function () { $btn.removeClass('js_wait'); }); //возвращаем назад дата атрибут $data.api = $url; } //return false; }); //мультичексбокс $(document).on("change", '.form_multi_checkbox .data input', function () { var arr = []; var i = 0; $(this).parents('.data').find('input:checked').each(function () { arr[i] = $(this).val(); i++; }); $(this).parents('.data').next('input').val(arr); }); //min-max $(document).on("change", '.form_input2 input', function () { var min = parseInt($(this).parents('.form_input2').find('input.form_input2_1').val()); var max = parseInt($(this).parents('.form_input2').find('input.form_input2_2').val()); $(this).parents('.form_input2').find('input[type=hidden]').val(min + '-' + max); }); //открытие языка $(document).on("click", '.languages_title', function () { $(this).toggleClass('active'); $(this).next().toggleClass('open'); }); //закрытие языка $(document).on("click", function (e) { if (!$(e.target).closest(".languages_title, .languages_drop").length) { $('.languages_drop').removeClass('open'); $('.languages_title').removeClass('active'); } }); //открытие меню $(document).on("click", '.mobile_btn', function () { $(this).toggleClass('active'); $('.mobile_menu').toggleClass('open'); $('body').toggleClass('locked'); }); //running line $('.running_line').marquee({ duration: 12000, duplicated: true, pauseOnHover: true, startVisible: true, gap: 24, }); $('.logo_line').marquee({ duration: 15000, duplicated: true, pauseOnHover: true, startVisible: true, gap: 24, }); lax.init(); lax.addDriver("scrollDriver", function () { return window.scrollY; }); let easing = "easeInOutQuad"; let pieces = [{ y: "-313", x: "-298", y1: "-313", x1: "-185", }, { y: "-155", x: "261", y1: "-155", x1: "226", }, { y: "-227", x: "-321", y1: "-227", x1: "-266", }, { y: "-461", x: "-375", y1: "-461", x1: "-226", }, { y: "-590", x: "419", y1: "-590", x1: "290", }, { y: "-308", x: "371", y1: "-308", x1: "170", }, { y: "-289", x: "-152", y1: "-289", x1: "-220", }, { y: "-803", x: "-154", y1: "-803", x1: "-154", }, { y: "-770", x: "251", y1: "-770", x1: "176", }, { y: "-297", x: "238", y1: "-297", x1: "220", } ]; pieces.forEach((p, i) => { lax.addElements(`.anim_item_${i + 1}`, { scrollDriver: { translateY: [ [`0`, `300`], { // 500: [p.y, 0], // Ширина экрана < 500 990: [0, 0], // Ширина экрана > 500 и < 900 1400: [p.y, 0], } // [`0`, `300`], // [p.y, 0], // { // easing // } ], translateX: [ [`0`, `300`], { // 500: [p.x, 0], // Ширина экрана < 500 990: [0, 0], // Ширина экрана > 500 и < 900 1400: [p.x, 0], } // [`0`, `300`], // [p.x, 0], // { // easing // } ] } }); }); lax.addElements( '.anim_text', { scrollDriver: { scale: [ ["0", "600"], [1, 0.3] ], opacity: [ ["0", "600"], [1, 0] ], } } ) lax.addElements( '.worth_anim_el', { scrollDriver: { translateY: [ // ["elInY", "elOutY"], // [100, 0], { // easing // } ["elInY", "elOutY"], { 576: [50, 0], 1400: [100, 0], } ], translateX: [ ["elInY", "elOutY"], { 576: [50, 0], 1400: [100, 0], } ], translateZ: [ ["elInY", "elOutY"], { 576: [50, 0], 1400: [100, 0], } ], } } ) var rellax = new Rellax('.rellax'); var scene = document.querySelector('.scene'); if (scene) { var parallaxInstance = new Parallax(scene) } var sceneTwo = document.querySelector('.sceneTwo'); if (sceneTwo) { var parallaxInstance = new Parallax(sceneTwo) } function calculator(e) { $('.calculator_select select').select2({ minimumResultsForSearch: Infinity, theme: 'calculator_select', }); const inputParent = $('.calculator_item_right'); if (inputParent.length) { inputParent.each(function () { let $input = $(this).find('input[type="text"]'), $buffer = $(this).find('.buffer'); $buffer.text($input.val()); $input.width($buffer.width()); $input.on('input', function () { $buffer.text($input.val()); $input.width($buffer.width()); }); }); } for (let e of document.querySelectorAll('input[type="range"]')) { console.log(e.value, e.max); e.style.setProperty('--value', +e.value >= +e.max ? +e.max : +e.value); e.style.setProperty('--min', e.min == '' ? '0' : e.min); e.style.setProperty('--max', e.max == '' ? '100' : e.max); e.addEventListener('input', () => e.style.setProperty('--value', e.value), { once: true }); } } calculator() window.calculatorWindow = calculator; var swiper = new Swiper(".modal_swiper", { slidesPerView: 1, spaceBetween: 24, navigation: { nextEl: ".swiper_arrow-next", prevEl: ".swiper_arrow-prev", }, breakpoints: { 771: { slidesPerView: 2, spaceBetween: 24, }, 1101: { slidesPerView: 3, spaceBetween: 24, }, }, }); });