diff --git a/app/assets/javascripts/simple_discussion/application.js b/app/assets/javascripts/simple_discussion/application.js deleted file mode 100644 index 6ec9251..0000000 --- a/app/assets/javascripts/simple_discussion/application.js +++ /dev/null @@ -1 +0,0 @@ -import "./controllers"; diff --git a/app/assets/javascripts/simple_discussion/controllers/application.js b/app/assets/javascripts/simple_discussion/controllers/application.js deleted file mode 100644 index f408ed0..0000000 --- a/app/assets/javascripts/simple_discussion/controllers/application.js +++ /dev/null @@ -1,9 +0,0 @@ -import { Application } from "@hotwired/stimulus" - -const application = Application.start() - -application.warnings = true -application.debug = false -window.Stimulus = application - -export { application } diff --git a/app/assets/javascripts/simple_discussion/controllers/dropdown_controller.js b/app/assets/javascripts/simple_discussion/controllers/dropdown_controller.js deleted file mode 100644 index c828ddb..0000000 --- a/app/assets/javascripts/simple_discussion/controllers/dropdown_controller.js +++ /dev/null @@ -1,20 +0,0 @@ -import { Controller } from "@hotwired/stimulus" - -export default class extends Controller { - static targets = ["dropdownButton", "dropdownMenu"] - - connect() { - this.dropdownButtonTarget.addEventListener("click", this.toggleDropdown.bind(this)) - // if click somewhere else in the document, close the dropdown - window.addEventListener("click", (event) => { - if (!this.dropdownButtonTarget.contains(event.target)) { - this.dropdownMenuTarget.classList.remove("show") - } - }) - } - - // note that we are using bootstrap - toggleDropdown() { - this.dropdownMenuTarget.classList.toggle("show") - } -} diff --git a/app/assets/javascripts/simple_discussion/controllers/index.js b/app/assets/javascripts/simple_discussion/controllers/index.js deleted file mode 100644 index 9051e62..0000000 --- a/app/assets/javascripts/simple_discussion/controllers/index.js +++ /dev/null @@ -1,9 +0,0 @@ -import { application } from "./application" - -import DropdownController from "./dropdown_controller" -import ReportSpamController from "./report_spam_controller"; -import SimplemdeController from "./simplemde_controller"; - -application.register("dropdown", DropdownController); -application.register("report-spam", ReportSpamController); -application.register("simplemde",SimplemdeController); diff --git a/app/assets/javascripts/simple_discussion/controllers/report_spam_controller.js b/app/assets/javascripts/simple_discussion/controllers/report_spam_controller.js deleted file mode 100644 index 1250f7f..0000000 --- a/app/assets/javascripts/simple_discussion/controllers/report_spam_controller.js +++ /dev/null @@ -1,18 +0,0 @@ -import { Controller } from "@hotwired/stimulus" - -export default class extends Controller { - static targets = ["reportSpamButton"] - - connect() { - const reportSpamForm = document.getElementById("reportSpamForm") - const postId = this.element.dataset.postId - this.reportSpamButtonTarget.addEventListener("click", () => { - const formActionArray = reportSpamForm.action.split("/") - if (formActionArray[formActionArray.length - 2] === "threads") { - reportSpamForm.action += `/posts/${postId}/report_spam` - } else { - reportSpamForm.action = reportSpamForm.action.replace(/\/\d+\//, `/${postId}/`) - } - }) - } -} diff --git a/app/assets/javascripts/simple_discussion/controllers/simplemde_controller.js b/app/assets/javascripts/simple_discussion/controllers/simplemde_controller.js deleted file mode 100644 index 7c98c25..0000000 --- a/app/assets/javascripts/simple_discussion/controllers/simplemde_controller.js +++ /dev/null @@ -1,41 +0,0 @@ -import { Controller } from "@hotwired/stimulus" -//import SimpleMDE from "simplemde"; - -export default class extends Controller { - static targets = ["textarea"] - - connect() { - this.initializeEditor(); - - const previewButton = document.querySelector(".preview") - previewButton.style.width = "80px" - previewButton.style.height = "34px" - } - - initializeEditor() { - this.editor = new SimpleMDE({ - element: this.textareaTarget, - forceSync: true, - toolbar: [ - "bold", - "italic", - "heading", - "|", - "quote", - "unordered-list", - "ordered-list", - "|", - "link", - { - name: "preview", - className: "preview no-disable", - action: function(editor) { - SimpleMDE.togglePreview(editor); - }, - title: "Preview", - } - ], - spellChecker: false, - }); - } -} diff --git a/app/views/layouts/simple_discussion.html.erb b/app/views/layouts/simple_discussion.html.erb index f0bb2b5..c5502c1 100644 --- a/app/views/layouts/simple_discussion.html.erb +++ b/app/views/layouts/simple_discussion.html.erb @@ -119,5 +119,44 @@ }) } }) + + Stimulus.register("simplemde", class extends Controller { + static targets = ["textarea"] + + connect() { + this.initializeEditor(); + + const previewButton = document.querySelector(".preview") + previewButton.style.width = "80px" + previewButton.style.height = "34px" + } + + initializeEditor() { + this.editor = new SimpleMDE({ + element: this.textareaTarget, + forceSync: true, + toolbar: [ + "bold", + "italic", + "heading", + "|", + "quote", + "unordered-list", + "ordered-list", + "|", + "link", + { + name: "preview", + className: "preview no-disable", + action: function(editor) { + SimpleMDE.togglePreview(editor); + }, + title: "Preview", + } + ], + spellChecker: false, + }); + } + }) diff --git a/app/views/simple_discussion/forum_posts/_forum_post.html.erb b/app/views/simple_discussion/forum_posts/_forum_post.html.erb index 8db1088..fe17edf 100644 --- a/app/views/simple_discussion/forum_posts/_forum_post.html.erb +++ b/app/views/simple_discussion/forum_posts/_forum_post.html.erb @@ -10,7 +10,6 @@ <%= icon("fas","ellipsis-v") %>