خطا در بارگذاری نظرات.
');
}
},
error: function() {
container.html('خطا در ارتباط با سرور.
');
}
});
}
class SlideStories {
/** @param {string} id */
constructor(id) {
this.slide = document.querySelector(`[data-slide="${id}"]`);
// Only initialize for image stories
if (this.slide && this.slide.classList.contains('video-story')) {
return;
}
// Always start with the first slide when creating a new instance
this.active = 0;
this.storyContent = this.slide.querySelector('.story-slide-content');
this.productsData = JSON.parse(this.slide.getAttribute('data-products') || '{}');
this.init();
}
/** @param {Number} index */
activeSlide(index) {
this.active = index;
// Hide all items
this.items.forEach((item) => {
item.classList.remove('active');
item.querySelector('img').classList.remove('active');
});
// Show active item
this.items[index].classList.add('active');
const imageElement = this.items[index].querySelector('img');
imageElement.classList.add('active');
if (!imageElement.getAttribute('src').includes('story-loader-min.png')) {
// Image is already loaded
} else {
// Load the image
const attributeValue = imageElement.getAttribute('data-image-get');
const preloadImage = new Image();
preloadImage.src = attributeValue;
preloadImage.onload = () => {
imageElement.src = attributeValue;
};
}
// Update thumbnails
this.thumbItems.forEach((item, i) => {
item.classList.remove('active');
if (i <= index) {
item.classList.add('active');
}
});
// Load related content for this slide
this.loadSlideContent(index);
$(this.slide).find('.story-wrapper-close-related').click(() => {
$(this.slide).closest('[data-slide-ref]').fadeOut();
this.destroy();
});
}
loadSlideContent(index) {
const slideItem = this.items[index];
const enableComments = slideItem.getAttribute('data-enable-comments');
const relatedProduct = slideItem.getAttribute('data-related-product');
const slideUniqueId = slideItem.getAttribute('data-slide-unique-id');
// Clear previous content
this.storyContent.innerHTML = '';
// Always create the wrapper
let anchorHtml = '';
if (relatedProduct && relatedProduct !== '' && this.productsData[relatedProduct]) {
const productData = this.productsData[relatedProduct];
anchorHtml = `
${productData.image}
${productData.title}
`;
}
const productHtml = `
${anchorHtml}
';
commentsHtml += `
`;
this.storyContent.insertAdjacentHTML('beforeend', commentsHtml);
// Load comments for this slide
loadComments(
this.slide.getAttribute('data-slide'),
slideUniqueId,
$(`.story-comments-list[data-slide-unique-id="${slideUniqueId}"]`)
);
$(document).off('click', '.emoji');
// Then add a new handler using event delegation
$(document).on('click', '.emoji', function() {
const emoji = $(this).text();
const textarea = $(this).closest('.comment-form-container').find('textarea');
textarea.val(textarea.val() + emoji);
textarea.focus();
});
}
// Close related product box when clicking the close button
// $('.story-wrapper-close-related').off('click').on('click', function(event) {
// $(this).closest('.story-related-related-product').fadeOut();
// });
$('.story-comments-top-head button').click(function() {
$(this).parent().parent().css("display", "none");
});
}
next() {
if (this.active < this.items.length - 1) {
this.activeSlide(this.active + 1);
} else {
// Only close if we're at the last slide
$(this.slide).closest('[data-slide-ref]').fadeOut();
this.destroy();
}
}
prev() {
if (this.active > 0) {
this.activeSlide(this.active - 1);
} else {
// Only close if we're at the first slide
$(this.slide).closest('[data-slide-ref]').fadeOut();
this.destroy();
}
}
addNavigation() {
const nextBtn = this.slide.querySelector('.story-slide-next');
const prevBtn = this.slide.querySelector('.story-slide-prev');
// Remove any existing event listeners first
if (this.eventHandlers) {
nextBtn.removeEventListener('click', this.eventHandlers.nextClick);
prevBtn.removeEventListener('click', this.eventHandlers.prevClick);
}
this.eventHandlers = {
nextClick: this.next.bind(this),
prevClick: this.prev.bind(this)
};
nextBtn.addEventListener('click', this.eventHandlers.nextClick);
prevBtn.addEventListener('click', this.eventHandlers.prevClick);
}
addThumbItems() {
this.thumb.innerHTML = "";
this.items.forEach(() => {
this.thumb.innerHTML += ``;
});
this.thumbItems = Array.from(this.thumb.children);
}
destroy() {
// Only perform cleanup for image stories
if (!this.slide || this.slide.classList.contains('video-story')) {
return;
}
const nextBtn = this.slide.querySelector('.story-slide-next');
const prevBtn = this.slide.querySelector('.story-slide-prev');
if (this.eventHandlers) {
nextBtn.removeEventListener('click', this.eventHandlers.nextClick);
prevBtn.removeEventListener('click', this.eventHandlers.prevClick);
}
// Nullify properties to release memory
this.slide = null;
this.items = null;
this.thumb = null;
this.thumbItems = null;
this.eventHandlers = null;
this.storyContent = null;
this.productsData = null;
}
init() {
this.items = this.slide.querySelectorAll('.story-slide-items > .story-slide-item');
this.thumb = this.slide.querySelector('.story-slide-thumbs');
this.addThumbItems();
this.activeSlide(0); // Always start with the first slide
this.addNavigation();
}
}
function makeNotif(type, text) {
var notifBar = $('.notifBar');
var seperator = '';
var icon = '';
switch (type) {
case 'success':
icon = ``;
break;
case 'success-message':
icon = ``;
break;
case 'error':
icon = ``;
break;
case 'warning':
icon = ``;
break;
case 'info':
icon = ``;
break;
default:
icon = ``;
break;
}
notifBar.html(icon + seperator + text);
notifBar.addClass(type);
notifBar.addClass('active');
setTimeout(function() {
notifBar.removeClass('active');
notifBar.removeClass(type);
}, 6000);
}
$('.notifBar').click(function() {
$(this).removeClass('active');
setTimeout(function() {
$(this).removeClass('error');
$(this).removeClass('success');
$(this).removeClass('success-message');
$(this).removeClass('warning');
$(this).removeClass('info');
}, 600);
});
// Handle comment submission with AJAX
$(document).on('submit', '.story-comment-form', function(e) {
e.preventDefault();
const form = $(this);
const storyId = form.data('story-id');
const slideUniqueId = form.data('slide-unique-id');
const text = form.find('textarea[name="comment_text"]').val();
if (!text.trim()) {
return;
}
// Show loading state
const submitBtn = form.find('button');
const originalText = submitBtn.text();
submitBtn.prop('disabled', true).css('opacity', 0.5);
// Send to server
$.ajax({
url: story_comments_obj.ajax_url,
type: 'POST',
data: {
action: 'save_story_comment',
nonce: story_comments_obj.nonce,
story_id: storyId,
slide_id: slideUniqueId,
comment_text: text
},
success: function(response) {
form.find('textarea').val('');
submitBtn.prop('disabled', false).css('opacity', 1);
if (response.success) {
const commentsContainer = $(`.story-comments-list[data-slide-unique-id="${slideUniqueId}"]`);
// If there's a "no comments" message, remove it
commentsContainer.find('.no-comments').remove();
// Add new comment at the top
commentsContainer.append(response.data.html);
commentsContainer.scrollTop(commentsContainer[0].scrollHeight);
} else {
makeNotif('error', response.data.message || 'خطا در ثبت نظر');
}
},
error: function() {
submitBtn.prop('disabled', false).css('opacity', 1);
makeNotif('error', 'خطا در ارتباط با سرور. لطفا مجددا تلاش کنید.');
}
});
});
// Click handler for opening stories
$('.slider_6aeaf99ec93d2 .story-item').click(function() {
const story_id = $(this).attr('data-story-slide');
// Show the story wrapper
const wrapper = $('[data-slide-ref="' + story_id + '"]');
wrapper.fadeIn();
// Reset any previous state
const slideElement = $('[data-slide="' + story_id + '"]');
const items = slideElement.find('.story-slide-items > .story-slide-item');
// Hide all items and remove active class
items.removeClass('active');
items.find('img').removeClass('active');
// Reset thumbs if they exist
const thumbItems = slideElement.find('.story-slide-thumbs .story-slide-thumb-item');
thumbItems.removeClass('active');
// For image stories, initialize SlideStories
if (!slideElement.hasClass('video-story')) {
const slideStories = new SlideStories(story_id);
$(document).off('click', '.emoji');
// Then add a new handler using event delegation
$(document).on('click', '.emoji', function() {
const emoji = $(this).text();
const textarea = $(this).closest('.comment-form-container').find('textarea');
textarea.val(textarea.val() + emoji);
textarea.focus();
});
// Close button handler
$('.story-wrapper-close-story').off('click').on('click', function() {
$(this).closest('[data-slide-ref]').fadeOut();
slideStories.destroy();
});
// Outside click handler (close the story)
wrapper.off('click').on('click', function(event) {
if ($(event.target).closest('.story-slide').length === 0) {
$(this).fadeOut();
slideStories.destroy();
}
});
} else {
// For video stories, initialize video controls
const videoId = wrapper.find('video').attr('id');
if (videoId) {
initVideoControls(videoId);
}
$(document).off('click', '.emoji');
// Then add a new handler using event delegation
$(document).on('click', '.emoji', function() {
const emoji = $(this).text();
const textarea = $(this).closest('.comment-form-container').find('textarea');
textarea.val(textarea.val() + emoji);
textarea.focus();
});
// Handle the close event
$('.story-wrapper-close-story').off('click').on('click', function() {
const wrapper = $(this).closest('[data-slide-ref]');
// Cleanup video controls
const videoId = wrapper.find('video').attr('id');
if (videoId) {
cleanupVideoControls(videoId);
}
wrapper.fadeOut();
$(this).closest('.story-comments').css("display", "none");
});
$('.story-wrapper-close-related').click(function() {
const wrapper = $(this).closest('[data-slide-ref]');
// Cleanup video controls
const videoId = wrapper.find('video').attr('id');
if (videoId) {
cleanupVideoControls(videoId);
}
wrapper.fadeOut();
$(this).closest('.story-comments').css("display", "none");
})
// Outside click handler for video stories
wrapper.off('click').on('click', function(event) {
if ($(event.target).closest('.story-slide').length === 0) {
const videoId = $(this).find('video').attr('id');
if (videoId) {
cleanupVideoControls(videoId);
}
$(this).find('.story-comments').css("display", "none");
$(this).fadeOut();
}
});
// $('.story-wrapper-close-related').closest('.story-related-related-product').show();
// Close related product box when clicking the close button
// $('.story-wrapper-close-related').off('click').on('click', function(event) {
// $(this).closest('.story-related-related-product').fadeOut();
// });
// Load comments for video if needed
const slideUniqueId = slideElement.attr('data-slide-unique-id');
if (slideUniqueId && slideElement.find('.story-comments-list').length > 0) {
loadComments(
story_id,
slideUniqueId,
slideElement.find('.story-comments-list')
);
}
}
});
$('#close-story-comments').click(function() {
$(this).parent().parent().css("display", "none");
});
$(document).on('click', '.like-button', function(e) {
e.preventDefault();
e.stopPropagation();
const btn = $(this);
const storyId = btn.data('story-id');
const slideId = btn.data('slide-id');
if (!story_comments_obj.is_logged_in) {
makeNotif('error', 'برای لایک کردن ابتدا وارد سایت شوید.');
return;
}
// Prevent double-clicks
if (btn.hasClass('processing')) {
return;
}
btn.addClass('processing');
// Toggle like via AJAX
$.ajax({
url: story_comments_obj.ajax_url,
type: 'POST',
data: {
action: 'toggle_story_like',
nonce: story_comments_obj.nonce,
story_id: storyId,
slide_id: slideId
},
success: function(response) {
btn.removeClass('processing');
if (response.success) {
const svgElement = btn.find('svg');
const countElement = btn.find('.like-count');
// Update count
countElement.text(response.data.count);
// Update visual state
if (response.data.liked) {
btn.addClass('liked');
svgElement.attr('fill', 'red');
} else {
btn.removeClass('liked');
svgElement.attr('fill', 'none');
}
// Update any other instances of this same slide
updateOtherLikeButtons(slideId, response.data.count, response.data.liked);
}
},
error: function() {
btn.removeClass('processing');
makeNotif('error', 'خطا در ارتباط با سرور. لطفا مجددا تلاش کنید.');
}
});
});
// Handle comment button clicks (scrolls to comment section)
$(document).on('click', '.comment-button', function(e) {
e.preventDefault();
e.stopPropagation();
const slideId = $(this).data('slide-id');
const commentsSection = $(`.story-comments-list[data-slide-unique-id="${slideId}"]`).closest('.story-comments');
if (commentsSection.length) {
$(commentsSection).css("display", "flex");
}
});
// Update all instances of the same slide like button (in case multiple are visible)
function updateOtherLikeButtons(slideId, count, liked) {
$(`.like-button[data-slide-id="${slideId}"]`).each(function() {
const btn = $(this);
const svg = btn.find('svg');
const countElem = btn.find('.like-count');
// Update count
countElem.text(count);
// Update appearance
if (liked) {
btn.addClass('liked');
svg.attr('fill', 'red');
} else {
btn.removeClass('liked');
svg.attr('fill', 'none');
}
});
}
// Update comment counts after adding a new comment
const originalSubmitComment = handleCommentSubmit;
function handleCommentSubmit(e) {
// Call the original handler first
originalSubmitComment.call(this, e);
// Then update the count
const form = $(this);
const slideId = form.data('slide-unique-id');
// Update comment count across all instances
const commentCountElements = $(`.comment-button[data-slide-id="${slideId}"] .comment-count`);
if (commentCountElements.length) {
const currentCount = parseInt(commentCountElements.first().text()) || 0;
commentCountElements.text(currentCount + 1);
}
}
// Function to update counts via AJAX
function refreshCounts(storyId, slideId) {
$.ajax({
url: story_comments_obj.ajax_url,
type: 'GET',
data: {
action: 'get_story_counts',
story_id: storyId,
slide_id: slideId
},
success: function(response) {
if (response.success) {
// Update like count and state
$(`.like-button[data-slide-id="${slideId}"] .like-count`).text(response.data.like_count);
const likeButtons = $(`.like-button[data-slide-id="${slideId}"]`);
likeButtons.each(function() {
const btn = $(this);
const svg = btn.find('svg');
if (response.data.user_has_liked) {
btn.addClass('liked');
svg.attr('fill', 'red');
} else {
btn.removeClass('liked');
svg.attr('fill', 'none');
}
});
// Update comment count
$(`.comment-button[data-slide-id="${slideId}"] .comment-count`).text(response.data.comment_count);
}
}
});
}
// Add styles for bottom bar
const styleElement = document.createElement('style');
document.head.appendChild(styleElement);
// Modify the SlideStories.loadSlideContent method to update counts
const originalLoadSlideContent = SlideStories.prototype.loadSlideContent;
SlideStories.prototype.loadSlideContent = function(index) {
// Call the original method
originalLoadSlideContent.call(this, index);
// Get slide information
const slideItem = this.items[index];
const slideId = slideItem.getAttribute('data-slide-unique-id');
const storyId = this.slide.getAttribute('data-slide');
// Refresh counts for this slide
refreshCounts(storyId, slideId);
};
})(jQuery);
});
کامنت ها
در حال بارگذاری نظرات...
تجربه واقعی خنکی با کولر های پلیمری نیرو تهویه البرز
خرید بر اساس دستهبندی محصولات
4.8
133,000,000
6
IRT 125,020,000
خرید اقساطی از فروشگاه بصورت حضوری
در صورت تمایل می توانید با حضور در فروشگاه تاسیسات ارشد نسبت به خرید نقدی یا اقساطی اقدام نمایید یا به صورت فیزیکی محصولات را بررسی کنید. کارشناسان ما در فروشگاه تاسیسات ارشد، همواره آماده پاسخ گویی و راهنمایی شما عزیزان می باشند.
- یزد – بلوار مدرس-بعداز پارک بزرگ شهر- روبروی برج آجری
دسته بندی های محبوب
مشاهده همه
وبلاگ
مشاهده همه
لوح تقدیرنامه حضور مجموعه تاسیسات ارشد در نمایشگاههای استانی و کشور
تقدیرنامه های مجموعه تاسیسات ارشد برای حضور در نمایشگاههای استانی و کشوری در این بخش، تصاویر تقدیرنامه های مجموعه تاسیسات
مدیر سایت
۰۵ تیر ۷۸۴
0
همایش معرفی محصولات جدید گرمایشی و سرمایشی شرکت آذرتهویه-شهریور 1405
همایش معرفی محصولات جدید سرمایشی و گرمایشی شرکت آذر تهویه- شهریور1405- یزد در این بخش، تصاویری از همایش آذر تهویه
مدیر سایت
۲۰ مرداد ۷۸۴
0
گزارش تصویری همایش معرفی محصولات گرمایشی دمراد- شهریور1405- یزد
گزارش تصویری همایش معرفی محصولات گرمایشی دمراد(پکیج و رادیاتور)- شهریور1405- یزد در این بخش، تصاویری از همایش دمراد ۱۴۰۵ و
مدیر سایت
۰۴ تیر ۷۸۴
0
یخچال گازسوز؛ راهکار نگهداری مواد غذایی در زمان قطعی برق
یخچال فریزر گازسوز چیست و چرا در زمان قطعی برق اهمیت دارد؟ یخچال فریزر گازسوز یکی از راهکارهای تأمین سرمایش
مدیر سایت
۰۵ تیر ۷۸۴
0
موتورخانه و گرمایش
تهویه مطبوع و سرمایش
دستگاه تصفیه آب




