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.KeyboardView = Backbone.View.extend({ Chris@0: initialize: function initialize() { Chris@0: this.$el.on('keydown.ckeditor', '.ckeditor-buttons a, .ckeditor-multiple-buttons a', this.onPressButton.bind(this)); Chris@0: this.$el.on('keydown.ckeditor', '[data-drupal-ckeditor-type="group"]', this.onPressGroup.bind(this)); Chris@0: }, Chris@0: render: function render() {}, Chris@0: onPressButton: function onPressButton(event) { Chris@0: var upDownKeys = [38, 63232, 40, 63233]; Chris@0: var leftRightKeys = [37, 63234, 39, 63235]; Chris@0: Chris@0: if (event.keyCode === 13) { Chris@0: event.stopPropagation(); Chris@0: } Chris@0: Chris@0: if (_.indexOf(_.union(upDownKeys, leftRightKeys), event.keyCode) > -1) { Chris@0: var view = this; Chris@0: var $target = $(event.currentTarget); Chris@0: var $button = $target.parent(); Chris@0: var $container = $button.parent(); Chris@0: var $group = $button.closest('.ckeditor-toolbar-group'); Chris@0: var $row = void 0; Chris@0: var containerType = $container.data('drupal-ckeditor-button-sorting'); Chris@0: var $availableButtons = this.$el.find('[data-drupal-ckeditor-button-sorting="source"]'); Chris@0: var $activeButtons = this.$el.find('.ckeditor-toolbar-active'); Chris@0: Chris@0: var $originalGroup = $group; Chris@0: var dir = void 0; Chris@0: Chris@0: if (containerType === 'source') { Chris@0: if (_.indexOf([40, 63233], event.keyCode) > -1) { Chris@0: $activeButtons.find('.ckeditor-toolbar-group-buttons').eq(0).prepend($button); Chris@0: } Chris@0: } else if (containerType === 'target') { Chris@0: if (_.indexOf(leftRightKeys, event.keyCode) > -1) { Chris@0: var $siblings = $container.children(); Chris@0: var index = $siblings.index($button); Chris@0: if (_.indexOf([37, 63234], event.keyCode) > -1) { Chris@0: if (index > 0) { Chris@0: $button.insertBefore($container.children().eq(index - 1)); Chris@0: } else { Chris@0: $group = $container.parent().prev(); Chris@0: if ($group.length > 0) { Chris@0: $group.find('.ckeditor-toolbar-group-buttons').append($button); Chris@0: } else { Chris@0: $container.closest('.ckeditor-row').prev().find('.ckeditor-toolbar-group').not('.placeholder').find('.ckeditor-toolbar-group-buttons').eq(-1).append($button); Chris@0: } Chris@0: } Chris@0: } else if (_.indexOf([39, 63235], event.keyCode) > -1) { Chris@0: if (index < $siblings.length - 1) { Chris@0: $button.insertAfter($container.children().eq(index + 1)); Chris@0: } else { Chris@0: $container.parent().next().find('.ckeditor-toolbar-group-buttons').prepend($button); Chris@0: } Chris@0: } Chris@0: } else if (_.indexOf(upDownKeys, event.keyCode) > -1) { Chris@0: dir = _.indexOf([38, 63232], event.keyCode) > -1 ? 'prev' : 'next'; Chris@0: $row = $container.closest('.ckeditor-row')[dir](); Chris@0: Chris@0: if (dir === 'prev' && $row.length === 0) { Chris@0: if ($button.data('drupal-ckeditor-type') === 'separator') { Chris@0: $button.off().remove(); Chris@0: Chris@0: $activeButtons.find('.ckeditor-toolbar-group-buttons').eq(0).children().eq(0).children().trigger('focus'); Chris@0: } else { Chris@0: $availableButtons.prepend($button); Chris@0: } Chris@0: } else { Chris@0: $row.find('.ckeditor-toolbar-group-buttons').eq(0).prepend($button); Chris@0: } Chris@0: } Chris@0: } else if (containerType === 'dividers') { Chris@0: if (_.indexOf([40, 63233], event.keyCode) > -1) { Chris@0: $button = $button.clone(true); Chris@0: $activeButtons.find('.ckeditor-toolbar-group-buttons').eq(0).prepend($button); Chris@0: $target = $button.children(); Chris@0: } Chris@0: } Chris@0: Chris@0: view = this; Chris@0: Chris@0: Drupal.ckeditor.registerButtonMove(this, $button, function (result) { Chris@0: if (!result && $originalGroup) { Chris@0: $originalGroup.find('.ckeditor-buttons').append($button); Chris@0: } else { Chris@0: view.$el.find('.ui-sortable').sortable('refresh'); Chris@0: } Chris@0: Chris@0: $target.trigger('focus'); Chris@0: }); Chris@0: Chris@0: event.preventDefault(); Chris@0: event.stopPropagation(); Chris@0: } Chris@0: }, Chris@0: onPressGroup: function onPressGroup(event) { Chris@0: var upDownKeys = [38, 63232, 40, 63233]; Chris@0: var leftRightKeys = [37, 63234, 39, 63235]; Chris@0: Chris@0: if (event.keyCode === 13) { Chris@0: var view = this; Chris@0: Chris@0: window.setTimeout(function () { Chris@0: Drupal.ckeditor.openGroupNameDialog(view, $(event.currentTarget)); Chris@0: }, 0); Chris@0: event.preventDefault(); Chris@0: event.stopPropagation(); Chris@0: } Chris@0: Chris@0: if (_.indexOf(_.union(upDownKeys, leftRightKeys), event.keyCode) > -1) { Chris@0: var $group = $(event.currentTarget); Chris@0: var $container = $group.parent(); Chris@0: var $siblings = $container.children(); Chris@0: var index = void 0; Chris@0: var dir = void 0; Chris@0: Chris@0: if (_.indexOf(leftRightKeys, event.keyCode) > -1) { Chris@0: index = $siblings.index($group); Chris@0: Chris@0: if (_.indexOf([37, 63234], event.keyCode) > -1) { Chris@0: if (index > 0) { Chris@0: $group.insertBefore($siblings.eq(index - 1)); Chris@0: } else { Chris@14: var $rowChildElement = $container.closest('.ckeditor-row').prev().find('.ckeditor-toolbar-groups').children().eq(-1); Chris@14: $group.insertBefore($rowChildElement); Chris@0: } Chris@0: } else if (_.indexOf([39, 63235], event.keyCode) > -1) { Chris@0: if (!$siblings.eq(index + 1).hasClass('placeholder')) { Chris@0: $group.insertAfter($container.children().eq(index + 1)); Chris@0: } else { Chris@0: $container.closest('.ckeditor-row').next().find('.ckeditor-toolbar-groups').prepend($group); Chris@0: } Chris@0: } Chris@0: } else if (_.indexOf(upDownKeys, event.keyCode) > -1) { Chris@0: dir = _.indexOf([38, 63232], event.keyCode) > -1 ? 'prev' : 'next'; Chris@0: $group.closest('.ckeditor-row')[dir]().find('.ckeditor-toolbar-groups').eq(0).prepend($group); Chris@0: } Chris@0: Chris@0: Drupal.ckeditor.registerGroupMove(this, $group); Chris@0: $group.trigger('focus'); Chris@0: event.preventDefault(); Chris@0: event.stopPropagation(); Chris@0: } Chris@0: } Chris@0: }); Chris@0: })(jQuery, Drupal, Backbone, _);