Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image pasting ability #579

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

deejayy
Copy link

@deejayy deejayy commented Nov 5, 2022

I don't know CoffeScript at all, so a thorough review is required, the changes here are reversed from a proven JS implementation I made. If you like it, please adjust accordingly.

Example code for handling the paste event:

  const uploader = function (ev) {
    var formData = new FormData();
    formData.append("image", ev.detail().file);

    var xhr = new XMLHttpRequest();
    xhr.open("POST", "/api/upload");
    xhr.onload = function () {
      if (xhr.status == 200) {
        const response = JSON.parse(xhr.responseText) || {};
        if (ev.detail().element && response.url) {
          editor.pasteHTML(ev.detail().element, `<p><img src="${response.url}"/></p>`, true);
        }
      } else {
        console.log("Nope");
      }
    };

    xhr.send(formData);
  };

  editor.addEventListener("imagepaste", uploader);

Or, you can close it, no hard feelings :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant