CKEditor 3.x - Dynamically add UI elements to plugin dialog

安稳与你 提交于 2019-12-22 08:56:03

问题


I'm building a CKEditor 3.x plug-in that allows certain sections of HTML to be conditionally displayed by a separate viewer application that is tied in to our back-end systems. My CKEditor plug-in will be used to define these conditions, but I'm getting stuck on how to dynamically add UI elements to the plug-in dialog.

After I select the 'AND' option in the last select UI element (see the screenshot), I want to dynamically add another 3 select UI elements, similiar to the first 3 select's.

I've trawled through this forum and the plug-in tutorials and I haven't been able to figure it out. All the examples I looked at only have static dialog definitions. Any help with this would be appreciated.


回答1:


You can add an iFrame with an external page that you can customize using a set of usual and easier tools like jQuery (javascript) and your server-side programming language. In some cases you would like to make sure that the iFrame's content will not be cached by appending some random text in the query string. Then iframe page can communicate with the dialog by calling parent.*




回答2:


Currently I'm working with CKEditor, too. Though our problem is not exactly alike, my approach is to use a component in the plugin dialog that contains a div. Then, in onShow, I will load a certain page to the div.

I find it easier since I can manipulate that certain page more freely (like dynamically add UI element).

But there is a problem with this approach. CKEditor never deletes its dialog divs. So if after browsing other pages and then going back to the editor page, a click on the plugin button will duplicate dialog div (which contain the page in which I do my manipulation).

I'm still looking for the solution or perhaps another way to do this. I'll try to update my answer if I've got something.




回答3:


As Denis Volovik mentioned, this can be achieved using an Iframe with an external page. This is exactly what I did a while ago to resolve my issue. Apologies for only posting it now, but here is some skeleton code of how I accomplished this:

function iframeDialog(editor) {
    return {
         title : 'someTitle',
         minWidth : 820,
         minHeight : 100,
         maxHeight: 200,
         contents :
               [
                  {
                     id : 'someTab',
                     label : '',
                     expand : true,
                     elements :
                           [
                              {
                                 id : 'myIframe',
                                 type : 'iframe',
                                 src : 'my_dialog_contents.html',
                                 width : '100%',
                                 height : 200,
                                 onContentLoad : function() {
                                        //...

                                    var iframe = document.getElementById(this._.frameId);
                                    iframeWindow = iframe.contentWindow;
                                    // can now call methods in the iframe window
                                 }
                              }
                           ]
                  }
               ],
         onShow : function() {
            // check if should display dialog, do dialog.hide if not
         },    
         onOk : function()
         {          
            var myIframe = this.getContentElement('someTab', 'myIframe');
            var iframeWindow = document.getElementById(myIframe.domId).contentWindow;
            var iframeDocument = iframeWindow.document;         

                        // can now interrogate values in the iframe, call javascript methods

                        // can also call editor methods, e.g. editor.focus(), editor.getSelection(),
        }        
    };
}

CKEDITOR.dialog.add( 'mydialog', function( editor )
{
    return iframeDialog(iframeDialog);
} );


来源:https://stackoverflow.com/questions/4510360/ckeditor-3-x-dynamically-add-ui-elements-to-plugin-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!