Sha256: 5e49174f53f6f4ea0e231f51a94c280b362bd3a4d427c293a0925df5ed66b54a

Contents?: true

Size: 1.01 KB

Versions: 6

Compression:

Stored size: 1.01 KB

Contents

import EditorComponentController from "satis/components/editor/component_controller"

/***
 * Text editor controller
 *
 * Control codemirror
 */
export default class extends EditorComponentController {
  static targets = ["textarea"]

  save() {
    const self = this

    const formData = new FormData()
    formData.append("_method", "PATCH")
    formData.append("content[data_with_frontmatter]", this.inputTarget.value)

    fetch(self.data.get("save-url"), {
      method: "POST",
      headers: {
        Accept: "application/json, text/javascript",
        "X-CSRF-Token": document.querySelector("meta[name=csrf-token]").content,
      },
      body: formData,
    }).then((response) => {
      if (response.status == 200) {
        let event = new CustomEvent("content-editor.changed", {
          bubbles: true,
          cancelable: true,
          detail: {
            contentId: self.data.get("content-id"),
            dirty: false,
          },
        })
        self.element.dispatchEvent(event)
      }
    })
  }
}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
scribo-1.0.44 app/javascript/scribo/controllers/text_editor_controller.js
scribo-1.0.43 app/javascript/scribo/controllers/text_editor_controller.js
scribo-1.0.42 app/javascript/scribo/controllers/text_editor_controller.js
scribo-1.0.41 app/javascript/scribo/controllers/text_editor_controller.js
scribo-1.0.40 app/javascript/scribo/controllers/text_editor_controller.js
scribo-1.0.39 app/javascript/scribo/controllers/text_editor_controller.js