Quill: Insert image with url

Created on 27 Mar 2018  路  4Comments  路  Source: quilljs/quill

Is possible insert image without uploading? Just put image link, and display it in tag.

Most helpful comment

custom handler + insertEmbed. why don't you read the guides first?

Logged in just to down vote this comment.

Its kind of lazy that the developers left out such a crucial part of wysiwyg editing.

also here is some actually useful code

```
var toolbarOptions = [
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block'],

        [{ 'header': 1 }, { 'header': 2 }],               // custom button values
        [{ 'list': 'ordered' }, { 'list': 'bullet' }],
        [{ 'script': 'sub' }, { 'script': 'super' }],      // superscript/subscript
        [{ 'indent': '-1' }, { 'indent': '+1' }],          // outdent/indent
        [{ 'direction': 'rtl' }],                         // text direction

        [{ 'size': ['small', false, 'large', 'huge'] }],  // custom dropdown
        [{ 'header': [1, 2, 3, 4, 5, 6, false] }],

        [{ 'color': [] }, { 'background': [] }],          // dropdown with defaults from theme
        [{ 'font': [] }],
        [{ 'align': [] }],

        ['clean'],                                         // remove formatting button
        ['image']
    ];

    var quill = new Quill('#editor', {
        theme: 'snow',
        modules: {
            toolbar: {
                container: toolbarOptions,
                handlers: {
                    image: imageHandler
                }
            }
        },
    });

    function imageHandler() {
        var range = this.quill.getSelection();
        var value = prompt('What is the image URL');
        if(value){
            this.quill.insertEmbed(range.index, 'image', value, Quill.sources.USER);
        }
    }

All 4 comments

custom handler + insertEmbed. why don't you read the guides first?

Logged in just to down vote this comment.

Its kind of lazy that the developers left out such a crucial part of wysiwyg editing.

also here is some actually useful code

```
var toolbarOptions = [
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block'],

        [{ 'header': 1 }, { 'header': 2 }],               // custom button values
        [{ 'list': 'ordered' }, { 'list': 'bullet' }],
        [{ 'script': 'sub' }, { 'script': 'super' }],      // superscript/subscript
        [{ 'indent': '-1' }, { 'indent': '+1' }],          // outdent/indent
        [{ 'direction': 'rtl' }],                         // text direction

        [{ 'size': ['small', false, 'large', 'huge'] }],  // custom dropdown
        [{ 'header': [1, 2, 3, 4, 5, 6, false] }],

        [{ 'color': [] }, { 'background': [] }],          // dropdown with defaults from theme
        [{ 'font': [] }],
        [{ 'align': [] }],

        ['clean'],                                         // remove formatting button
        ['image']
    ];

    var quill = new Quill('#editor', {
        theme: 'snow',
        modules: {
            toolbar: {
                container: toolbarOptions,
                handlers: {
                    image: imageHandler
                }
            }
        },
    });

    function imageHandler() {
        var range = this.quill.getSelection();
        var value = prompt('What is the image URL');
        if(value){
            this.quill.insertEmbed(range.index, 'image', value, Quill.sources.USER);
        }
    }

@Gibigbig Hi! I am using Markdown with nix-quill. I've tried inserting your part of the code in the app module, but apparently Quill is not packed there. May you help me fixing this?

@Gibigbig Hi! I am using Markdown with nix-quill. I've tried inserting your part of the code in the app module, but apparently Quill is not packed there. May you help me fixing this?

I'm also using ngx-quill. I managed to get this to work in Angular by:

import { QuillModules, defaultModules } from 'ngx-quill';

export class MyComponent {

    quillModules: QuillModules = {
    toolbar: {
      container: defaultModules.toolbar, 
      handlers: {
        image: imageHandler
      }
    }
  };

}

imageHandler(this: any) {
    const tooltip = this.quill.theme.tooltip;
    const originalSave = tooltip.save;
    const originalHide = tooltip.hide;
    tooltip.save = function(this: any) {
      const range = this.quill.getSelection(true);
      const value = this.textbox.value;
      if (value) {
        this.quill.insertEmbed(range.index, 'image', value, 'user');
      }
    };
    // Called on hide and save.
    tooltip.hide = function (this: any) {
       tooltip.save = originalSave;
       tooltip.hide = originalHide;
       tooltip.hide();
    };
    tooltip.edit('image');
    tooltip.textbox.placeholder = "Embed URL";
  }

<quill-editor [modules]="quillModules"></quill-editor>

@chrisbmoore Hi, you have to update you tooltip.save funtion .
You can change your code like this:
const value = this.textbox.value to const value = tooltip.textbox.value

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sferoze picture sferoze  路  3Comments

DaniilVeriga picture DaniilVeriga  路  3Comments

splacentino picture splacentino  路  3Comments

aletorrado picture aletorrado  路  3Comments

GildedHonour picture GildedHonour  路  3Comments