position: ' smartlid_right',
isSmartlidVisible: 'smartlid_visible',
yaCounter40976409.reachGoal('SMARTLID');
styleForm: ' dark-space',
navBtnIcon: '<img src="/smartlid/img/line-menu.svg" height="18" width="18" alt="">',
callFormBtnIcon: '<img src="/smartlid/img/phone.svg" height="18" width="18" alt="">',
requestFormBtnIcon: '<img src="/smartlid/img/envelope.svg" height="18" width="18" alt="">',
placeholderName: 'Введите ваше имя',
placeholderPhone: 'Введите ваш телефон',
placeholderMail: 'Введите ваш email',
placeholderText: 'Введите ваше сообщение',
autoOpenPeriodicity: '1',
callFormTitle: 'Оставьте ваш номер телефона, и наш консультант свяжется с вами',
buttonTextCallForm: 'Отправить',
callFormIcon: '/smartlid/img/call.svg',
requestFormTitle: 'Оставьте сообщение, и наш консультант свяжется с вами',
buttonTextRequestForm: 'Отправить',
requestFormIcon: '/smartlid/img/mail.svg',
requestFormAddFile: true,
requestFormTelInput: true,
attantion: '<p class="smartlid__respond-fail">Внимание! Вы заполнили не все обязательные поля</p>',
failfile: '<p class="smartlid__respond-fail">Ошибка отправки файла, попробуйте еще раз</p>',
successmsgs: '<p class="smartlid__respond-success">Спасибо за обращение. Сообщение успешно отправлено</p>',
failmsgs: '<p class="smartlid__respond-fail">Сообщение не отправлено, попробуйте еще раз</p>',
agreementText: 'Я <span class="toggle--on">принимаю</span><span class="toggle--off">не принимаю</span> условия пользовательского соглашения',
checkLocalStorageTime: '1000',
referrer: document.referrer,
init: function (options) {
var settings = $.extend(defaults, options);
return this.each(function () {
$(this).append(methods.showButtons());
if ((defaults.referrer).length) {
var ref = new URL(defaults.referrer);
if (location.host !== ref.host) {
localStorage.setItem('userRef', ref.host);
localStorage.setItem('userRef', 'Не удалось определить источник перехода на сайт');
createButtons: function () {
let smartLid = $('<div>').attr({
class: 'smartlid' + defaults.position + ' ' + defaults.isSmartlidVisible,
let smartLidRounds = $('<span>').attr({
if (defaults.callForm && !defaults.requestForm && !defaults.contactForm) {
let smartLidNavButton = $('<button>').attr({
class: 'smartlid__call-button',
}).html(defaults.callFormBtnIcon);
smartLidNavButton.click(function () {
methods.showModal(methods.createCallForm().attr('class'));
$(this).attr("disabled", "disabled");
$(this).attr("disabled", false);
smartLid.append(smartLidNavButton.append(smartLidRounds).append(smartLidRounds.clone()).append(smartLidRounds.clone()));
} else if (!defaults.callForm && defaults.requestForm && !defaults.contactForm) {
console.log('defaults.requestForm');
var smartLidNavButton = $('<button>').attr({
class: 'smartlid__request-button',
}).html(defaults.requestFormBtnIcon);
smartLidNavButton.click(function () {
methods.showModal(methods.createRequestForm().attr('class'));
$(this).attr("disabled", "disabled");
$(this).attr("disabled", false);
smartLid.append(smartLidNavButton.append(smartLidRounds).append(smartLidRounds.clone()).append(smartLidRounds.clone()));
} else if (!defaults.callForm && !defaults.requestForm && defaults.contactForm) {
console.log('defaults.contactForm');
let smartLidNavButton = $('<button>').attr({
class: 'smartlid__nav-button',
}).html(defaults.navBtnIcon);
let smartLidModalButtons = $('<div>').attr({
class: 'smartlid__modal-buttons smartlid__modal-buttons_hidden'
let smartLidCallButton = $('<button>');
smartLidCallButton.attr({
class: 'smartlid__call-button',
}).html(defaults.callFormBtnIcon);
smartLidModalButtons.append(smartLidCallButton);
smartLidCallButton.click(function () {
methods.showModal(methods.createCallForm().attr('class'));
$(this).attr("disabled", "disabled");
$(this).attr("disabled", false);
if (defaults.requestForm) {
let smartLidRequestButton = $('<button>');
smartLidModalButtons.append(smartLidRequestButton);
smartLidRequestButton.attr({
class: 'smartlid__request-button',
}).html(defaults.requestFormBtnIcon);
smartLidRequestButton.click(function () {
methods.showModal(methods.createRequestForm().attr('class'));
$(this).attr("disabled", "disabled");
$(this).attr("disabled", false);
smartLidNavButton.click(function () {
smartLidModalButtons.toggleClass("smartlid__modal-buttons_open");
smartLidModalButtons.toggleClass("smartlid__modal-buttons_hidden");
smartLidRounds.appendTo(smartLidNavButton);
smartLidRounds.clone().appendTo(smartLidNavButton);
smartLidRounds.clone().appendTo(smartLidNavButton);
smartLid.append(smartLidNavButton).append(smartLidModalButtons);
$('.smartlid__call-button_custom').click(function () {
methods.showModal(methods.createCallForm().attr('class'));
$(this).attr("disabled", "disabled");
$(this).attr("disabled", false);
if (defaults.requestForm) {
$('.smartlid__request-button_custom').click(function () {
methods.showModal(methods.createRequestForm().attr('class'));
$(this).attr("disabled", "disabled");
$(this).attr("disabled", false);
return !isNaN(parseFloat(n)) && isFinite(n);
if(isNumber(defaults.autoOpenPeriodicity) && defaults.autoOpenForm) {
let limit, localStorageInitTime, getStateTime;
if(defaults.autoOpenTime > 3000){
getStateTime = defaults.autoOpenTime - defaults.checkLocalStorageTime;
limit = defaults.autoOpenPeriodicity * 3600 * 1000;
localStorageInitTime = localStorage.getItem('sLlocalStorageInitTime');
if (localStorageInitTime === null) {
localStorage.setItem('sLlocalStorageInitTime', +new Date());
methods.autoOpenModal(defaults.checkLocalStorageTime);
} else if(+new Date() - localStorageInitTime > limit){
localStorage.setItem('localStorageInitTime', +new Date());
methods.autoOpenModal(defaults.checkLocalStorageTime);
createModal: function (params) {
let smartLidModal = $('<div>').attr({
class: 'smartlid__modal' + defaults.styleForm,
if (params == methods.createCallForm().attr('class')) {
smartLidModal.fadeIn(function () {
$(this).append(methods.createCallForm().addClass('smartlid__form_open').append(methods.closeModal(smartLidModal)));
smartLidModal.addClass('smartlid__modal_open');
if (params == methods.createRequestForm().attr('class')) {
smartLidModal.fadeIn(function () {
$(this).append(methods.createRequestForm().addClass('smartlid__form_open').append(methods.closeModal(smartLidModal)));
closeModal: function (smartLidModal) {
let smartLidCloseButton = $('<button>').attr({
class: 'smartlid__close-button',
smartLidCloseButton.click(function (event) {
smartLidModal.fadeOut(function () {
$(smartLidModal).mouseup(function (e) {
var div = $(".smartlid__form");
div.has(e.target).length === 0) {
smartLidModal.fadeOut(function () {
return smartLidCloseButton;
initLocalStorage: function() {
if(defaults.autoOpenForm) {
let limit = defaults.autoOpenPeriodicity * 3600 * 1000;
let localStorageInitTime = localStorage.getItem('sLlocalStorageInitTime');
if (localStorageInitTime === null) {
localStorage.setItem('sLlocalStorageInitTime', +new Date());
} else if(+new Date() - localStorageInitTime > limit){
localStorage.setItem('localStorageInitTime', +new Date());
autoOpenModal: function (openTime) {
if(defaults.callForm && defaults.autoOpenForm === 'callForm') {
methods.showModal(methods.createCallForm().attr('class'));
if(defaults.requestForm && defaults.autoOpenForm === 'requestForm') {
methods.showModal(methods.createRequestForm().attr('class'));
createCallForm: function () {
let callForm = $('<form>').attr({
class: 'smartlid__form smartlid__form_call',
enctype: 'multipart/form-data',
let formImages = $('<img>').attr({
class: 'smartlid__form-icon',
src: defaults.callFormIcon,
let formTitle = $('<div>').attr({
class: 'smartlid__form-title'
class: 'smartlid__default-msgs'
}).html(defaults.callFormTitle))
.append($('<div>').attr({
class: 'smartlid__respond-msgs'
.append($('<div>').attr({
class: 'smartlid__preloader'
let inpName = $('<input>').attr({
class: 'smartlid__input smartlid__input_name',
placeholder: defaults.placeholderName,
let inpTel = $('<input>').attr({
class: 'smartlid__input smartlid__input_tel',
placeholder: defaults.placeholderPhone,
let inpRef = $('<input>').attr({
class: 'smartlid__input smartlid__input_ref',
value: localStorage.getItem('userRef'),
if (defaults.agreement) {
var checkboxWrapper = $('<div>').attr({
class: 'smartlid__checkbox-wrapper'
var inpCheckbox = $('<input>').attr({
class: 'smartlid__checkbox smartlid__checkbox_agreement',
id: 'smartlid__checkbox_agreement',
checked: defaults.agreementIsActive,
let inputCheckboxLabel = $('<label>').attr({
for: 'smartlid__checkbox_agreement',
class: 'smartlid__label smartlid__label_agreement'
let checkboxLink = $('<a>').attr({
href: defaults.agreementLink,
}).html(defaults.agreementText);
checkboxWrapper.append(inpCheckbox).append(inputCheckboxLabel.append(checkboxLink));
if (defaults.callFormAddFile) {
var fileWrapper = $('<div>').attr({
class: 'smartlid__file-wrapper'
var fileName = $('<input>').attr({
class: 'smartlid__input smartlid__file-name',
placeholder: 'Прикрепить файл',
let inputFileLabel = $('<label>').attr({
for: 'smartlid__input_file',
class: 'smartlid__label smartlid__label_file'
let inpFile = $('<input>').attr({
class: 'smartlid__input smartlid__input_file',
id: 'smartlid__input_file'
fileName.val($(this).val().replace(/.*\\/, ""));
fileWrapper.append(fileName).append(inputFileLabel).append(inpFile);
let formButton = $('<button>').attr({
class: 'smartlid__form-button',
}).html(defaults.buttonTextCallForm);
formButton.click(function (event) {
if (defaults.agreement) {
if (inpCheckbox.is(":checked")) {
methods.sendMail($(callForm).attr('id'));
formTitle.find('.smartlid__default-msgs').css('display', 'none');
formTitle.find('.smartlid__respond-msgs').html('<p class="smartlid__respond-fail">Вы не приняли условия пользовательского соглашения</p>');
formTitle.find('.smartlid__default-msgs').css('display', 'block');
formTitle.find('.smartlid__respond-msgs').html('');
methods.sendMail($(callForm).attr('id'));
callForm.append(formImages).append(formTitle).append(inpName).append(inpTel).append(inpRef).append(fileWrapper).append(checkboxWrapper).append(formButton);
createRequestForm: function () {
let requestForm = $('<form>').attr({
class: 'smartlid__form smartlid__form_request',
enctype: 'multipart/form-data'
let formImages = $('<img>').attr({
class: 'smartlid__form-icon',
alt: 'Форма обратной связи',
src: defaults.requestFormIcon,
let formTitle = $('<div>').attr({
class: 'smartlid__form-title'
class: 'smartlid__default-msgs'
}).html(defaults.requestFormTitle))
.append($('<div>').attr({
class: 'smartlid__respond-msgs'
.append($('<div>').attr({
class: 'smartlid__preloader'
let inpName = $('<input>').attr({
class: 'smartlid__input smartlid__input_name',
placeholder: defaults.placeholderName,
if (defaults.requestFormTelInput) {
var inpTel = $('<input>').attr({
class: 'smartlid__input smartlid__input_tel',
placeholder: defaults.placeholderPhone,
let inpMail = $('<input>').attr({
class: 'smartlid__input smartlid__input_mail',
placeholder: defaults.placeholderMail,
let inpText = $('<textarea>').attr({
class: 'smartlid__input smartlid__input_text',
placeholder: defaults.placeholderText,
let inpRef = $('<input>').attr({
class: 'smartlid__input smartlid__input_ref',
value: localStorage.getItem('userRef'),
if (defaults.agreement) {
var checkboxWrapper = $('<div>').attr({
class: 'smartlid__checkbox-wrapper'
var inpCheckbox = $('<input>').attr({
class: 'smartlid__checkbox smartlid__checkbox_agreement',
id: 'smartlid__checkbox_agreement',
checked: defaults.agreementIsActive,
let inputCheckboxLabel = $('<label>').attr({
for: 'smartlid__checkbox_agreement',
class: 'smartlid__label smartlid__label_agreement'
let checkboxLink = $('<a>').attr({
href: defaults.agreementLink,
}).html(defaults.agreementText);
checkboxWrapper.append(inpCheckbox).append(inputCheckboxLabel.append(checkboxLink));
if (defaults.requestFormAddFile) {
var fileWrapper = $('<div>').attr({
class: 'smartlid__file-wrapper'
var fileName = $('<input>').attr({
class: 'smartlid__input smartlid__file-name',
placeholder: 'Прикрепить файл',
let inputFileLabel = $('<label>').attr({
for: 'smartlid__input_file',
class: 'smartlid__label smartlid__label_file'
let inpFile = $('<input>').attr({
class: 'smartlid__input smartlid__input_file',
id: 'smartlid__input_file'
fileName.val($(this).val().replace(/.*\\/, ""));
fileWrapper.append(fileName).append(inputFileLabel).append(inpFile);
let formButton = $('<button>').attr({
class: 'smartlid__form-button',
}).html(defaults.buttonTextRequestForm);
formButton.click(function (event) {
if (defaults.agreement) {
if (inpCheckbox.is(":checked")) {
methods.sendMail($(requestForm).attr('id'));
formTitle.find('.smartlid__default-msgs').css('display', 'none');
formTitle.find('.smartlid__respond-msgs').html('<p class="smartlid__respond-fail">Вы не приняли условия пользовательского соглашения</p>');
formTitle.find('.smartlid__default-msgs').css('display', 'block');
formTitle.find('.smartlid__respond-msgs').html('');
methods.sendMail($(requestForm).attr('id'));
requestForm.append(formImages).append(formTitle).append(inpName).append(inpTel).append(inpMail).append(inpRef).append(fileWrapper).append(inpText).append(checkboxWrapper).append(formButton);
sendMail: function (formid) {
var formId = "#" + formid;
var fd = new FormData(document.querySelector(formId));
url: "/smartlid/php/smartlid.php",
beforeSend: function () {
$(formId).find('.smartlid__preloader').css('display', 'block');
$(formId).find('.smartlid__default-msgs').css('display', 'none');
$(formId).find('.smartlid__form-button').prop('disabled', true);
$(formId).find('.smartlid__respond-msgs').html('Отправка письма');
success: function (data) {
$(formId).find('.smartlid__preloader').css('display', 'none');
$(formId).find('.smartlid__respond-msgs').html('').append(defaults.attantion);
$(formId).find('.smartlid__respond-msgs').html('').append(defaults.successmsgs);
$(formId).find('.smartlid__respond-msgs').html('').append(defaults.failmsgs);
$(formId).find('.smartlid__respond-msgs').html('').append(defaults.failfile);
$(formId).find('.smartlid__default-msgs').css('display', 'block');
$(formId).find('.smartlid__respond-msgs').html('');
$(formId).find('.smartlid__form-button').prop("disabled", false);
complete: function (data) {
if (data.responseText == 'successmsgs') {
$(formId).find($('input').not(':input[type=hidden]')).val('');
$(formId).find($('textarea').val(''));
showModal: function (formClass) {
methods.initLocalStorage();
return $('body').append(methods.createModal(formClass));
showButtons: function () {
return methods.createButtons();
$.fn.smartLid = function (method) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
$.error('Метод ' + method + ' не найден');