TinyMCE 在 Bootstrap 5 模式中不起作用 [英] TinyMCE doesn't work within Bootstrap 5 modal

查看:38
本文介绍了TinyMCE 在 Bootstrap 5 模式中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望你能帮助我
所以这是我的问题:
我想在 Bootstrap 5 模态中集成 TinyMCE 编辑器
但问题是在 TinyMCE 模态(例如链接模态)中,我无法编辑输入.这是我的代码:

 

你可以告诉我这样做:https://www.tiny.cloud/docs/integrations/bootstrap/
我已经尝试过这个解决方案,我做了一些测试,它只解决了 Bootstrap V4.7 之前的问题.
我真的希望你能帮助我,再见:)

解决方案

由于对 Bootstrap 5 的更改,正如 OP 所述,Tiny 文档站点 (见这里)不适用于 Bootstrap 5(在发布时,我可以确认 Tiny 的文档团队知道这一点,并且有一个开放的任务要在即将到来的文档更新中解决这个问题.)

以下是此问题的解决方法:

  1. 适用于 Bootstrap 5
  2. 不需要 jQuery
  3. ...在 IE11 中不起作用.

document.addEventListener('focusin', function (e) {if (e.target.closest('.tox-tinymce-aux, .moxman-window, .tam-assetmanager-root') !== null) {e.stopImmediatePropagation();}});

这是一个 Tiny Fiddle 演示:https://fiddle.tiny.cloud/R8haab

hope you'll be able to help me
so here is my problem:
I would like to integrate a TinyMCE editor in a Bootstrap 5 modal
But the problem is that in TinyMCE modals (for example link modal), I'm unable to edit the input. Here is my code:

    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/5.7.1/tinymce.min.js" integrity="sha512-RnlQJaTEHoOCt5dUTV0Oi0vOBMI9PjCU7m+VHoJ4xmhuUNcwnB5Iox1es+skLril1C3gHTLbeRepHs1RpSCLoQ==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/5.7.1/plugins/link/plugin.min.js" integrity="sha512-itGgetRaXe7QX3rkrGYJyUR6heF0LMLMU97a5lpiVRlPESh0xbMkD+7L+ScFuiQf+Wg1PEeKmvmABXvMOUVuxw==" crossorigin="anonymous"></script>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
    <body>
        <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
             Launch demo modal
        </button>
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <textarea></textarea>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
        <script>
        tinymce.init({
                selector: 'textarea',
                menubar: false,
                height: '400',
                plugins: 'link',
                toolbar: 'link'
        });
        </script>
    </body>

You may tell me to do this: https://www.tiny.cloud/docs/integrations/bootstrap/
I already tried this solution, I did some tests and it only fix the problem up to Bootstrap V4.7.
I really hope you'll be able to help me, see you :)

解决方案

Because of changes to Bootstrap 5, as OP mentions, the current fix on Tiny's documentation site (see here) does not work for Bootstrap 5 (At the time of posting, I can confirm that Tiny's documentation team is aware of this, and has an open task to address it in an upcoming docs update.)

Here is a workaround for this issue that:

  1. Works in Bootstrap 5
  2. Doesn't require jQuery
  3. ...doesn't work in IE11.

document.addEventListener('focusin', function (e) { 
  if (e.target.closest('.tox-tinymce-aux, .moxman-window, .tam-assetmanager-root') !== null) { 
    e.stopImmediatePropagation();
  } 
});

Here is a Tiny Fiddle demonstration: https://fiddle.tiny.cloud/R8haab

这篇关于TinyMCE 在 Bootstrap 5 模式中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