diff options
Diffstat (limited to 'addons/web_editor/static/src/js/editor')
| -rw-r--r-- | addons/web_editor/static/src/js/editor/snippets.options.js | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index 3b1360c8951..635360677fc 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -82,17 +82,25 @@ function _buildTitleElement(title) { * @param {string} src * @returns {HTMLElement} */ +const _buildImgElementCache = {}; async function _buildImgElement(src) { - if (src.split('.').pop() === 'svg') { - const response = await window.fetch(src); - const text = await response.text(); - const parser = new window.DOMParser(); - const xmlDoc = parser.parseFromString(text, 'text/xml'); - return xmlDoc.getElementsByTagName('svg')[0]; + if (!(src in _buildImgElementCache)) { + _buildImgElementCache[src] = (async () => { + if (src.split('.').pop() === 'svg') { + const response = await window.fetch(src); + const text = await response.text(); + const parser = new window.DOMParser(); + const xmlDoc = parser.parseFromString(text, 'text/xml'); + return xmlDoc.getElementsByTagName('svg')[0]; + } else { + const imgEl = document.createElement('img'); + imgEl.src = src; + return imgEl; + } + })(); } - const imgEl = document.createElement('img'); - imgEl.src = src; - return imgEl; + const node = await _buildImgElementCache[src]; + return node.cloneNode(true); } /** * Build the correct DOM for a we-row element. @@ -868,7 +876,9 @@ const SelectUserValueWidget = BaseSelectionUserValueWidget.extend({ */ close: function () { this._super(...arguments); - this.menuTogglerEl.classList.remove('active'); + if (this.menuTogglerEl) { + this.menuTogglerEl.classList.remove('active'); + } }, /** * @override |
