如何在 CKEditor 中更改已注册的对话框

2024-04-24

我正在尝试编写一个插件,向图像对话框添加一个附加选项卡(页面)。我不想更改对话框的源本身,而是使用插件来增强它。

我搜索文档和论坛已经有一段时间了,现在我知道我可以在对话框对象上调用“addPage”来添加另一个选项卡。我也了解内容对象必须是什么样子。 但我未能找到如何获取已存在对话框的对话框对象的方法。

我尝试了一个

var ImageDialog = new CKEDITOR.dialog( editor, 'image' );

在插件的 init 方法中,但这导致了 JS 错误“R 不是函数”...

有人可以帮我吗?

提前致谢, 马克


I found 这个链接 https://github.com/ckeditor/ckeditor4/blob/master/plugins/dialog/samples/dialog.html在阿方索的回答中的一条评论中,它对我起了作用。

由于链接变坏,尤其是在这些年之后,以下是链接页面的代码:

<!DOCTYPE html>
<!--
Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
-->
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Using API to Customize Dialog Windows &mdash; CKEditor Sample</title>
    <script src="../../../ckeditor.js"></script>
    <link rel="stylesheet" href="../../../samples/old/sample.css">
    <meta name="ckeditor-sample-name" content="Using the JavaScript API to customize dialog windows">
    <meta name="ckeditor-sample-group" content="Advanced Samples">
    <meta name="ckeditor-sample-description" content="Using the dialog windows API to customize dialog windows without changing the original editor code.">
    <meta name="description" content="Try the latest sample of CKEditor 4 and learn more about customizing your WYSIWYG editor with endless possibilities.">
    <style>

        .cke_button__mybutton_icon
        {
            display: none !important;
        }

        .cke_button__mybutton_label
        {
            display: inline !important;
        }

    </style>
    <script>

        CKEDITOR.on( 'instanceCreated', function( ev ){
            var editor = ev.editor;

            // Listen for the "pluginsLoaded" event, so we are sure that the
            // "dialog" plugin has been loaded and we are able to do our
            // customizations.
            editor.on( 'pluginsLoaded', function() {

                // If our custom dialog has not been registered, do that now.
                if ( !CKEDITOR.dialog.exists( 'myDialog' ) ) {
                    // We need to do the following trick to find out the dialog
                    // definition file URL path. In the real world, you would simply
                    // point to an absolute path directly, like "/mydir/mydialog.js".
                    var href = document.location.href.split( '/' );
                    href.pop();
                    href.push( 'assets/my_dialog.js' );
                    href = href.join( '/' );

                    // Finally, register the dialog.
                    CKEDITOR.dialog.add( 'myDialog', href );
                }

                // Register the command used to open the dialog.
                editor.addCommand( 'myDialogCmd', new CKEDITOR.dialogCommand( 'myDialog' ) );

                // Add the a custom toolbar buttons, which fires the above
                // command..
                editor.ui.add( 'MyButton', CKEDITOR.UI_BUTTON, {
                    label: 'My Dialog',
                    command: 'myDialogCmd'
                });
            });
        });

        // When opening a dialog, its "definition" is created for it, for
        // each editor instance. The "dialogDefinition" event is then
        // fired. We should use this event to make customizations to the
        // definition of existing dialogs.
        CKEDITOR.on( 'dialogDefinition', function( ev ) {
            // Take the dialog name and its definition from the event data.
            var dialogName = ev.data.name;
            var dialogDefinition = ev.data.definition;

            // Check if the definition is from the dialog we're
            // interested on (the "Link" dialog).
            if ( dialogName == 'myDialog' && ev.editor.name == 'editor2' ) {
                // Get a reference to the "Link Info" tab.
                var infoTab = dialogDefinition.getContents( 'tab1' );

                // Add a new text field to the "tab1" tab page.
                infoTab.add( {
                    type: 'text',
                    label: 'My Custom Field',
                    id: 'customField',
                    'default': 'Sample!',
                    validate: function() {
                        if ( ( /\d/ ).test( this.getValue() ) )
                            return 'My Custom Field must not contain digits';
                    }
                });

                // Remove the "select1" field from the "tab1" tab.
                infoTab.remove( 'select1' );

                // Set the default value for "input1" field.
                var input1 = infoTab.get( 'input1' );
                input1[ 'default' ] = 'www.example.com';

                // Remove the "tab2" tab page.
                dialogDefinition.removeContents( 'tab2' );

                // Add a new tab to the "Link" dialog.
                dialogDefinition.addContents( {
                    id: 'customTab',
                    label: 'My Tab',
                    accessKey: 'M',
                    elements: [
                        {
                            id: 'myField1',
                            type: 'text',
                            label: 'My Text Field'
                        },
                        {
                            id: 'myField2',
                            type: 'text',
                            label: 'Another Text Field'
                        }
                    ]
                });

                // Provide the focus handler to start initial focus in "customField" field.
                dialogDefinition.onFocus = function() {
                    var urlField = this.getContentElement( 'tab1', 'customField' );
                    urlField.select();
                };
            }
        });

        var config = {
            extraPlugins: 'dialog',
            toolbar: [ [ 'MyButton' ] ]
        };

    </script>
