Skip to content

Commit b72a917

Browse files
committed
make letter groups collapsible manually
1 parent c3180fa commit b72a917

File tree

6 files changed

+94
-2
lines changed

6 files changed

+94
-2
lines changed

amd/build/lettergroup.min.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/build/lettergroup.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/lettergroup.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// This file is part of Moodle - http://moodle.org/
2+
//
3+
// Moodle is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// Moodle is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15+
16+
/**
17+
* JavaScript for the letter group.
18+
*
19+
* @module block_townsquare/lettergroup
20+
* @copyright 2025 Tamaro Walter
21+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22+
*/
23+
24+
const letterboxes = document.getElementsByClassName('ts-letter-box');
25+
26+
const Selectors = {
27+
actions: {
28+
collapsegroup: '[data-action="block_townsquare/collapse_group"]',
29+
},
30+
};
31+
32+
/**
33+
* Init function. Adds event listener to orientation marker of letter group to enable
34+
* collapsing a letter group.
35+
*/
36+
export function init() {
37+
letterboxes.forEach(
38+
(element) => {
39+
element.style.maxHeight = `${element.scrollHeight}px`;
40+
element.setAttribute('expanded', 'true');
41+
}
42+
);
43+
44+
document.addEventListener('click', e => {
45+
const group = e.target.closest(Selectors.actions.collapsegroup);
46+
if (group) {
47+
const icon = group.querySelector('i');
48+
let groupid = group.dataset.groupid;
49+
letterboxes.forEach(
50+
(element) => {
51+
if (element.dataset.groupid === groupid) {
52+
if (element.getAttribute('expanded') === 'true') {
53+
icon.classList.remove('fa-chevron-down');
54+
icon.classList.add('fa-chevron-up');
55+
element.style.maxHeight = '0px';
56+
element.setAttribute('expanded', 'false');
57+
} else {
58+
icon.classList.remove('fa-chevron-up');
59+
icon.classList.add('fa-chevron-down');
60+
element.style.maxHeight = `${element.scrollHeight}px`;
61+
element.setAttribute('expanded', 'true');
62+
}
63+
}
64+
}
65+
);
66+
}
67+
});
68+
}

block_townsquare.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public function get_content(): stdClass {
5757
$this->page->requires->js_call_amd('block_townsquare/timefilter', 'init');
5858
$this->page->requires->js_call_amd('block_townsquare/letterfilter', 'init');
5959
$this->page->requires->js_call_amd('block_townsquare/filtercontroller', 'init');
60+
$this->page->requires->js_call_amd('block_townsquare/lettergroup', 'init');
6061
$this->page->requires->js_call_amd('block_townsquare/usersettings_save', 'init', [$USER->id, $usersettings]);
6162
$this->page->requires->js_call_amd('block_townsquare/usersettings_reset', 'init', [$USER->id]);
6263
return $this->content;

styles.css

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/blockcontent.mustache

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@
9292
<div class="orientationmarker">
9393
<span class="orientationmarker_date">{{day}}</span>
9494
<span class="orientationmarker_line" aria-hidden="true"></span>
95-
<i class="orientationmarker_arrow fa fa-chevron-down ml-3 mr-2"></i>
95+
<span class="orientationmarker-collapse" data-action="block_townsquare/collapse_group" data-groupid="{{day}}">
96+
<i class="fa fa-chevron-down ml-3 mr-2"></i>
97+
</span>
9698
</div>
97-
<div class="ts-letter-box" id="ts-letters-{{day}}">
99+
<div class="ts-letter-box" data-groupid="{{day}}">
98100
{{#letters}}
99101
{{#isbasic}}
100102
{{> block_townsquare/basicletter}}

0 commit comments

Comments
 (0)