簡體   English   中英

完成編輯后如何關閉羽毛筆編輯器

[英]How to close the quill editor when done with editing

我在 DOM 中元素的單擊事件上動態實例化 QuillJS 編輯器。 所以我的要求是,一旦用戶完成對該元素的編輯,他/她應該能夠關閉編輯器。 目前,我在 quill API 中沒有看到任何關閉方法。啟用/禁用 API 方法對我不起作用,因為我想完全關閉編輯器並向用戶顯示他/她在看到 quill 編輯器之前的相同視圖但當然還有保存的更改。

這個的演示可以在這里看到
https://codepen.io/curiousdj/pen/eEjbPK

const options = { theme: "snow" };
var divs = document.getElementsByTagName("div");
var initializeQuill = function (e){
     if(!this.quill){
        console.log(e);
        this.target = event.currentTarget;
        this.quill = new Quill(this.target, options);
        this.target.children[0].onclick = function(et) { et.preventDefault(); };
        this.target.children[0].onblur = function(l) {
               l.target.parentElement.quill.close;
         };
        }
        this.quill.focus();
        e.stopPropagation();
        e.preventDefault();
}
for(var i = 0; i < divs.length; i++){
    divs[i].onclick = initializeQuill;
}

我建議:

  1. 復制 quill 實例的內容,銷毀實例綁定的 DOM 元素,創建一個新的 DOM 元素並將內容粘貼回
  2. 正如您已經嘗試過的那樣,通過 API 使用 disable,但也要設置禁用的 Quill 實例的樣式,以不顯示 Quill 的格式與您自己的格式之間的任何區別。

我在此處更新了您的筆以舉例說明具有基本更改的第二個選項

.ql-editor {
  padding:0;
  line-height:inherit;
}

.ql-editor p {
  margin-bottom:10px;
}

.ql-toolbar {
  display:none;
}

.ql-container.ql-snow {
  border:none;
  font-family:inherit;
  font-size:inherit;
}

您可以通過在內容 div 上設置contenteditable="false"來嘗試。

這對我有用:

function destory_editor(selector){
    if($(selector)[0])
    {
        var content = $(selector).find('.ql-editor').html();
        $(selector).html(content);

        $(selector).siblings('.ql-toolbar').remove();
        $(selector + " *[class*='ql-']").removeClass (function (index, css) {
           return (css.match (/(^|\s)ql-\S+/g) || []).join(' ');
        });

        $(selector + "[class*='ql-']").removeClass (function (index, css) {
           return (css.match (/(^|\s)ql-\S+/g) || []).join(' ');
        });
    }
    else
    {
        console.error('editor not exists');
    }
}

要使用它,只需調用:

destory_editor('.editor');

在最新版本(也許是以前的版本)上, ql-toolbar始終是 quill 編輯器的previousSibling 所以刪除工具欄變得很簡單;

document.getElementById("editor element id").previousSibling.remove();

這具有一次“處理”一個編輯器的好處。

如何調整羽毛筆編輯器的大小以適應<div> ?</div><div id="text_translate"><p> 我希望羽毛筆編輯器自動適應父&lt;div&gt;元素。</p><p> 我創建了&lt;div&gt;元素,並在其中再次創建了一個&lt;div&gt;元素,該元素將成為 quill 編輯器的容器。 工具欄是自動創建的。 我使用 css 將父&lt;div&gt;元素的大小調整為width:50%和height:50% ,我希望其中的所有內容(羽毛筆編輯器和工具欄)都適合其中,但是羽毛筆編輯器的某些部分會出現父&lt;div&gt;元素的。</p><p> <strong>HTML:</strong></p><pre class="lang-html prettyprint-override"> &lt;,-- parent div element: in which quill editor should fit --&gt; &lt;div id="parent" style="width;50%:height;70%:border:2px solid green"&gt; &lt;!-- Quill editor div --&gt; &lt;div id="editor"&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> <strong>Javascript:</strong></p><pre> var tool = [[{ 'header': '1' }, { 'header': '2' }], [{ size: ['small', false, 'large', 'huge'] }], ['bold', 'italic', 'underline', 'strike'], [{ 'color': [] }, { 'background': [] }, { 'font': [] }, { 'align': [] }], ['image',]]; var option = { placeholder: 'Compose an epic...', theme: 'snow', modules: { toolbar: tool }, bounds:'#parent' }; var quill = new Quill('#editor', option);</pre><p> 我在父 div 周圍放了一個綠色邊框,我發現編輯器從邊框出來了。 請看截圖:</p><p> <a href="https://i.stack.imgur.com/RlASQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RlASQ.png" alt="截屏"></a></p><p> 注意:我只想保持父 div 的大小固定。 所以,請告訴我該怎么辦?</p><p> 編輯:我將整個代碼(html 文件)上傳到我的服務器(<a href="http://tu.unaux.com/game.html" rel="nofollow noreferrer">這里</a>)。 問題仍然存在。 請檢查一下,您可以使用“檢查元素”查看整個代碼。</p></div>

[英]How to resize quill editor to fit inside a <div>?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 編輯完成后隱藏或關閉dijit.editor 如何為羽毛筆編輯器設置內容? 如何使用vue-quill包關注Quill編輯器? 如何將 Wiris 或 Mathjax 添加到 Quill 編輯器 如何用angular和js附加多個鵝毛筆編輯器 如何調整羽毛筆編輯器的大小以適應<div> ?</div><div id="text_translate"><p> 我希望羽毛筆編輯器自動適應父&lt;div&gt;元素。</p><p> 我創建了&lt;div&gt;元素,並在其中再次創建了一個&lt;div&gt;元素,該元素將成為 quill 編輯器的容器。 工具欄是自動創建的。 我使用 css 將父&lt;div&gt;元素的大小調整為width:50%和height:50% ,我希望其中的所有內容(羽毛筆編輯器和工具欄)都適合其中,但是羽毛筆編輯器的某些部分會出現父&lt;div&gt;元素的。</p><p> <strong>HTML:</strong></p><pre class="lang-html prettyprint-override"> &lt;,-- parent div element: in which quill editor should fit --&gt; &lt;div id="parent" style="width;50%:height;70%:border:2px solid green"&gt; &lt;!-- Quill editor div --&gt; &lt;div id="editor"&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> <strong>Javascript:</strong></p><pre> var tool = [[{ 'header': '1' }, { 'header': '2' }], [{ size: ['small', false, 'large', 'huge'] }], ['bold', 'italic', 'underline', 'strike'], [{ 'color': [] }, { 'background': [] }, { 'font': [] }, { 'align': [] }], ['image',]]; var option = { placeholder: 'Compose an epic...', theme: 'snow', modules: { toolbar: tool }, bounds:'#parent' }; var quill = new Quill('#editor', option);</pre><p> 我在父 div 周圍放了一個綠色邊框,我發現編輯器從邊框出來了。 請看截圖:</p><p> <a href="https://i.stack.imgur.com/RlASQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RlASQ.png" alt="截屏"></a></p><p> 注意:我只想保持父 div 的大小固定。 所以,請告訴我該怎么辦?</p><p> 編輯:我將整個代碼(html 文件)上傳到我的服務器(<a href="http://tu.unaux.com/game.html" rel="nofollow noreferrer">這里</a>)。 問題仍然存在。 請檢查一下,您可以使用“檢查元素”查看整個代碼。</p></div> 如何在 Vue.js 中自動對焦 Quill Editor? 如何在羽毛筆編輯器中啟用功能粘貼表 如何在羽毛筆編輯器中使用ng-repeat nuxt.js中quill編輯器onkeyup的使用方法
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM