jQuery(document).ready(function($) {
const history = $('#ml-history');
const optsBox = $('#ml-opts');
const startBtn = $('#ml-start');
const inputArea = $('#ml-input-area');
const textInput = $('#ml-text-input');
const submitBtn = $('#ml-submit-input');
const floatContainer = $('#ml-float-container'); // کانتینر جدید دکمهها
const modal = $('#ml-wiki-modal');
const modalContent = $('#ml-wiki-content');
const modalClose = $('.ml-wiki-close');
let userState = { name: '', phone: '', step: 'start' };
let qIndex = 0;
let keywords = [];
let userChoices = [];
// --- 1. رندر کردن دکمههای شناور ---
function renderFloatingButtons() {
if (!mlData.buttons || mlData.buttons.length === 0) return;
// اگر تنظیم شده باشد "فقط بعد از نتیجه"، فعلا مخفی بماند
if(mlData.extras.show_after_result == '1') {
floatContainer.hide();
}
let size = mlData.extras.btn_size || 55;
let btnStyle = `width:${size}px; height:${size}px;`;
mlData.buttons.forEach(btn => {
let tooltipHtml = btn.tooltip ? `
${btn.tooltip}
` : '';
let iconHtml = btn.icon ? ` ` : `📞 `;
let html = `
`;
floatContainer.append(html);
});
}
renderFloatingButtons();
// آپدیت لینکها هنگام کلیک (برای جایگزینی {history})
$(document).on('click', '.ml-float-btn', function(e) {
let rawLink = $(this).data('link');
if(!rawLink) return;
let choicesStr = userChoices.length ? userChoices.join(' > ') : 'هنوز انتخابی نشده';
let historyText = `نام: ${userState.name || '-'} | شماره: ${userState.phone || '-'} | انتخابها: ${choicesStr}`;
let finalLink = rawLink.replace('{history}', encodeURIComponent(historyText));
$(this).attr('href', finalLink);
});
// --- 2. لاجیک دیکشنری ---
$(document).on('click', '.ml-wiki-term', function() {
let title = $(this).data('key');
let desc = $(this).find('.ml-wiki-desc-hidden').html();
let img = $(this).find('.ml-wiki-img-hidden').attr('src');
let imgHtml = img ? ` ` : '';
modalContent.html(`${imgHtml}${title} ${desc}
`);
modal.fadeIn(300).css('display', 'flex');
});
modalClose.click(function() { modal.fadeOut(300); });
modal.click(function(e) { if(e.target === this) modal.fadeOut(300); });
// --- 3. جریان چت ---
startBtn.click(function() { $(this).hide(); askName(); });
function askName() {
userState.step = 'name';
addMsg('bot', 'سلام! لطفا **نام** خودت رو بگو:');
showInput('مثلا: علی');
}
function askPhone() {
userState.step = 'phone';
addMsg('bot', `خوشبختم ${userState.name} عزیز! 🌹 \nلطفا **شماره موبایلت** رو وارد کن:`);
showInput('مثلا: 0912...');
}
submitBtn.click(handleInput);
textInput.keypress(function(e) { if(e.which == 13) handleInput(); });
function handleInput() {
let val = textInput.val().trim();
if(!val) return;
addMsg('user', val);
textInput.val('');
inputArea.hide();
if(userState.step === 'name') {
userState.name = val;
askPhone();
} else if(userState.step === 'phone') {
if(val.length < 10) { addMsg('bot', 'لطفا یک شماره معتبر وارد کنید.'); showInput(); return; }
userState.phone = val;
saveLead();
userState.step = 'questions';
nextQuestion();
}
}
function saveLead() { $.post(mlData.ajax, { action: 'mobo_save_lead', name: userState.name, phone: userState.phone }); }
function nextQuestion() {
if (!mlData.questions || qIndex >= mlData.questions.length) { fetchResults(); return; }
let q = mlData.questions[qIndex];
let personalizedText = q.text.replace(/{name}/g, userState.name);
addMsg('bot', personalizedText);
setTimeout(() => { showOpts(q.options); }, 600);
}
function showOpts(options) {
optsBox.empty().show();
options.forEach(o => {
let btn = $(`${o.label} `);
btn.click(function() {
addMsg('user', o.label);
userChoices.push(o.label);
if(o.keyword) keywords.push(o.keyword);
optsBox.empty();
qIndex++;
setTimeout(nextQuestion, 400);
});
optsBox.append(btn);
});
scrollBottom();
}
function showInput(placeholder = '...') { textInput.attr('placeholder', placeholder); inputArea.css('display', 'flex'); textInput.focus(); scrollBottom(); }
function fetchResults() {
addMsg('bot', 'در حال تحلیل بازار...', false);
$.post(mlData.ajax, { action: 'mobo_lp_process', keywords: keywords }, function(res) {
if(mlData.extras.compare_msg) addMsg('bot', mlData.extras.compare_msg);
if(res.success) {
addMsg('bot', `نتایج مخصوص ${userState.name} عزیز:`, true);
addMsg('bot', res.data.html, true);
if(mlData.extras.enable_share == '1') addShareButton();
// اگر تنظیم شده که دکمهها بعد از نتیجه بیایند، الان نمایش بده
if(mlData.extras.show_after_result == '1') {
floatContainer.fadeIn(500).css('display','flex');
}
}
});
}
$('.ml-restart').click(function() {
history.empty(); qIndex = 0; keywords = []; userChoices = []; userState = { name: '', phone: '', step: 'start' };
startBtn.show(); optsBox.empty(); inputArea.hide();
// اگر دکمهها فقط در آخر بودند، دوباره مخفی شوند
if(mlData.extras.show_after_result == '1') floatContainer.hide();
});
function addMsg(type, text, isHtml = false) {
let name = type === 'bot' ? (mlData.texts.bot_name || 'مشاور') : (userState.name || 'شما');
let contentStr = text;
if(type === 'bot' && !isHtml && Array.isArray(mlData.wiki_items) && mlData.wiki_items.length > 0) contentStr = processWiki(text);
let content = isHtml ? text : `${contentStr}
`;
let avatarHtml = (type === 'bot' && mlData.design.bot_avatar) ? ` ` : '';
history.append(`${type === 'bot' ? avatarHtml : ''}
${name} ${content}
`);
scrollBottom();
}
function processWiki(text) {
let newText = text;
let styleClass = 'ml-wiki-style-' + (mlData.extras.wiki_style || 'dotted');
mlData.wiki_items.forEach(item => {
if(!item.key) return;
let regex = new RegExp(`(${item.key})`, 'gi');
let imgTag = item.img ? ` ` : '';
newText = newText.replace(regex, `${item.key}${item.desc} ${imgTag} `);
});
return newText;
}
function addShareButton() { /* ... */ }
function scrollBottom() { history.stop().animate({scrollTop: history[0].scrollHeight}, 800); }
});
Warning : session_start(): Session cannot be started after headers have already been sent in /home/tekraz/public_html/wp-content/themes/parskala/inc/auth/auth.php on line 0
مقایسه – فروشگاه اینترنتی تک راز جنوب
کارت گرافیک ایسوس مدل ROG Strix GeForce RTX...
21,540,000 تومان مشاهده و خرید محصول
×
لپ تاپ 16.2 اینچی اپل مدل MacBook Pro...
71,430,000 تومان مشاهده و خرید محصول
×
کارت گرافیک گیگابایت مدل GeForce_RTX_3090_EAGLE_OC_24G
36,980,000 تومان مشاهده و خرید محصول
×
لپ تاپ 13 اینچی اپل مدل MacBook Air...
33,410,000 تومان مشاهده و خرید محصول
×
رابطها :
نوع حافظه :
HDMI:
DisplayPort:
فضای نصب مورد نیاز :
مقدار حافظه :