From 8025205bb4dee4d92a85de86a0cc4436cfb70149 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Mon, 9 Sep 2019 15:51:47 +0000 Subject: [PATCH] [IMP] web_editor, *: introduce wysiwyg frontend loader * website_forum, website_profile - Share some code between website_forum and website_profile by exposing a function in web_editor to instantiate a wysiwyg instance on a textarea - Use no-lazy loaded JS to add a visual loading effect while the wysiwyg is not yet available. This is made in preparation of task-2024197 (see https://github.com/odoo/odoo/pull/35749) Thanks to @stefanorigano closes odoo/odoo#36581 Signed-off-by: Quentin Smetz (qsm) --- .../static/src/js/frontend/loader.js | 28 +++++++++++++++++ .../static/src/js/frontend/loader_loading.js | 30 +++++++++++++++++++ .../static/src/scss/web_editor.frontend.scss | 11 +++++++ addons/web_editor/views/editor.xml | 9 ++++++ .../static/src/js/website_forum.js | 15 ++++------ addons/website_forum/views/website_forum.xml | 8 ++--- .../static/src/js/website_profile.js | 19 +++++++----- .../website_profile/views/website_profile.xml | 2 +- 8 files changed, 99 insertions(+), 23 deletions(-) create mode 100644 addons/web_editor/static/src/js/frontend/loader.js create mode 100644 addons/web_editor/static/src/js/frontend/loader_loading.js diff --git a/addons/web_editor/static/src/js/frontend/loader.js b/addons/web_editor/static/src/js/frontend/loader.js new file mode 100644 index 00000000000..9c6cf0ef984 --- /dev/null +++ b/addons/web_editor/static/src/js/frontend/loader.js @@ -0,0 +1,28 @@ +odoo.define('web_editor.loader', function (require) { +'use strict'; + +var Wysiwyg = require('web_editor.wysiwyg.root'); + +function load(parent, textarea, options) { + var loading = textarea.nextElementSibling; + if (loading && !loading.classList.contains('o_wysiwyg_loading')) { + loading = null; + } + + if (!textarea.value.match(/\S/)) { + textarea.value = '


'; + } + + var wysiwyg = new Wysiwyg(parent, options); + return wysiwyg.attachTo(textarea).then(() => { + if (loading) { + loading.parentNode.removeChild(loading); + } + return wysiwyg; + }); +} + +return { + load: load, +}; +}); diff --git a/addons/web_editor/static/src/js/frontend/loader_loading.js b/addons/web_editor/static/src/js/frontend/loader_loading.js new file mode 100644 index 00000000000..b5156944470 --- /dev/null +++ b/addons/web_editor/static/src/js/frontend/loader_loading.js @@ -0,0 +1,30 @@ +(function () { +'use strict'; + +/** + * This file makes sure textarea elements with a specific editor class are + * tweaked as soon as the DOM is ready so that they appear to be loading. + * + * They must then be loaded using standard Odoo modules system. In particular, + * @see web_editor.loader + */ + +document.addEventListener('DOMContentLoaded', () => { + document.querySelectorAll('textarea.o_wysiwyg_loader').forEach(textarea => { + var wrapper = document.createElement('div'); + wrapper.classList.add('position-relative', 'o_wysiwyg_wrapper'); + + var loadingElement = document.createElement('div'); + loadingElement.classList.add('o_wysiwyg_loading'); + var loadingIcon = document.createElement('i'); + loadingIcon.classList.add('text-600', 'text-center', + 'fa', 'fa-circle-o-notch', 'fa-spin', 'fa-2x'); + loadingElement.appendChild(loadingIcon); + wrapper.appendChild(loadingElement); + + textarea.parentNode.insertBefore(wrapper, textarea); + wrapper.insertBefore(textarea, loadingElement); + }); +}); + +})(); diff --git a/addons/web_editor/static/src/scss/web_editor.frontend.scss b/addons/web_editor/static/src/scss/web_editor.frontend.scss index 7df7cacccb4..58a314bb7ad 100644 --- a/addons/web_editor/static/src/scss/web_editor.frontend.scss +++ b/addons/web_editor/static/src/scss/web_editor.frontend.scss @@ -3,3 +3,14 @@ transform: none !important; } } + +.o_wysiwyg_loader { + @extend .form-control:disabled; + pointer-events: none; + min-height: 100px; + color: transparent; +} +.o_wysiwyg_loading { + @include o-position-absolute($top: 50%, $left: 50%); + transform: translate(-50%, -50%) +} diff --git a/addons/web_editor/views/editor.xml b/addons/web_editor/views/editor.xml index 484ca4994c4..8c9c2028cd2 100644 --- a/addons/web_editor/views/editor.xml +++ b/addons/web_editor/views/editor.xml @@ -157,11 +157,20 @@ +