admin管理员组文章数量:1287631
I'm using Quill text editor as the text editor of my site, one of the site options is to create dynamic text editors, the function that defines the quill editor looks like that:
function quillDefine(quillID) //quillID is the id of the div that I'm going to define as quill element
{
var toolbarOptions =
[
['bold', 'italic', 'underline', 'strike'],
['blockquote'],
[{'align':[]}],
['clean']
]
var quill = new Quill('#'+quillID, {
modules: {toolbar: toolbarOptions},
theme: 'snow'
});
}
how can I use this quill instance that I created inside other funcitons? for example:
funciton getQuillInstanceText(quillID)
{
//I know I can use $('#'quillID).html(), but is that the proper way to do so?
}
I want to use the quill API functions like getContents() and etc.
How can I reach to the instance I just created? Thanks a lot.
I'm using Quill text editor as the text editor of my site, one of the site options is to create dynamic text editors, the function that defines the quill editor looks like that:
function quillDefine(quillID) //quillID is the id of the div that I'm going to define as quill element
{
var toolbarOptions =
[
['bold', 'italic', 'underline', 'strike'],
['blockquote'],
[{'align':[]}],
['clean']
]
var quill = new Quill('#'+quillID, {
modules: {toolbar: toolbarOptions},
theme: 'snow'
});
}
how can I use this quill instance that I created inside other funcitons? for example:
funciton getQuillInstanceText(quillID)
{
//I know I can use $('#'quillID).html(), but is that the proper way to do so?
}
I want to use the quill API functions like getContents() and etc.
How can I reach to the instance I just created? Thanks a lot.
Share Improve this question asked Jan 16, 2017 at 9:56 FinFonFinFon 951 gold badge2 silver badges8 bronze badges3 Answers
Reset to default 10Unfortunately there is no Quill API that will return a Quill instance from a corresponding DOM container. If you are using jQuery you can use $.data():
var quill = new Quill(quillID);
$(quillID).data("quill", quill);
funciton getQuillInstanceText(quillID) {
var quill = $(quillID).data("quill");
var text = quill.getText();
return text;
}
Or with plain JS:
var container = document.querySelector(quillID);
var quill = new Quill(container);
container.__quill = quill;
funciton getQuillInstanceText(quillID) {
var container = document.querySelector(quillID);
var quill = container.__quill;
var text = quill.getText();
return text;
}
Edit: As of Quill 1.2.0, you can now use the experimental find API.
Instead of saving the editor object as an attribute of the HTML, you can also create an object that will hold all editors, and you can store and get each editor by key (ID) whenever you want:
var editors={};
editors[quilID] = new Quill(quilID);
function getQuillInstanceText(quillID) {
var quill = editors[quillID];
var text = quill.getText();
return text;
}
In this case you don't need any DOM querying nor JQuery.
According to Quill Rich Text Editor Documentation you can get the editor instance by getting the DOM element and inserting it inside the Static method find()
. This method returns the Quill or Blot instance for the given DOM node.
You can use the method as follows:
function getQuillInstanceText(quillID)
{
var linkNode = document.querySelector(quillID);
var linkBlot = Quill.find(linkNode);
return linkBlot;
}
本文标签: javascriptQuill text editor how to use instances after creating with JQueryStack Overflow
版权声明:本文标题:javascript - Quill text editor how to use instances after creating with JQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741251551a2365884.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论