server/assets/development/scripts/organization.js

235 lines
6.9 KiB
JavaScript
Raw Permalink 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')
2020-07-21 14:41:07 +00:00
let descriptionOpened = false
let defaultMaxHeight = ""
if (description !== null) {
let btn = document.querySelector('.description-btn')
let btnIcon = document.getElementById('description-btn-icon')
let btnText = document.getElementById('description-btn-text')
2020-07-21 14:41:07 +00:00
btn.onclick = () => {
if (!descriptionOpened) {
// open the full description
descriptionActions.className = descriptionActions.className.replace(' closed', '')
defaultMaxHeight = description.style.maxHeight
description.style.maxHeight = description.scrollHeight + "px"
btnText.textContent = "Fermer la description"
btnIcon.style.transform = 'rotate(180deg)'
2020-07-21 14:41:07 +00:00
} else {
// initial max Height
descriptionActions.className += ' closed'
description.style.maxHeight = defaultMaxHeight
btnText.textContent = "Ouvrir la description"
btnIcon.style.transform = 'rotate(0deg)'
2020-07-21 14:41:07 +00:00
}
descriptionOpened = !descriptionOpened
}
}
2020-07-17 22:12:11 +00:00
/**
* Gallery modal to view media in large
*/
2020-07-18 10:43:13 +00:00
// 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() {
2020-07-18 10:43:13 +00:00
// window.onscroll = function() {};
// }
let mediaModal = document.querySelector('#media-modal')
let mediaModalContent = document.querySelector('#media-modal-content')
let navLeft = document.getElementById('media-nav-left')
let navRight = document.getElementById('media-nav-right')
let currentMedia = {}
let mediaData = []
let loadMedias = () => {
let list = document.querySelectorAll('.media-container')
//console.log(list)
list.forEach(m => {
mediaData.push({
isVideo: m.getAttribute('data-video') == 'true',
location: m.getAttribute('data-location')
})
})
}
2020-07-18 10:43:13 +00:00
loadMedias()
2020-07-18 10:43:13 +00:00
let openModal = (index) => {
if (index === 'extra') {
index = 5
}
2020-07-17 22:12:11 +00:00
mediaModal.style.visibility = 'visible'
mediaModal.style.opacity = 1
currentMedia = mediaData[index]
fillModal(currentMedia)
//document.body.style.height = '100vh'
document.body.style.overflow = 'hidden'
document.body.style.userSelect = 'none'
document.body.style.touchAction = 'none'
setTimeout(() => {
const outsideClickListener = event => {
if (
!mediaModalContent.contains(event.target) && isVisible(mediaModalContent) &&
navLeft.querySelector(':hover') === null &&
navRight.querySelector(':hover') === null
) {
closeModal()
document.removeEventListener('click', outsideClickListener)
}
}
document.addEventListener('click', outsideClickListener)
}, 100)
}
const isVisible = elem => !!elem && !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length )
2020-07-18 10:43:13 +00:00
let fillModal = () => {
console.log(currentMedia)
mediaModalContent.innerHTML = ""
2020-07-17 22:12:11 +00:00
let attr = document.createAttribute('src')
attr.value = currentMedia.location
2020-07-18 10:43:13 +00:00
let el = null
if (currentMedia.isVideo) {
2020-07-18 10:43:13 +00:00
el = document.createElement('video')
el.setAttribute('controls', '')
el.setAttribute('autoplay', '')
el.setAttribute('name', 'media')
let source = document.createElement('source')
source.setAttribute('src', currentMedia.location)
2020-07-18 10:43:13 +00:00
source.setAttribute('type', 'video/mp4')
el.appendChild(source)
} else {
el = document.createElement('img')
el.attributes.setNamedItem(attr)
}
mediaModalContent.appendChild(el)
2020-07-21 14:41:07 +00:00
if (mediaData.indexOf(currentMedia) === 0) {
navLeft.className += ' disabled'
} else {
navLeft.className = navLeft.className.replace('disabled', '')
}
2020-07-21 14:41:07 +00:00
if (mediaData.indexOf(currentMedia) + 1 === mediaData.length) {
navRight.className += ' disabled'
} else {
navRight.className = navRight.className.replace('disabled', '')
}
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'
document.body.style.userSelect = '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
}
2020-08-19 09:56:38 +00:00
if (document.querySelector('.media-mosaic') != null) {
navLeft.onclick = () => {
if (mediaData.indexOf(currentMedia) === 0) { return; }
currentMedia = mediaData[mediaData.indexOf(currentMedia) - 1]
fillModal()
}
2020-08-19 09:56:38 +00:00
navRight.onclick = () => {
if (mediaData.indexOf(currentMedia) + 1 === mediaData.length) { return; }
currentMedia = mediaData[mediaData.indexOf(currentMedia) + 1]
fillModal()
}
}
/**
* Decode things
*/
let formatPhone = (phone) => {
if (phone.indexOf('+33') === 0) {
phone = '0' + phone.substr(3)
}
let phoneSplit = ''
let partEnd = false
for (var i = 0; i < phone.length; i++) {
phoneSplit += phone.charAt(i)
if (partEnd === true) {
phoneSplit += ' '
}
partEnd = !partEnd
}
return ["+33" + phone.substr(1), phoneSplit]
}
/**
* Decode email and phone data
*/
document.querySelectorAll('.offuscated').forEach(node => {
let data = node.getAttribute('data-source')
let type = node.getAttribute('data-source-type')
data = data.replace(/'/gm, '"').replace(/%_/gm, '')
data = data.replace(/\$/gm, 'A')
data = data.replace(/£/gm, 'c')
data = data.replace(/ù/gm, 'b')
data = data.replace(/#/gm, 'd')
data = data.replace(/µ/gm, 'e')
data = data.replace(/§/gm, 'z')
data = data.replace(/à/gm, 'i')
data = data.replace(/\|/gm, 'f')
data = JSON.parse(data).join('')
data = atob(data)
if (type === 'phone') {
data = formatPhone(data)
node.href = node.href.replace('data', data[0])
data = data[1]
} else {
node.href = node.href.replace('data', data)
}
node.textContent = data
})