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