summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js/transcoder.js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2016-09-22 15:36:25 +0200
committerqsm-odoo <qsm@odoo.com>2016-09-23 11:16:16 +0200
commitc15a99b49ae5d9776a2901b47a26d65bebe69946 (patch)
treea8b5653f345374e2bc6e84afb0bdda552c7b8f51 /addons/web_editor/static/src/js/transcoder.js
parentbee594e58204d8f611c01c6fe8b4de22be2151a8 (diff)
[FIX] web_editor: properly convert fa icon to images with transcoder
Previous implementation was not robust as css style was able to change the image height. Also refactore the method to be more efficient.
Diffstat (limited to 'addons/web_editor/static/src/js/transcoder.js')
-rw-r--r--addons/web_editor/static/src/js/transcoder.js29
1 files changed, 13 insertions, 16 deletions
diff --git a/addons/web_editor/static/src/js/transcoder.js b/addons/web_editor/static/src/js/transcoder.js
index ddd8ce73533..20d4f5844af 100644
--- a/addons/web_editor/static/src/js/transcoder.js
+++ b/addons/web_editor/static/src/js/transcoder.js
@@ -118,7 +118,7 @@ var getMatchedCSSRules = function (a) {
// convert font awsome into image
var font_to_img = function ($editable) {
- $(".fa", $editable).each(function () {
+ $editable.find(".fa").each(function () {
var $font = $(this);
var icon, content;
_.find(widget.fontIcons, function (font) {
@@ -132,15 +132,13 @@ var font_to_img = function ($editable) {
});
if (content) {
var color = $font.css("color").replace(/\s/g, '');
- var src = _.str.sprintf('/web_editor/font_to_img/%s/%s/'+Math.max(1, $font.height()), content.charCodeAt(0), window.encodeURI(color));
- var $img = $("<img/>").attr("src", src)
- .attr("data-class", $font.attr("class"))
- .attr("class", $font.attr("class").replace(new RegExp("(^|\\s+)" + icon + "(-[^\\s]+)?", "gi"), '')) // remove inline font-awsome style
- .attr("style", $font.attr("style"))
- .attr("height", $font.height())
- .css("height", "")
- .css("font-size", "");
- $font.replaceWith($img);
+ $font.replaceWith($("<img/>", {
+ "src": _.str.sprintf('/web_editor/font_to_img/%s/%s/%s', content.charCodeAt(0), window.encodeURI(color), Math.max(1, $font.height())),
+ "data-class": $font.attr("class"),
+ "data-style": $font.attr("style"),
+ "class": $font.attr("class").replace(new RegExp("(^|\\s+)" + icon + "(-[^\\s]+)?", "gi"), ''), // remove inline font-awsome style
+ "style": $font.attr("style")
+ }).css({height: "auto", width: "auto"}));
} else {
$font.remove();
}
@@ -148,13 +146,12 @@ var font_to_img = function ($editable) {
};
// convert image into font awsome
var img_to_font = function ($editable) {
- $("img[src*='/web_editor/font_to_img/']", $editable).each(function () {
+ $editable.find("img[src*='/web_editor/font_to_img/']").each(function () {
var $img = $(this);
- var $font = $("<span/>")
- .attr("class", $img.data("class"))
- .attr("style", $img.attr("style"))
- .css("height", "");
- $img.replaceWith($font);
+ $img.replaceWith($("<span/>", {
+ "class": $img.data("class"),
+ "style": $img.data("style")
+ }));
});
};