</head>
<body>
    <h1 class="samples">
        <a href="../../../samples/old/index.html">CKEditor Samples</a> &raquo; Using CKEditor Dialog API
    </h1>
    <div class="warning deprecated">
        This sample is not maintained anymore. Check out the <a href="https://ckeditor.com/docs/ckeditor4/latest/examples/index.html">brand new samples in CKEditor Examples</a>.
    </div>
    <div class="description">
        <p>
            This sample shows how to use the
            <a class="samples" href="https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_dialog.html">CKEditor Dialog API</a>
            to customize CKEditor dialog windows without changing the original editor code.
            The following customizations are being done in the example below:
        </p>
        <p>
            For details on how to create this setup check the source code of this sample page.
        </p>
    </div>
    <p>A custom dialog is added to the editors using the <code>pluginsLoaded</code> event, from an external <a target="_blank" href="assets/my_dialog.js">dialog definition file</a>:</p>
    <ol>
        <li><strong>Creating a custom dialog window</strong> &ndash; "My Dialog" dialog window opened with the "My Dialog" toolbar button.</li>
        <li><strong>Creating a custom button</strong> &ndash; Add button to open the dialog with "My Dialog" toolbar button.</li>
    </ol>
    <textarea cols="80" id="editor1" name="editor1" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="https://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea>
    <script>
        // Replace the <textarea id="editor1"> with an CKEditor instance.
        CKEDITOR.replace( 'editor1', config );
    </script>
    <p>The below editor modify the dialog definition of the above added dialog using the <code>dialogDefinition</code> event:</p>
    <ol>
        <li><strong>Adding dialog tab</strong> &ndash; Add new tab "My Tab" to dialog window.</li>
        <li><strong>Removing a dialog window tab</strong> &ndash; Remove "Second Tab" page from the dialog window.</li>
        <li><strong>Adding dialog window fields</strong> &ndash; Add "My Custom Field" to the dialog window.</li>
        <li><strong>Removing dialog window field</strong> &ndash; Remove "Select Field" selection field from the dialog window.</li>
        <li><strong>Setting default values for dialog window fields</strong> &ndash; Set default value of "Text Field" text field. </li>
        <li><strong>Setup initial focus for dialog window</strong> &ndash; Put initial focus on "My Custom Field" text field. </li>
    </ol>
    <textarea cols="80" id="editor2" name="editor2" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="https://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea>
    <script>

        // Replace the <textarea id="editor1"> with an CKEditor instance.
        CKEDITOR.replace( 'editor2', config );

    </script>
    <div id="footer">
        <hr>
        <p>
            CKEditor - The text editor for the Internet - <a class="samples" href="https://ckeditor.com/">https://ckeditor.com</a>
        </p>
        <p id="copy">
            Copyright &copy; 2003-2022, <a class="samples" href="https://cksource.com/">CKSource</a> Holding sp. z o.o. All rights reserved.
        </p>
    </div>
</body>
</html>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 CKEditor 中更改已注册的对话框 的相关文章

