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