Skip to content

Commit

Permalink
Collapse/Expand by subtitle
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloalba committed Jul 9, 2024
1 parent e6ac846 commit 86d7c73
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
14 changes: 13 additions & 1 deletion editor/css/trotamundos.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ a:visited {
justify-content: center;
}

.draggable {
.section-item {
border: 1px dotted white;
color: white;
border-radius: 10px;
Expand All @@ -91,6 +91,18 @@ a:visited {
flex-direction: row;
align-items: center;
justify-content: center;
}

.draggable {
border: 1px dotted white;
color: white;
border-radius: 10px;
width: 100%;
height: 200px;
margin-bottom: 10px;
display: flex;
flex-direction: row;
align-items: center;
cursor: pointer;
}

Expand Down
Binary file added editor/icons/collapse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added editor/icons/expand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 49 additions & 1 deletion editor/js/trotamundos.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ var tripsList = {};
var currentTripId = null;
var currentSectionId = null;
var currentSection = null;
var collapsed = [];

var sectionsSortable = null;
var sortedSections = [];
Expand All @@ -133,12 +134,20 @@ if (localStorage.tripsList) {
tripsList = JSON.parse(localStorage.tripsList);
}

if (localStorage.collapsed) {
collapsed = JSON.parse(localStorage.collapsed);
}

////////////////////

function save() {
localStorage.tripsList = JSON.stringify(tripsList);
}

function saveCollapsed() {
localStorage.collapsed = JSON.stringify(collapsed);
}

function getSection(trip, sectionId) {
for (var i = 0; i < trip.sections.length; i++) {
if (sectionId == trip.sections[i].id) {
Expand Down Expand Up @@ -463,8 +472,21 @@ function reloadSection(data) {
text.dataset.sectionId = data.id;
text.addEventListener('click', openEditSubtitleEv, false);

expand = document.createElement('img');
if (collapsed.includes(data.id)) {
expand.src = 'icons/expand.png';
section.classList.remove("draggable");
} else {
expand.src = 'icons/collapse.png';
}

expand.classList.add('icon');
expand.dataset.sectionId = data.id;
expand.addEventListener('click', toggleSubtitleEv, false);

section.appendChild(img);
section.appendChild(text);
section.appendChild(expand);
}
document.getElementById('sections-container').appendChild(section);
}
Expand All @@ -479,7 +501,19 @@ function reloadSections(sections) {
sortedSections = Object.values(sections)
sortedSections.sort((a, b) => a.pos - b.pos);

sortedSections.forEach(reloadSection);
show = true;

for (let section of sortedSections) {
if (show || ('subtitle' == section.type)) {
reloadSection(section);
}

if ('subtitle' == section.type) {
show = !collapsed.includes(section.id);
}
}

//sortedSections.forEach(reloadSection);

initSectionsSortable(sectionsContainer);
}
Expand Down Expand Up @@ -759,6 +793,20 @@ function openEditSubtitle() {
openSection('section-subtitle');
}

function toggleSubtitleEv(ev) {
handleToggleSubtitleEv(ev.currentTarget.dataset.sectionId);
}

function handleToggleSubtitleEv(id) {
if (collapsed.includes(id)) {
collapsed = collapsed.filter(item => item !== id);
} else {
collapsed.push(id);
}
saveCollapsed();
openViewTrip();
}


function previewImage(ev) {
handleImagePreview('trip-image', 'trip-image-preview');
Expand Down

0 comments on commit 86d7c73

Please sign in to comment.