Commit 85bea600 authored by JC Brand's avatar JC Brand

Some of refactoring to avoid code duplication and jQuery

parent 292a75d3
...@@ -32,14 +32,14 @@ ...@@ -32,14 +32,14 @@
var jid = 'theplay@conference.shakespeare.lit'; var jid = 'theplay@conference.shakespeare.lit';
var view = _converse.chatboxviews.get(jid); var view = _converse.chatboxviews.get(jid);
spyOn(view, 'renderBookmarkForm').and.callThrough(); spyOn(view, 'renderBookmarkForm').and.callThrough();
spyOn(view, 'cancelConfiguration').and.callThrough(); spyOn(view, 'closeForm').and.callThrough();
var $bookmark = view.$el.find('.icon-pushpin'); var $bookmark = view.$el.find('.icon-pushpin');
$bookmark.click(); $bookmark.click();
expect(view.renderBookmarkForm).toHaveBeenCalled(); expect(view.renderBookmarkForm).toHaveBeenCalled();
view.$el.find('.button-cancel').click(); view.$el.find('.button-cancel').click();
expect(view.cancelConfiguration).toHaveBeenCalled(); expect(view.closeForm).toHaveBeenCalled();
expect($bookmark.hasClass('on-button'), false); expect($bookmark.hasClass('on-button'), false);
$bookmark.click(); $bookmark.click();
......
...@@ -132,10 +132,8 @@ ...@@ -132,10 +132,8 @@
child.classList.add('hidden'); child.classList.add('hidden');
}); });
// Remove any existing forms // Remove any existing forms
let form = body.querySelector('form.chatroom-form'); _.each(body.querySelectorAll('.chatroom-form-container'), utils.removeElement);
if (!_.isNull(form)) {
form.parentNode.removeChild(form);
}
body.insertAdjacentHTML( body.insertAdjacentHTML(
'beforeend', 'beforeend',
tpl_chatroom_bookmark_form({ tpl_chatroom_bookmark_form({
...@@ -148,14 +146,14 @@ ...@@ -148,14 +146,14 @@
label_cancel: __('Cancel') label_cancel: __('Cancel')
}) })
); );
form = body.querySelector('form.chatroom-form'); const form = body.querySelector('form.chatroom-form');
form.addEventListener( form.addEventListener(
'submit', 'submit',
this.onBookmarkFormSubmitted.bind(this) this.onBookmarkFormSubmitted.bind(this)
); );
form.querySelector('.button-cancel').addEventListener( form.querySelector('.button-cancel').addEventListener(
'click', 'click',
this.cancelConfiguration.bind(this) this.closeForm.bind(this)
); );
}, },
......
This diff is collapsed.
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<ul class="chat-toolbar no-text-select"></ul> <ul class="chat-toolbar no-text-select"></ul>
{[ } ]} {[ } ]}
<textarea type="text" class="chat-textarea {[ if (o.show_send_button) { ]}chat-textarea-send-button{[ } ]}" <textarea type="text" class="chat-textarea {[ if (o.show_send_button) { ]}chat-textarea-send-button{[ } ]}"
placeholder="{{{o.label_message}}}"/> placeholder="{{{o.label_message}}}"></textarea>
{[ if (o.show_send_button) { ]} {[ if (o.show_send_button) { ]}
<button type="submit" class="pure-button send-button">{{{ o.label_send }}}</button> <button type="submit" class="pure-button send-button">{{{ o.label_send }}}</button>
{[ } ]} {[ } ]}
......
<div class="flyout box-flyout"> <div class="flyout box-flyout">
<div class="chat-head chat-head-chatroom"></div> <div class="chat-head chat-head-chatroom"></div>
<div class="chat-body chatroom-body"><span class="spinner centered"/></div> <div class="chat-body chatroom-body"></div>
</div> </div>
...@@ -104,6 +104,18 @@ ...@@ -104,6 +104,18 @@
var u = {}; var u = {};
u.removeElement = function (el) {
if (!_.isNil(el) && !_.isNil(el.parentNode)) {
el.parentNode.removeChild(el);
}
}
u.hideElement = function (el) {
if (!_.isNil(el)) {
el.classList.add('hidden');
}
}
u.addHyperlinks = function (text) { u.addHyperlinks = function (text) {
const list = text.match(URL_REGEX) || []; const list = text.match(URL_REGEX) || [];
var links = []; var links = [];
......
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