/*
MIT License
Copyright (c) 2016 Edenspiekermann
*/
(function () {
'use strict';
var internalId = 0;
var togglesMap = {};
var targetsMap = {};
function $ (selector, context) {
return Array.prototype.slice.call(
(context || document).querySelectorAll(selector)
);
}
function getClosestToggle (element) {
if (element.closest) {
return element.closest('[data-a11y-toggle]');
}
while (element) {
if (element.nodeType === 1 && element.hasAttribute('data-a11y-toggle')) {
return element;
}
element = element.parentNode;
}
return null;
}
function handleToggle (toggle) {
var target = toggle && targetsMap[toggle.getAttribute('aria-controls')];
if (!target) {
return false;
}
var toggles = togglesMap['#' + target.id];
var isExpanded = target.getAttribute('aria-hidden') === 'false';
target.setAttribute('aria-hidden', isExpanded);
toggles.forEach(function (toggle) {
toggle.setAttribute('aria-expanded', !isExpanded);
});
}
var initA11yToggle = function (context) {
togglesMap = $('[data-a11y-toggle]', context).reduce(function (acc, toggle) {
var selector = '#' + toggle.getAttribute('data-a11y-toggle');
acc[selector] = acc[selector] || [];
acc[selector].push(toggle);
return acc;
}, togglesMap);
var targets = Object.keys(togglesMap);
targets.length && $(targets).forEach(function (target) {
var toggles = togglesMap['#' + target.id];
var isExpanded = target.hasAttribute('data-a11y-toggle-open');
var labelledby = [];
toggles.forEach(function (toggle) {
toggle.id || toggle.setAttribute('id', 'a11y-toggle-' + internalId++);
toggle.setAttribute('aria-controls', target.id);
toggle.setAttribute('aria-expanded', isExpanded);
labelledby.push(toggle.id);
});
target.setAttribute('aria-hidden', !isExpanded);
target.hasAttribute('aria-labelledby') || target.setAttribute('aria-labelledby', labelledby.join(' '));
targetsMap[target.id] = target;
});
};
document.addEventListener('DOMContentLoaded', function () {
initA11yToggle();
});
document.addEventListener('click', function (event) {
var toggle = getClosestToggle(event.target);
handleToggle(toggle);
});
document.addEventListener('keyup', function (event) {
if (event.which === 13 || event.which === 32) {
var toggle = getClosestToggle(event.target);
if (toggle && toggle.getAttribute('role') === 'button') {
handleToggle(toggle);
}
}
});
window && (window.a11yToggle = initA11yToggle);
})();
istro/collabora/co-24.04'>distro/collabora/co-24.04
LibreOffice 核心代码仓库 | 文档基金会 |
Age | Commit message (Collapse) | Author |
|
Change-Id: I077509af72c16b08be836baba6855ac1fd7ba070
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108734
Tested-by: Jenkins
Reviewed-by: Rizal Muttaqin <riz_17_oke@yahoo.co.id>
|
|
Change-Id: Ic8f2e9f87ae5bab7fbfca623f960604bb93fdc12
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108208
Tested-by: Jenkins
Reviewed-by: Rizal Muttaqin <riz_17_oke@yahoo.co.id>
|
|
distribute, etc
Change-Id: I7759aef51af2f400f3f5ec69854fd9133e845f48
Reviewed-on: https://gerrit.libreoffice.org/62730
Tested-by: Jenkins
Reviewed-by: Rizal Muttaqin <riz_17_oke@yahoo.co.id>
|
|
Change-Id: I28f0e7b964a229320ede7accfd3a98e35ef113b3
Reviewed-on: https://gerrit.libreoffice.org/61180
Tested-by: Jenkins
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
|
|
Change-Id: I6a2bcdd8403494490a44c11179bf87411f73d32a
|
|
Change-Id: I28f0e7b964a229320ede7accfd3a98e35ef113b6
Reviewed-on: https://gerrit.libreoffice.org/60920
Tested-by: Jenkins
Reviewed-by: andreas_kainz <kainz.a@gmail.com>
|
|
Change-Id: Ie1e82545d7e6374acaab17470c0d84383a82ec8c
Reviewed-on: https://gerrit.libreoffice.org/46174
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: andreas_kainz <kainz.a@gmail.com>
|
|
Change-Id: I6db076e67ca742c410899a2f6cbf9728bc16b92b
Reviewed-on: https://gerrit.libreoffice.org/44219
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: andreas_kainz <kainz.a@gmail.com>
|