Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] web_editor: lazy load the wysiwyg
Issue: wysiwyg asset slow down the loading of the website, error inadvertently introduced: #29775 The assets are now loaded assynchroneously, when the editor is needed, its assets will be loaded. closes #30700
- Loading branch information
Showing
31 changed files
with
955 additions
and
806 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
odoo.define('web_editor.wysiwyg.root', function (require) { | ||
'use strict'; | ||
|
||
var Widget = require('web.Widget'); | ||
|
||
var assetsLoaded = false; | ||
|
||
var WysiwygRoot = Widget.extend({ | ||
assetLibs: ['web_editor.compiled_assets_wysiwyg'], | ||
|
||
publicMethods: ['isDirty', 'save', 'getValue', 'setValue', 'getEditable', 'on', 'trigger'], | ||
|
||
/** | ||
* @see 'web_editor.wysiwyg' module | ||
**/ | ||
init: function (parent, params) { | ||
this._super.apply(this, arguments); | ||
this._params = params; | ||
this.$editor = null; | ||
}, | ||
/** | ||
* Load assets | ||
* | ||
* @override | ||
**/ | ||
willStart: function () { | ||
var self = this; | ||
|
||
var $target = this.$el; | ||
this.$el = null; | ||
|
||
return this._super().then(function () { | ||
if (!assetsLoaded) { | ||
var Wysiwyg = odoo.__DEBUG__.services['web_editor.wysiwyg']; | ||
_.each(['getRange', 'setRange', 'setRangeFromNode'], function (methodName) { | ||
WysiwygRoot[methodName] = Wysiwyg[methodName].bind(Wysiwyg); | ||
}); | ||
assetsLoaded = true; | ||
} | ||
|
||
var Wysiwyg = self._getWysiwygContructor(); | ||
var instance = new Wysiwyg(self, self._params); | ||
self._params = null; | ||
|
||
_.each(self.publicMethods, function (methodName) { | ||
self[methodName] = instance[methodName].bind(instance); | ||
}); | ||
|
||
return instance.attachTo($target).then(function () { | ||
self.$editor = instance.$el; | ||
}); | ||
}); | ||
}, | ||
|
||
_getWysiwygContructor: function () { | ||
return odoo.__DEBUG__.services['web_editor.wysiwyg']; | ||
} | ||
}); | ||
|
||
return WysiwygRoot; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.