summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js/frontend/loader.js
blob: 9c6cf0ef9849cb4acc92a779b74f3febe4c4f8f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 = '<p><br/></p>';
    }

    var wysiwyg = new Wysiwyg(parent, options);
    return wysiwyg.attachTo(textarea).then(() => {
        if (loading) {
            loading.parentNode.removeChild(loading);
        }
        return wysiwyg;
    });
}

return {
    load: load,
};
});