server/assets/development/scripts/organization.js

126 lines
4 KiB
JavaScript
Raw Normal View History

2020-07-17 22:12:11 +00:00
/**
* Schedule collapsable section animation
*/
2020-07-05 12:36:10 +00:00
document.querySelectorAll('.schedule-category').forEach(node => {
let opened = false
let icon = node.querySelector('.schedule-category-collapse-icon')
let content = node.querySelector('.schedule-category-table')
let header = node.querySelector('.schedule-category-header')
header.onclick = () => {
if (!opened) {
// open the table
2020-07-21 14:41:07 +00:00
icon.style.transform = "rotate(0deg)"
2020-07-05 12:36:10 +00:00
content.style.maxHeight = content.scrollHeight + "px"
} else {
// close the table
2020-07-21 14:41:07 +00:00
icon.style.transform = "rotate(180deg)"
2020-07-05 12:36:10 +00:00
content.style.maxHeight = null
}
opened = !opened
}
})
2020-07-21 14:41:07 +00:00
/**
* Description
*/
let description = document.querySelector('.description-cutted')
let descriptionActions = document.querySelector('.description-actions-container')
let descriptionOpened = false
let defaultMaxHeight = ""
if (description !== null) {
let btn = document.querySelector('.description-btn')
btn.onclick = () => {
if (!descriptionOpened) {
// open the full description
descriptionActions.className = descriptionActions.className.replace(' closed', '')
defaultMaxHeight = description.style.maxHeight
description.style.maxHeight = description.scrollHeight + "px"
btn.textContent = "Fermer la description"
} else {
// initial max Height
descriptionActions.className += ' closed'
description.style.maxHeight = defaultMaxHeight
btn.textContent = "Ouvrir la description"
}
descriptionOpened = !descriptionOpened
}
}
2020-07-17 22:12:11 +00:00
/**
* Gallery modal to view media in large
*/
let mediaModal = document.querySelector('#media-modal')
2020-07-18 10:43:13 +00:00
let mediaModalContent = document.querySelector('#media-modal-content')
// let mediaModalImage = document.querySelector('#media-modal img')
// let mediaModalVideo = document.querySelector('#media-modal video')
// let mediaModalSource = document.querySelector('#media-modal video source')
2020-07-17 22:12:11 +00:00
2020-07-18 10:43:13 +00:00
// function disableScroll() {
// // Get the current page scroll position
// scrollTop = window.pageYOffset || document.documentElement.scrollTop;
// scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
// // if any scroll is attempted, set this to the previous value
// window.onscroll = function() {
// window.scrollTo(scrollLeft, scrollTop);
// };
// }
// function enableScroll() {
// window.onscroll = function() {};
// }
let openModal = (url, isVideo) => {
2020-07-17 22:12:11 +00:00
mediaModal.style.visibility = 'visible'
mediaModal.style.opacity = 1
2020-07-18 10:43:13 +00:00
mediaModalContent.innerHTML = ""
2020-07-17 22:12:11 +00:00
let attr = document.createAttribute('src')
attr.value = url
2020-07-18 10:43:13 +00:00
let el = null
if (isVideo) {
el = document.createElement('video')
el.setAttribute('controls', '')
el.setAttribute('autoplay', '')
el.setAttribute('name', 'media')
let source = document.createElement('source')
source.setAttribute('src', url)
source.setAttribute('type', 'video/mp4')
el.appendChild(source)
} else {
el = document.createElement('img')
el.attributes.setNamedItem(attr)
}
mediaModalContent.appendChild(el)
//document.body.style.height = '100vh'
document.body.style.overflow = 'hidden'
document.body.style.touchAction = 'none'
2020-07-21 14:41:07 +00:00
setTimeout(() => {
const outsideClickListener = event => {
if (!mediaModalContent.contains(event.target) && isVisible(mediaModalContent)) {
closeModal()
document.removeEventListener('click', outsideClickListener)
}
}
document.addEventListener('click', outsideClickListener)
}, 100)
2020-07-17 22:12:11 +00:00
}
2020-07-21 14:41:07 +00:00
const isVisible = elem => !!elem && !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length )
2020-07-17 22:12:11 +00:00
let closeModal = () => {
mediaModal.style.visibility = 'hidden'
mediaModal.style.opacity = 0
2020-07-18 10:43:13 +00:00
document.body.style.overflow = 'initial'
document.body.style.height = 'initial'
2020-08-12 12:37:48 +00:00
document.body.style.touchAction = 'initial'
2020-07-18 10:43:13 +00:00
let video = document.querySelector('#media-modal video')
if (video !== null) {
video.pause()
}
2020-07-17 22:12:11 +00:00
}