diff options
| author | Christophe Matthieu <chm@odoo.com> | 2019-01-28 09:39:56 +0000 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2019-02-14 15:11:19 +0000 |
| commit | b49745e52d7a7bc27afd416206dcd5fa242aa07a (patch) | |
| tree | ae6a047da7e77b951db241e1342278ce543972e2 /addons/web_editor/static/src/js/backend/field_html.js | |
| parent | 7daa85dd12ff522be510bc2f8db1d968cae7d891 (diff) | |
[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
Diffstat (limited to 'addons/web_editor/static/src/js/backend/field_html.js')
| -rw-r--r-- | addons/web_editor/static/src/js/backend/field_html.js | 27 |
1 files changed, 21 insertions, 6 deletions
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($('<textarea>')).then(function () { + wysiwyg.destroy(); + var def = assetsLoaded; + assetsLoaded = true; + def.resolve(); + }); + } + + return $.when(this._super(), assetsLoaded, defAsset); }, /** * @override @@ -147,7 +162,7 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, { // by default this is synchronous because the assets are already loaded in willStart // but it can be async in the case of options such as iframe, snippets... return this.wysiwyg.attachTo(this.$target).then(function () { - self.$content = self.wysiwyg.$el; + self.$content = self.wysiwyg.$editor; self._onLoadWysiwyg(); }); }, @@ -444,7 +459,7 @@ var FieldHtml = basic_fields.DebouncedField.extend(TranslatableFieldMixin, { position: 'absolute', right: '+5px', }); - var $toolbar = this.$content.closest('.note-editor').find('.note-toolbar'); + var $toolbar = this.$content.find('.note-toolbar'); $toolbar.css('position', 'relative'); $toolbar.append($button); }, |
