2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function (Drupal, Backbone, $) {
9 Drupal.ckeditor.VisualView = Backbone.View.extend({
12 'click .ckeditor-toolbar-group-name': 'onGroupNameClick',
13 'click .ckeditor-groupnames-toggle': 'onGroupNamesToggleClick',
14 'click .ckeditor-add-new-group button': 'onAddGroupButtonClick'
17 initialize: function initialize() {
18 this.listenTo(this.model, 'change:isDirty change:groupNamesVisible', this.render);
20 $(Drupal.theme('ckeditorButtonGroupNamesToggle')).prependTo(this.$el.find('#ckeditor-active-toolbar').parent());
24 render: function render(model, value, changedAttributes) {
25 this.insertPlaceholders();
28 var groupNamesVisible = this.model.get('groupNamesVisible');
30 if (changedAttributes && changedAttributes.changes && changedAttributes.changes.isDirty) {
31 this.model.set({ groupNamesVisible: true }, { silent: true });
32 groupNamesVisible = true;
34 this.$el.find('[data-toolbar="active"]').toggleClass('ckeditor-group-names-are-visible', groupNamesVisible);
35 this.$el.find('.ckeditor-groupnames-toggle').text(groupNamesVisible ? Drupal.t('Hide group names') : Drupal.t('Show group names')).attr('aria-pressed', groupNamesVisible);
39 onGroupNameClick: function onGroupNameClick(event) {
40 var $group = $(event.currentTarget).closest('.ckeditor-toolbar-group');
41 Drupal.ckeditor.openGroupNameDialog(this, $group);
43 event.stopPropagation();
44 event.preventDefault();
46 onGroupNamesToggleClick: function onGroupNamesToggleClick(event) {
47 this.model.set('groupNamesVisible', !this.model.get('groupNamesVisible'));
48 event.preventDefault();
50 onAddGroupButtonClick: function onAddGroupButtonClick(event) {
51 function insertNewGroup(success, $group) {
53 $group.appendTo($(event.currentTarget).closest('.ckeditor-row').children('.ckeditor-toolbar-groups'));
55 $group.trigger('focus');
59 Drupal.ckeditor.openGroupNameDialog(this, $(Drupal.theme('ckeditorToolbarGroup')), insertNewGroup);
61 event.preventDefault();
63 endGroupDrag: function endGroupDrag(event, ui) {
65 Drupal.ckeditor.registerGroupMove(this, ui.item, function (success) {
67 view.$el.find('.ckeditor-toolbar-configuration').find('.ui-sortable').sortable('cancel');
71 startButtonDrag: function startButtonDrag(event, ui) {
72 this.$el.find('a:focus').trigger('blur');
74 this.model.set('groupNamesVisible', true);
76 endButtonDrag: function endButtonDrag(event, ui) {
78 Drupal.ckeditor.registerButtonMove(this, ui.item, function (success) {
80 view.$el.find('.ui-sortable').sortable('cancel');
83 ui.item.find('a').trigger('focus');
86 applySorting: function applySorting() {
87 this.$el.find('.ckeditor-buttons').not('.ui-sortable').sortable({
88 connectWith: '.ckeditor-buttons',
89 placeholder: 'ckeditor-button-placeholder',
90 forcePlaceholderSize: true,
93 start: this.startButtonDrag.bind(this),
95 stop: this.endButtonDrag.bind(this)
96 }).disableSelection();
98 this.$el.find('.ckeditor-toolbar-groups').not('.ui-sortable').sortable({
99 connectWith: '.ckeditor-toolbar-groups',
100 cancel: '.ckeditor-add-new-group',
101 placeholder: 'ckeditor-toolbar-group-placeholder',
102 forcePlaceholderSize: true,
104 stop: this.endGroupDrag.bind(this)
107 this.$el.find('.ckeditor-multiple-buttons li').draggable({
108 connectToSortable: '.ckeditor-toolbar-active .ckeditor-buttons',
112 insertPlaceholders: function insertPlaceholders() {
113 this.insertPlaceholderRow();
114 this.insertNewGroupButtons();
116 insertPlaceholderRow: function insertPlaceholderRow() {
117 var $rows = this.$el.find('.ckeditor-row');
119 if (!$rows.eq(-1).hasClass('placeholder')) {
120 this.$el.find('.ckeditor-toolbar-active').children('.ckeditor-active-toolbar-configuration').append(Drupal.theme('ckeditorRow'));
123 $rows = this.$el.find('.ckeditor-row');
125 var len = $rows.length;
126 $rows.filter(function (index, row) {
127 if (index + 1 === len) {
130 return $(row).find('.ckeditor-toolbar-group').not('.placeholder').length === 0;
133 insertNewGroupButtons: function insertNewGroupButtons() {
134 this.$el.find('.ckeditor-row').each(function () {
136 var $groups = $row.find('.ckeditor-toolbar-group');
137 var $button = $row.find('.ckeditor-add-new-group');
138 if ($button.length === 0) {
139 $row.children('.ckeditor-toolbar-groups').append(Drupal.theme('ckeditorNewButtonGroup'));
140 } else if (!$groups.eq(-1).hasClass('ckeditor-add-new-group')) {
141 $button.appendTo($row.children('.ckeditor-toolbar-groups'));
146 })(Drupal, Backbone, jQuery);