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

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 1fec387a4317
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.KeyboardView = Backbone.View.extend({
Chris@0 10 initialize: function initialize() {
Chris@0 11 this.$el.on('keydown.ckeditor', '.ckeditor-buttons a, .ckeditor-multiple-buttons a', this.onPressButton.bind(this));
Chris@0 12 this.$el.on('keydown.ckeditor', '[data-drupal-ckeditor-type="group"]', this.onPressGroup.bind(this));
Chris@0 13 },
Chris@0 14 render: function render() {},
Chris@0 15 onPressButton: function onPressButton(event) {
Chris@0 16 var upDownKeys = [38, 63232, 40, 63233];
Chris@0 17 var leftRightKeys = [37, 63234, 39, 63235];
Chris@0 18
Chris@0 19 if (event.keyCode === 13) {
Chris@0 20 event.stopPropagation();
Chris@0 21 }
Chris@0 22
Chris@0 23 if (_.indexOf(_.union(upDownKeys, leftRightKeys), event.keyCode) > -1) {
Chris@0 24 var view = this;
Chris@0 25 var $target = $(event.currentTarget);
Chris@0 26 var $button = $target.parent();
Chris@0 27 var $container = $button.parent();
Chris@0 28 var $group = $button.closest('.ckeditor-toolbar-group');
Chris@0 29 var $row = void 0;
Chris@0 30 var containerType = $container.data('drupal-ckeditor-button-sorting');
Chris@0 31 var $availableButtons = this.$el.find('[data-drupal-ckeditor-button-sorting="source"]');
Chris@0 32 var $activeButtons = this.$el.find('.ckeditor-toolbar-active');
Chris@0 33
Chris@0 34 var $originalGroup = $group;
Chris@0 35 var dir = void 0;
Chris@0 36
Chris@0 37 if (containerType === 'source') {
Chris@0 38 if (_.indexOf([40, 63233], event.keyCode) > -1) {
Chris@0 39 $activeButtons.find('.ckeditor-toolbar-group-buttons').eq(0).prepend($button);
Chris@0 40 }
Chris@0 41 } else if (containerType === 'target') {
Chris@0 42 if (_.indexOf(leftRightKeys, event.keyCode) > -1) {
Chris@0 43 var $siblings = $container.children();
Chris@0 44 var index = $siblings.index($button);
Chris@0 45 if (_.indexOf([37, 63234], event.keyCode) > -1) {
Chris@0 46 if (index > 0) {
Chris@0 47 $button.insertBefore($container.children().eq(index - 1));
Chris@0 48 } else {
Chris@0 49 $group = $container.parent().prev();
Chris@0 50 if ($group.length > 0) {
Chris@0 51 $group.find('.ckeditor-toolbar-group-buttons').append($button);
Chris@0 52 } else {
Chris@0 53 $container.closest('.ckeditor-row').prev().find('.ckeditor-toolbar-group').not('.placeholder').find('.ckeditor-toolbar-group-buttons').eq(-1).append($button);
Chris@0 54 }
Chris@0 55 }
Chris@0 56 } else if (_.indexOf([39, 63235], event.keyCode) > -1) {
Chris@0 57 if (index < $siblings.length - 1) {
Chris@0 58 $button.insertAfter($container.children().eq(index + 1));
Chris@0 59 } else {
Chris@0 60 $container.parent().next().find('.ckeditor-toolbar-group-buttons').prepend($button);
Chris@0 61 }
Chris@0 62 }
Chris@0 63 } else if (_.indexOf(upDownKeys, event.keyCode) > -1) {
Chris@0 64 dir = _.indexOf([38, 63232], event.keyCode) > -1 ? 'prev' : 'next';
Chris@0 65 $row = $container.closest('.ckeditor-row')[dir]();
Chris@0 66
Chris@0 67 if (dir === 'prev' && $row.length === 0) {
Chris@0 68 if ($button.data('drupal-ckeditor-type') === 'separator') {
Chris@0 69 $button.off().remove();
Chris@0 70
Chris@0 71 $activeButtons.find('.ckeditor-toolbar-group-buttons').eq(0).children().eq(0).children().trigger('focus');
Chris@0 72 } else {
Chris@0 73 $availableButtons.prepend($button);
Chris@0 74 }
Chris@0 75 } else {
Chris@0 76 $row.find('.ckeditor-toolbar-group-buttons').eq(0).prepend($button);
Chris@0 77 }
Chris@0 78 }
Chris@0 79 } else if (containerType === 'dividers') {
Chris@0 80 if (_.indexOf([40, 63233], event.keyCode) > -1) {
Chris@0 81 $button = $button.clone(true);
Chris@0 82 $activeButtons.find('.ckeditor-toolbar-group-buttons').eq(0).prepend($button);
Chris@0 83 $target = $button.children();
Chris@0 84 }
Chris@0 85 }
Chris@0 86
Chris@0 87 view = this;
Chris@0 88
Chris@0 89 Drupal.ckeditor.registerButtonMove(this, $button, function (result) {
Chris@0 90 if (!result && $originalGroup) {
Chris@0 91 $originalGroup.find('.ckeditor-buttons').append($button);
Chris@0 92 } else {
Chris@0 93 view.$el.find('.ui-sortable').sortable('refresh');
Chris@0 94 }
Chris@0 95
Chris@0 96 $target.trigger('focus');
Chris@0 97 });
Chris@0 98
Chris@0 99 event.preventDefault();
Chris@0 100 event.stopPropagation();
Chris@0 101 }
Chris@0 102 },
Chris@0 103 onPressGroup: function onPressGroup(event) {
Chris@0 104 var upDownKeys = [38, 63232, 40, 63233];
Chris@0 105 var leftRightKeys = [37, 63234, 39, 63235];
Chris@0 106
Chris@0 107 if (event.keyCode === 13) {
Chris@0 108 var view = this;
Chris@0 109
Chris@0 110 window.setTimeout(function () {
Chris@0 111 Drupal.ckeditor.openGroupNameDialog(view, $(event.currentTarget));
Chris@0 112 }, 0);
Chris@0 113 event.preventDefault();
Chris@0 114 event.stopPropagation();
Chris@0 115 }
Chris@0 116
Chris@0 117 if (_.indexOf(_.union(upDownKeys, leftRightKeys), event.keyCode) > -1) {
Chris@0 118 var $group = $(event.currentTarget);
Chris@0 119 var $container = $group.parent();
Chris@0 120 var $siblings = $container.children();
Chris@0 121 var index = void 0;
Chris@0 122 var dir = void 0;
Chris@0 123
Chris@0 124 if (_.indexOf(leftRightKeys, event.keyCode) > -1) {
Chris@0 125 index = $siblings.index($group);
Chris@0 126
Chris@0 127 if (_.indexOf([37, 63234], event.keyCode) > -1) {
Chris@0 128 if (index > 0) {
Chris@0 129 $group.insertBefore($siblings.eq(index - 1));
Chris@0 130 } else {
Chris@14 131 var $rowChildElement = $container.closest('.ckeditor-row').prev().find('.ckeditor-toolbar-groups').children().eq(-1);
Chris@14 132 $group.insertBefore($rowChildElement);
Chris@0 133 }
Chris@0 134 } else if (_.indexOf([39, 63235], event.keyCode) > -1) {
Chris@0 135 if (!$siblings.eq(index + 1).hasClass('placeholder')) {
Chris@0 136 $group.insertAfter($container.children().eq(index + 1));
Chris@0 137 } else {
Chris@0 138 $container.closest('.ckeditor-row').next().find('.ckeditor-toolbar-groups').prepend($group);
Chris@0 139 }
Chris@0 140 }
Chris@0 141 } else if (_.indexOf(upDownKeys, event.keyCode) > -1) {
Chris@0 142 dir = _.indexOf([38, 63232], event.keyCode) > -1 ? 'prev' : 'next';
Chris@0 143 $group.closest('.ckeditor-row')[dir]().find('.ckeditor-toolbar-groups').eq(0).prepend($group);
Chris@0 144 }
Chris@0 145
Chris@0 146 Drupal.ckeditor.registerGroupMove(this, $group);
Chris@0 147 $group.trigger('focus');
Chris@0 148 event.preventDefault();
Chris@0 149 event.stopPropagation();
Chris@0 150 }
Chris@0 151 }
Chris@0 152 });
Chris@0 153 })(jQuery, Drupal, Backbone, _);