Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 12... Línea 12...
12
//
12
//
13
// You should have received a copy of the GNU General Public License
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/>.
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 15... Línea 15...
15
 
15
 
16
/**
16
/**
17
 * Screen reader-only (sr-only) reactive mutations logger class.
17
 * Screen reader-only (visually-hidden) reactive mutations logger class.
18
 *
18
 *
19
 * This logger can be used by the StateManager to log mutation feedbacks and actions.
19
 * This logger can be used by the StateManager to log mutation feedbacks and actions.
20
 * The feedback messages logged by this logger will be rendered in a sr-only, ARIA live region.
20
 * The feedback messages logged by this logger will be rendered in a visually-hidden, ARIA live region.
21
 *
21
 *
22
 * @module     core/local/reactive/srlogger
22
 * @module     core/local/reactive/srlogger
23
 * @class      SRLogger
23
 * @class      SRLogger
24
 * @copyright  2023 Jun Pataleta <jun@moodle.com>
24
 * @copyright  2023 Jun Pataleta <jun@moodle.com>
Línea 33... Línea 33...
33
 * @typedef {object} LoggerEntry
33
 * @typedef {object} LoggerEntry
34
 * @property {string} feedbackMessage Feedback message.
34
 * @property {string} feedbackMessage Feedback message.
35
 */
35
 */
Línea 36... Línea 36...
36
 
36
 
37
/**
37
/**
38
 * Screen reader-only (sr-only) reactive mutations logger class.
38
 * Screen reader-only (visually-hidden) reactive mutations logger class.
39
 *
39
 *
40
 * @class SRLogger
40
 * @class SRLogger
41
 */
41
 */
42
export default class SRLogger extends Logger {
42
export default class SRLogger extends Logger {
Línea 56... Línea 56...
56
            // Fetch or create an ARIA live region that will serve as the container for the logger feedback.
56
            // Fetch or create an ARIA live region that will serve as the container for the logger feedback.
57
            let loggerFeedback = document.getElementById(SRLogger.liveRegionId);
57
            let loggerFeedback = document.getElementById(SRLogger.liveRegionId);
58
            if (!loggerFeedback) {
58
            if (!loggerFeedback) {
59
                loggerFeedback = document.createElement('div');
59
                loggerFeedback = document.createElement('div');
60
                loggerFeedback.id = SRLogger.liveRegionId;
60
                loggerFeedback.id = SRLogger.liveRegionId;
61
                loggerFeedback.classList.add('sr-only');
61
                loggerFeedback.classList.add('visually-hidden');
62
                loggerFeedback.setAttribute('aria-live', 'polite');
62
                loggerFeedback.setAttribute('aria-live', 'polite');
63
                document.body.append(loggerFeedback);
63
                document.body.append(loggerFeedback);
64
            }
64
            }
65
            // Set the ARIA live region's contents with the feedback.
65
            // Set the ARIA live region's contents with the feedback.
66
            loggerFeedback.innerHTML = entry.feedbackMessage;
66
            loggerFeedback.innerHTML = entry.feedbackMessage;