annotate core/modules/ckeditor/js/views/AuralView.js @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 /**
Chris@0 2 * DO NOT EDIT THIS FILE.
Chris@0 3 * See the following change record for more information,
Chris@0 4 * https://www.drupal.org/node/2815083
Chris@0 5 * @preserve
Chris@0 6 **/
Chris@0 7
Chris@0 8 (function (Drupal, Backbone, $) {
Chris@0 9 Drupal.ckeditor.AuralView = Backbone.View.extend({
Chris@0 10 events: {
Chris@0 11 'click .ckeditor-buttons a': 'announceButtonHelp',
Chris@0 12 'click .ckeditor-multiple-buttons a': 'announceSeparatorHelp',
Chris@0 13 'focus .ckeditor-button a': 'onFocus',
Chris@0 14 'focus .ckeditor-button-separator a': 'onFocus',
Chris@0 15 'focus .ckeditor-toolbar-group': 'onFocus'
Chris@0 16 },
Chris@0 17
Chris@0 18 initialize: function initialize() {
Chris@0 19 this.listenTo(this.model, 'change:isDirty', this.announceMove);
Chris@0 20 },
Chris@0 21 announceMove: function announceMove(model, isDirty) {
Chris@0 22 if (!isDirty) {
Chris@0 23 var item = document.activeElement || null;
Chris@0 24 if (item) {
Chris@0 25 var $item = $(item);
Chris@0 26 if ($item.hasClass('ckeditor-toolbar-group')) {
Chris@0 27 this.announceButtonGroupPosition($item);
Chris@0 28 } else if ($item.parent().hasClass('ckeditor-button')) {
Chris@0 29 this.announceButtonPosition($item.parent());
Chris@0 30 }
Chris@0 31 }
Chris@0 32 }
Chris@0 33 },
Chris@0 34 onFocus: function onFocus(event) {
Chris@0 35 event.stopPropagation();
Chris@0 36
Chris@0 37 var $originalTarget = $(event.target);
Chris@0 38 var $currentTarget = $(event.currentTarget);
Chris@0 39 var $parent = $currentTarget.parent();
Chris@0 40 if ($parent.hasClass('ckeditor-button') || $parent.hasClass('ckeditor-button-separator')) {
Chris@0 41 this.announceButtonPosition($currentTarget.parent());
Chris@0 42 } else if ($originalTarget.attr('role') !== 'button' && $currentTarget.hasClass('ckeditor-toolbar-group')) {
Chris@0 43 this.announceButtonGroupPosition($currentTarget);
Chris@0 44 }
Chris@0 45 },
Chris@0 46 announceButtonGroupPosition: function announceButtonGroupPosition($group) {
Chris@0 47 var $groups = $group.parent().children();
Chris@0 48 var $row = $group.closest('.ckeditor-row');
Chris@0 49 var $rows = $row.parent().children();
Chris@0 50 var position = $groups.index($group) + 1;
Chris@0 51 var positionCount = $groups.not('.placeholder').length;
Chris@0 52 var row = $rows.index($row) + 1;
Chris@0 53 var rowCount = $rows.not('.placeholder').length;
Chris@0 54 var text = Drupal.t('@groupName button group in position @position of @positionCount in row @row of @rowCount.', {
Chris@0 55 '@groupName': $group.attr('data-drupal-ckeditor-toolbar-group-name'),
Chris@0 56 '@position': position,
Chris@0 57 '@positionCount': positionCount,
Chris@0 58 '@row': row,
Chris@0 59 '@rowCount': rowCount
Chris@0 60 });
Chris@0 61
Chris@0 62 if (position === 1 && row === rowCount) {
Chris@0 63 text += '\n';
Chris@0 64 text += Drupal.t('Press the down arrow key to create a new row.');
Chris@0 65 }
Chris@0 66 Drupal.announce(text, 'assertive');
Chris@0 67 },
Chris@0 68 announceButtonPosition: function announceButtonPosition($button) {
Chris@0 69 var $row = $button.closest('.ckeditor-row');
Chris@0 70 var $rows = $row.parent().children();
Chris@0 71 var $buttons = $button.closest('.ckeditor-buttons').children();
Chris@0 72 var $group = $button.closest('.ckeditor-toolbar-group');
Chris@0 73 var $groups = $group.parent().children();
Chris@0 74 var groupPosition = $groups.index($group) + 1;
Chris@0 75 var groupPositionCount = $groups.not('.placeholder').length;
Chris@0 76 var position = $buttons.index($button) + 1;
Chris@0 77 var positionCount = $buttons.length;
Chris@0 78 var row = $rows.index($row) + 1;
Chris@0 79 var rowCount = $rows.not('.placeholder').length;
Chris@0 80
Chris@0 81 var type = $button.attr('data-drupal-ckeditor-type') === 'separator' ? '' : Drupal.t('button');
Chris@0 82 var text = void 0;
Chris@0 83
Chris@0 84 if ($button.closest('.ckeditor-toolbar-disabled').length > 0) {
Chris@0 85 text = Drupal.t('@name @type.', {
Chris@0 86 '@name': $button.children().attr('aria-label'),
Chris@0 87 '@type': type
Chris@0 88 });
Chris@0 89 text += '\n' + Drupal.t('Press the down arrow key to activate.');
Chris@0 90
Chris@0 91 Drupal.announce(text, 'assertive');
Chris@0 92 } else if ($group.not('.placeholder').length === 1) {
Chris@0 93 text = Drupal.t('@name @type in position @position of @positionCount in @groupName button group in row @row of @rowCount.', {
Chris@0 94 '@name': $button.children().attr('aria-label'),
Chris@0 95 '@type': type,
Chris@0 96 '@position': position,
Chris@0 97 '@positionCount': positionCount,
Chris@0 98 '@groupName': $group.attr('data-drupal-ckeditor-toolbar-group-name'),
Chris@0 99 '@row': row,
Chris@0 100 '@rowCount': rowCount
Chris@0 101 });
Chris@0 102
Chris@0 103 if (groupPosition === 1 && position === 1 && row === rowCount) {
Chris@0 104 text += '\n';
Chris@0 105 text += Drupal.t('Press the down arrow key to create a new button group in a new row.');
Chris@0 106 }
Chris@0 107
Chris@0 108 if (groupPosition === groupPositionCount && position === positionCount) {
Chris@0 109 text += '\n';
Chris@0 110 text += Drupal.t('This is the last group. Move the button forward to create a new group.');
Chris@0 111 }
Chris@0 112 Drupal.announce(text, 'assertive');
Chris@0 113 }
Chris@0 114 },
Chris@0 115 announceButtonHelp: function announceButtonHelp(event) {
Chris@0 116 var $link = $(event.currentTarget);
Chris@0 117 var $button = $link.parent();
Chris@0 118 var enabled = $button.closest('.ckeditor-toolbar-active').length > 0;
Chris@0 119 var message = void 0;
Chris@0 120
Chris@0 121 if (enabled) {
Chris@0 122 message = Drupal.t('The "@name" button is currently enabled.', {
Chris@0 123 '@name': $link.attr('aria-label')
Chris@0 124 });
Chris@0 125 message += '\n' + Drupal.t('Use the keyboard arrow keys to change the position of this button.');
Chris@0 126 message += '\n' + Drupal.t('Press the up arrow key on the top row to disable the button.');
Chris@0 127 } else {
Chris@0 128 message = Drupal.t('The "@name" button is currently disabled.', {
Chris@0 129 '@name': $link.attr('aria-label')
Chris@0 130 });
Chris@0 131 message += '\n' + Drupal.t('Use the down arrow key to move this button into the active toolbar.');
Chris@0 132 }
Chris@0 133 Drupal.announce(message);
Chris@0 134 event.preventDefault();
Chris@0 135 },
Chris@0 136 announceSeparatorHelp: function announceSeparatorHelp(event) {
Chris@0 137 var $link = $(event.currentTarget);
Chris@0 138 var $button = $link.parent();
Chris@0 139 var enabled = $button.closest('.ckeditor-toolbar-active').length > 0;
Chris@0 140 var message = void 0;
Chris@0 141
Chris@0 142 if (enabled) {
Chris@0 143 message = Drupal.t('This @name is currently enabled.', {
Chris@0 144 '@name': $link.attr('aria-label')
Chris@0 145 });
Chris@0 146 message += '\n' + Drupal.t('Use the keyboard arrow keys to change the position of this separator.');
Chris@0 147 } else {
Chris@0 148 message = Drupal.t('Separators are used to visually split individual buttons.');
Chris@0 149 message += '\n' + Drupal.t('This @name is currently disabled.', {
Chris@0 150 '@name': $link.attr('aria-label')
Chris@0 151 });
Chris@0 152 message += '\n' + Drupal.t('Use the down arrow key to move this separator into the active toolbar.');
Chris@0 153 message += '\n' + Drupal.t('You may add multiple separators to each button group.');
Chris@0 154 }
Chris@0 155 Drupal.announce(message);
Chris@0 156 event.preventDefault();
Chris@0 157 }
Chris@0 158 });
Chris@0 159 })(Drupal, Backbone, jQuery);