【发布时间】:2021-10-22 02:20:50
【问题描述】:
我正在尝试为链接输入值编写自定义处理程序。如果用户输入的链接没有自定义协议,我希望在输入值之前添加 http:。这是因为如果链接值缺少 http:,则不会解释链接,而是会显示 about:blank。 (https://github.com/quilljs/quill/issues/1268#issuecomment-272959998)
这是我写的(类似于官方示例here):
toolbar.addHandler("link", function sanitizeLinkInput(linkValueInput) {
console.log(linkValueInput); // debugging
if (linkValueInput === "")
this.quill.format(false);
// do nothing, since it implies user has just clicked the icon
// for link, hasn't entered url yet
else if (linkValueInput == true);
// do nothing, since this implies user's already using a custom protocol
else if (/^\w+:/.test(linkValueInput));
else if (!/^https?:/.test(linkValueInput)) {
linkValueInput = "http:" + linkValueInput;
this.quill.format("link", linkValueInput);
}
});
每次用户单击链接图标时,什么都不会发生,true 会记录到控制台。我实际上希望当人们在按下链接图标后显示的工具提示上单击“保存”时执行此处理程序。
知道怎么做吗?提示或建议也值得赞赏。
谢谢!
【问题讨论】:
标签: javascript quill