Fix block and container highlight for resizing
Previously the position of cursor (inside/outside block) was tracked during the resizing. This commit changes this focus detection so that it is detected once at the end of resizing based on the final mouse position. Thanks to event bubbling parent containers could set correct highlight state as well. [MAILPOET-1819]
This commit is contained in:
committed by
M. Shull
parent
ad05c0ca94
commit
cc9a0c4141
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
import Marionette from 'backbone.marionette';
|
||||
import BL from 'newsletter_editor/behaviors/BehaviorsLookup';
|
||||
import { isEventInsideElement } from 'newsletter_editor/utils';
|
||||
|
||||
BL.HighlightEditingBehavior = Marionette.Behavior.extend({
|
||||
modelEvents: {
|
||||
@@ -12,17 +13,11 @@ BL.HighlightEditingBehavior = Marionette.Behavior.extend({
|
||||
stopEditing: 'onStopEditing',
|
||||
startResizing: 'onStartResizing',
|
||||
stopResizing: 'onStopResizing',
|
||||
resizeMove: 'onResizeMove',
|
||||
},
|
||||
events: {
|
||||
mouseenter: 'onMouseEnter',
|
||||
mouseleave: 'onMouseLeave',
|
||||
},
|
||||
// mouseleave event is not always triggered during resizing
|
||||
// so we have to check if the pointer is still inside using resize event coordinates
|
||||
onResizeMove: function onResizeMove(event) {
|
||||
this.isFocusedByPointer = event.isViewFocused;
|
||||
},
|
||||
onMouseEnter: function onMouseEnter(mouseEvent) {
|
||||
this.isFocusedByPointer = true;
|
||||
// Ignore mouse events when dragging
|
||||
@@ -54,6 +49,7 @@ BL.HighlightEditingBehavior = Marionette.Behavior.extend({
|
||||
this.view.triggerMethod('resizeStart');
|
||||
},
|
||||
onStopResizing: function onStopResizing(event) {
|
||||
this.isFocusedByPointer = isEventInsideElement(event, this.view.$el);
|
||||
this.onStopEditing();
|
||||
this.view.triggerMethod('resizeStop', event);
|
||||
},
|
||||
@@ -63,10 +59,13 @@ BL.HighlightEditingBehavior = Marionette.Behavior.extend({
|
||||
}
|
||||
},
|
||||
onChildviewResizeStart: function onChildviewResizeStart() {
|
||||
this.onStartEditing();
|
||||
// Let event bubble up
|
||||
this.view.triggerMethod('resizeStart');
|
||||
},
|
||||
onChildviewResizeStop: function onChildviewResizeStop(event) {
|
||||
this.isFocusedByPointer = isEventInsideElement(event, this.view.$el);
|
||||
this.onStopEditing();
|
||||
// Let event bubble up
|
||||
this.view.triggerMethod('resizeStop', event);
|
||||
},
|
||||
|
@@ -60,7 +60,6 @@ BL.ResizableBehavior = Marionette.Behavior.extend({
|
||||
that.$el.addClass('mailpoet_resize_active');
|
||||
}).on('resizemove', function resizemove(event) {
|
||||
var onResize = that.options.onResize.bind(that);
|
||||
that.view.model.trigger('resizeMove', that.detectMousePointerFocus(event));
|
||||
return onResize(event);
|
||||
})
|
||||
.on('resizeend', function resizeend(event) {
|
||||
|
Reference in New Issue
Block a user