Commit 4451a7c8 authored by Seve's avatar Seve Committed by JC Brand

Use events in a less obscure manner

parent affd08bd
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
moment = converse.env.moment; moment = converse.env.moment;
function isEditSpoilerMessage() { function isEditSpoilerMessage() {
return document.querySelector('.toggle-spoiler').getAttribute('active') === 'true'; return document.querySelector('.toggle-spoiler-edit').getAttribute('active') === 'true';
} }
function hasHint() { function hasHint() {
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
function getHint() { function getHint() {
return document.querySelector('.chat-textarea-hint').value; return document.querySelector('.chat-textarea-hint').value;
} }
// The following line registers your plugin. // The following line registers your plugin.
converse.plugins.add("converse-spoilers", { converse.plugins.add("converse-spoilers", {
...@@ -102,19 +102,18 @@ ...@@ -102,19 +102,18 @@
*/ */
const initSpoilers = function () { const initSpoilers = function () {
var spoiler_button = document.createElement('li'); var spoiler_button = document.createElement('li');
spoiler_button.classList.add("toggle-spoiler"); spoiler_button.classList.add("toggle-spoiler-edit");
spoiler_button.setAttribute("active", "false"); spoiler_button.setAttribute("active", "false");
spoiler_button.onclick = toggleEditSpoilerMessage;
spoiler_button.innerHTML = '<a class="icon-eye" title="' + _('Click here to write a message as a spoiler') + '"></a>'; 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); document.querySelector('.chat-toolbar').appendChild(spoiler_button);
}; };
function toggleEditSpoilerMessage() { function toggleEditSpoilerMessage() {
let form = document.querySelector('.sendXMPPMessage'); let form = document.querySelector('.sendXMPPMessage');
let textArea = document.querySelector('.chat-textarea'); let textArea = document.querySelector('.chat-textarea');
let hintTextArea = null; let hintTextArea = null;
let spoiler_button = document.querySelector('.toggle-spoiler'); let spoiler_button = document.querySelector('.toggle-spoiler-edit');
if (!isEditSpoilerMessage()) { if (!isEditSpoilerMessage()) {
textArea.style['background-color'] = '#D5FFD2'; textArea.style['background-color'] = '#D5FFD2';
textArea.setAttribute('placeholder', _('Write your spoiler\'s content here')); textArea.setAttribute('placeholder', _('Write your spoiler\'s content here'));
...@@ -132,12 +131,12 @@ ...@@ -132,12 +131,12 @@
hintTextArea = document.querySelector('.chat-textarea-hint'); hintTextArea = document.querySelector('.chat-textarea-hint');
if ( hintTextArea ) { if ( hintTextArea ) {
hintTextArea.remove(); hintTextArea.remove();
} }
} }
} }
function createHintTextArea(){ function createHintTextArea(){
let hintTextArea = document.createElement('input'); let hintTextArea = document.createElement('input');
hintTextArea.setAttribute('type', 'text'); hintTextArea.setAttribute('type', 'text');
...@@ -156,6 +155,10 @@ ...@@ -156,6 +155,10 @@
*/ */
'overrides': { 'overrides': {
'ChatBoxView': { 'ChatBoxView': {
'events': {
'click .toggle-spoiler-edit': toggleEditSpoilerMessage
},
'createMessageStanza': function () { 'createMessageStanza': function () {
let messageStanza = this.__super__.createMessageStanza.apply(this, arguments); let messageStanza = this.__super__.createMessageStanza.apply(this, arguments);
if (isEditSpoilerMessage()) { if (isEditSpoilerMessage()) {
......
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