随机推荐

  • 错误:$compile:tpload 无法加载模板 Http 状态:404

    当我尝试使用 Angular 运行本地项目时 我从 Chrome 收到 404 状态 我不确定问题出在哪里 并且我已经尝试过类似问题的建议答案 这是我的指令文件 use strict ngdoc directive name stockDo
  • cmake:在 CMakeLists.txt 中选择生成器

    我想强制CMake使用 Unix Makefiles 发电机来自 CMakeLists txt 中 这是我现在使用的命令 cmake G Unix Makefiles 我希望是这样的 cmake 当在安装了 VC 和自定义工具链的 Wind
  • 在引导响应页面中如何将 div 居中

    我需要使用 bootstrap 将 div 放置在页面的中心来创建响应式页面 如下面提到的布局所示 Bootstrap 5 更新 使用弹性盒进行简单的垂直网格对齐 import url https cdnjs cloudflare com
  • 如何在 shell 函数中获得“set -e”的效果和用处?

    set e 或以 bin sh e 对于出现问题时自动轰炸非常有用 它使我不必对每个可能失败的命令进行错误检查 如何在函数内获得与此等效的内容 例如 我有以下脚本 该脚本在出现错误时立即退出 并显示错误退出状态 bin sh e echo
  • 根据内部数组中的值对外部数组进行排序,javascript

    我有一个包含数组的数组 我想根据内部特定列中的值对外部数组进行排序 我敢打赌这听起来有点令人困惑 所以我将直接跳到一个例子 初始数据 var data row 1 col1 2 row 1 col2 c row 1 coln row 2 c
  • 分析跟踪新 Web+App 中的自定义事件

    我曾经使用以下命令跟踪自定义事件 API 命中 google analytics and PHP via cURL 但现在分析正在弃用这种方法 我知道新的分析 Web App 用于跟踪此类事件 但我找不到任何可以让我跟踪这些事件的东西 我当
  • React Native项目没有index.ios.js或index.android.js

    你好 我是 React Native 的新手 我按照下面的链接构建了我的第一个项目 但发现没有 index ios js 或 index android js 可供我编辑 https facebook github io react nat
  • 如何在gnuplot中绘制带有彩色边框的矩形

    我想在我的图中画一个空矩形 到目前为止我有 set style rect back fs empty border lt 3 set object 1 rect from 1 1 to 2 2 我有一个带有虚线的矩形 如何更改线条的颜色 l
  • F# 中的异步 EF 查询

    在使用 EF6 的 C 中 我可以轻松地进行如下异步操作 using var context new MyDbContext var item await context SomeEntities Where e gt e Id 1 Fir
  • 如何在窗口窗体中制作圆形标签?

    众所周知 标签通常是正方形或长方形 我真的需要制作圆形标签 谁能告诉我这是否可能 或者至少为我指出正确的方向 抱歉 只是为了把事情说清楚 我想要一个圆形标签 不仅仅是在屏幕上画一个圆圈 您可以设置 Label 的 Region 属性 var
  • 在 CentOS 6.4 中意外删除了符号链接 libc.so.6。如何获得 sudo 权限来重新创建它?

    我不小心删除了符号链接 lib64 libc so 6 gt lib64 libc 2 12 so sudo rm libc so 6 然后我不能使用任何东西 包括ls命令 我输入的任何命令都会出现错误 ls error while loa
  • 如何使用 USPS 验证给定地址?

    我想向 USPS 验证给定的地址 地址 城市 州 邮政编码 如果提供的地址是有效地址 则返回结果 如果不是有效地址 则返回无效地址 那么我怎样才能在 C Net 中做到这一点呢 美国邮政服务 USPS 通过其地址信息 API 提供此服务 U
  • 扁平按钮与凸起按钮

    我想知道之间的基本区别Flat button and Raised Button 根据新Android材料设计指南 我想使用凸起按钮 但我不知道它们是什么 网络上有一些论坛显示一个凸起的按钮 但他们称之为 扁平 谁能告诉我两者之间的基本区别
  • Android 找不到类异常

    我正在使用两个单独的类 其中一个有一些按钮 另一个打开谷歌地图 我正在其上进行覆盖 如果有人能看到我打开 Map class 的意图的问题 请告诉我 我将输入我的错误消息和代码 package com state park import j
  • ORM 是用于迁移数据的正确工具吗?

    背景 我们正在升级旧版导入工具 它的作用是将数据从连接到 SQL Server 的一个数据库移动到同一服务器上的第二个数据库 并使用不同的模式沿途执行转换和映射 这是一个帮助解释正在发生的事情的示例 假设源数据库有一张表名为Client I
  • Java - 点在线

    我如何找出点 x y 是否位于其他两个点之间创建的线上 我尝试了这个 但似乎有些问题 因为我没有得到我应该得到的结果 public boolean intersects Point k Point z Point p Line2D line
  • Jackson 或 JAXB,哪一个更适合 JSON? [关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 我想知道 JSON Jackson 或 JAXB 哪一个更好 我做了一些研究 我知道 也许我错了 我们不应该使用 JAXB 来转换 JSON 某
  • 比较当前月份和上个月的列上的行,SQL Server 2012

    我需要一些指导和帮助来解决我不完全确定如何在 SQL Server 2012 中解决的问题 我认为LAG and LEAD函数可能有用 但我不确定 这就是我的数据现在的样子 YearMonth LocationCode Active 201
  • 是否可以使用文件名模式创建 blob 触发的 azure 函数?

    我正在开发一个 blob 触发的 azure 函数 以下是我的 function json 文件的配置 disabled false bindings name myBlob type blobTrigger direction in pa
  • 如何在 CKEditor 中更改已注册的对话框

    我正在尝试编写一个插件 向图像对话框添加一个附加选项卡 页面 我不想更改对话框的源本身 而是使用插件来增强它 我搜索文档和论坛已经有一段时间了 现在我知道我可以在对话框对象上调用 addPage 来添加另一个选项卡 我也了解内容对象必须是什