Commit 7f9f6247 authored by JC Brand's avatar JC Brand

Render spoiler button as a template

parent ed33d4e5
...@@ -308,6 +308,9 @@ ...@@ -308,6 +308,9 @@
return this; return this;
}, },
renderTextArea () {
},
insertHeading () { insertHeading () {
this.heading = new _converse.ChatBoxHeading({'model': this.model}); this.heading = new _converse.ChatBoxHeading({'model': this.model});
this.heading.render(); this.heading.render();
......
(function (root, factory) { (function (root, factory) {
define(["converse-core", "strophe.vcard", "converse-chatview"], factory); define([
}(this, function (converse, tpl_message) { "converse-core",
"tpl!spoiler_button",
"converse-chatview"
], factory);
}(this, function (converse, tpl_spoiler_button) {
const { _ } = converse.env;
const u = converse.env.utils;
function isEditSpoilerMessage () { function isEditSpoilerMessage () {
return document.querySelector('.toggle-spoiler-edit').getAttribute('active') === 'true'; return document.querySelector('.toggle-spoiler-edit').getAttribute('active') === 'true';
...@@ -43,21 +50,37 @@ ...@@ -43,21 +50,37 @@
'events': { 'events': {
'click .toggle-spoiler-edit': 'toggleEditSpoilerMessage', 'click .toggle-spoiler-edit': 'toggleEditSpoilerMessage',
'click .toggle-spoiler-display': 'toggleDisplaySpoilerMessage' 'click .toggle-spoiler-display': 'toggleSpoilerMessage'
},
'renderToolbar': function (toolbar, options) {
const { _converse } = this.__super__;
const result = this.__super__.renderToolbar.apply(this, arguments);
if (!_converse.show_toolbar) { return result; }
const html = tpl_spoiler_button({
'title': _converse.__('Click here to write a message as a spoiler')
});
const toolbar_el = this.el.querySelector('.chat-toolbar');
if (!_.isNull(toolbar_el)) {
toolbar_el.appendChild(u.stringToElement(html));
}
return result;
}, },
'toggleDisplaySpoilerMessage': function (event) { 'toggleSpoilerMessage': function (event) {
const { _converse } = this.__super__, const { _converse } = this.__super__,
{ __ } = _converse; { __ } = _converse;
const button = event.target; const button = event.target;
const isClosed = button.getAttribute("closed"); const textarea = button.nextElementSibling;
const content = button.nextElementSibling; const hint = textarea.children[0];
const hint = content.children[0]; const contentHidden = textarea.children[1];
const contentHidden = content.children[1];
const container = button.parentElement; const container = button.parentElement;
if (isClosed == "true") { //Show spoiler's content if (button.getAttribute("closed") == "true") {
//Show spoiler's content
button.classList.remove("icon-eye"); button.classList.remove("icon-eye");
button.classList.add("toggle-spoiler-display"); button.classList.add("toggle-spoiler-display");
button.classList.add("icon-eye-blocked"); button.classList.add("icon-eye-blocked");
...@@ -94,9 +117,9 @@ ...@@ -94,9 +117,9 @@
const { _converse } = this.__super__, const { _converse } = this.__super__,
{ __ } = _converse; { __ } = _converse;
const form = document.querySelector('.sendXMPPMessage'); const form = this.el.querySelector('.sendXMPPMessage');
const textArea = document.querySelector('.chat-textarea'); const textArea = this.el.querySelector('.chat-textarea');
const spoiler_button = document.querySelector('.toggle-spoiler-edit'); const spoiler_button = this.el.querySelector('.toggle-spoiler-edit');
if (!isEditSpoilerMessage()) { if (!isEditSpoilerMessage()) {
textArea.style['background-color'] = '#D5FFD2'; textArea.style['background-color'] = '#D5FFD2';
...@@ -229,17 +252,11 @@ ...@@ -229,17 +252,11 @@
/* Inside this method, you have access to the private /* Inside this method, you have access to the private
* `_converse` object. * `_converse` object.
*/ */
const { _converse } = this, const { _converse } = this;
{ __ } = _converse;
function initSpoilers () { function initSpoilers (chatbox) {
const spoiler_button = document.createElement('li'); chatbox.renderToolbar();
spoiler_button.classList.add("toggle-spoiler-edit");
spoiler_button.setAttribute("active", "false");
spoiler_button.innerHTML = '<a class="icon-eye" title="' + __('Click here to write a message as a spoiler') + '"></a>';
document.querySelector('.chat-toolbar').appendChild(spoiler_button);
} }
_converse.on('chatBoxFocused', initSpoilers); _converse.on('chatBoxFocused', initSpoilers);
} }
}); });
......
<li class="toggle-spoiler-edit" data-active="false">
<a class="icon-eye" title="{{ o.title }}"></a>
</li>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment