JavaScript inserts an attachment into the Ckeditor5

Source: Internet
Author: User

Ckeditor5 related things in Chinese is too little, today realized the custom Add content function here to record, hoping to help the needs of friends

<div name="content" id="editor">    <p>欢迎访问</p></div><button id="insert-text" class="btn btn-light">添加图片</button>
$(function () {    ClassicEditor.create(document.querySelector('#editor'), {            //language: 'zh-cn',            toolbar: ['heading', '|', 'bold', 'italic', 'link', 'blockQuote', 'bulletedList',                'numberedList'            ]        }).then(editor => {            console.log(editor)            window.editor = editor;        })        .catch(error => {            console.log(error);        });    console.log(editor)    $('#insert-text').on('click', function () {        var obj = document.createElement('img') // 添加的内容可以自定义, 这里以添加图片为例        obj.setAttribute('src',            'image.jpg'        )        const viewFragment = editor.data.processor.toView(obj.outerHTML);        const modelFragment = editor.data.toModel(viewFragment);        editor.model.insertContent(modelFragment, editor.model.document.selection);    })})

JavaScript inserts an attachment into the Ckeditor5

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.