Chris@0: /** Chris@0: * DO NOT EDIT THIS FILE. Chris@0: * See the following change record for more information, Chris@0: * https://www.drupal.org/node/2815083 Chris@0: * @preserve Chris@0: **/ Chris@0: Chris@0: (function (Drupal, Backbone, $) { Chris@0: Drupal.ckeditor.AuralView = Backbone.View.extend({ Chris@0: events: { Chris@0: 'click .ckeditor-buttons a': 'announceButtonHelp', Chris@0: 'click .ckeditor-multiple-buttons a': 'announceSeparatorHelp', Chris@0: 'focus .ckeditor-button a': 'onFocus', Chris@0: 'focus .ckeditor-button-separator a': 'onFocus', Chris@0: 'focus .ckeditor-toolbar-group': 'onFocus' Chris@0: }, Chris@0: Chris@0: initialize: function initialize() { Chris@0: this.listenTo(this.model, 'change:isDirty', this.announceMove); Chris@0: }, Chris@0: announceMove: function announceMove(model, isDirty) { Chris@0: if (!isDirty) { Chris@0: var item = document.activeElement || null; Chris@0: if (item) { Chris@0: var $item = $(item); Chris@0: if ($item.hasClass('ckeditor-toolbar-group')) { Chris@0: this.announceButtonGroupPosition($item); Chris@0: } else if ($item.parent().hasClass('ckeditor-button')) { Chris@0: this.announceButtonPosition($item.parent()); Chris@0: } Chris@0: } Chris@0: } Chris@0: }, Chris@0: onFocus: function onFocus(event) { Chris@0: event.stopPropagation(); Chris@0: Chris@0: var $originalTarget = $(event.target); Chris@0: var $currentTarget = $(event.currentTarget); Chris@0: var $parent = $currentTarget.parent(); Chris@0: if ($parent.hasClass('ckeditor-button') || $parent.hasClass('ckeditor-button-separator')) { Chris@0: this.announceButtonPosition($currentTarget.parent()); Chris@0: } else if ($originalTarget.attr('role') !== 'button' && $currentTarget.hasClass('ckeditor-toolbar-group')) { Chris@0: this.announceButtonGroupPosition($currentTarget); Chris@0: } Chris@0: }, Chris@0: announceButtonGroupPosition: function announceButtonGroupPosition($group) { Chris@0: var $groups = $group.parent().children(); Chris@0: var $row = $group.closest('.ckeditor-row'); Chris@0: var $rows = $row.parent().children(); Chris@0: var position = $groups.index($group) + 1; Chris@0: var positionCount = $groups.not('.placeholder').length; Chris@0: var row = $rows.index($row) + 1; Chris@0: var rowCount = $rows.not('.placeholder').length; Chris@0: var text = Drupal.t('@groupName button group in position @position of @positionCount in row @row of @rowCount.', { Chris@0: '@groupName': $group.attr('data-drupal-ckeditor-toolbar-group-name'), Chris@0: '@position': position, Chris@0: '@positionCount': positionCount, Chris@0: '@row': row, Chris@0: '@rowCount': rowCount Chris@0: }); Chris@0: Chris@0: if (position === 1 && row === rowCount) { Chris@0: text += '\n'; Chris@0: text += Drupal.t('Press the down arrow key to create a new row.'); Chris@0: } Chris@0: Drupal.announce(text, 'assertive'); Chris@0: }, Chris@0: announceButtonPosition: function announceButtonPosition($button) { Chris@0: var $row = $button.closest('.ckeditor-row'); Chris@0: var $rows = $row.parent().children(); Chris@0: var $buttons = $button.closest('.ckeditor-buttons').children(); Chris@0: var $group = $button.closest('.ckeditor-toolbar-group'); Chris@0: var $groups = $group.parent().children(); Chris@0: var groupPosition = $groups.index($group) + 1; Chris@0: var groupPositionCount = $groups.not('.placeholder').length; Chris@0: var position = $buttons.index($button) + 1; Chris@0: var positionCount = $buttons.length; Chris@0: var row = $rows.index($row) + 1; Chris@0: var rowCount = $rows.not('.placeholder').length; Chris@0: Chris@0: var type = $button.attr('data-drupal-ckeditor-type') === 'separator' ? '' : Drupal.t('button'); Chris@0: var text = void 0; Chris@0: Chris@0: if ($button.closest('.ckeditor-toolbar-disabled').length > 0) { Chris@0: text = Drupal.t('@name @type.', { Chris@0: '@name': $button.children().attr('aria-label'), Chris@0: '@type': type Chris@0: }); Chris@0: text += '\n' + Drupal.t('Press the down arrow key to activate.'); Chris@0: Chris@0: Drupal.announce(text, 'assertive'); Chris@0: } else if ($group.not('.placeholder').length === 1) { Chris@0: text = Drupal.t('@name @type in position @position of @positionCount in @groupName button group in row @row of @rowCount.', { Chris@0: '@name': $button.children().attr('aria-label'), Chris@0: '@type': type, Chris@0: '@position': position, Chris@0: '@positionCount': positionCount, Chris@0: '@groupName': $group.attr('data-drupal-ckeditor-toolbar-group-name'), Chris@0: '@row': row, Chris@0: '@rowCount': rowCount Chris@0: }); Chris@0: Chris@0: if (groupPosition === 1 && position === 1 && row === rowCount) { Chris@0: text += '\n'; Chris@0: text += Drupal.t('Press the down arrow key to create a new button group in a new row.'); Chris@0: } Chris@0: Chris@0: if (groupPosition === groupPositionCount && position === positionCount) { Chris@0: text += '\n'; Chris@0: text += Drupal.t('This is the last group. Move the button forward to create a new group.'); Chris@0: } Chris@0: Drupal.announce(text, 'assertive'); Chris@0: } Chris@0: }, Chris@0: announceButtonHelp: function announceButtonHelp(event) { Chris@0: var $link = $(event.currentTarget); Chris@0: var $button = $link.parent(); Chris@0: var enabled = $button.closest('.ckeditor-toolbar-active').length > 0; Chris@0: var message = void 0; Chris@0: Chris@0: if (enabled) { Chris@0: message = Drupal.t('The "@name" button is currently enabled.', { Chris@0: '@name': $link.attr('aria-label') Chris@0: }); Chris@0: message += '\n' + Drupal.t('Use the keyboard arrow keys to change the position of this button.'); Chris@0: message += '\n' + Drupal.t('Press the up arrow key on the top row to disable the button.'); Chris@0: } else { Chris@0: message = Drupal.t('The "@name" button is currently disabled.', { Chris@0: '@name': $link.attr('aria-label') Chris@0: }); Chris@0: message += '\n' + Drupal.t('Use the down arrow key to move this button into the active toolbar.'); Chris@0: } Chris@0: Drupal.announce(message); Chris@0: event.preventDefault(); Chris@0: }, Chris@0: announceSeparatorHelp: function announceSeparatorHelp(event) { Chris@0: var $link = $(event.currentTarget); Chris@0: var $button = $link.parent(); Chris@0: var enabled = $button.closest('.ckeditor-toolbar-active').length > 0; Chris@0: var message = void 0; Chris@0: Chris@0: if (enabled) { Chris@0: message = Drupal.t('This @name is currently enabled.', { Chris@0: '@name': $link.attr('aria-label') Chris@0: }); Chris@0: message += '\n' + Drupal.t('Use the keyboard arrow keys to change the position of this separator.'); Chris@0: } else { Chris@0: message = Drupal.t('Separators are used to visually split individual buttons.'); Chris@0: message += '\n' + Drupal.t('This @name is currently disabled.', { Chris@0: '@name': $link.attr('aria-label') Chris@0: }); Chris@0: message += '\n' + Drupal.t('Use the down arrow key to move this separator into the active toolbar.'); Chris@0: message += '\n' + Drupal.t('You may add multiple separators to each button group.'); Chris@0: } Chris@0: Drupal.announce(message); Chris@0: event.preventDefault(); Chris@0: } Chris@0: }); Chris@0: })(Drupal, Backbone, jQuery);