Tudo: Primeiro commit
This commit is contained in:
commit
06a90928dc
4633 files changed
+6327263
No files matched your search
@@ -0,0 +1,155 @@
|
||||
/* ===========================================
|
||||
CONTROLADOR DA APRESENTACAO
|
||||
Escala o palco fixo 1920x1080 uniformemente.
|
||||
=========================================== */
|
||||
class SlidePresentation {
|
||||
constructor() {
|
||||
this.slides = Array.from(document.querySelectorAll('.slide'));
|
||||
this.current = 0;
|
||||
this.stage = document.getElementById('deckStage');
|
||||
this.progress = document.getElementById('progress');
|
||||
this.setupScale();
|
||||
this.setupKeyboard();
|
||||
this.setupTouch();
|
||||
this.setupWheel();
|
||||
this.showSlide(0);
|
||||
}
|
||||
|
||||
/* Escala o palco mantendo 16:9, com letterbox */
|
||||
setupScale() {
|
||||
const scale = () => {
|
||||
const f = Math.min(window.innerWidth / 1920, window.innerHeight / 1080);
|
||||
const x = (window.innerWidth - 1920 * f) / 2;
|
||||
const y = (window.innerHeight - 1080 * f) / 2;
|
||||
this.stage.style.transform = `translate(${x}px, ${y}px) scale(${f})`;
|
||||
};
|
||||
scale();
|
||||
window.addEventListener('resize', scale);
|
||||
}
|
||||
|
||||
setupKeyboard() {
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.target.getAttribute && e.target.getAttribute('contenteditable') === 'true') return;
|
||||
if (['ArrowRight', 'ArrowDown', ' ', 'PageDown'].includes(e.key)) { e.preventDefault(); this.next(); }
|
||||
if (['ArrowLeft', 'ArrowUp', 'PageUp'].includes(e.key)) { e.preventDefault(); this.prev(); }
|
||||
if (e.key === 'Home') this.showSlide(0);
|
||||
if (e.key === 'End') this.showSlide(this.slides.length - 1);
|
||||
});
|
||||
}
|
||||
|
||||
setupTouch() {
|
||||
let x0 = null;
|
||||
window.addEventListener('touchstart', (e) => { x0 = e.touches[0].clientX; }, { passive: true });
|
||||
window.addEventListener('touchend', (e) => {
|
||||
if (x0 === null) return;
|
||||
const dx = e.changedTouches[0].clientX - x0;
|
||||
if (Math.abs(dx) > 60) { dx < 0 ? this.next() : this.prev(); }
|
||||
x0 = null;
|
||||
}, { passive: true });
|
||||
}
|
||||
|
||||
setupWheel() {
|
||||
let lock = false;
|
||||
window.addEventListener('wheel', (e) => {
|
||||
if (lock || Math.abs(e.deltaY) < 20) return;
|
||||
lock = true;
|
||||
e.deltaY > 0 ? this.next() : this.prev();
|
||||
setTimeout(() => lock = false, 700);
|
||||
}, { passive: true });
|
||||
}
|
||||
|
||||
next() { this.showSlide(this.current + 1); }
|
||||
prev() { this.showSlide(this.current - 1); }
|
||||
|
||||
showSlide(i) {
|
||||
this.current = Math.max(0, Math.min(i, this.slides.length - 1));
|
||||
this.slides.forEach((s, k) => {
|
||||
s.classList.toggle('active', k === this.current);
|
||||
s.classList.toggle('visible', k === this.current);
|
||||
});
|
||||
if (this.progress) {
|
||||
this.progress.style.width = ((this.current + 1) / this.slides.length * 100) + '%';
|
||||
}
|
||||
if (this.editor) this.editor.currentSlide = this.current;
|
||||
}
|
||||
}
|
||||
|
||||
/* ===========================================
|
||||
EDITOR INLINE - edita texto no browser, salva local
|
||||
=========================================== */
|
||||
class InlineEditor {
|
||||
constructor(presentation) {
|
||||
this.pres = presentation;
|
||||
this.isActive = false;
|
||||
this.currentSlide = 0;
|
||||
this.STORAGE_KEY = 'unicap-robo-etapa2-edits';
|
||||
this.loadEdits();
|
||||
}
|
||||
|
||||
/* Conjunto de nos editaveis: mesma regra na gravacao e no carregamento */
|
||||
nodes(slide) {
|
||||
return Array.from(slide.querySelectorAll('.reveal, h1, h2, p, li, td, div'))
|
||||
.filter(el => el.children.length === 0 || el.classList.contains('card-title'));
|
||||
}
|
||||
|
||||
toggleEditMode() {
|
||||
this.isActive = !this.isActive;
|
||||
const btn = document.getElementById('editToggle');
|
||||
if (btn) btn.classList.toggle('active', this.isActive);
|
||||
this.pres.slides.forEach(slide => {
|
||||
this.nodes(slide).forEach(el => {
|
||||
el.setAttribute('contenteditable', this.isActive ? 'true' : 'false');
|
||||
if (this.isActive) el.addEventListener('blur', () => this.saveEdits());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
saveEdits() {
|
||||
const data = {};
|
||||
this.pres.slides.forEach((slide, i) => {
|
||||
data[i] = this.nodes(slide).map(e => e.innerHTML);
|
||||
});
|
||||
try { localStorage.setItem(this.STORAGE_KEY, JSON.stringify(data)); } catch (e) {}
|
||||
}
|
||||
|
||||
loadEdits() {
|
||||
try {
|
||||
const raw = localStorage.getItem(this.STORAGE_KEY);
|
||||
if (!raw) return;
|
||||
const data = JSON.parse(raw);
|
||||
this.pres.slides.forEach((slide, i) => {
|
||||
if (!data[i]) return;
|
||||
this.nodes(slide).forEach((n, k) => { if (data[i][k] != null) n.innerHTML = data[i][k]; });
|
||||
});
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
const presentation = new SlidePresentation();
|
||||
const editor = new InlineEditor(presentation);
|
||||
presentation.editor = editor;
|
||||
|
||||
/* Hotzone hover com janela de tolerancia de 400ms (nao usar seletor ~) */
|
||||
const hotzone = document.querySelector('.edit-hotzone');
|
||||
const editToggle = document.getElementById('editToggle');
|
||||
let hideTimeout = null;
|
||||
|
||||
if (hotzone && editToggle) {
|
||||
hotzone.addEventListener('mouseenter', () => { clearTimeout(hideTimeout); editToggle.classList.add('show'); });
|
||||
hotzone.addEventListener('mouseleave', () => {
|
||||
hideTimeout = setTimeout(() => { if (!editor.isActive) editToggle.classList.remove('show'); }, 400);
|
||||
});
|
||||
editToggle.addEventListener('mouseenter', () => clearTimeout(hideTimeout));
|
||||
editToggle.addEventListener('mouseleave', () => {
|
||||
hideTimeout = setTimeout(() => { if (!editor.isActive) editToggle.classList.remove('show'); }, 400);
|
||||
});
|
||||
hotzone.addEventListener('click', () => editor.toggleEditMode());
|
||||
editToggle.addEventListener('click', () => editor.toggleEditMode());
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if ((e.key === 'e' || e.key === 'E') && e.target.getAttribute && e.target.getAttribute('contenteditable') !== 'true') {
|
||||
editor.toggleEditMode();
|
||||
}
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === 's') { e.preventDefault(); editor.saveEdits(); }
|
||||
});
|
||||
Reference in new issue
Block a user