Upgrade live reactive preview with sticky container, real-time sync, and WYSIWYG click-to-edit

This commit is contained in:
nertyog 2026-10-20 17:15:08 +03:00
parent dfed664d20
commit a5ee1acff9
2 changed files with 210 additions and 110 deletions

View File

@ -420,6 +420,35 @@ body.dark .nat-settings-license-row {
background: rgba(255, 255, 255, 0.03) !important;
border-color: #334155 !important;
}
@keyframes natGradientShift {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
.preview-clickable-block:hover {
outline: 1px dashed rgba(255, 255, 255, 0.8) !important;
outline-offset: 2px !important;
transform: translateY(-1px);
}
html.nat-dark-mode #nat-slide-preview-sticky-container,
body.nat-dark-mode #nat-slide-preview-sticky-container,
[data-bs-theme="dark"] #nat-slide-preview-sticky-container,
[data-theme="dark"] #nat-slide-preview-sticky-container,
.dark #nat-slide-preview-sticky-container,
.dark-theme #nat-slide-preview-sticky-container {
background: #1e293b !important;
border-color: #334155 !important;
box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
}
html.nat-dark-mode #nat-slide-preview-sticky-container label,
body.nat-dark-mode #nat-slide-preview-sticky-container label {
color: #f1f5f9 !important;
}
html.nat-dark-mode #slide-preview-bar-wrapper,
body.nat-dark-mode #slide-preview-bar-wrapper {
background: #0f172a !important;
border-color: #334155 !important;
}
</style>
<div id="content">
<div class="page-header">
@ -805,6 +834,36 @@ body.dark .nat-settings-license-row {
<!-- Right panel: slide editor (col-sm-9) -->
<div class="col-sm-9" id="slide-editor-panel" style="display: none; padding-left: 15px;">
<!-- Sticky Live Preview Header (Always Visible) -->
<div id="nat-slide-preview-sticky-container" style="position: sticky; top: 10px; z-index: 99; background: #ffffff; border: 1px solid #cbd5e1; border-radius: 8px; padding: 12px 15px; margin-bottom: 15px; box-shadow: 0 4px 12px rgba(0,0,0,0.06);">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; flex-wrap: wrap; gap: 8px;">
<label style="font-weight: bold; margin-bottom: 0; font-size: 13px; color: #1e293b;">
<i class="fa fa-eye" style="color: #ec741c;"></i> Живой предпросмотр полосы (Live Preview):
</label>
<div style="display: flex; gap: 10px; align-items: center;">
<!-- Viewport Switcher -->
<div class="btn-group btn-group-xs" id="preview-viewport-switch">
<button type="button" class="btn btn-default active preview-viewport-btn" data-viewport="desktop" title="Предпросмотр на компьютере"><i class="fa fa-desktop"></i> Desktop</button>
<button type="button" class="btn btn-default preview-viewport-btn" data-viewport="mobile" title="Предпросмотр на смартфоне"><i class="fa fa-mobile"></i> Mobile</button>
</div>
<!-- Language Switcher -->
<div class="btn-group btn-group-xs" id="preview-lang-switch">
{% for language in languages %}
<button type="button" class="btn btn-default {% if loop.first %}active{% endif %} preview-lang-btn" data-lang="{{ language.language_id }}"><img src="language/{{ language.code }}/{{ language.code }}.png" /> {{ language.code|upper }}</button>
{% endfor %}
</div>
</div>
</div>
<div id="slide-preview-bar-wrapper" style="border: 1px solid #cbd5e1; border-radius: 6px; overflow: hidden; background: #f8fafc; padding: 0; transition: all 0.3s ease;">
<div id="slide-preview-bar" style="position: relative; min-height: 42px; display: flex; align-items: center; justify-content: center; gap: 15px; padding: 10px 40px 10px 20px; transition: all 0.2s ease;">
<!-- Live preview will render here -->
</div>
</div>
<div style="display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 11px; color: #94a3b8;">
<span><i class="fa fa-info-circle"></i> Кликните по элементу в превью, чтобы перейти к его настройке</span>
<span id="preview-active-title" style="font-weight: 600; color: #64748b;"></span>
</div>
</div>
<ul class="nav nav-tabs" id="slide-sub-tabs" style="margin-bottom: 15px;">
<li class="active"><a href="#slide-sub-blocks" data-bs-toggle="tab" data-toggle="tab"><i class="fa fa-puzzle-piece"></i> Блоки и макет</a></li>
<li><a href="#slide-sub-settings" data-bs-toggle="tab" data-toggle="tab"><i class="fa fa-cog"></i> Настройки слайда</a></li>
@ -1320,23 +1379,7 @@ body.dark .nat-settings-license-row {
<!-- Visual Layout Builder -->
<div style="background: #fff; border: 1px solid #ddd; border-radius: 8px; padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.05);">
<div style="background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; padding: 15px; margin-bottom: 20px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; flex-wrap: wrap; gap: 8px;">
<label style="font-weight: bold; margin-bottom: 0;"><i class="fa fa-eye"></i> Интерактивный предпросмотр слайда:</label>
<div style="display: flex; gap: 10px; align-items: center;">
<!-- Viewport Switcher -->
<div class="btn-group btn-group-xs" id="preview-viewport-switch">
<button type="button" class="btn btn-default active preview-viewport-btn" data-viewport="desktop"><i class="fa fa-desktop"></i> Desktop</button>
<button type="button" class="btn btn-default preview-viewport-btn" data-viewport="mobile"><i class="fa fa-mobile"></i> Mobile</button>
</div>
<!-- Language Switcher -->
<div class="btn-group btn-group-xs" id="preview-lang-switch">
{% for language in languages %}
<button type="button" class="btn btn-default {% if loop.first %}active{% endif %} preview-lang-btn" data-lang="{{ language.language_id }}"><img src="language/{{ language.code }}/{{ language.code }}.png" /> {{ language.code|upper }}</button>
{% endfor %}
</div>
</div>
</div>
<div id="slide-preview-bar-wrapper" style="border: 1px solid #cbd5e1; border-radius: 4px; overflow: hidden; background: #f1f5f9; padding: 10px 0;">
<div id="slide-preview-bar" style="min-height: 40px; display: flex; align-items: center; justify-content: center; gap: 15px; padding: 10px 20px; transition: all 0.3s ease;">
<!-- Live preview will render here -->
@ -3079,6 +3122,7 @@ function selectBlock(idx, event) {
if (event) event.stopPropagation();
currentBlockIndex = idx;
renderActiveBlocks();
if (typeof renderPreview === 'function') { renderPreview(); }
var block = slides[currentSlideIndex].blocks[idx];
$('#block-editor-container').show();
@ -4419,18 +4463,42 @@ function renderPreview(langId) {
if (typeof currentSlideIndex === 'undefined' || currentSlideIndex < 0 || !slides[currentSlideIndex]) {
$('#slide-preview-bar').html('<span style="opacity: 0.5; font-style: italic;">Выберите или добавьте слайд</span>');
$('#preview-active-title').text('');
return;
}
var slide = slides[currentSlideIndex];
var $preview = $('#slide-preview-bar');
if (slide.title) {
$('#preview-active-title').text('Слайд: ' + slide.title);
} else {
$('#preview-active-title').text('');
}
// Dynamically load Google Font if specified
if (slide.font_family) {
var fontSlug = slide.font_family.replace(/\s+/g, '+');
if (!document.getElementById('nat-font-link-' + fontSlug)) {
var flink = document.createElement('link');
flink.id = 'nat-font-link-' + fontSlug;
flink.rel = 'stylesheet';
flink.href = 'https://fonts.googleapis.com/css2?family=' + fontSlug + ':wght@400;600;700&display=swap';
document.head.appendChild(flink);
}
}
// Apply slide styling
var style = 'min-height: 40px; display: flex; align-items: center; justify-content: center; gap: 15px; padding: 10px 20px; transition: all 0.3s ease;';
var style = 'position: relative; min-height: 42px; display: flex; align-items: center; justify-content: center; gap: 15px; padding: 10px 40px 10px 20px; transition: all 0.2s ease;';
// Background
if (slide.bg_type === 'gradient') {
style += 'background: ' + (slide.bg_gradient || 'linear-gradient(90deg, #ff416c, #ff4b2b)') + ';';
var grad = slide.bg_gradient || 'linear-gradient(90deg, #ff416c, #ff4b2b)';
if (slide.gradient_animated == '1' || $('#slide-gradient-animated').is(':checked')) {
style += 'background: ' + grad + '; background-size: 200% 200%; animation: natGradientShift 4s ease infinite;';
} else {
style += 'background: ' + grad + ';';
}
} else if (slide.bg_type === 'pattern') {
var bgPatternImg = $('#input-slide-bg-pattern').val();
if (bgPatternImg && bgPatternImg.indexOf('placeholder.png') === -1) {
@ -4454,14 +4522,10 @@ function renderPreview(langId) {
$preview.empty();
if (!slide.blocks || slide.blocks.length === 0) {
$preview.append('<span style="opacity: 0.5; font-style: italic;">Пустой слайд (добавьте блоки справа)</span>');
return;
}
slide.blocks.forEach(function(block) {
$preview.append('<span style="opacity: 0.5; font-style: italic;">Пустой слайд (добавьте блоки в конструкторе)</span>');
} else {
slide.blocks.forEach(function(block, idx) {
var blockHtml = '';
// Inline style for block overrides
var blockStyle = '';
if (block.font_size) blockStyle += 'font-size: ' + block.font_size + ';';
if (block.font_weight) blockStyle += 'font-weight: ' + block.font_weight + ';';
@ -4494,21 +4558,21 @@ function renderPreview(langId) {
var btnText = (block.text && block.text[previewLangId]) ? block.text[previewLangId] : 'Кнопка';
var btnBg = block.bg || '#e74c3c';
var btnColor = block.color || '#ffffff';
var btnStyle = 'background: ' + btnBg + '; color: ' + btnColor + '; padding: 4px 12px; border-radius: 4px; font-weight: bold; text-decoration: none; font-size: 12px; display: inline-block;';
blockHtml = '<span style="' + btnStyle + blockStyle + '">' + btnText + '</span>';
var btnStyle = 'background: ' + btnBg + '; color: ' + btnColor + '; padding: 4px 14px; border-radius: 4px; font-weight: bold; text-decoration: none; font-size: 12px; display: inline-block; box-shadow: 0 2px 4px rgba(0,0,0,0.15); transition: all 0.2s ease;';
blockHtml = '<span class="preview-btn-elem" style="' + btnStyle + blockStyle + '">' + btnText + '</span>';
} else if (block.type === 'timer') {
var timerColor = block.color ? 'color: ' + block.color + ';' : '';
var timeStr = block.timer_mode === 'evergreen' ? (block.timer_minutes + 'м') : '00:00:00';
blockHtml = '<span style="font-family: monospace; font-weight: bold;' + timerColor + blockStyle + '"><i class="fa fa-clock-o"></i> ' + timeStr + '</span>';
var timeStr = block.timer_mode === 'evergreen' ? ((block.timer_minutes || 5) + 'м 00с') : '23:59:59';
blockHtml = '<span style="display: inline-flex; align-items: center; gap: 5px; font-family: monospace; font-size: 13px; font-weight: bold; background: rgba(0,0,0,0.2); padding: 3px 8px; border-radius: 4px;' + timerColor + blockStyle + '"><i class="fa fa-clock-o"></i> ' + timeStr + '</span>';
} else if (block.type === 'shipping') {
var shText = (block.shipping_text_before && block.shipping_text_before[previewLangId]) ? block.shipping_text_before[previewLangId] : 'До бесплатной доставки осталось {diff}';
shText = shText.replace('{diff}', '1000');
shText = shText.replace('{diff}', '500 грн');
blockHtml = '<div style="display: inline-flex; align-items: center; gap: 8px;' + blockStyle + '">';
blockHtml += ' <span style="font-size:11px;">' + shText + '</span>';
blockHtml += ' <div style="width: 60px; height: 8px; background: ' + (block.color_bg || '#e2e8f0') + '; border-radius: 4px; overflow:hidden;">';
blockHtml += ' <div style="width: 60%; height: 100%; background: ' + (block.color_fill || '#2ecc71') + ';"></div>';
blockHtml += ' <span style="font-size:12px;">' + shText + '</span>';
blockHtml += ' <div style="width: 70px; height: 8px; background: ' + (block.color_bg || '#e2e8f0') + '; border-radius: 4px; overflow:hidden;">';
blockHtml += ' <div style="width: 65%; height: 100%; background: ' + (block.color_fill || '#2ecc71') + ';"></div>';
blockHtml += ' </div>';
blockHtml += '</div>';
@ -4516,33 +4580,43 @@ function renderPreview(langId) {
var subPl = (block.subscribe_placeholder && block.subscribe_placeholder[previewLangId]) ? block.subscribe_placeholder[previewLangId] : 'Email...';
var subBtn = (block.subscribe_button_text && block.subscribe_button_text[previewLangId]) ? block.subscribe_button_text[previewLangId] : 'Ок';
blockHtml = '<div style="display: inline-flex; gap: 4px; align-items: center;' + blockStyle + '">';
blockHtml += ' <input type="text" placeholder="' + subPl + '" style="background: ' + (block.subscribe_input_bg || '#fff') + '; color: ' + (block.subscribe_input_color || '#333') + '; padding: 2px 6px; border: 1px solid #ccc; border-radius: 3px; font-size: 11px; width: 80px;" disabled />';
blockHtml += ' <span style="background: ' + (block.subscribe_button_bg || '#3498db') + '; color: ' + (block.subscribe_button_color || '#fff') + '; padding: 2px 8px; border-radius: 3px; font-size: 11px; font-weight: bold;">' + subBtn + '</span>';
blockHtml += ' <input type="text" placeholder="' + subPl + '" style="background: ' + (block.subscribe_input_bg || '#fff') + '; color: ' + (block.subscribe_input_color || '#333') + '; padding: 3px 8px; border: 1px solid #ccc; border-radius: 3px; font-size: 11px; width: 90px;" disabled />';
blockHtml += ' <span style="background: ' + (block.subscribe_button_bg || '#3498db') + '; color: ' + (block.subscribe_button_color || '#fff') + '; padding: 3px 8px; border-radius: 3px; font-size: 11px; font-weight: bold;">' + subBtn + '</span>';
blockHtml += '</div>';
} else if (block.type === 'coupon') {
var cpText = (block.coupon_text && block.coupon_text[previewLangId]) ? block.coupon_text[previewLangId] : 'SALE10';
blockHtml = '<span style="border: 1px dashed ' + (block.coupon_border || '#d35400') + '; background: ' + (block.coupon_bg || '#f39c12') + '; color: ' + (block.coupon_color || '#fff') + '; padding: 2px 6px; border-radius: 3px; font-size: 11px; font-weight: bold;' + blockStyle + '"><i class="fa fa-ticket"></i> ' + cpText + '</span>';
var cpText = (block.coupon_text && block.coupon_text[previewLangId]) ? block.coupon_text[previewLangId] : (block.coupon_code && block.coupon_code[previewLangId] ? block.coupon_code[previewLangId] : 'SALE20');
blockHtml = '<span style="border: 1px dashed ' + (block.coupon_border || '#ffffff') + '; background: ' + (block.coupon_bg || 'rgba(255,255,255,0.2)') + '; color: ' + (block.coupon_color || '#ffffff') + '; padding: 3px 8px; border-radius: 4px; font-size: 12px; font-weight: bold; letter-spacing: 0.5px;' + blockStyle + '"><i class="fa fa-ticket"></i> ' + cpText + '</span>';
} else if (block.type === 'activity') {
var actText = (block.activity_text && block.activity_text[previewLangId]) ? block.activity_text[previewLangId] : 'Просмотров сегодня: {count}';
actText = actText.replace('{count}', '123');
var actText = (block.activity_text && block.activity_text[previewLangId]) ? block.activity_text[previewLangId] : 'Просмотров сейчас: {count}';
actText = actText.replace('{count}', '14');
var actColor = block.color ? 'color: ' + block.color + ';' : '';
blockHtml = '<span style="' + actColor + blockStyle + '"><i class="fa fa-' + (block.activity_icon || 'fire') + '"></i> ' + actText + '</span>';
blockHtml = '<span style="' + actColor + blockStyle + '"><i class="fa fa-' + (block.activity_icon || 'fire') + '" style="color: #f39c12;"></i> ' + actText + '</span>';
} else if (block.type === 'product') {
var pName = block.product_name || 'Товар';
blockHtml = '<span style="font-size: 11px; font-weight: bold;' + blockStyle + '"><i class="fa fa-shopping-bag"></i> ' + pName + '</span>';
var pName = block.product_name || 'Товар дня';
blockHtml = '<span style="display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: bold;' + blockStyle + '"><i class="fa fa-shopping-bag"></i> ' + pName + '</span>';
} else if (block.type === 'anim_icon') {
var iconColor = block.icon_color ? 'color: ' + block.icon_color + ';' : '';
blockHtml = '<i class="fa fa-' + (block.icon_type || 'bell') + '" style="font-size: ' + (block.icon_size || '16') + 'px; ' + iconColor + blockStyle + '"></i>';
}
$preview.append(blockHtml);
var isBlockActive = (typeof currentBlockIndex !== 'undefined' && currentBlockIndex === idx);
var activeOutline = isBlockActive ? 'outline: 2px solid #38bdf8; outline-offset: 3px; background: rgba(56, 189, 248, 0.15);' : '';
var blockItemWrapper = '<div class="preview-clickable-block" data-block-index="' + idx + '" title="Кликните для перехода к настройкам этого элемента" style="display: inline-flex; align-items: center; cursor: pointer; transition: all 0.15s ease; border-radius: 4px; padding: 2px 4px; ' + activeOutline + '">' + blockHtml + '</div>';
$preview.append(blockItemWrapper);
});
}
// Close Button in preview
if (slide.show_close !== '0' && $('#slide-show-close-select').val() !== '0') {
var closeColor = slide.text_color || '#ffffff';
var closeBtnHtml = '<button type="button" class="nat-preview-close-btn" title="Кнопка закрытия полосы" style="position: absolute; right: 12px; top: 50%; transform: translateY(-50%); background: transparent; border: none; font-size: 18px; line-height: 1; color: ' + closeColor + '; opacity: 0.65; cursor: pointer; padding: 2px 6px;">&times;</button>';
$preview.append(closeBtnHtml);
}
}
$(document).on('click', '.preview-lang-btn', function(e) {
e.preventDefault();
$('.preview-lang-btn').removeClass('active');
@ -4562,9 +4636,9 @@ $(document).on('click', '.preview-viewport-btn', function(e) {
$wrapper.css({
'max-width': '375px',
'margin': '0 auto',
'border': '8px solid #333',
'border-radius': '20px',
'box-shadow': '0 4px 16px rgba(0,0,0,0.15)',
'border': '8px solid #1e293b',
'border-radius': '24px',
'box-shadow': '0 8px 24px rgba(0,0,0,0.2)',
'transition': 'all 0.3s ease'
});
} else {
@ -4572,15 +4646,41 @@ $(document).on('click', '.preview-viewport-btn', function(e) {
'max-width': '100%',
'margin': '0',
'border': '1px solid #cbd5e1',
'border-radius': '4px',
'border-radius': '6px',
'box-shadow': 'none',
'transition': 'all 0.3s ease'
});
}
renderPreview();
});
// Click-to-edit listener from within the preview bar
$(document).on('click', '.preview-clickable-block', function(e) {
e.preventDefault();
var bIdx = parseInt($(this).attr('data-block-index'));
if (!isNaN(bIdx)) {
$('#slide-sub-tabs a[href="#slide-sub-blocks"]').tab('show');
if (typeof selectBlock === 'function') {
selectBlock(bIdx);
}
if ($('#block-editor-container').length && $('#block-editor-container').is(':visible')) {
$('html, body').animate({
scrollTop: $('#block-editor-container').offset().top - 140
}, 200);
}
}
});
// Global reactive listener: instant live updates on any input or change
$(document).on('input change keyup',
'#slide-title-input, #slide-status-select, #slide-text-color, #slide-text-color-hex, #slide-bg-type, #slide-bg-color, #slide-bg-color-hex, #slide-show-close-select, #slide-font-family, #slide-custom-css, #slide-gradient-color1, #slide-gradient-color2, #slide-gradient-angle, #slide-gradient-type, #slide-gradient-animated, #slide-gradient-anim-speed, #input-slide-bg-pattern, .block-field-input, .block-color-picker, .block-color-hex, .block-field-checkbox, select[data-field], #coupon-code-global, .block-field-image-input',
function() {
if (typeof renderPreview === 'function') {
renderPreview();
}
}
);
var recentColors = [];
try {
recentColors = JSON.parse(localStorage.getItem('nat_recent_colors') || '[]');

Binary file not shown.