indvd00m@0
|
1 |
<!DOCTYPE html>
|
indvd00m@0
|
2 |
<!--
|
indvd00m@0
|
3 |
Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
|
indvd00m@0
|
4 |
For licensing, see LICENSE.md or http://ckeditor.com/license
|
indvd00m@0
|
5 |
-->
|
indvd00m@0
|
6 |
<html>
|
indvd00m@0
|
7 |
<head>
|
indvd00m@0
|
8 |
<meta charset="utf-8">
|
indvd00m@0
|
9 |
<title>Using API to Customize Dialog Windows — CKEditor Sample</title>
|
indvd00m@0
|
10 |
<script src="../../../ckeditor.js"></script>
|
indvd00m@0
|
11 |
<link rel="stylesheet" href="../../../samples/old/sample.css">
|
indvd00m@0
|
12 |
<meta name="ckeditor-sample-name" content="Using the JavaScript API to customize dialog windows">
|
indvd00m@0
|
13 |
<meta name="ckeditor-sample-group" content="Advanced Samples">
|
indvd00m@0
|
14 |
<meta name="ckeditor-sample-description" content="Using the dialog windows API to customize dialog windows without changing the original editor code.">
|
indvd00m@0
|
15 |
<style>
|
indvd00m@0
|
16 |
|
indvd00m@0
|
17 |
.cke_button__mybutton_icon
|
indvd00m@0
|
18 |
{
|
indvd00m@0
|
19 |
display: none !important;
|
indvd00m@0
|
20 |
}
|
indvd00m@0
|
21 |
|
indvd00m@0
|
22 |
.cke_button__mybutton_label
|
indvd00m@0
|
23 |
{
|
indvd00m@0
|
24 |
display: inline !important;
|
indvd00m@0
|
25 |
}
|
indvd00m@0
|
26 |
|
indvd00m@0
|
27 |
</style>
|
indvd00m@0
|
28 |
<script>
|
indvd00m@0
|
29 |
|
indvd00m@0
|
30 |
CKEDITOR.on( 'instanceCreated', function( ev ){
|
indvd00m@0
|
31 |
var editor = ev.editor;
|
indvd00m@0
|
32 |
|
indvd00m@0
|
33 |
// Listen for the "pluginsLoaded" event, so we are sure that the
|
indvd00m@0
|
34 |
// "dialog" plugin has been loaded and we are able to do our
|
indvd00m@0
|
35 |
// customizations.
|
indvd00m@0
|
36 |
editor.on( 'pluginsLoaded', function() {
|
indvd00m@0
|
37 |
|
indvd00m@0
|
38 |
// If our custom dialog has not been registered, do that now.
|
indvd00m@0
|
39 |
if ( !CKEDITOR.dialog.exists( 'myDialog' ) ) {
|
indvd00m@0
|
40 |
// We need to do the following trick to find out the dialog
|
indvd00m@0
|
41 |
// definition file URL path. In the real world, you would simply
|
indvd00m@0
|
42 |
// point to an absolute path directly, like "/mydir/mydialog.js".
|
indvd00m@0
|
43 |
var href = document.location.href.split( '/' );
|
indvd00m@0
|
44 |
href.pop();
|
indvd00m@0
|
45 |
href.push( 'assets/my_dialog.js' );
|
indvd00m@0
|
46 |
href = href.join( '/' );
|
indvd00m@0
|
47 |
|
indvd00m@0
|
48 |
// Finally, register the dialog.
|
indvd00m@0
|
49 |
CKEDITOR.dialog.add( 'myDialog', href );
|
indvd00m@0
|
50 |
}
|
indvd00m@0
|
51 |
|
indvd00m@0
|
52 |
// Register the command used to open the dialog.
|
indvd00m@0
|
53 |
editor.addCommand( 'myDialogCmd', new CKEDITOR.dialogCommand( 'myDialog' ) );
|
indvd00m@0
|
54 |
|
indvd00m@0
|
55 |
// Add the a custom toolbar buttons, which fires the above
|
indvd00m@0
|
56 |
// command..
|
indvd00m@0
|
57 |
editor.ui.add( 'MyButton', CKEDITOR.UI_BUTTON, {
|
indvd00m@0
|
58 |
label: 'My Dialog',
|
indvd00m@0
|
59 |
command: 'myDialogCmd'
|
indvd00m@0
|
60 |
});
|
indvd00m@0
|
61 |
});
|
indvd00m@0
|
62 |
});
|
indvd00m@0
|
63 |
|
indvd00m@0
|
64 |
// When opening a dialog, its "definition" is created for it, for
|
indvd00m@0
|
65 |
// each editor instance. The "dialogDefinition" event is then
|
indvd00m@0
|
66 |
// fired. We should use this event to make customizations to the
|
indvd00m@0
|
67 |
// definition of existing dialogs.
|
indvd00m@0
|
68 |
CKEDITOR.on( 'dialogDefinition', function( ev ) {
|
indvd00m@0
|
69 |
// Take the dialog name and its definition from the event data.
|
indvd00m@0
|
70 |
var dialogName = ev.data.name;
|
indvd00m@0
|
71 |
var dialogDefinition = ev.data.definition;
|
indvd00m@0
|
72 |
|
indvd00m@0
|
73 |
// Check if the definition is from the dialog we're
|
indvd00m@0
|
74 |
// interested on (the "Link" dialog).
|
indvd00m@0
|
75 |
if ( dialogName == 'myDialog' && ev.editor.name == 'editor2' ) {
|
indvd00m@0
|
76 |
// Get a reference to the "Link Info" tab.
|
indvd00m@0
|
77 |
var infoTab = dialogDefinition.getContents( 'tab1' );
|
indvd00m@0
|
78 |
|
indvd00m@0
|
79 |
// Add a new text field to the "tab1" tab page.
|
indvd00m@0
|
80 |
infoTab.add( {
|
indvd00m@0
|
81 |
type: 'text',
|
indvd00m@0
|
82 |
label: 'My Custom Field',
|
indvd00m@0
|
83 |
id: 'customField',
|
indvd00m@0
|
84 |
'default': 'Sample!',
|
indvd00m@0
|
85 |
validate: function() {
|
indvd00m@0
|
86 |
if ( ( /\d/ ).test( this.getValue() ) )
|
indvd00m@0
|
87 |
return 'My Custom Field must not contain digits';
|
indvd00m@0
|
88 |
}
|
indvd00m@0
|
89 |
});
|
indvd00m@0
|
90 |
|
indvd00m@0
|
91 |
// Remove the "select1" field from the "tab1" tab.
|
indvd00m@0
|
92 |
infoTab.remove( 'select1' );
|
indvd00m@0
|
93 |
|
indvd00m@0
|
94 |
// Set the default value for "input1" field.
|
indvd00m@0
|
95 |
var input1 = infoTab.get( 'input1' );
|
indvd00m@0
|
96 |
input1[ 'default' ] = 'www.example.com';
|
indvd00m@0
|
97 |
|
indvd00m@0
|
98 |
// Remove the "tab2" tab page.
|
indvd00m@0
|
99 |
dialogDefinition.removeContents( 'tab2' );
|
indvd00m@0
|
100 |
|
indvd00m@0
|
101 |
// Add a new tab to the "Link" dialog.
|
indvd00m@0
|
102 |
dialogDefinition.addContents( {
|
indvd00m@0
|
103 |
id: 'customTab',
|
indvd00m@0
|
104 |
label: 'My Tab',
|
indvd00m@0
|
105 |
accessKey: 'M',
|
indvd00m@0
|
106 |
elements: [
|
indvd00m@0
|
107 |
{
|
indvd00m@0
|
108 |
id: 'myField1',
|
indvd00m@0
|
109 |
type: 'text',
|
indvd00m@0
|
110 |
label: 'My Text Field'
|
indvd00m@0
|
111 |
},
|
indvd00m@0
|
112 |
{
|
indvd00m@0
|
113 |
id: 'myField2',
|
indvd00m@0
|
114 |
type: 'text',
|
indvd00m@0
|
115 |
label: 'Another Text Field'
|
indvd00m@0
|
116 |
}
|
indvd00m@0
|
117 |
]
|
indvd00m@0
|
118 |
});
|
indvd00m@0
|
119 |
|
indvd00m@0
|
120 |
// Provide the focus handler to start initial focus in "customField" field.
|
indvd00m@0
|
121 |
dialogDefinition.onFocus = function() {
|
indvd00m@0
|
122 |
var urlField = this.getContentElement( 'tab1', 'customField' );
|
indvd00m@0
|
123 |
urlField.select();
|
indvd00m@0
|
124 |
};
|
indvd00m@0
|
125 |
}
|
indvd00m@0
|
126 |
});
|
indvd00m@0
|
127 |
|
indvd00m@0
|
128 |
var config = {
|
indvd00m@0
|
129 |
extraPlugins: 'dialog',
|
indvd00m@0
|
130 |
toolbar: [ [ 'MyButton' ] ]
|
indvd00m@0
|
131 |
};
|
indvd00m@0
|
132 |
|
indvd00m@0
|
133 |
</script>
|
indvd00m@0
|
134 |
</head>
|
indvd00m@0
|
135 |
<body>
|
indvd00m@0
|
136 |
<h1 class="samples">
|
indvd00m@0
|
137 |
<a href="../../../samples/old/index.html">CKEditor Samples</a> » Using CKEditor Dialog API
|
indvd00m@0
|
138 |
</h1>
|
indvd00m@0
|
139 |
<div class="warning deprecated">
|
indvd00m@0
|
140 |
This sample is not maintained anymore. Check out the <a href="http://sdk.ckeditor.com/">brand new samples in CKEditor SDK</a>.
|
indvd00m@0
|
141 |
</div>
|
indvd00m@0
|
142 |
<div class="description">
|
indvd00m@0
|
143 |
<p>
|
indvd00m@0
|
144 |
This sample shows how to use the
|
indvd00m@0
|
145 |
<a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.dialog">CKEditor Dialog API</a>
|
indvd00m@0
|
146 |
to customize CKEditor dialog windows without changing the original editor code.
|
indvd00m@0
|
147 |
The following customizations are being done in the example below:
|
indvd00m@0
|
148 |
</p>
|
indvd00m@0
|
149 |
<p>
|
indvd00m@0
|
150 |
For details on how to create this setup check the source code of this sample page.
|
indvd00m@0
|
151 |
</p>
|
indvd00m@0
|
152 |
</div>
|
indvd00m@0
|
153 |
<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>
|
indvd00m@0
|
154 |
<ol>
|
indvd00m@0
|
155 |
<li><strong>Creating a custom dialog window</strong> – "My Dialog" dialog window opened with the "My Dialog" toolbar button.</li>
|
indvd00m@0
|
156 |
<li><strong>Creating a custom button</strong> – Add button to open the dialog with "My Dialog" toolbar button.</li>
|
indvd00m@0
|
157 |
</ol>
|
indvd00m@0
|
158 |
<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>
|
indvd00m@0
|
159 |
<script>
|
indvd00m@0
|
160 |
// Replace the <textarea id="editor1"> with an CKEditor instance.
|
indvd00m@0
|
161 |
CKEDITOR.replace( 'editor1', config );
|
indvd00m@0
|
162 |
</script>
|
indvd00m@0
|
163 |
<p>The below editor modify the dialog definition of the above added dialog using the <code>dialogDefinition</code> event:</p>
|
indvd00m@0
|
164 |
<ol>
|
indvd00m@0
|
165 |
<li><strong>Adding dialog tab</strong> – Add new tab "My Tab" to dialog window.</li>
|
indvd00m@0
|
166 |
<li><strong>Removing a dialog window tab</strong> – Remove "Second Tab" page from the dialog window.</li>
|
indvd00m@0
|
167 |
<li><strong>Adding dialog window fields</strong> – Add "My Custom Field" to the dialog window.</li>
|
indvd00m@0
|
168 |
<li><strong>Removing dialog window field</strong> – Remove "Select Field" selection field from the dialog window.</li>
|
indvd00m@0
|
169 |
<li><strong>Setting default values for dialog window fields</strong> – Set default value of "Text Field" text field. </li>
|
indvd00m@0
|
170 |
<li><strong>Setup initial focus for dialog window</strong> – Put initial focus on "My Custom Field" text field. </li>
|
indvd00m@0
|
171 |
</ol>
|
indvd00m@0
|
172 |
<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>
|
indvd00m@0
|
173 |
<script>
|
indvd00m@0
|
174 |
|
indvd00m@0
|
175 |
// Replace the <textarea id="editor1"> with an CKEditor instance.
|
indvd00m@0
|
176 |
CKEDITOR.replace( 'editor2', config );
|
indvd00m@0
|
177 |
|
indvd00m@0
|
178 |
</script>
|
indvd00m@0
|
179 |
<div id="footer">
|
indvd00m@0
|
180 |
<hr>
|
indvd00m@0
|
181 |
<p>
|
indvd00m@0
|
182 |
CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
|
indvd00m@0
|
183 |
</p>
|
indvd00m@0
|
184 |
<p id="copy">
|
indvd00m@0
|
185 |
Copyright © 2003-2016, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
|
indvd00m@0
|
186 |
Knabben. All rights reserved.
|
indvd00m@0
|
187 |
</p>
|
indvd00m@0
|
188 |
</div>
|
indvd00m@0
|
189 |
</body>
|
indvd00m@0
|
190 |
</html>
|