slab / quill

Quill is a modern WYSIWYG editor built for compatibility and extensibility
https://quilljs.com
BSD 3-Clause "New" or "Revised" License
43.65k stars 3.39k forks source link

Make the tooltip save method extendable #1077

Open ghost opened 8 years ago

ghost commented 8 years ago

It's not a bug, it's a feature request

I would like to add a tooltip to handle image-links

I am opening the image-links tooltip with

this.quill.tooltip.edit('image-link') but it's not possible to handle the save of it because the implementation is hardcoded as a switch, and cant be extended without replacing the whole save method.

https://github.com/quilljs/quill/blob/189563a27fe18ef97688d948d458eabe316db1d3/themes/base.js#L203

I think it would be better to move the save methods to a map, and call them from the save method directly instead of the switch statement.

saveMethods = {
  image(value) {  },
  video(value) { }
}
save() {
    let value = this.textbox.value;
    const mode = this.root.getAttribute('data-mode');
    if (typeof this.saveMethods[mode] === "function") {
       this.saveMethods[mode](value)
    }    

    this.textbox.value = '';
    this.hide();
}

I am not sure how to add saveMethods, but if you like it, you can ping me, and I'll create a PR

What do you think guys?

baturian commented 2 years ago

Any updates here? I would like to use this.