Files
Backend-Api/ServiceHost/wwwroot/AssetsAdminNew/Tasks/js/DetailsScheduleModal.js
2025-04-07 19:44:22 +03:30

158 lines
5.4 KiB
JavaScript

$(document).ready(function() {
loadGallery();
});
// برای نمایش تصاویر
function loadGallery() {
if ($('.gallery').length) {
// Lightbox Gallery
(function () {
var lightboxEnabled = document.querySelectorAll('.lightbox-enabled');
var lightboxArray = Array.from(lightboxEnabled);
var lastImage = lightboxArray.length - 1;
var lightboxContainer = document.querySelector('.lightbox-container');
var lightboxImage = document.querySelector('.lightbox-image');
var lightboxBtns = document.querySelectorAll('.lightbox-btn');
var lightboxBtnRight = document.querySelector('#right');
var lightboxBtnLeft = document.querySelector('#left');
var close = document.querySelector('#close');
let activeImage;
var showLightBox = () => { lightboxContainer.classList.add('active'); }
var hideLightBox = () => {
lightboxContainer.classList.remove('active');
document.removeEventListener('keydown', handleKeyDown);
}
var setActiveImage = (image) => {
lightboxImage.src = image.dataset.imgsrc;
activeImage = lightboxArray.indexOf(image);
}
var transitionSlidesLeft = () => {
lightboxBtnLeft.focus();
$('.lightbox-image').addClass('slideright');
setTimeout(function () {
activeImage === 0 ? setActiveImage(lightboxArray[lastImage]) : setActiveImage(lightboxArray[activeImage - 1]);
}, 250);
setTimeout(function () {
$('.lightbox-image').removeClass('slideright');
}, 500);
}
var transitionSlidesRight = () => {
lightboxBtnRight.focus();
$('.lightbox-image').addClass('slideleft');
setTimeout(function () {
activeImage === lastImage ? setActiveImage(lightboxArray[0]) : setActiveImage(lightboxArray[activeImage + 1]);
}, 250);
setTimeout(function () {
$('.lightbox-image').removeClass('slideleft');
}, 500);
}
var transitionSlideHandler = (moveItem) => {
moveItem.includes('left') ? transitionSlidesLeft() : transitionSlidesRight();
}
var handleKeyDown = (e) => {
if (e.key === 'ArrowLeft') {
transitionSlidesLeft();
} else if (e.key === 'ArrowRight') {
transitionSlidesRight();
} else if (e.key === 'Escape' || e.key === 'Esc') {
hideLightBox();
}
}
lightboxEnabled.forEach(image => {
image.addEventListener('click', (e) => {
showLightBox();
setActiveImage(image);
document.addEventListener('keydown', handleKeyDown);
});
});
lightboxContainer.addEventListener('click', () => { hideLightBox(); });
close.addEventListener('click', () => { hideLightBox(); });
lightboxBtns.forEach(btn => {
btn.addEventListener('click', (e) => {
e.stopPropagation();
transitionSlideHandler(e.currentTarget.id);
});
});
lightboxImage.addEventListener('click', (e) => {
e.stopPropagation();
});
})();
}
}
// برای نمایش تصاویر
var wavesurfer = null;
if (voiceSrc) {
waveVoice(voiceSrc);
}
function waveVoice(voiceSrc) {
// Ensure identifiers are only declared once
var playPauseButton = $('#play-pause');
var currentTimeEl = $('#current-time');
var durationEl = $('#duration');
var voiceSource = decodeURIComponent(voiceSrc.replace(/&/g, '&'));
// If a wavesurfer instance already exists, destroy it
if (wavesurfer) {
wavesurfer.destroy();
}
// Initialize Wavesurfer
wavesurfer = WaveSurfer.create({
container: '#waveform',
waveColor: '#e0e0e0',
progressColor: '#23a9a9',
cursorWidth: 2,
cursorColor: '#23a9a9',
height: 40,
barWidth: 2,
responsive: true
});
// Load the audio file
wavesurfer.load(`${voiceSource}`);
$("#waveArea").show();
// Play/pause functionality
playPauseButton.off('click'); // Remove previous event handlers
playPauseButton.on('click', function () {
if (wavesurfer.isPlaying()) {
wavesurfer.pause();
playPauseButton.removeClass('pause').addClass('play');
} else {
wavesurfer.play();
playPauseButton.removeClass('play').addClass('pause');
}
});
// Update time and progress
wavesurfer.on('audioprocess', function () {
currentTimeEl.text(formatTime(wavesurfer.getCurrentTime()));
});
// Set duration once ready
wavesurfer.on('ready', function () {
durationEl.text(formatTime(wavesurfer.getDuration()));
});
// Format time function
function formatTime(seconds) {
var minutes = Math.floor(seconds / 60);
seconds = Math.floor(seconds % 60);
return minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
}
}