Add resize events bubbling from block to containers

https://marionettejs.com/docs/master/events.html#event-bubbling
[MAIPOET-1816]
This commit is contained in:
Rostislav Wolny
2019-03-12 15:56:28 +01:00
committed by M. Shull
parent d445495cba
commit ad05c0ca94
3 changed files with 26 additions and 2 deletions

View File

@@ -10,6 +10,8 @@ BL.HighlightEditingBehavior = Marionette.Behavior.extend({
modelEvents: { modelEvents: {
startEditing: 'onStartEditing', startEditing: 'onStartEditing',
stopEditing: 'onStopEditing', stopEditing: 'onStopEditing',
startResizing: 'onStartResizing',
stopResizing: 'onStopResizing',
resizeMove: 'onResizeMove', resizeMove: 'onResizeMove',
}, },
events: { events: {
@@ -47,9 +49,25 @@ BL.HighlightEditingBehavior = Marionette.Behavior.extend({
this.view.removeHighlight(); this.view.removeHighlight();
} }
}, },
onStartResizing: function onStartResizing() {
this.onStartEditing();
this.view.triggerMethod('resizeStart');
},
onStopResizing: function onStopResizing(event) {
this.onStopEditing();
this.view.triggerMethod('resizeStop', event);
},
onDomRefresh: function onDomRefresh() { onDomRefresh: function onDomRefresh() {
if (this.isBeingEdited) { if (this.isBeingEdited) {
this.view.addHighlight(); this.view.addHighlight();
} }
}, },
onChildviewResizeStart: function onChildviewResizeStart() {
// Let event bubble up
this.view.triggerMethod('resizeStart');
},
onChildviewResizeStop: function onChildviewResizeStop(event) {
// Let event bubble up
this.view.triggerMethod('resizeStop', event);
},
}); });

View File

@@ -55,7 +55,7 @@ BL.ResizableBehavior = Marionette.Behavior.extend({
}, },
}) })
.on('resizestart', function resizestart() { .on('resizestart', function resizestart() {
that.view.model.trigger('startEditing'); that.view.model.trigger('startResizing');
that.isBeingResized = true; that.isBeingResized = true;
that.$el.addClass('mailpoet_resize_active'); that.$el.addClass('mailpoet_resize_active');
}).on('resizemove', function resizemove(event) { }).on('resizemove', function resizemove(event) {
@@ -64,7 +64,7 @@ BL.ResizableBehavior = Marionette.Behavior.extend({
return onResize(event); return onResize(event);
}) })
.on('resizeend', function resizeend(event) { .on('resizeend', function resizeend(event) {
that.view.model.trigger('stopEditing'); that.view.model.trigger('stopResizing', event);
that.isBeingResized = null; that.isBeingResized = null;
if (!isEventInsideElement(event, that.view.$el)) { if (!isEventInsideElement(event, that.view.$el)) {
that.hideResizeHandle(); that.hideResizeHandle();

View File

@@ -96,6 +96,12 @@ Module.ContainerBlocksView = Marionette.CollectionView.extend({
initialize: function (options) { initialize: function (options) {
this.renderOptions = options.renderOptions; this.renderOptions = options.renderOptions;
}, },
onChildviewResizeStart: function onChildviewResizeStart() {
this.triggerMethod('resizeStart');
},
onChildviewResizeStop: function onChildviewResizeStart(event) {
this.triggerMethod('resizeStop', event);
},
}); });
Module.ContainerBlockView = base.BlockView.extend({ Module.ContainerBlockView = base.BlockView.extend({