From 013697adc6f109699eec9b46a6371e21f063bfbe Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 12 Mar 2019 12:32:53 +0100 Subject: [PATCH] Improved ARIA support --- .../redactor2/plugins/WoltLabButton.js | 28 +-- .../redactor2/plugins/WoltLabObserve.js | 4 + .../redactor2/plugins/WoltLabSource.js | 4 - .../js/3rdParty/redactor2/plugins/source.js | 174 ++++-------------- .../files/js/3rdParty/redactor2/redactor.js | 22 ++- .../WoltLabSuite/Core/Ui/Dropdown/Simple.js | 4 - 6 files changed, 60 insertions(+), 176 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js index 7d9b4f9bec..e57f590fb2 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabButton.js @@ -5,20 +5,6 @@ $.Redactor.prototype.WoltLabButton = function() { return { init: function() { - // tooltips are handled on our own - this.button.buildButtonTooltip = function () {}; - - var mpClickCallback = this.button.clickCallback; - this.button.clickCallback = (function(e, callback, btnName, args) { - // prevent the browser from breaking the editor focus - if (typeof e.preventDefault === 'function') { - e.preventDefault(); - } - - //noinspection JSUnresolvedFunction - mpClickCallback.call(this, e, callback, btnName, args); - }).bind(this); - // add custom buttons var button, buttonName, i, length; //noinspection JSUnresolvedVariable @@ -30,6 +16,8 @@ $.Redactor.prototype.WoltLabButton = function() { this.button.addCallback(button, this.WoltLabButton._handleCustomButton); } + var toolbar = this.core.toolbar()[0]; + // set button icons and labels var buttonData, icon, iconIsImage; for (i = 0, length = this.opts.buttons.length; i < length; i++) { @@ -73,10 +61,7 @@ $.Redactor.prototype.WoltLabButton = function() { } icon = buttonData.icon; - iconIsImage = false; - if (!icon.match(/^fa-/) && icon.match(/\.(gif|jpe?g|png|svg)$/)) { - iconIsImage = true; - } + iconIsImage = (!icon.match(/^fa-/) && icon.match(/\.(gif|jpe?g|png|svg)$/)); // set icon //noinspection CssUnknownTarget @@ -87,7 +72,7 @@ $.Redactor.prototype.WoltLabButton = function() { // set title //noinspection JSUnresolvedVariable - elAttr(button[0], 'title', buttonData.title); + button[0].title = buttonData.title; button[0].classList.add('jsTooltip'); // update dropdown label for list @@ -98,9 +83,6 @@ $.Redactor.prototype.WoltLabButton = function() { } } - var toolbar = this.core.toolbar()[0]; - elBySelAll('.re-button-tooltip', toolbar.parentNode, elRemove); - // enforce button order as provided with `opts.buttons` var listItem, toolbarButtons = {}, toolbarOrder = []; while (toolbar.childElementCount) { @@ -154,7 +136,7 @@ $.Redactor.prototype.WoltLabButton = function() { }).bind(this)); // prevent drag & drop of toolbar buttons - this.$toolbar[0].addEventListener('dragstart', function (event) { + toolbar.addEventListener('dragstart', function (event) { event.preventDefault(); }); diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabObserve.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabObserve.js index 00a2b1dbfd..91d42f462e 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabObserve.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabObserve.js @@ -81,6 +81,10 @@ $.Redactor.prototype.WoltLabObserve = function() { this.button.enable('woltlabQuote'); } + if (isSource) { + this.button.setActive('html'); + } + // WoltLab modification: we know that there will be quite a few // active button states, so we'll simply check all ancestors one // by one instead of searching the DOM over and over again diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js index fefba54a90..9b07098964 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSource.js @@ -58,10 +58,6 @@ $.Redactor.prototype.WoltLabSource = function() { }); } - // disable caret position in source mode - this.source.setCaretOnShow = function () {}; - this.source.setCaretOnHide = function (html) { return html; }; - var mpHide = this.source.hide; this.source.hide = (function () { // use jQuery to parse, its parser is much more graceful diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/source.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/source.js index 8724a96520..09496cc879 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/source.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/source.js @@ -1,13 +1,10 @@ -(function($) -{ - $.Redactor.prototype.source = function() - { +(function ($) { + $.Redactor.prototype.source = function () { return { - init: function() - { + init: function () { var button = this.button.addFirst('html', 'HTML'); this.button.addCallback(button, this.source.toggle); - + var style = { 'width': '100%', 'margin': '0', @@ -20,175 +17,76 @@ 'line-height': '22px', 'font-family': 'Menlo, Monaco, Consolas, "Courier New", monospace' }; - + this.source.$textarea = $('