From 0ddb68be81189ee056418756f9a023b58c6c320b Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Mon, 17 Aug 2015 10:25:37 +0200 Subject: [PATCH] [FIX] website: manage css margin for resizing In some case margin could be applied via CSS and not via mb* classes (e.g several themes with different aspects but a shared snippet). This commit allow this if custom CSS margin matches a CSS mb* class value (currently 0, 4, 8, 16, 32, 48, 92 and 128). --- addons/website/static/src/js/website.snippets.editor.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/website/static/src/js/website.snippets.editor.js b/addons/website/static/src/js/website.snippets.editor.js index 85f9564e9e0..abb4b9e859f 100644 --- a/addons/website/static/src/js/website.snippets.editor.js +++ b/addons/website/static/src/js/website.snippets.editor.js @@ -1411,9 +1411,13 @@ } else { var xy = event['page'+XY]; var current = resize[2] || 0; + var margin_dir = {s:'bottom', n: 'top', w: 'left', e: 'right'}[compass]; + var real_margin = parseInt(self.$target.css('margin-'+margin_dir)); _.each(resize[0], function (val, key) { if (self.$target.hasClass(val)) { current = key; + } else if (resize[1][key] === real_margin) { + current = key; } }); var begin = current; @@ -1509,12 +1513,12 @@ if (offset === 0) overlay_class+= " block-w-left"; var mb = _class.match(/mb([0-9-]+)/i); - mb = mb ? +mb[1] : 0; + mb = mb ? +mb[1] : parseInt(this.$target.css('margin-bottom')); if (mb >= 128) overlay_class+= " block-s-bottom"; else if (!mb) overlay_class+= " block-s-top"; var mt = _class.match(/mt([0-9-]+)/i); - mt = mt ? +mt[1] : 0; + mt = mt ? +mt[1] : parseInt(this.$target.css('margin-top')); if (mt >= 128) overlay_class+= " block-n-top"; else if (!mt) overlay_class+= " block-n-bottom";