JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.3
[ckeditor.git] / _samples / api_dialog.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
2 <!--\r
3 Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.\r
4 For licensing, see LICENSE.html or http://ckeditor.com/license\r
5 -->\r
6 <html xmlns="http://www.w3.org/1999/xhtml">\r
7 <head>\r
8         <title>Using API to Customize Dialog Windows &mdash; CKEditor Sample</title>\r
9         <meta content="text/html; charset=utf-8" http-equiv="content-type" />\r
10         <script type="text/javascript" src="../ckeditor.js"></script>\r
11         <script src="sample.js" type="text/javascript"></script>\r
12         <link href="sample.css" rel="stylesheet" type="text/css" />\r
13         <style id="styles" type="text/css">\r
14 \r
15                 .cke_button_myDialogCmd .cke_icon\r
16                 {\r
17                         display: none !important;\r
18                 }\r
19 \r
20                 .cke_button_myDialogCmd .cke_label\r
21                 {\r
22                         display: inline !important;\r
23                 }\r
24 \r
25         </style>\r
26         <script type="text/javascript">\r
27         //<![CDATA[\r
28 \r
29 // When opening a dialog, its "definition" is created for it, for\r
30 // each editor instance. The "dialogDefinition" event is then\r
31 // fired. We should use this event to make customizations to the\r
32 // definition of existing dialogs.\r
33 CKEDITOR.on( 'dialogDefinition', function( ev )\r
34         {\r
35                 // Take the dialog name and its definition from the event\r
36                 // data.\r
37                 var dialogName = ev.data.name;\r
38                 var dialogDefinition = ev.data.definition;\r
39 \r
40                 // Check if the definition is from the dialog we're\r
41                 // interested on (the "Link" dialog).\r
42                 if ( dialogName == 'link' )\r
43                 {\r
44                         // Get a reference to the "Link Info" tab.\r
45                         var infoTab = dialogDefinition.getContents( 'info' );\r
46 \r
47                         // Add a text field to the "info" tab.\r
48                         infoTab.add( {\r
49                                         type : 'text',\r
50                                         label : 'My Custom Field',\r
51                                         id : 'customField',\r
52                                         'default' : 'Sample!',\r
53                                         validate : function()\r
54                                         {\r
55                                                 if ( /\d/.test( this.getValue() ) )\r
56                                                         return 'My Custom Field must not contain digits';\r
57                                         }\r
58                                 });\r
59 \r
60                         // Remove the "Link Type" combo and the "Browser\r
61                         // Server" button from the "info" tab.\r
62                         infoTab.remove( 'linkType' );\r
63                         infoTab.remove( 'browse' );\r
64 \r
65                         // Set the default value for the URL field.\r
66                         var urlField = infoTab.get( 'url' );\r
67                         urlField['default'] = 'www.example.com';\r
68 \r
69                         // Remove the "Target" tab from the "Link" dialog.\r
70                         dialogDefinition.removeContents( 'target' );\r
71 \r
72                         // Add a new tab to the "Link" dialog.\r
73                         dialogDefinition.addContents({\r
74                                 id : 'customTab',\r
75                                 label : 'My Tab',\r
76                                 accessKey : 'M',\r
77                                 elements : [\r
78                                         {\r
79                                                 id : 'myField1',\r
80                                                 type : 'text',\r
81                                                 label : 'My Text Field'\r
82                                         },\r
83                                         {\r
84                                                 id : 'myField2',\r
85                                                 type : 'text',\r
86                                                 label : 'Another Text Field'\r
87                                         }\r
88                                 ]\r
89                         });\r
90 \r
91                         // Rewrite the 'onFocus' handler to always focus 'url' field.\r
92                         dialogDefinition.onFocus = function()\r
93                         {\r
94                                 var urlField = this.getContentElement( 'info', 'url' );\r
95                                 urlField.select();\r
96                         };\r
97                 }\r
98         });\r
99 \r
100         //]]>\r
101         </script>\r
102 \r
103 </head>\r
104 <body>\r
105         <h1 class="samples">\r
106                 CKEditor Sample &mdash; Using CKEditor Dialog API\r
107         </h1>\r
108         <div class="description">\r
109         <p>\r
110                 This sample shows how to use the\r
111                 <a class="samples" href="http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.dialog.html">CKEditor Dialog API</a>\r
112                 to customize CKEditor dialog windows without changing the original editor code.\r
113                 The following customizations are being done in the example below:\r
114         </p>\r
115         <ol>\r
116                 <li><strong>Adding dialog window tabs</strong> &ndash; "My Tab" in the "Link" dialog window.</li>\r
117                 <li><strong>Removing a dialog window tab</strong> &ndash; "Target" tab from the "Link" dialog window.</li>\r
118                 <li><strong>Adding dialog window fields</strong> &ndash; "My Custom Field" in the "Link" dialog window.</li>\r
119                 <li><strong>Removing dialog window fields</strong> &ndash; "Link Type" and "Browse Server" in the "Link"\r
120                         dialog window.</li>\r
121                 <li><strong>Setting default values for dialog window fields</strong> &ndash; "URL" field in the\r
122                         "Link" dialog window. </li>\r
123                 <li><strong>Creating a custom dialog window</strong> &ndash; "My Dialog" dialog window opened with the "My Dialog" toolbar button.</li>\r
124         </ol>\r
125         <p>\r
126 For details on how to create this setup check the source code of this sample page.\r
127         </p>\r
128         </div>\r
129 \r
130 \r
131         <!-- This <div> holds alert messages to be display in the sample page. -->\r
132         <div id="alerts">\r
133                 <noscript>\r
134                         <p>\r
135                                 <strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript\r
136                                 support, like yours, you should still see the contents (HTML data) and you should\r
137                                 be able to edit it normally, without a rich editor interface.\r
138                         </p>\r
139                 </noscript>\r
140         </div>\r
141         <!-- This <fieldset> holds the HTML that you will usually find in your\r
142              pages. -->\r
143         <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="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea>\r
144         <script type="text/javascript">\r
145                 //<![CDATA[\r
146                         // Replace the <textarea id="editor1"> with an CKEditor instance.\r
147                         var editor = CKEDITOR.replace( 'editor1',\r
148                                 {\r
149                                         // Defines a simpler toolbar to be used in this sample.\r
150                                         // Note that we have added out "MyButton" button here.\r
151                                         toolbar : [ [ 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike','-','Link', '-', 'MyButton' ] ]\r
152                                 });\r
153 \r
154                         // Listen for the "pluginsLoaded" event, so we are sure that the\r
155                         // "dialog" plugin has been loaded and we are able to do our\r
156                         // customizations.\r
157                         editor.on( 'pluginsLoaded', function( ev )\r
158                                 {\r
159                                         // If our custom dialog has not been registered, do that now.\r
160                                         if ( !CKEDITOR.dialog.exists( 'myDialog' ) )\r
161                                         {\r
162                                                 // We need to do the following trick to find out the dialog\r
163                                                 // definition file URL path. In the real world, you would simply\r
164                                                 // point to an absolute path directly, like "/mydir/mydialog.js".\r
165                                                 var href = document.location.href.split( '/' );\r
166                                                 href.pop();\r
167                                                 href.push( 'api_dialog', 'my_dialog.js' );\r
168                                                 href = href.join( '/' );\r
169 \r
170                                                 // Finally, register the dialog.\r
171                                                 CKEDITOR.dialog.add( 'myDialog', href );\r
172                                         }\r
173 \r
174                                         // Register the command used to open the dialog.\r
175                                         editor.addCommand( 'myDialogCmd', new CKEDITOR.dialogCommand( 'myDialog' ) );\r
176 \r
177                                         // Add the a custom toolbar buttons, which fires the above\r
178                                         // command..\r
179                                         editor.ui.addButton( 'MyButton',\r
180                                                 {\r
181                                                         label : 'My Dialog',\r
182                                                         command : 'myDialogCmd'\r
183                                                 } );\r
184                                 });\r
185                 //]]>\r
186         </script>\r
187         <div id="footer">\r
188                 <hr />\r
189                 <p>\r
190                         CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>\r
191                 </p>\r
192                 <p id="copy">\r
193                         Copyright &copy; 2003-2012, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico\r
194                         Knabben. All rights reserved.\r
195                 </p>\r
196         </div>\r
197 </body>\r
198 </html>\r