diff --git a/core/modules/edit/js/util.js b/core/modules/edit/js/util.js index ef5f3dc..78db78d 100644 --- a/core/modules/edit/js/util.js +++ b/core/modules/edit/js/util.js @@ -16,6 +16,31 @@ Drupal.edit.util.calcPropertyID = function(entity, predicate) { return entity.getSubjectUri() + '/' + predicate; }; +/** + * Return an aspect of the editor-specific edit UI integration. + * + * @param editor + * A create.js editor instance + * + * @param aspect + * Name of the integration configuration aspect. + * + * @return {*} + */ +Drupal.edit.util.getEditUiIntegrationAspect = function(editor, aspect) { + var config = {}; + // @todo: provide this drupalSettings? + var defaultConfig = { + padding: false, + unifiedToolbar: false, + fullWidthToolbar: false + }; + if (typeof editor.getEditUiIntegration === 'function') { + config = editor.getEditUiIntegration(); + } + return _.extend(defaultConfig, config)[aspect]; +} + Drupal.edit.util.buildUrl = function(id, urlFormat) { var parts = id.split('/'); return Drupal.formatString(decodeURIComponent(urlFormat), { diff --git a/core/modules/edit/js/views/propertyeditordecoration-view.js b/core/modules/edit/js/views/propertyeditordecoration-view.js index d0c52e0..b9ccf31 100644 --- a/core/modules/edit/js/views/propertyeditordecoration-view.js +++ b/core/modules/edit/js/views/propertyeditordecoration-view.js @@ -64,7 +64,7 @@ Drupal.edit.views.PropertyEditorDecorationView = Backbone.View.extend({ this.startHighlight(); break; case 'activating': - // NOTE: this stage is not used by every editor! It's only used by those + // NOTE: this state is not used by every editor! It's only used by those // that need to interact with the server. this.prepareEdit(); break; @@ -166,12 +166,12 @@ Drupal.edit.views.PropertyEditorDecorationView = Backbone.View.extend({ /** * Determines whether the PropertyEditor widget needs us to add padding. * - * @see Drupal.edit.views.ToolbarView._editUI() + * @see Drupal.edit.util.getEditUiIntegrationAspect(). * * @return bool */ _needsPadding: function() { - return Drupal.edit.views.ToolbarView._editUI(this.editor, 'padding'); + return Drupal.edit.util.getEditUiIntegrationAspect(this.editor, 'padding'); }, _pad: function () { diff --git a/core/modules/edit/js/views/toolbar-view.js b/core/modules/edit/js/views/toolbar-view.js index 31de8a2..ec9b8ce 100644 --- a/core/modules/edit/js/views/toolbar-view.js +++ b/core/modules/edit/js/views/toolbar-view.js @@ -70,7 +70,7 @@ Drupal.edit.views.ToolbarView = Backbone.View.extend({ break; case 'candidate': if (from !== 'inactive') { - if (from !== 'highlighted' && this._editUI('padding')) { + if (from !== 'highlighted' && this._needsPadding()) { this._unpad(); } this.remove(); @@ -87,14 +87,14 @@ Drupal.edit.views.ToolbarView = Backbone.View.extend({ case 'active': this.startEdit(); this.setLoadingIndicator(false); - if (this._editUI('fullWidthToolbar')) { + if (this.getEditUiIntegrationAspect('fullWidthToolbar')) { this.$el.addClass('edit-toolbar-fullwidth'); } - if (this._editUI('padding')) { + if (this._needsPadding()) { this._pad(); } - if (this._editUI('unifiedToolbar')) { + if (this.getEditUiIntegrationAspect('unifiedToolbar')) { this.insertWYSIWYGToolGroups(); } break; @@ -307,12 +307,21 @@ Drupal.edit.views.ToolbarView = Backbone.View.extend({ }, /** + * Determines whether the Editor needs us to add padding. + * + * @return bool + */ + _needsPadding: function() { + return this.getEditUiIntegrationAspect('padding'); + }, + + /** * Retrieves an Edit UI integration aspect as defined by the editor. * - * @see Drupal.edit.views.ToolbarView._editUI() + * @see Drupal.edit.util.getEditUiIntegrationAspect(). */ - _editUI: function(aspect) { - return Drupal.edit.views.ToolbarView._editUI(this.editor, aspect); + getEditUiIntegrationAspect: function(aspect) { + return Drupal.edit.util.getEditUiIntegrationAspect(this.editor, aspect); }, /** @@ -321,19 +330,19 @@ Drupal.edit.views.ToolbarView = Backbone.View.extend({ * @see PropertyEditorDecorationView._pad(). */ _pad: function() { - // The whole toolbar must move to the top when the property's DOM element - // is displayed inline. - if (this.editor.element.css('display') === 'inline') { - this.$el.css('top', parseInt(this.$el.css('top'), 10) - 5 + 'px'); - } + // The whole toolbar must move to the top when the property's DOM element + // is displayed inline. + if (this.editor.element.css('display') === 'inline') { + this.$el.css('top', parseInt(this.$el.css('top'), 10) - 5 + 'px'); + } - // The toolbar must move to the top and the left. - var $hf = this.$el.find('.edit-toolbar-heightfaker'); - $hf.css({ bottom: '6px', left: '-5px' }); + // The toolbar must move to the top and the left. + var $hf = this.$el.find('.edit-toolbar-heightfaker'); + $hf.css({ bottom: '6px', left: '-5px' }); - if (this._editUI('fullWidthToolbar')) { - $hf.css({ width: this.editor.element.width() + 10 }); - } + if (this.getEditUiIntegrationAspect('fullWidthToolbar')) { + $hf.css({ width: this.editor.element.width() + 10 }); + } }, /** @@ -342,13 +351,13 @@ Drupal.edit.views.ToolbarView = Backbone.View.extend({ * @see PropertyEditorDecorationView._unpad(). */ _unpad: function() { - // Move the toolbar back to its original position. - var $hf = this.$el.find('.edit-toolbar-heightfaker'); - $hf.css({ bottom: '1px', left: '' }); + // Move the toolbar back to its original position. + var $hf = this.$el.find('.edit-toolbar-heightfaker'); + $hf.css({ bottom: '1px', left: '' }); - if (this._editUI('fullWidthToolbar')) { - $hf.css({ width: '' }); - } + if (this.getEditUiIntegrationAspect('fullWidthToolbar')) { + $hf.css({ width: '' }); + } }, insertWYSIWYGToolGroups: function() { @@ -496,27 +505,6 @@ Drupal.edit.views.ToolbarView = Backbone.View.extend({ _find: function (toolgroup) { return this.$el.find('.edit-toolbar .edit-toolgroup.' + toolgroup); } -}, { - /** - * Retrieves an Edit UI integration aspect as defined by the editor. - * - * If the editor (Create.js PropertyEditor widget) does not configure an - * aspect, a default value is used. - * - * @param editWidget editor - * An editor (Create.js PropertyEditor widget). - * @param string aspect - * An Edit UI integration aspect. - */ - _editUI: function(editor, aspect) { - var config = {}, defaultConfig = { - needsPadding: false, needsFullWidth: false, needsUnifiedToolbar: false - }; - if (typeof editor.getEditUiIntegration === 'function') { - config = editor.getEditUiIntegration(); - } - return _.extend(defaultConfig, config)[aspect]; - } }); })(jQuery, _, Backbone, Drupal);