Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui-modals.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * UI Modals
  3. */
  4. 'use strict';
  5. (function () {
  6. // Animation Dropdown
  7. const animationDropdown = document.querySelector('#animation-dropdown'),
  8. animationModal = document.querySelector('#animationModal');
  9. if (animationDropdown) {
  10. animationDropdown.onchange = function () {
  11. animationModal.classList = '';
  12. animationModal.classList.add('modal', 'animate__animated', this.value);
  13. };
  14. }
  15. // On hiding modal, remove iframe video/audio to stop playing
  16. const youTubeModal = document.querySelector('#youTubeModal'),
  17. youTubeModalVideo = youTubeModal.querySelector('iframe');
  18. youTubeModal.addEventListener('hidden.bs.modal', function () {
  19. youTubeModalVideo.setAttribute('src', '');
  20. });
  21. // Function to get and auto play youTube video
  22. const autoPlayYouTubeModal = function () {
  23. const modalTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="modal"]'));
  24. modalTriggerList.map(function (modalTriggerEl) {
  25. modalTriggerEl.onclick = function () {
  26. const theModal = this.getAttribute('data-bs-target'),
  27. videoSRC = this.getAttribute('data-theVideo'),
  28. videoSRCauto = `${videoSRC}?autoplay=1`,
  29. modalVideo = document.querySelector(`${theModal} iframe`);
  30. if (modalVideo) {
  31. modalVideo.setAttribute('src', videoSRCauto);
  32. }
  33. };
  34. });
  35. };
  36. // Calling function on load
  37. autoPlayYouTubeModal();
  38. // Onboarding modal carousel height animation
  39. document.querySelectorAll('.carousel').forEach(carousel => {
  40. carousel.addEventListener('slide.bs.carousel', event => {
  41. // Ensure next slide exists
  42. if (!event.relatedTarget) {
  43. console.error('Next slide not found');
  44. return;
  45. }
  46. // Use requestAnimationFrame to wait for render
  47. requestAnimationFrame(() => {
  48. // Force reflow
  49. void event.relatedTarget.offsetHeight;
  50. const nextHeight = Math.max(
  51. event.relatedTarget.offsetHeight,
  52. event.relatedTarget.scrollHeight,
  53. event.relatedTarget.getBoundingClientRect().height
  54. );
  55. const carouselParent = carousel.querySelector('.active.carousel-item').parentElement;
  56. // Animate only if we have valid heights
  57. if (nextHeight > 0 && carouselParent) {
  58. carouselParent.animate([{ height: carouselParent.offsetHeight + 'px' }, { height: nextHeight + 'px' }], {
  59. duration: 500,
  60. easing: 'ease',
  61. fill: 'forwards'
  62. });
  63. }
  64. });
  65. });
  66. });
  67. })();