+++ /dev/null
-<!DOCTYPE html>\r
-<!--\r
-Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.\r
-For licensing, see LICENSE.md or http://ckeditor.com/license\r
--->\r
-<html>\r
-<head>\r
- <title>Using API to Customize Dialog Windows — CKEditor Sample</title>\r
- <meta charset="utf-8">\r
- <script src="../../../ckeditor.js"></script>\r
- <link rel="stylesheet" href="../../../samples/sample.css">\r
- <meta name="ckeditor-sample-name" content="Using the JavaScript API to customize dialog windows">\r
- <meta name="ckeditor-sample-group" content="Advanced Samples">\r
- <meta name="ckeditor-sample-description" content="Using the dialog windows API to customize dialog windows without changing the original editor code.">\r
- <style>\r
-\r
- .cke_button__mybutton_icon\r
- {\r
- display: none !important;\r
- }\r
-\r
- .cke_button__mybutton_label\r
- {\r
- display: inline !important;\r
- }\r
-\r
- </style>\r
- <script>\r
-\r
- CKEDITOR.on( 'instanceCreated', function( ev ){\r
- var editor = ev.editor;\r
-\r
- // Listen for the "pluginsLoaded" event, so we are sure that the\r
- // "dialog" plugin has been loaded and we are able to do our\r
- // customizations.\r
- editor.on( 'pluginsLoaded', function() {\r
-\r
- // If our custom dialog has not been registered, do that now.\r
- if ( !CKEDITOR.dialog.exists( 'myDialog' ) ) {\r
- // We need to do the following trick to find out the dialog\r
- // definition file URL path. In the real world, you would simply\r
- // point to an absolute path directly, like "/mydir/mydialog.js".\r
- var href = document.location.href.split( '/' );\r
- href.pop();\r
- href.push( 'assets/my_dialog.js' );\r
- href = href.join( '/' );\r
-\r
- // Finally, register the dialog.\r
- CKEDITOR.dialog.add( 'myDialog', href );\r
- }\r
-\r
- // Register the command used to open the dialog.\r
- editor.addCommand( 'myDialogCmd', new CKEDITOR.dialogCommand( 'myDialog' ) );\r
-\r
- // Add the a custom toolbar buttons, which fires the above\r
- // command..\r
- editor.ui.add( 'MyButton', CKEDITOR.UI_BUTTON, {\r
- label: 'My Dialog',\r
- command: 'myDialogCmd'\r
- });\r
- });\r
- });\r
-\r
- // When opening a dialog, its "definition" is created for it, for\r
- // each editor instance. The "dialogDefinition" event is then\r
- // fired. We should use this event to make customizations to the\r
- // definition of existing dialogs.\r
- CKEDITOR.on( 'dialogDefinition', function( ev ) {\r
- // Take the dialog name and its definition from the event data.\r
- var dialogName = ev.data.name;\r
- var dialogDefinition = ev.data.definition;\r
-\r
- // Check if the definition is from the dialog we're\r
- // interested on (the "Link" dialog).\r
- if ( dialogName == 'myDialog' && ev.editor.name == 'editor2' ) {\r
- // Get a reference to the "Link Info" tab.\r
- var infoTab = dialogDefinition.getContents( 'tab1' );\r
-\r
- // Add a new text field to the "tab1" tab page.\r
- infoTab.add( {\r
- type: 'text',\r
- label: 'My Custom Field',\r
- id: 'customField',\r
- 'default': 'Sample!',\r
- validate: function() {\r
- if ( ( /\d/ ).test( this.getValue() ) )\r
- return 'My Custom Field must not contain digits';\r
- }\r
- });\r
-\r
- // Remove the "select1" field from the "tab1" tab.\r
- infoTab.remove( 'select1' );\r
-\r
- // Set the default value for "input1" field.\r
- var input1 = infoTab.get( 'input1' );\r
- input1[ 'default' ] = 'www.example.com';\r
-\r
- // Remove the "tab2" tab page.\r
- dialogDefinition.removeContents( 'tab2' );\r
-\r
- // Add a new tab to the "Link" dialog.\r
- dialogDefinition.addContents( {\r
- id: 'customTab',\r
- label: 'My Tab',\r
- accessKey: 'M',\r
- elements: [\r
- {\r
- id: 'myField1',\r
- type: 'text',\r
- label: 'My Text Field'\r
- },\r
- {\r
- id: 'myField2',\r
- type: 'text',\r
- label: 'Another Text Field'\r
- }\r
- ]\r
- });\r
-\r
- // Provide the focus handler to start initial focus in "customField" field.\r
- dialogDefinition.onFocus = function() {\r
- var urlField = this.getContentElement( 'tab1', 'customField' );\r
- urlField.select();\r
- };\r
- }\r
- });\r
-\r
- var config = {\r
- extraPlugins: 'dialog',\r
- toolbar: [ [ 'MyButton' ] ]\r
- };\r
-\r
- </script>\r
-</head>\r
-<body>\r
- <h1 class="samples">\r
- <a href="../../../samples/index.html">CKEditor Samples</a> » Using CKEditor Dialog API\r
- </h1>\r
- <div class="description">\r
- <p>\r
- This sample shows how to use the\r
- <a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.dialog">CKEditor Dialog API</a>\r
- to customize CKEditor dialog windows without changing the original editor code.\r
- The following customizations are being done in the example below:\r
- </p>\r
- <p>\r
- For details on how to create this setup check the source code of this sample page.\r
- </p>\r
- </div>\r
- <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>\r
- <ol>\r
- <li><strong>Creating a custom dialog window</strong> – "My Dialog" dialog window opened with the "My Dialog" toolbar button.</li>\r
- <li><strong>Creating a custom button</strong> – Add button to open the dialog with "My Dialog" toolbar button.</li>\r
- </ol>\r
- <textarea cols="80" id="editor1" name="editor1" rows="10"><p>This is some <strong>sample text</strong>. You are using <a href="http://ckeditor.com/">CKEditor</a>.</p></textarea>\r
- <script>\r
- // Replace the <textarea id="editor1"> with an CKEditor instance.\r
- CKEDITOR.replace( 'editor1', config );\r
- </script>\r
- <p>The below editor modify the dialog definition of the above added dialog using the <code>dialogDefinition</code> event:</p>\r
- <ol>\r
- <li><strong>Adding dialog tab</strong> – Add new tab "My Tab" to dialog window.</li>\r
- <li><strong>Removing a dialog window tab</strong> – Remove "Second Tab" page from the dialog window.</li>\r
- <li><strong>Adding dialog window fields</strong> – Add "My Custom Field" to the dialog window.</li>\r
- <li><strong>Removing dialog window field</strong> – Remove "Select Field" selection field from the dialog window.</li>\r
- <li><strong>Setting default values for dialog window fields</strong> – Set default value of "Text Field" text field. </li>\r
- <li><strong>Setup initial focus for dialog window</strong> – Put initial focus on "My Custom Field" text field. </li>\r
- </ol>\r
- <textarea cols="80" id="editor2" name="editor2" rows="10"><p>This is some <strong>sample text</strong>. You are using <a href="http://ckeditor.com/">CKEditor</a>.</p></textarea>\r
- <script>\r
-\r
- // Replace the <textarea id="editor1"> with an CKEditor instance.\r
- CKEDITOR.replace( 'editor2', config );\r
-\r
- </script>\r
- <div id="footer">\r
- <hr>\r
- <p>\r
- CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>\r
- </p>\r
- <p id="copy">\r
- Copyright © 2003-2013, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico\r
- Knabben. All rights reserved.\r
- </p>\r
- </div>\r
-</body>\r
-</html>\r