limitting width with CSS

This commit is contained in:
Amine Ben hammou
2017-09-14 14:58:46 +00:00
parent f135b89de9
commit 20c936d13b
3 changed files with 9 additions and 26 deletions

View File

@@ -13,6 +13,8 @@
.mailpoet_content .mailpoet_content
margin: auto margin: auto
max-width: 100%
min-width: 36px
a:hover a:hover
cursor: all-scroll cursor: all-scroll

View File

@@ -25,8 +25,6 @@ define([
fullWidth: true, // true | false fullWidth: true, // true | false
width: '64px', width: '64px',
height: '64px', height: '64px',
maxWidth: false,
minWidth: '36px',
styles: { styles: {
block: { block: {
textAlign: 'center' textAlign: 'center'
@@ -51,40 +49,23 @@ define([
resizeHandleSelector: '.mailpoet_image_resize_handle', resizeHandleSelector: '.mailpoet_image_resize_handle',
onResize: function(event) { onResize: function(event) {
var corner = this.$('.mailpoet_image').offset(), var corner = this.$('.mailpoet_image').offset(),
width = event.pageX - corner.left, width = event.pageX - corner.left;
minWidth = parseInt(this.view.model.get('minWidth')), this.view.model.set('width', width + 'px');
maxWidth = parseInt(this.view.model.get('maxWidth'));
width = Math.min(maxWidth, Math.max(minWidth, width));
var height = (this.view.model.get('height') / this.view.model.get('width')) * width;
this.view.model.set({ width: width, height: height });
} }
}, },
ShowSettingsBehavior: { ShowSettingsBehavior: {
ignoreFrom: '.mailpoet_image_resize_handle' ignoreFrom: '.mailpoet_image_resize_handle'
} }
}), }),
onDomRefresh: function() {
var maxWidth = Math.min(660, this.$el.width());
this.model.set('maxWidth', maxWidth + 'px');
},
onRender: function() { onRender: function() {
this.toolsView = new Module.ImageBlockToolsView({ model: this.model }); this.toolsView = new Module.ImageBlockToolsView({ model: this.model });
this.showChildView('toolsRegion', this.toolsView); this.showChildView('toolsRegion', this.toolsView);
var maxWidth = parseInt(this.model.get('maxWidth')),
minWidth = parseInt(this.model.get('minWidth')),
width = parseInt(this.model.get('width'));
width = Math.min(maxWidth, Math.max(minWidth, width));
this.model.set('width', width + 'px');
this.$('.mailpoet_content').css('width', width + 'px');
if (this.model.get('fullWidth')) { if (this.model.get('fullWidth')) {
this.$el.addClass('mailpoet_full_image'); this.$el.addClass('mailpoet_full_image');
} else { } else {
this.$el.removeClass('mailpoet_full_image'); this.$el.removeClass('mailpoet_full_image');
} }
this.$('.mailpoet_content').css('width', this.model.get('width'));
} }
}); });

View File

@@ -32,8 +32,8 @@
name="image-width-input" name="image-width-input"
type="number" type="number"
value="{{getNumber model.width}}" value="{{getNumber model.width}}"
min="{{getNumber model.minWidth}}" min="36"
max="{{getNumber model.maxWidth}}" max="660"
step="2" step="2"
/> px /> px
<input <input
@@ -41,8 +41,8 @@
name="image-width" name="image-width"
type="range" type="range"
value="{{getNumber model.width}}" value="{{getNumber model.width}}"
min="{{getNumber model.minWidth}}" min="36"
max="{{getNumber model.maxWidth}}" max="660"
step="2" step="2"
/> />
</div> </div>