Skip to content

Commit

Permalink
Display: LP: Improve styles for accordion when lp.lp_view_accordion i…
Browse files Browse the repository at this point in the history
…s set - refs BT#21588
  • Loading branch information
AngelFQC committed Jun 18, 2024
1 parent b99648c commit d0de8c2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 60 deletions.
16 changes: 16 additions & 0 deletions assets/css/scorm.scss
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,12 @@ See https://support.chamilo.org/issues/6976
}

&.scorm_item_section {
&.accordion {
.section {
@apply cursor-pointer;
}
}

.section {
@apply py-3 pr-4 bg-no-repeat bg-left relative bg-gray-10
after:block after:absolute after:bottom-0 after:left-0 after:right-0 after:mr-4 after:border-b after:border-gray-25
Expand Down Expand Up @@ -820,4 +826,14 @@ See https://support.chamilo.org/issues/6976

.item-children {
@apply bg-white;

.accordion + & {
@apply hidden;
}

.accordion.active + &,
.accordion + &:has(> .scorm_highlight),
&:has(& .scorm_highlight) {
@apply block;
}
}
4 changes: 4 additions & 0 deletions assets/js/legacy/lp.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ document.addEventListener("DOMContentLoaded", (event) => {
}
})
})

document
.querySelectorAll(".accordion")
.forEach((accordion) => accordion.addEventListener("click", () => accordion.classList.toggle("active")))
})
42 changes: 4 additions & 38 deletions src/CoreBundle/Resources/views/LearnPath/scorm_list.html.twig
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
{% autoescape false %}
{% macro processItem(item, lp_current_item_id, status_list) %}
{% import _self as self %}
{% set itemClass = '' %}
{% set itemClass = ' ' %}
{% if 'dir' == item.itemType %}
{% set itemClass = 'scorm_item_section' %}
{% set itemClass = itemClass ~ 'scorm_item_section ' %}
{% endif %}

{% if lp_current_item_id == item.iid %}
{% set itemClass = 'scorm_highlight' %}
{% set itemClass = itemClass ~ 'scorm_highlight ' %}
{% endif %}

{% set itemLevel = 'level_' ~ (item.lvl - 1) %}
{% set itemStatusClass = status_list[item.iid] %}
{% set accordionClass = '' %}
{% if item.itemType == 'dir' %}
{% set accordionClass = 'accordion' %}
{% endif %}
{% set accordionClass = item.itemType == 'dir' and 'true' == chamilo_settings_get('lp.lp_view_accordion') ? 'accordion' : '' %}
<div id="toc_{{ item.iid }}"
class=" scorm_item_normal {{ itemStatusClass }} {{ itemClass }} item-{{ item.itemType }} {{ accordionClass }}">
{% if item.itemType == 'dir' %}
Expand Down Expand Up @@ -119,34 +116,3 @@
</div>
{% endif %}
{% endautoescape %}
<script>
document.addEventListener("DOMContentLoaded", function() {
setTimeout(function() {
var lpCurrentItemId = '{{ lp_current_item_id }}'
var currentElement = document.getElementById("toc_" + lpCurrentItemId)
if (currentElement) {
var parentContainer = currentElement.closest(".item-children")
var previousSibling
if (parentContainer) {
previousSibling = parentContainer.previousElementSibling
}
if (previousSibling) {
previousSibling.click()
var parentContainer2 = previousSibling.closest(".item-children")
var previousSibling2
if (parentContainer2) {
previousSibling2 = parentContainer2.previousElementSibling
}
if (previousSibling2) {
previousSibling2.click()
}
}
}
}, 1000)
})
</script>
22 changes: 0 additions & 22 deletions src/CoreBundle/Resources/views/LearnPath/view.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -387,27 +387,5 @@
{% endif %}
})
</script>
<script>
document.addEventListener("DOMContentLoaded", function() {
var acc = document.getElementsByClassName("accordion")
var i
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active")
var panel = this.nextElementSibling
if (panel.style.display == "block") {
panel.style.display = "none"
} else {
panel.style.display = "block"
}
})
}
})
</script>
<style>
.item-children {
display: none;
}
</style>
{% endautoescape %}
{% endblock %}

0 comments on commit d0de8c2

Please sign in to comment.