[英]Adding data-src and changing src to all Joomla images inside editor
[英]TinyMCE Editor: Lazy Load & Data-src
使用 Tiny 編輯器添加新圖像時,我得到類似這樣的信息
< img class="img-fluid" src="images/example.webp" alt="" />
理想情況下,我想要這樣的東西
< img src="/assets/img/1px.png" data-src="images/example.webp" class="img-fluid lazyload" width="600" height="254" alt="" />
我添加了 class lazyload,但我不知道如何在 src 和 data-src 上添加 1px.png。 有人可以給我任何建議嗎?
您可以在使用 init 和ExecCommand
中的setup
選項插入圖像時添加數據屬性。 示例: https://fiddle.tiny.cloud/Mtiaab
tinymce.init({
selector: "textarea",
plugins: "image advcode",
toolbar: "image code",
setup: function (editor) {
editor.on('ExecCommand', function (e) {
if (e.command === 'mceUpdateImage') {
const img = editor.selection.getNode();
img.setAttribute('data-src', img.src);
}
});
},
});
請參閱此處的文檔: https://www.tiny.cloud/docs/tinymce/6/editor-important-options/#setup https://www.tiny.cloud/docs/tinymce/6/apis/tinymce.editor/ #execCommand
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.