From 56f1f37e96bcd02a2e890d59f0597a9b2d3ab8cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=2E=20Rene=CC=81e=20Beach?= <splendidnoise@gmail.com>
Date: Fri, 15 Nov 2013 16:59:23 -0500
Subject: [PATCH] don't hide comments; position the toolbar better
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: J. Renée Beach <splendidnoise@gmail.com>
---
 core/modules/edit/css/edit.theme.css            |  6 ------
 core/modules/edit/js/views/EntityToolbarView.js | 28 +++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/core/modules/edit/css/edit.theme.css b/core/modules/edit/css/edit.theme.css
index 985f28a..fd5d64a 100644
--- a/core/modules/edit/css/edit.theme.css
+++ b/core/modules/edit/css/edit.theme.css
@@ -3,12 +3,6 @@
  */
 
 /**
- * Hide comments on entities
- */
-.edit-entity-active .comment-wrapper {
-  display: none ;
-}
-/**
  * Editable.
  */
 .edit-field.edit-editable,
diff --git a/core/modules/edit/js/views/EntityToolbarView.js b/core/modules/edit/js/views/EntityToolbarView.js
index d154362..34cc189 100644
--- a/core/modules/edit/js/views/EntityToolbarView.js
+++ b/core/modules/edit/js/views/EntityToolbarView.js
@@ -230,7 +230,31 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({
         top: Math.floor(suggested.top)
       });
       // Determine if the pointer should be on the top or bottom.
-      info.element.element.toggleClass('edit-toolbar-pointer-top', info.element.top > info.target.top);
+      var isBelow = suggested.top > info.target.top;
+      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]) {
+        // 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);
+      }
+      // Don't let the toolbar go outside the fence.
+      var fenceTop = this.$fence.offset().top;
+      var fenceHeight = this.$fence.height();
+      var toolbarHeight = info.element.element.outerHeight(true);
+      if (suggested.top < fenceTop) {
+        suggested.top = fenceTop;
+      }
+      else if ((suggested.top + toolbarHeight) > (fenceTop + fenceHeight)) {
+        suggested.top = fenceTop + fenceHeight - toolbarHeight;
+      }
+      // Position the toolbar.
+      info.element.element.css({
+        left: Math.floor(suggested.left),
+        top: Math.floor(suggested.top)
+      });
     }
 
     /**
@@ -246,7 +270,7 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({
           at: edge + '+' + (1 + horizontalPadding) + ' top',
           of: of,
           collision: 'flipfit',
-          using: refinePosition,
+          using: refinePosition.bind(that),
           within: that.$fence
         })
         // Resize the toolbar to match the dimensions of the field, up to a
-- 
1.8.2

