From cf258f0b4ceda338378a7e5cf8910d94b89673d7 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Wed, 10 Jun 2020 12:30:52 +0200 Subject: [PATCH] Add new public API method `converse.insertInto` --- CHANGES.md | 1 + Makefile | 2 +- src/converse-chatboxviews.js | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index f59143d43..5798a1d25 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -43,6 +43,7 @@ Soon we'll deprecate the latter, so prepare now. - New config option [muc_hats_from_vcard](https://conversejs.org/docs/html/configuration.html#muc-hats-from-vcard). - New config option [muc_send_probes](https://conversejs.org/docs/html/configuration.html#muc-send-probes). - New config option [show_message_avatar](https://conversejs.org/docs/html/configuration.html#show-message-avatar). +- New public API [converse.insertInto](https://conversejs.org/docs/html/api/converse.html#.insertInto) ## 6.0.0 (2020-01-09) diff --git a/Makefile b/Makefile index 539c0ff66..14a941ad3 100644 --- a/Makefile +++ b/Makefile @@ -208,7 +208,7 @@ test: ## Documentation ./bin/activate: - python3.7 -m venv . + python3 -m venv . .installed.cfg: requirements.txt buildout.cfg ./bin/pip install -r requirements.txt diff --git a/src/converse-chatboxviews.js b/src/converse-chatboxviews.js index c2d5d39df..fe8a7e7c8 100644 --- a/src/converse-chatboxviews.js +++ b/src/converse-chatboxviews.js @@ -154,5 +154,29 @@ converse.plugins.add('converse-chatboxviews', { api.listen.on('chatBoxViewsInitialized', () => calculateViewportHeightUnit()); window.addEventListener('resize', () => calculateViewportHeightUnit()); /************************ END Event Handlers ************************/ + + + Object.assign(converse, { + /** + * Public API method which will ensure that the #conversejs element + * is inserted into a container element. + * + * This method is useful when the #conversejs element has been + * detached from the DOM somehow. + * @async + * @memberOf converse + * @method insertInto + * @example + * converse.insertInto(document.querySelector('#converse-container')); + */ + insertInto (container) { + const el = _converse.chatboxviews?.el; + if (el && !container.contains(el)) { + container.insertAdjacentElement('afterBegin', el); + } else if (!el) { + throw new Error("Cannot insert non-existing #conversejs element into the DOM"); + } + } + }); } });