From b27d24bfe9404c6013405df7dbeef69c31e9d58c Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 18 Jan 2016 16:47:36 +0100 Subject: [FIX] web_editor: don't limit the css inliner to the class but for all tag (can reduce the performances) --- addons/web_editor/static/src/js/transcoder.js | 47 +++++++++++++++++---------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'addons/web_editor/static/src/js/transcoder.js') diff --git a/addons/web_editor/static/src/js/transcoder.js b/addons/web_editor/static/src/js/transcoder.js index bd7848d2e97..852201c6f49 100644 --- a/addons/web_editor/static/src/js/transcoder.js +++ b/addons/web_editor/static/src/js/transcoder.js @@ -30,9 +30,7 @@ var getMatchedCSSRules = function (a) { var selectorText = rules[r].selectorText; if (selectorText && rules[r].cssText && - selectorText.indexOf(".") !== -1 && - selectorText.indexOf(".note-") === -1 && - + selectorText !== "*" && selectorText.indexOf(":hover") === -1 && selectorText.indexOf(":before") === -1 && selectorText.indexOf(":after") === -1 && @@ -83,12 +81,31 @@ var getMatchedCSSRules = function (a) { var style = {}; _.each(css, function (v,k) { _.each(v[1], function (v,k) { - if (!style[k] || style[k].indexOf('important') === -1 || v.indexOf('important') !== -1) { + if (k.indexOf('-webkit') === -1 && (!style[k] || style[k].indexOf('important') === -1 || v.indexOf('important') !== -1)) { style[k] = v; } }); }); - return cache[a.tagName + "." +a.className] = style; + + if (style.display === 'block') { + delete style.display; + } + if (style['margin-top']) { + style.margin = (style['margin-top'] || 0) + ' ' + (style['margin-right'] || 0) + ' ' + (style['margin-bottom'] || 0) + ' ' + (style['margin-left'] || 0); + delete style['margin-top']; + delete style['margin-right']; + delete style['margin-bottom']; + delete style['margin-left']; + } + if (style['padding-top']) { + style.padding = (style['padding-top'] || 0) + ' ' + (style['padding-right'] || 0) + ' ' + (style['padding-bottom'] || 0) + ' ' + (style['padding-left'] || 0); + delete style['padding-top']; + delete style['padding-right']; + delete style['padding-bottom']; + delete style['padding-left']; + } + + return a.className ? cache[a.tagName + "." +a.className] = style : style; }; // convert font awsome into image @@ -138,8 +155,7 @@ var class_to_style = function ($editable) { if (!rulesCache.length) { getMatchedCSSRules($editable[0]); } - var selector = _.map(rulesCache, function (a) { return a.selector;}).join(","); - $editable.find(selector).each(function () { + $editable.find('*').each(function () { var $target = $(this); var css = getMatchedCSSRules(this); var style = $target.attr("style") || ""; @@ -154,18 +170,10 @@ var class_to_style = function ($editable) { // convert style into inline class from mail var style_to_class = function ($editable) { getMatchedCSSRules($editable[0]); - var classes = []; - $editable.find("[class]").each(function () { - classes = classes.concat(this.className.split(/\s+/)); - }); - classes = _.compact(classes); - - var maybe_selector = _.filter(rulesCache, function (a) { return !!_.find(classes, function (b) { return a.selector.indexOf("."+b) !== -1; } ); }); - var selector = _.map(maybe_selector, function (a) { return a.selector;}).join(","); var $c = $('').appendTo("body"); - $editable.find(selector).each(function () { + $editable.find('*').each(function () { var $target = $(this); var css = getMatchedCSSRules(this); var style = ""; @@ -179,7 +187,12 @@ var style_to_class = function ($editable) { _.each(css, function (v) { style = style.replace(v, ''); }); - $target.attr("style", style.replace(/;+(\s;)*/g, ';').replace(/^;/g, '')); + style = style.replace(/;+(\s;)*/g, ';').replace(/^;/g, ''); + if (style !== '') { + $target.attr("style", style); + } else { + $target.removeAttr("style"); + } }); $c.remove(); }; -- cgit v1.2.3 From 958656d7e678ed567ac605285f5b2f4376715e06 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 18 Jan 2016 16:48:35 +0100 Subject: [FIX] web_editor: inliner take in care the '!important' attributes --- addons/web_editor/static/src/js/transcoder.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'addons/web_editor/static/src/js/transcoder.js') diff --git a/addons/web_editor/static/src/js/transcoder.js b/addons/web_editor/static/src/js/transcoder.js index 852201c6f49..24465804bc8 100644 --- a/addons/web_editor/static/src/js/transcoder.js +++ b/addons/web_editor/static/src/js/transcoder.js @@ -59,6 +59,9 @@ var getMatchedCSSRules = function (a) { var style_obj = {}; for (var k=0, len=style.length; k Date: Mon, 18 Jan 2016 16:50:18 +0100 Subject: [FIX] web_editor: inliner don't apply color when background-color --- addons/web_editor/static/src/js/transcoder.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/web_editor/static/src/js/transcoder.js') diff --git a/addons/web_editor/static/src/js/transcoder.js b/addons/web_editor/static/src/js/transcoder.js index 24465804bc8..5e699367dc2 100644 --- a/addons/web_editor/static/src/js/transcoder.js +++ b/addons/web_editor/static/src/js/transcoder.js @@ -169,7 +169,7 @@ var class_to_style = function ($editable) { var css = getMatchedCSSRules(this); var style = $target.attr("style") || ""; _.each(css, function (v,k) { - if (style.indexOf(k) === -1) { + if (!(new RegExp('(^|;)\s*' + k).test(style))) { style = k+":"+v+";"+style; } }); @@ -187,7 +187,7 @@ var style_to_class = function ($editable) { var css = getMatchedCSSRules(this); var style = ""; _.each(css, function (v,k) { - if (style.indexOf(k) === -1) { + if (!(new RegExp('(^|;)\s*' + k).test(style))) { style = k+":"+v+";"+style; } }); -- cgit v1.2.3 From 6e47472486b2d546bb768cdffc0bda65185c6228 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 20 Jan 2016 11:44:28 +0100 Subject: [FIX] web_editor: firefox can have undefined value for style and broke inliner feature --- addons/web_editor/static/src/js/transcoder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_editor/static/src/js/transcoder.js') diff --git a/addons/web_editor/static/src/js/transcoder.js b/addons/web_editor/static/src/js/transcoder.js index 5e699367dc2..20779bf19aa 100644 --- a/addons/web_editor/static/src/js/transcoder.js +++ b/addons/web_editor/static/src/js/transcoder.js @@ -84,7 +84,7 @@ var getMatchedCSSRules = function (a) { var style = {}; _.each(css, function (v,k) { _.each(v[1], function (v,k) { - if (k.indexOf('-webkit') === -1 && (!style[k] || style[k].indexOf('important') === -1 || v.indexOf('important') !== -1)) { + if (v && k.indexOf('-webkit') === -1 && (!style[k] || style[k].indexOf('important') === -1 || v.indexOf('important') !== -1)) { style[k] = v; } }); -- cgit v1.2.3