Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions assets/css/main.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/css/main.css.map

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions assets/js-translations/teacher.fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"Filter":
"Suodatus",

"Reset filters":
"Nollaa suodattimet",

"Collapse":
"Supista",

Expand All @@ -38,6 +41,18 @@
"Student name":
"Opiskelijan nimi",

"First name":
"Etunimi",

"Last name":
"Sukunimi",

"Email":
"S\u00E4hk\u00F6posti",

"Status":
"Tila",

"Organization":
"Organisaatio",

Expand Down
50 changes: 33 additions & 17 deletions assets/js/buttons_popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,54 @@ $.fn.extend({
*/
buttons_popover: function (buttons, options) {
this.each(function (i, elem) {
const this_buttons = typeof buttons === "function" ?
buttons(elem) :
buttons;
const this_buttons = typeof buttons === "function" ? buttons(elem) : buttons;
const default_options = {
html: true,
sanitize: false,
placement: 'bottom',
trigger: 'focus',
}
container: 'body',
};
const all_options = $.extend({}, default_options, options);

const buttons_html = this_buttons.map(function (btn) {
return ('<button id="' + btn.id + '" class="btn ' + btn.classes +
'" ' + (btn.extra_attrs || "") + ">" + btn.text + "</button>")
}).join(' ');
// We have to attach the event handlers to body because the buttons are
// created only when the popover is open and are destroyed when it is closed

const $elem = $(elem);
// Make focusable for trigger: 'focus'
$elem.attr({ 'tabindex': 0 });

// Attach delegated handlers for dynamically created buttons
// Namespace per-button id to avoid duplicate handlers on re-init
this_buttons.forEach(function (btn) {
$('body').on('click', 'button#' + btn.id, function () {
// Close this popover by triggering a click
$elem.trigger('click');
return btn.onclick();
});
const ev = 'click.buttonsPopover.' + btn.id;
$('body')
.off(ev, 'button#' + btn.id)
.on(ev, 'button#' + btn.id, function () {
// Hide popover then execute action
try {
const inst = bootstrap.Popover.getInstance($elem[0]);
if (inst) inst.hide();
} catch (e) { /* ignore */ }
return btn.onclick();
});
});

$elem.attr({
'data-bs-toggle': 'popover',
'data-content': buttons_html,
'tabindex': 0
});
$elem.popover(all_options);
// Initialize Bootstrap 5 popover (idempotent)
try {
const existing = bootstrap.Popover.getInstance($elem[0]);
if (!existing) {
new bootstrap.Popover($elem[0], $.extend({}, all_options, { content: buttons_html }));
} else {
// Update content attribute for existing instance
$elem.attr('data-bs-content', buttons_html);
}
} catch (e) {
// As a fallback, set data attributes for any legacy initializers
$elem.attr({ 'data-bs-toggle': 'popover', 'data-bs-content': buttons_html });
}
});
},
});
Loading
Loading