diff --git a/core/modules/edit/js/views/EntityToolbarView.js b/core/modules/edit/js/views/EntityToolbarView.js index 34cc189..a412821 100644 --- a/core/modules/edit/js/views/EntityToolbarView.js +++ b/core/modules/edit/js/views/EntityToolbarView.js @@ -224,7 +224,7 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({ * element that the 'my' element will be positioned against. Also known * as the 'of' element. */ - function refinePosition (suggested, info) { + function refinePosition (view, suggested, info) { info.element.element.css({ left: Math.floor(suggested.left), top: Math.floor(suggested.top) @@ -234,15 +234,17 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({ info.element.element.toggleClass('edit-toolbar-pointer-top', isBelow); // Don't position the toolbar past the first or last editable field if // the entity is the target. - if (this.$entity[0] === info.target.element[0]) { + if (view.$entity[0] === info.target.element[0]) { // Get the first or last field according to whether the toolbar is above // or below the entity. - var $field = this.$entity.find('.edit-editable').eq((isBelow) ? -1 : 0); - suggested.top = (isBelow) ? ($field.offset().top + $field.outerHeight(true)) : $field.offset().top - info.element.element.outerHeight(true); + var $field = view.$entity.find('.edit-editable').eq((isBelow) ? -1 : 0); + if ($field.length > 0) { + suggested.top = (isBelow) ? ($field.offset().top + $field.outerHeight(true)) : $field.offset().top - info.element.element.outerHeight(true); + } } // Don't let the toolbar go outside the fence. - var fenceTop = this.$fence.offset().top; - var fenceHeight = this.$fence.height(); + var fenceTop = view.$fence.offset().top; + var fenceHeight = view.$fence.height(); var toolbarHeight = info.element.element.outerHeight(true); if (suggested.top < fenceTop) { suggested.top = fenceTop; @@ -270,7 +272,7 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({ at: edge + '+' + (1 + horizontalPadding) + ' top', of: of, collision: 'flipfit', - using: refinePosition.bind(that), + using: refinePosition.bind(null, that), within: that.$fence }) // Resize the toolbar to match the dimensions of the field, up to a