+
+ const dl_comments = document.createElement('dl');
+ const comments_id = "comments_" + image.index;
+ dl_comments.className = "comments";
+ dl_comments.id = comments_id;
+ figure.appendChild(dl_comments);
+
+ const comment_form = document.createElement('form');
+ const comment_input = document.createElement('input')
+ comment_input.type = "text";
+ comment_input.className = "comment";
+ comment_input.placeholder = "Add a comment";
+ comment_form.appendChild(comment_input);
+ figure.appendChild(comment_form);
+
+ comment_input.addEventListener('focus', () => {
+ /* Do nothing if name is already set. */
+ if (name.value)
+ return;
+
+ /* Otherwise, bring up the modal dialog to set the name. */
+ name_dialog.showModal();
+ });
+
+ comment_form.addEventListener('submit', function(e) {
+ e.preventDefault();
+ if (comment_input.value) {
+ socket.emit('comment', {comments_id: comments_id,
+ text: comment_input.value});
+ comment_input.value = '';
+ }
+ });
+