Javascript 在羽毛笔编辑器中为链接弹出窗口创建处理程序
我想用弹出式表单创建一个链接,该表单获取表单数据(链接标题和链接url),然后将此链接添加到编辑器中 类似Reddit编辑器的东西 我的启动代码没有按我希望的那样工作Javascript 在羽毛笔编辑器中为链接弹出窗口创建处理程序,javascript,quill,Javascript,Quill,我想用弹出式表单创建一个链接,该表单获取表单数据(链接标题和链接url),然后将此链接添加到编辑器中 类似Reddit编辑器的东西 我的启动代码没有按我希望的那样工作 class LinkBlot extends Inline { static create(url, title) { let node = super.create(); // Sanitize url value if desired node.setAttribute('href'
class LinkBlot extends Inline {
static create(url, title) {
let node = super.create();
// Sanitize url value if desired
node.setAttribute('href', url);
// Okay to set other non-format related attributes
// These are invisible to Parchment so must be static
node.setAttribute('target', '_blank');
node.setAttribute('title', title);
return node;
}
static formats(node) {
// We will only be called with a node already
// determined to be a Link blot, so we do
// not need to check ourselves
return node.getAttribute('href') || true;
}
format(name, value) {
if (name === 'link' && value) {
this.domNode.setAttribute('href', value);
} else {
super.format(name, value);
}
}
formats() {
let formats = super.formats();
formats['link'] = LinkBlot.formats(this.domNode);
return formats;
}
}
LinkBlot.blotName = 'link';
LinkBlot.tagName = 'a';
Quill.register(LinkBlot);
document.querySelector('#link-insert-btn').addEventListener('click', function(event){
event.preventDefault();
var linkText = document.getElementById('link-text').value;
var linkURL = document.getElementById('link-url').value;
quill.format('link', linkURL, linkText);
});
我们将非常感谢您的帮助