【问题标题】:TinyMCE link and code popups in BootstrapBootstrap 中的 TinyMCE 链接和代码弹出窗口
【发布时间】:2020-03-30 12:46:05
【问题描述】:

是否可以让 TinyMCE 弹出窗口进入 Bootstrap 模式?不是实际的编辑器本身,而是链接或代码的弹出窗口。如果是这样,你是怎么做到的?

【问题讨论】:

  • 是的,有可能。
  • 请提供一个最小的、可重现的例子:stackoverflow.com/help/minimal-reproducible-example
  • 如果我有一个例子,我会知道怎么做,哈哈
  • 不确定在这种情况下否决票是否公平。 Tiny MCE 的 api 非常详细,我认为问题类似于:“我从哪里开始?”
  • 我也一直在寻找一种连接弹出窗口的方法,在我的例子中是锚标签,而你如何开始这样做远非显而易见

标签: javascript jquery jquery-ui tinymce tinymce-5


【解决方案1】:

这里我创建了一个例子https://jsbin.com/sevowetifi/1/edit?html,output

textarea 或目标元素放入模态框的.modal-body

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
          <textarea>Next, use our Get Started docs to setup Tiny!</textarea>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
</div>

【讨论】:

    【解决方案2】:

    查看 jsfiddle 以获得完整功能: https://jsfiddle.net/ndxy1pqt/ Stack 的 iframe 沙箱和 TinyMCE 存在问题,因此嵌入式演示不可编辑,但它显示了启动 Bootstrap 模式功能的按钮。

    它基本上只需要添加一个插件,并使用editor.addButton 添加一个启动 Bootstrap 的按钮。您将需要查看有关 Bootstrap 插件的更多详细信息,以执行诸如获取正确坐标以创建嵌入式工具提示等内容之类的操作。我会去看一些带有自定义工具栏的 TinyMCE 插件以了解更多信息。

    tinymce.PluginManager.add('myPlugin', function (editor, url) {
        editor.addButton('launchModal', {
            text: 'My Bootstrap Modal',
            onclick: function () {
                $('#myModal').modal('show');
                $('#modal-button').on('click',function(){
                	editor.setContent('set content');
                  editor.selection.setNode(editor.dom.create('img', {src: 'some.gif', title: 'some title'}));
                });
            }
        });
    });
    tinymce.init({
    	selector: '#text-box',
    	plugins: 'myPlugin',
    	menubar: 'myPlugin',
    	toolbar: "launchModal",
        templates: [
    		{ title: 'Template 1', description: 'Description of template 1', content: '<p>alma</p><p>korte</p>' },
    		{ title: 'Template 2', description: 'Description of template  2', content: 'development.html' }
        ],
        height: 300
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
    <script src="https://cdn.tinymce.com/4/tinymce.min.js"></script>
    
    <body>
        <textarea id="text-box"></textarea>
        
    <div id="myModal" class="modal" tabindex="-1" role="dialog">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title">Modal title</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <button id="modal-button">button
            </button>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-primary">Save changes</button>
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>
    </body>

    【讨论】:

      猜你喜欢
      • 2011-02-15
      • 2020-12-15
      • 1970-01-01
      • 1970-01-01
      • 2012-06-11
      • 1970-01-01
      • 1970-01-01
      • 2018-10-05
      • 2018-11-08
      相关资源
      最近更新 更多