Coder Social home page Coder Social logo

Comments (14)

faresayyad avatar faresayyad commented on July 18, 2024 5

@deepakpapola this is my implementation:

  EditorCreated(quill) {
    const toolbar = quill.getModule('toolbar');
    toolbar.addHandler('image', this.imageHandler.bind(this));
    this.editor = quill;

}

imageHandler() {
  const Imageinput = document.createElement('input');
  Imageinput.setAttribute('type', 'file');
  Imageinput.setAttribute('accept', 'image/png, image/gif, image/jpeg, image/bmp, image/x-icon');
  Imageinput.classList.add('ql-image');

  Imageinput.addEventListener('change', () =>  {
    const file = Imageinput.files[0];
    if (Imageinput.files != null && Imageinput.files[0] != null) {
        this._service.sendFileToServer(file).subscribe(res => {
        this._returnedURL = res;
        this.pushImageToEditor();
        });
    }
});

  Imageinput.click();
}
pushImageToEditor() {
  const range = this.editor.getSelection(true);
  const index = range.index + range.length;
  this.editor.insertEmbed(range.index, 'image', this._returnedURL);
}

from ngx-quill-editor.

sujeetSharna avatar sujeetSharna commented on July 18, 2024 4

doc004

image uploading is working properly

from ngx-quill-editor.

nishadmenezes avatar nishadmenezes commented on July 18, 2024 2

This is possible by creating your own ImageHandler. Use this for reference -
Adding Custom Handlers

In Angular 4, Edit the onEditorCreated function -

onEditorCreated(quill) {
    var toolbar = quill.getModule('toolbar');
    toolbar.addHandler('image', this.imageHandler);
    this.quill = quill;
}
  
imageHandler(value) {
    /* Image Handler Code...
        Ex. Trigger a file dialog, save to file input in a form, save multipart form data to the
              server & finally retrieve the image url. */
        let range = this.quill.getSelection(true);
        let index = range.index + range.length;
        this.quill.insertEmbed(range.index, 'image', imgUrl);
}

from ngx-quill-editor.

deepakpapola avatar deepakpapola commented on July 18, 2024 1

@faresayyad thanx men. did you use the image resize module also?

from ngx-quill-editor.

faresayyad avatar faresayyad commented on July 18, 2024

@nishadmenezes thank you man

from ngx-quill-editor.

deepakpapola avatar deepakpapola commented on July 18, 2024

@nishadmenezes @faresayyad can you explain bit more? still i cant upload image to server and the url provided by you is not valid

from ngx-quill-editor.

nishadmenezes avatar nishadmenezes commented on July 18, 2024

* Just copy and paste the URL into the address bar of your browser I don't know what's wrong

What I have done is create a custom image handler that opens up a file dialog on clicking the image upload icon. Then, after saving the uploaded image, I am embedding an image into the quill-editor with the URL of the image I just uploaded.

According to docs, I am adding this custom image handler function to the toolbar of the quill editor so that it is called when the image icon is clicked.

from ngx-quill-editor.

deepakpapola avatar deepakpapola commented on July 18, 2024

@nishadmenezes can you tell how to open file dialog on image icon click

thanks

from ngx-quill-editor.

nishadmenezes avatar nishadmenezes commented on July 18, 2024

Image resize module wasn't packaged as well as this module. I had problems getting it to work. Let me know if you manage that...

from ngx-quill-editor.

faresayyad avatar faresayyad commented on July 18, 2024

@deepakpapola your'e welcome man, not yet because i'm dealing with backend right now, but i will try to configure it ASAP.
If you can use the image resize, please don't forget to share it hear.

from ngx-quill-editor.

deepakpapola avatar deepakpapola commented on July 18, 2024

@faresayyad @nishadmenezes sure bros 👍

from ngx-quill-editor.

lakinmohapatra avatar lakinmohapatra commented on July 18, 2024

const index = range.index + range.length;
this.editor.insertEmbed(range.index, 'image', this._returnedURL);

Above code is not working for getting current cursor location.
My image is always inserted at top.
Please help.

from ngx-quill-editor.

madhavan-sundararaj avatar madhavan-sundararaj commented on July 18, 2024

Hey @faresayyad is ql-image your custom class?

from ngx-quill-editor.

m7ammad7assan avatar m7ammad7assan commented on July 18, 2024

@deepakpapola this is my implementation:

  EditorCreated(quill) {
    const toolbar = quill.getModule('toolbar');
    toolbar.addHandler('image', this.imageHandler.bind(this));
    this.editor = quill;

}

imageHandler() {
  const Imageinput = document.createElement('input');
  Imageinput.setAttribute('type', 'file');
  Imageinput.setAttribute('accept', 'image/png, image/gif, image/jpeg, image/bmp, image/x-icon');
  Imageinput.classList.add('ql-image');

  Imageinput.addEventListener('change', () =>  {
    const file = Imageinput.files[0];
    if (Imageinput.files != null && Imageinput.files[0] != null) {
        this._service.sendFileToServer(file).subscribe(res => {
        this._returnedURL = res;
        this.pushImageToEditor();
        });
    }
});

  Imageinput.click();
}
pushImageToEditor() {
  const range = this.editor.getSelection(true);
  const index = range.index + range.length;
  this.editor.insertEmbed(range.index, 'image', this._returnedURL);
}

it is not working for me the server cannot recognize the post as image !

from ngx-quill-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.