From b49745e52d7a7bc27afd416206dcd5fa242aa07a Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 28 Jan 2019 09:39:56 +0000 Subject: [IMP] web_editor: lazy load the wysiwyg Issue: wysiwyg asset slow down the loading of the website, error inadvertently introduced: https://github.com/odoo/odoo/pull/29775 The assets are now loaded assynchroneously, when the editor is needed, its assets will be loaded. closes odoo/odoo#30700 --- .../static/src/js/backend/convert_inline.js | 3 +- .../web_editor/static/src/js/backend/field_html.js | 27 +++++++--- addons/web_editor/static/src/js/common/ace.js | 1 - .../static/src/js/wysiwyg/plugin/font.js | 5 ++ addons/web_editor/static/src/js/wysiwyg/root.js | 62 ++++++++++++++++++++++ addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 40 ++------------ .../static/src/js/wysiwyg/wysiwyg_iframe.js | 50 ++++------------- .../src/js/wysiwyg_snippets/wysiwyg_snippets.js | 11 ++++ addons/web_editor/static/src/xml/wysiwyg.xml | 42 +++++++++++++++ 9 files changed, 156 insertions(+), 85 deletions(-) create mode 100644 addons/web_editor/static/src/js/wysiwyg/root.js (limited to 'addons/web_editor/static/src') diff --git a/addons/web_editor/static/src/js/backend/convert_inline.js b/addons/web_editor/static/src/js/backend/convert_inline.js index 3b09bef5f31..b6b36a388ef 100644 --- a/addons/web_editor/static/src/js/backend/convert_inline.js +++ b/addons/web_editor/static/src/js/backend/convert_inline.js @@ -1,7 +1,6 @@ odoo.define('web_editor.convertInline', function (require) { 'use strict'; -var fonts = require('wysiwyg.fonts'); var FieldHtml = require('web_editor.field.html'); /** @@ -189,6 +188,8 @@ function getMatchedCSSRules(a) { * converted to images */ function fontToImg($editable) { + var fonts = odoo.__DEBUG__.services["wysiwyg.fonts"]; + $editable.find('.fa').each(function () { var $font = $(this); var icon, content; diff --git a/addons/web_editor/static/src/js/backend/field_html.js b/addons/web_editor/static/src/js/backend/field_html.js index 69e32fb815e..b78fcc1d35f 100644 --- a/addons/web_editor/static/src/js/backend/field_html.js +++ b/addons/web_editor/static/src/js/backend/field_html.js @@ -4,12 +4,12 @@ odoo.define('web_editor.field.html', function (require) { var ajax = require('web.ajax'); var basic_fields = require('web.basic_fields'); var core = require('web.core'); -var Wysiwyg = require('web_editor.wysiwyg'); +var Wysiwyg = require('web_editor.wysiwyg.root'); var field_registry = require('web.field_registry'); var TranslatableFieldMixin = basic_fields.TranslatableFieldMixin; - var QWeb = core.qweb; +var assetsLoaded = false; /** * FieldHtml Widget @@ -40,8 +40,23 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, { */ willStart: function () { this._onUpdateIframeId = 'onLoad_' + _.uniqueId('FieldHtml'); - var defAsset = this.nodeOptions.cssReadonly && ajax.loadAsset(this.nodeOptions.cssReadonly); - return $.when(this._super().then(Wysiwyg.prepare.bind(Wysiwyg, this)), defAsset); + var defAsset = null; + if (this.nodeOptions.cssReadonly) { + defAsset = ajax.loadAsset(this.nodeOptions.cssReadonly); + } + + if (!assetsLoaded) { // avoid flickering when begin to edit + assetsLoaded = $.Deferred(); + var wysiwyg = new Wysiwyg(this, {}); + wysiwyg.attachTo($('