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