diff --git a/assets/css/src/newsletter_editor/contentBlocks/image.styl b/assets/css/src/newsletter_editor/contentBlocks/image.styl index 1ad2b3e130..ee8e756bcf 100644 --- a/assets/css/src/newsletter_editor/contentBlocks/image.styl +++ b/assets/css/src/newsletter_editor/contentBlocks/image.styl @@ -3,12 +3,12 @@ img vertical-align: bottom max-width: 100% - width: auto height: auto &.mailpoet_full_image padding-left: 0 padding-right: 0 + margin: auto margin-bottom: 0 .mailpoet_content a:hover diff --git a/assets/js/src/newsletter_editor/behaviors/ResizableBehavior.js b/assets/js/src/newsletter_editor/behaviors/ResizableBehavior.js index 853b0c7302..e4d148bbeb 100644 --- a/assets/js/src/newsletter_editor/behaviors/ResizableBehavior.js +++ b/assets/js/src/newsletter_editor/behaviors/ResizableBehavior.js @@ -14,8 +14,9 @@ define([ defaults: { elementSelector: null, resizeHandleSelector: true, // true will use edges of the element itself - transformationFunction: function (y) { return y; }, + transformationFunction: function(event) { return event.dy; }, minLength: 0, + maxLength: Infinity, modelField: 'styles.block.height' }, events: { @@ -45,9 +46,10 @@ define([ that.$el.addClass('mailpoet_resize_active'); }).on('resizemove', function (event) { var currentLength = parseFloat(that.view.model.get(that.options.modelField)), - newLength = currentLength + that.options.transformationFunction(event.dy); + newLength = currentLength + that.options.transformationFunction(event); if (newLength < that.options.minLength) newLength = that.options.minLength; + if (newLength > that.options.maxLength) newLength = that.options.maxLength; that.view.model.set(that.options.modelField, newLength + 'px'); }) diff --git a/assets/js/src/newsletter_editor/blocks/image.js b/assets/js/src/newsletter_editor/blocks/image.js index 8bc028e9fa..12b281e6c2 100644 --- a/assets/js/src/newsletter_editor/blocks/image.js +++ b/assets/js/src/newsletter_editor/blocks/image.js @@ -44,11 +44,30 @@ define([ }, base.BlockView.prototype.templateContext.apply(this)); }, behaviors: _.extend({}, base.BlockView.prototype.behaviors, { - ShowSettingsBehavior: {} + ResizableBehavior: { + elementSelector: '.mailpoet_image', + resizeHandleSelector: '.mailpoet_resize_handle', + minLength: 36, + maxLength: 660, + modelField: 'width', + transformationFunction: function(event) { return event.dx; } + }, + ShowSettingsBehavior: { + ignoreFrom: '.mailpoet_resize_handle' + } }), - onRender: function () { + initialize: function() { + base.BlockView.prototype.initialize.apply(this, arguments); + this.listenTo(this.model, 'change:width', this.changeWidth); + }, + changeWidth: function() { + this.$('.mailpoet_resize_handle_text').text(this.model.get('width')); + }, + onRender: function() { this.toolsView = new Module.ImageBlockToolsView({ model: this.model }); this.showChildView('toolsRegion', this.toolsView); + this.$('.mailpoet_resize_handle').css('padding-right', '20px'); + this.$('.mailpoet_resize_handle').css('cursor', 'ew-resize'); if (this.model.get('fullWidth')) { this.$el.addClass('mailpoet_full_image'); @@ -82,10 +101,17 @@ define([ 'change .mailpoet_field_image_full_width': _.partial(this.changeBoolCheckboxField, 'fullWidth'), 'change .mailpoet_field_image_alignment': _.partial(this.changeField, 'styles.block.textAlign'), 'click .mailpoet_field_image_select_another_image': 'showMediaManager', - 'click .mailpoet_done_editing': 'close' + 'click .mailpoet_done_editing': 'close', + 'input .mailpoet_field_image_width': _.partial(this.updateValueAndCall, '.mailpoet_field_image_width_input', _.partial(this.changePixelField, 'width').bind(this)), + 'change .mailpoet_field_image_width': _.partial(this.updateValueAndCall, '.mailpoet_field_image_width_input', _.partial(this.changePixelField, 'width').bind(this)), + 'input .mailpoet_field_image_width_input': _.partial(this.updateValueAndCall, '.mailpoet_field_image_width', _.partial(this.changePixelField, 'width').bind(this)) }; }, - initialize: function (options) { + updateValueAndCall: function(fieldToUpdate, callable, event) { + this.$(fieldToUpdate).val(jQuery(event.target).val()); + callable(event); + }, + initialize: function(options) { base.BlockSettingsView.prototype.initialize.apply(this, arguments); if (options.showImageManager) { diff --git a/views/newsletter/templates/blocks/image/block.hbs b/views/newsletter/templates/blocks/image/block.hbs index d6efccc65a..75d2223e4b 100644 --- a/views/newsletter/templates/blocks/image/block.hbs +++ b/views/newsletter/templates/blocks/image/block.hbs @@ -1,3 +1,15 @@
-
{{ model.alt }}
+
+
+ + {{ model.alt }} + +
+
+ {{ model.width }} + <%= source('newsletter/templates/svg/block-icons/horizontal-spacer.svg') %> +
+
+
+
diff --git a/views/newsletter/templates/blocks/image/settings.hbs b/views/newsletter/templates/blocks/image/settings.hbs index 7c3dfe05a0..d4998b613c 100644 --- a/views/newsletter/templates/blocks/image/settings.hbs +++ b/views/newsletter/templates/blocks/image/settings.hbs @@ -23,6 +23,15 @@ +
+ +