| <!DOCTYPE html> |
| |
| |
| |
| |
| <html lang="en"> |
| <head> |
| <meta charset="utf-8"> |
| <title>Using API to Customize Dialog Windows — 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; |
| |
| |
| |
| |
| editor.on( 'pluginsLoaded', function() { |
| |
| |
| if ( !CKEDITOR.dialog.exists( 'myDialog' ) ) { |
| |
| |
| |
| var href = document.location.href.split( '/' ); |
| href.pop(); |
| href.push( 'assets/my_dialog.js' ); |
| href = href.join( '/' ); |
| |
| |
| CKEDITOR.dialog.add( 'myDialog', href ); |
| } |
| |
| |
| editor.addCommand( 'myDialogCmd', new CKEDITOR.dialogCommand( 'myDialog' ) ); |
| |
| |
| |
| editor.ui.add( 'MyButton', CKEDITOR.UI_BUTTON, { |
| label: 'My Dialog', |
| command: 'myDialogCmd' |
| }); |
| }); |
| }); |
| |
| |
| |
| |
| |
| CKEDITOR.on( 'dialogDefinition', function( ev ) { |
| |
| var dialogName = ev.data.name; |
| var dialogDefinition = ev.data.definition; |
| |
| |
| |
| if ( dialogName == 'myDialog' && ev.editor.name == 'editor2' ) { |
| |
| var infoTab = dialogDefinition.getContents( 'tab1' ); |
| |
| |
| 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'; |
| } |
| }); |
| |
| |
| infoTab.remove( 'select1' ); |
| |
| |
| var input1 = infoTab.get( 'input1' ); |
| input1[ 'default' ] = 'www.example.com'; |
| |
| |
| dialogDefinition.removeContents( 'tab2' ); |
| |
| |
| 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' |
| } |
| ] |
| }); |
| |
| |
| 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> » 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> – "My Dialog" dialog window opened with the "My Dialog" toolbar button.</li> |
| <li><strong>Creating a custom button</strong> – Add button to open the dialog with "My Dialog" toolbar button.</li> |
| </ol> |
| <textarea cols="80" id="editor1" name="editor1" rows="10"><p>This is some <strong>sample text</strong>. You are using <a href="https://ckeditor.com/">CKEditor</a>.</p></textarea> |
| <script> |
| |
| 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> – Add new tab "My Tab" to dialog window.</li> |
| <li><strong>Removing a dialog window tab</strong> – Remove "Second Tab" page from the dialog window.</li> |
| <li><strong>Adding dialog window fields</strong> – Add "My Custom Field" to the dialog window.</li> |
| <li><strong>Removing dialog window field</strong> – Remove "Select Field" selection field from the dialog window.</li> |
| <li><strong>Setting default values for dialog window fields</strong> – Set default value of "Text Field" text field. </li> |
| <li><strong>Setup initial focus for dialog window</strong> – Put initial focus on "My Custom Field" text field. </li> |
| </ol> |
| <textarea cols="80" id="editor2" name="editor2" rows="10"><p>This is some <strong>sample text</strong>. You are using <a href="https://ckeditor.com/">CKEditor</a>.</p></textarea> |
| <script> |
| |
| |
| 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 © 2003-2021, <a class="samples" href="https://cksource.com/">CKSource</a> - Frederico |
| Knabben. All rights reserved. |
| </p> |
| </div> |
| </body> |
| </html> |
|
|