From 885643a6a1451003d3a789b04197f6bb7e98672b Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 11 Mar 2019 17:58:56 +0100 Subject: [PATCH] Improved ARIA support, use native drop-down menus inside Redactor --- .../redactor2/plugins/WoltLabButton.js | 3 + .../redactor2/plugins/WoltLabDropdown.js | 67 +-- .../redactor2/plugins/WoltLabObserve.js | 2 + .../files/js/3rdParty/redactor2/redactor.js | 425 ++++++++---------- wcfsetup/install/files/style/ui/redactor.scss | 51 +-- 5 files changed, 222 insertions(+), 326 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js index aa245a2548..7d9b4f9bec 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js @@ -157,6 +157,9 @@ $.Redactor.prototype.WoltLabButton = function() { this.$toolbar[0].addEventListener('dragstart', function (event) { event.preventDefault(); }); + + // Set the tabindex of the HTML button to `0` to support tab navigation (ARIA). + elAttr(elBySel('.re-html', toolbar), 'tabindex', 0); }, _handleCustomButton: function (bbcode) { diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabDropdown.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabDropdown.js index 009bae4e01..4cd1823258 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabDropdown.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabDropdown.js @@ -16,56 +16,9 @@ $.Redactor.prototype.WoltLabDropdown = function() { // the original implementation didn't perform that well (especially with multiple // instance being launched at start) and suffered from too many live DOM manipulations - this.dropdown.build = (function(name, $dropdown, dropdownObject) { - dropdownObject = this.dropdown.buildFormatting(name, dropdownObject); - - var btnObject, fragment = document.createDocumentFragment(); - for (var btnName in dropdownObject) { - if (dropdownObject.hasOwnProperty(btnName)) { - btnObject = dropdownObject[btnName]; - - var item = this.dropdown.buildItem(btnName, btnObject); - - this.observe.addDropdown($(item), btnName, btnObject); - fragment.appendChild(item); - } - } - - var hasItems = false; - for (var i = 0, length = fragment.childNodes.length; i < length; i++) { - if (fragment.childNodes[i].nodeType === Node.ELEMENT_NODE) { - hasItems = true; - break; - } - } - - if (hasItems) { - $dropdown[0].rel = name; - $dropdown[0].appendChild(fragment); - } - }).bind(this); - - this.dropdown.buildItem = (function(btnName, btnObject) { - var itemContainer = elCreate('li'); - if (typeof btnObject.classname !== 'undefined') { - itemContainer.classList.add(btnObject.classname); - } - - if (btnName.toLowerCase().indexOf('divider') === 0) { - itemContainer.classList.add('redactor-dropdown-divider'); - - return itemContainer; - } - - itemContainer.innerHTML = '' + btnObject.title + ''; - itemContainer.children[0].addEventListener('mousedown', (function(event) { - event.preventDefault(); - - this.dropdown.buildClick(event, btnName, btnObject); - }).bind(this)); - - return itemContainer; - }).bind(this); + // Integrated into Redactor itself in WoltLab Suite 5.2: + // * this.dropdown.build + // * this.dropdown.buildItem }, _hideAll: function() { @@ -78,24 +31,12 @@ $.Redactor.prototype.WoltLabDropdown = function() { }, _show: function() { + return; var show = this.dropdown.show; this.dropdown.show = (function(e, key) { var $button = this.button.get(key); var $dropdown = $button.data('dropdown'); - if (!elDataBool($dropdown[0], 'woltlab')) { - var list = elCreate('ul'); - list.className = 'dropdownMenu'; - - while ($dropdown[0].childElementCount) { - list.appendChild($dropdown[0].children[0]); - } - - $dropdown[0].appendChild(list); - - elData($dropdown[0], 'woltlab', true); - } - var isActive = $button.hasClass('dropact'); show.call(this, e, key); diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabObserve.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabObserve.js index b8bc9e167c..00a2b1dbfd 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabObserve.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabObserve.js @@ -22,6 +22,8 @@ $.Redactor.prototype.WoltLabObserve = function() { } button.classList.remove('redactor-act'); + if (button.rel !== 'html') elAttr(button, 'tabindex', -1); + elAttr(button, 'aria-pressed', false); } }).bind(this); diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js b/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js index 4a59b55ec4..aa06c0aaea 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/redactor.js @@ -1599,15 +1599,34 @@ true ); - var $dropdown = $('