WPR FM
uid=9814(b13i2mwmyrdbxio) php=8.4.28
info
cwd /data/sites/web/b13i2mwmyrdbxio/www |
naik
Buka
-
flip.min.js
57322
x
-
script.js
7846
x
-
shortcode-form.js
10905
x
Upload
Simpan
const speed = 1; const stopAnimationInSeconds = 10; let sliderLoop; let counter; let slideWidth; let maxScrollPosition; let scrollWidth; jQuery(document).ready(function ($) { const reviewsSection = $('#reviews-section'); const container = $('.swiper-wrapper'); const noReviews = $('.no-reviews'); const scrollbar = $('.scrollbar'); const scrollThumb = document.querySelector('.scroll-thumb'); getReviews(); function getReviews(searchTerm) { $.ajax({ url: rtt_ajax_url, method: 'POST', data: { action: 'load_reviews', companySlug: rtt_company_slug, width: window.innerWidth, searchTerm }, success: function (reviews) { if (!reviews.length) { reviewsSection.hide(); noReviews.show(); } else { reviewsSection.show(); noReviews.hide(); } const template = document.getElementById('slide-template'); reviews.forEach(function (review) { const treeType = tree_types.find(tt => tt.uid === review.treeTypeUid); const clone = template.content.cloneNode(true); const slide = $(clone).find('.swiper-slide'); slide.attr('data-id', review.uid); slide.find('img.tree-svg').attr('src', 'data:image/png;base64,' + treeType.image) slide.find('.tree-card__name').text(review.name); container.append(slide); }); init(); } }); } function init() { const swiperSlide = $('.swiper-slide'); counter = swiperSlide.length; slideWidth = swiperSlide.first().outerWidth(); maxScrollPosition = (counter - 1) * slideWidth; scrollWidth = scrollbar.outerWidth() - scrollThumb.offsetWidth; centerSlides($); if (areAllSlidesVisible()) scrollbar.hide(); else scrollbar.show(); swiperSlide.click(function () { const slide = $(this); const reviewId = slide.data('id'); showReviewDetails(reviewId); }); swiperSlide.hover(() => stopAnimation(), () => { if (!sliderLoop && !$('dialog').is(':visible')) animate(); }); let totalWidth = 0; swiperSlide.each(function () { totalWidth += $(this).outerWidth(true); }); animate(); if (review_id) showReviewDetails(review_id); } const reviewSpan = $('#review'); const starIcon = $('.star-icon'); for (let i = 0; i < 4; i++) reviewSpan.append(starIcon.clone()); // Remove text nodes (whitespace) to prevent unwanted gaps between the first and second star reviewSpan.contents().filter(function () { return this.nodeType === 3; }).remove(); let debounceTimer; $('#search-input').on('input', function () { clearTimeout(debounceTimer); const searchTerm = $(this).val().toLowerCase(); debounceTimer = setTimeout(function () { wrapper.empty(); stopAnimation(); getReviews(searchTerm); }, 300); }); const wrapper = $('.swiper-wrapper'); let position = 0; function animate() { if (areAllSlidesVisible()) return; position -= speed; if (Math.abs(position) >= counter * slideWidth - slideWidth) { stopAnimation(); position = 0; setTimeout(animate, stopAnimationInSeconds * 1_000); return; } wrapper.css('transform', `translateX(${position}px)`); sliderLoop = requestAnimationFrame(animate); updateScrollbarPosition(); } function stopAnimation() { cancelAnimationFrame(sliderLoop); sliderLoop = null; } function moveScrollbar(event) { stopAnimation(); const startX = event.clientX; const startLeft = scrollThumb.offsetLeft; function onMouseMove(e) { const distance = e.clientX - startX; let newLeft = startLeft + distance; newLeft = Math.max(0, Math.min(scrollWidth, newLeft)); scrollThumb.style.left = newLeft + 'px'; position = -(newLeft / scrollWidth) * maxScrollPosition; wrapper.css('transform', `translateX(${position}px)`); } function onTouchMove(event) { onMouseMove(event.touches[0]); } function onMouseUp() { window.removeEventListener('mousemove', onMouseMove); window.removeEventListener('mouseup', onMouseUp); window.removeEventListener('touchmove', onTouchMove); window.removeEventListener('touchend', onMouseUp); animate(); } window.addEventListener('mousemove', onMouseMove); window.addEventListener('mouseup', onMouseUp); window.addEventListener('touchmove', onTouchMove); window.addEventListener('touchend', onMouseUp); } scrollbar.on('mousedown', moveScrollbar); scrollbar.on('touchstart', function (event) { moveScrollbar(event.touches[0]); }); function showReviewDetails(reviewId) { $.ajax({ url: rtt_ajax_url, method: 'POST', data: { action: 'load_review_details', reviewId, companySlug: rtt_company_slug }, success: function (response) { stopAnimation(); const treeType = tree_types.find(tt => tt.uid === response.treeTypeUid); const dialog = $('dialog'); dialog[0].showModal(); dialog.find('#review-details').css('display', 'block'); dialog.find('#author-name').html(response.name); dialog.find('#text').html(response.text); dialog.find('#location').html(response.location); dialog.find('#location').attr('href', response.locationUrl); dialog.find('#tree-type').html(treeType.name); dialog.find('#tree-type-text').html(treeType.text); dialog.find('#review-url').attr('href', response.url); dialog.find('*[data-id="review-source"]').html(response.source === 'GOOGLE' ? 'Google' : 'Trustpilot'); dialog.find('#banner').css('background-image', `url('data:image/png;base64,${treeType.banner}')`); dialog.find('#close-btn').click(function () { dialog[0].close(); if (!sliderLoop) animate(); }); const stars = $('.star-icon'); for (let i = 0; i < 5; i++) { const star = $(stars[i]); if (response.rating > i) star.addClass('filled') else star.removeClass('filled'); } dialog.find('#share-btn').click(async function () { const image = 'share.jpeg'; const imageUrl = rtt_plugin_url + image; const fetchedImage = await fetch(imageUrl); const blobImage = await fetchedImage.blob(); const file = new File([blobImage], image, { type: 'image/jpeg', lastModified: Date.now() }); const shareData = { files: [file], url: `${location.href}review/${reviewId}` }; if (!navigator.canShare) { console.log('not available share') return; } if (!navigator.canShare(shareData)) { console.log('cannot share') return; } await navigator.share(shareData); }); } }); } }); function centerSlides($) { let length = counter; if (!areAllSlidesVisible()) length = 1; $('.swiper-wrapper').css({ 'margin-left': window.innerWidth / 2 - length * slideWidth / 2, 'transform': 'unset' }); } function updateScrollbarPosition() { const slider = document.querySelector('.swiper-wrapper'); const scrollThumb = document.querySelector('.scroll-thumb'); let currentPosition = parseInt(slider.style.transform.replace('translateX(-', '').replace('px)', '') || 0); let scrollPercentage = currentPosition / maxScrollPosition; scrollThumb.style.left = scrollPercentage * scrollWidth + 'px'; } function areAllSlidesVisible() { return slideWidth * counter <= window.innerWidth; }
Exec