Skip to content

Commit e042dc4

Browse files
committed
fix: simplemde initialization for forum thread form
1 parent 2f669a9 commit e042dc4

File tree

9 files changed

+41
-101
lines changed

9 files changed

+41
-101
lines changed

app/assets/javascripts/simple_discussion/application.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/assets/javascripts/simple_discussion/controllers/application.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/assets/javascripts/simple_discussion/controllers/dropdown_controller.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

app/assets/javascripts/simple_discussion/controllers/index.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/assets/javascripts/simple_discussion/controllers/report_spam_controller.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

app/assets/javascripts/simple_discussion/controllers/simplemde_controller.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

app/views/layouts/simple_discussion.html.erb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,44 @@
119119
})
120120
}
121121
})
122+
123+
Stimulus.register("simplemde", class extends Controller {
124+
static targets = ["textarea"]
125+
126+
connect() {
127+
this.initializeEditor();
128+
129+
const previewButton = document.querySelector(".preview")
130+
previewButton.style.width = "80px"
131+
previewButton.style.height = "34px"
132+
}
133+
134+
initializeEditor() {
135+
this.editor = new SimpleMDE({
136+
element: this.textareaTarget,
137+
forceSync: true,
138+
toolbar: [
139+
"bold",
140+
"italic",
141+
"heading",
142+
"|",
143+
"quote",
144+
"unordered-list",
145+
"ordered-list",
146+
"|",
147+
"link",
148+
{
149+
name: "preview",
150+
className: "preview no-disable",
151+
action: function(editor) {
152+
SimpleMDE.togglePreview(editor);
153+
},
154+
title: "Preview",
155+
}
156+
],
157+
spellChecker: false,
158+
});
159+
}
160+
})
122161
</script>
123162

app/views/simple_discussion/forum_posts/_forum_post.html.erb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<%= icon("fas","ellipsis-v") %>
1111
</button>
1212
<div class="dropdown-menu dropdown-menu-right" data-dropdown-target="dropdownMenu">
13-
<%= link_to t('report_spam'), "#", class: "dropdown-item", data: { controller: "report-spam", report_spam_target: "reportSpamButton", toggle: "modal", target: "#reportSpamModal", post_id: forum_post.id } %>
1413
<% if is_moderator_or_owner?(forum_post) %>
1514
<%= link_to t('edit_post'), simple_discussion.edit_forum_thread_forum_post_path(@forum_thread, forum_post),
1615
class: "dropdown-item",

app/views/simple_discussion/forum_threads/_form.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<%= form_for @forum_thread,
22
url: (@forum_thread.persisted? ? simple_discussion.forum_thread_path(@forum_thread) : simple_discussion.forum_threads_path),
3-
html: { data: {behavior: "comment-form"} } do |f| %>
3+
html: { data: { behavior: "comment-form", controller: "simplemde" } } do |f| %>
44

55
<% if @forum_thread.errors.any? %>
66
<div class="alert alert-danger" role="alert">
@@ -24,7 +24,7 @@
2424
<%= f.fields_for :forum_posts do |p| %>
2525
<div class="form-group">
2626
<%= p.label :body, t('what_help_needed') %>
27-
<%= p.text_area :body, placeholder: t('add_a_comment'), rows: 10, class: "form-control simplemde", data: { behavior: "comment-body" } %>
27+
<%= p.text_area :body, placeholder: t('add_a_comment'), rows: 10, class: "form-control simplemde", data: { behavior: "comment-body", simplemde_target: "textarea" } %>
2828
</div>
2929
<% end %>
3030
<% end %>

0 commit comments

Comments
 (0)