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>Adding Event Handlers — CKEditor Sample</title>
|
danielebarchiesi@0
|
9 <meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
danielebarchiesi@0
|
10 <link href="../sample.css" rel="stylesheet" type="text/css"/>
|
danielebarchiesi@0
|
11 </head>
|
danielebarchiesi@0
|
12 <body>
|
danielebarchiesi@0
|
13 <h1 class="samples">
|
danielebarchiesi@0
|
14 CKEditor Sample — Adding Event Handlers
|
danielebarchiesi@0
|
15 </h1>
|
danielebarchiesi@0
|
16 <div class="description">
|
danielebarchiesi@0
|
17 <p>
|
danielebarchiesi@0
|
18 This sample shows how to add event handlers to CKEditor with PHP.
|
danielebarchiesi@0
|
19 </p>
|
danielebarchiesi@0
|
20 <p>
|
danielebarchiesi@0
|
21 A snippet of the configuration code can be seen below; check the source code of this page for
|
danielebarchiesi@0
|
22 the full definition:
|
danielebarchiesi@0
|
23 </p>
|
danielebarchiesi@0
|
24 <pre class="samples"><?php
|
danielebarchiesi@0
|
25 // Include the CKEditor class.
|
danielebarchiesi@0
|
26 include("ckeditor/ckeditor.php");
|
danielebarchiesi@0
|
27
|
danielebarchiesi@0
|
28 // Create a class instance.
|
danielebarchiesi@0
|
29 $CKEditor = new CKEditor();
|
danielebarchiesi@0
|
30
|
danielebarchiesi@0
|
31 // Path to the CKEditor directory.
|
danielebarchiesi@0
|
32 $CKEditor->basePath = '/ckeditor/';
|
danielebarchiesi@0
|
33
|
danielebarchiesi@0
|
34 // The initial value to be displayed in the editor.
|
danielebarchiesi@0
|
35 $initialValue = 'This is some sample text.';
|
danielebarchiesi@0
|
36
|
danielebarchiesi@0
|
37 // Add event handler, <em>instanceReady</em> is fired when editor is loaded.
|
danielebarchiesi@0
|
38 $CKEditor-><strong>addEventHandler</strong>('instanceReady', 'function (evt) {
|
danielebarchiesi@0
|
39 alert("Loaded editor: " + evt.editor.name);
|
danielebarchiesi@0
|
40 }');
|
danielebarchiesi@0
|
41
|
danielebarchiesi@0
|
42 // Create an editor instance.
|
danielebarchiesi@0
|
43 $CKEditor->editor("editor1", $initialValue);
|
danielebarchiesi@0
|
44 </pre>
|
danielebarchiesi@0
|
45 </div>
|
danielebarchiesi@0
|
46 <!-- This <div> holds alert messages to be display in the sample page. -->
|
danielebarchiesi@0
|
47 <div id="alerts">
|
danielebarchiesi@0
|
48 <noscript>
|
danielebarchiesi@0
|
49 <p>
|
danielebarchiesi@0
|
50 <strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript
|
danielebarchiesi@0
|
51 support, like yours, you should still see the contents (HTML data) and you should
|
danielebarchiesi@0
|
52 be able to edit it normally, without a rich editor interface.
|
danielebarchiesi@0
|
53 </p>
|
danielebarchiesi@0
|
54 </noscript>
|
danielebarchiesi@0
|
55 </div>
|
danielebarchiesi@0
|
56 <form action="../sample_posteddata.php" method="post">
|
danielebarchiesi@0
|
57 <label>Editor 1:</label>
|
danielebarchiesi@0
|
58 <?php
|
danielebarchiesi@0
|
59
|
danielebarchiesi@0
|
60 /**
|
danielebarchiesi@0
|
61 * Adds a global event, will hide the "Target" tab in the "Link" dialog window in all instances.
|
danielebarchiesi@0
|
62 */
|
danielebarchiesi@0
|
63 function CKEditorHideLinkTargetTab(&$CKEditor) {
|
danielebarchiesi@0
|
64
|
danielebarchiesi@0
|
65 $function = 'function (ev) {
|
danielebarchiesi@0
|
66 // Take the dialog window name and its definition from the event data.
|
danielebarchiesi@0
|
67 var dialogName = ev.data.name;
|
danielebarchiesi@0
|
68 var dialogDefinition = ev.data.definition;
|
danielebarchiesi@0
|
69
|
danielebarchiesi@0
|
70 // Check if the definition comes from the "Link" dialog window.
|
danielebarchiesi@0
|
71 if ( dialogName == "link" )
|
danielebarchiesi@0
|
72 dialogDefinition.removeContents("target")
|
danielebarchiesi@0
|
73 }';
|
danielebarchiesi@0
|
74
|
danielebarchiesi@0
|
75 $CKEditor->addGlobalEventHandler('dialogDefinition', $function);
|
danielebarchiesi@0
|
76 }
|
danielebarchiesi@0
|
77
|
danielebarchiesi@0
|
78 /**
|
danielebarchiesi@0
|
79 * Adds a global event, will notify about an open dialog window.
|
danielebarchiesi@0
|
80 */
|
danielebarchiesi@0
|
81 function CKEditorNotifyAboutOpenedDialog(&$CKEditor) {
|
danielebarchiesi@0
|
82 $function = 'function (evt) {
|
danielebarchiesi@0
|
83 alert("Loading a dialog window: " + evt.data.name);
|
danielebarchiesi@0
|
84 }';
|
danielebarchiesi@0
|
85
|
danielebarchiesi@0
|
86 $CKEditor->addGlobalEventHandler('dialogDefinition', $function);
|
danielebarchiesi@0
|
87 }
|
danielebarchiesi@0
|
88
|
danielebarchiesi@0
|
89 // Include the CKEditor class.
|
danielebarchiesi@0
|
90 include("../../ckeditor.php");
|
danielebarchiesi@0
|
91
|
danielebarchiesi@0
|
92 // Create a class instance.
|
danielebarchiesi@0
|
93 $CKEditor = new CKEditor();
|
danielebarchiesi@0
|
94
|
danielebarchiesi@0
|
95 // Set a configuration option for all editors.
|
danielebarchiesi@0
|
96 $CKEditor->config['width'] = 750;
|
danielebarchiesi@0
|
97
|
danielebarchiesi@0
|
98 // Path to the CKEditor directory, ideally use an absolute path instead of a relative dir.
|
danielebarchiesi@0
|
99 // $CKEditor->basePath = '/ckeditor/'
|
danielebarchiesi@0
|
100 // If not set, CKEditor will try to detect the correct path.
|
danielebarchiesi@0
|
101 $CKEditor->basePath = '../../';
|
danielebarchiesi@0
|
102
|
danielebarchiesi@0
|
103 // The initial value to be displayed in the editor.
|
danielebarchiesi@0
|
104 $initialValue = '<p>This is some <strong>sample text</strong>. You are using <a href="http://ckeditor.com/">CKEditor</a>.</p>';
|
danielebarchiesi@0
|
105
|
danielebarchiesi@0
|
106 // Event that will be handled only by the first editor.
|
danielebarchiesi@0
|
107 $CKEditor->addEventHandler('instanceReady', 'function (evt) {
|
danielebarchiesi@0
|
108 alert("Loaded editor: " + evt.editor.name);
|
danielebarchiesi@0
|
109 }');
|
danielebarchiesi@0
|
110
|
danielebarchiesi@0
|
111 // Create the first instance.
|
danielebarchiesi@0
|
112 $CKEditor->editor("editor1", $initialValue);
|
danielebarchiesi@0
|
113
|
danielebarchiesi@0
|
114 // Clear event handlers. Instances that will be created later will not have
|
danielebarchiesi@0
|
115 // the 'instanceReady' listener defined a couple of lines above.
|
danielebarchiesi@0
|
116 $CKEditor->clearEventHandlers();
|
danielebarchiesi@0
|
117 ?>
|
danielebarchiesi@0
|
118 <br />
|
danielebarchiesi@0
|
119 <label>Editor 2:</label>
|
danielebarchiesi@0
|
120 <?php
|
danielebarchiesi@0
|
121 // Configuration that will only be used by the second editor.
|
danielebarchiesi@0
|
122 $config['width'] = '600';
|
danielebarchiesi@0
|
123 $config['toolbar'] = 'Basic';
|
danielebarchiesi@0
|
124
|
danielebarchiesi@0
|
125 // Add some global event handlers (for all editors).
|
danielebarchiesi@0
|
126 CKEditorHideLinkTargetTab($CKEditor);
|
danielebarchiesi@0
|
127 CKEditorNotifyAboutOpenedDialog($CKEditor);
|
danielebarchiesi@0
|
128
|
danielebarchiesi@0
|
129 // Event that will only be handled by the second editor.
|
danielebarchiesi@0
|
130 // Instead of calling addEventHandler(), events may be passed as an argument.
|
danielebarchiesi@0
|
131 $events['instanceReady'] = 'function (evt) {
|
danielebarchiesi@0
|
132 alert("Loaded second editor: " + evt.editor.name);
|
danielebarchiesi@0
|
133 }';
|
danielebarchiesi@0
|
134
|
danielebarchiesi@0
|
135 // Create the second instance.
|
danielebarchiesi@0
|
136 $CKEditor->editor("editor2", $initialValue, $config, $events);
|
danielebarchiesi@0
|
137 ?>
|
danielebarchiesi@0
|
138 <p>
|
danielebarchiesi@0
|
139 <input type="submit" value="Submit"/>
|
danielebarchiesi@0
|
140 </p>
|
danielebarchiesi@0
|
141 </form>
|
danielebarchiesi@0
|
142 <div id="footer">
|
danielebarchiesi@0
|
143 <hr />
|
danielebarchiesi@0
|
144 <p>
|
danielebarchiesi@0
|
145 CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
|
danielebarchiesi@0
|
146 </p>
|
danielebarchiesi@0
|
147 <p id="copy">
|
danielebarchiesi@0
|
148 Copyright © 2003-2013, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
|
danielebarchiesi@0
|
149 Knabben. All rights reserved.
|
danielebarchiesi@0
|
150 </p>
|
danielebarchiesi@0
|
151 </div>
|
danielebarchiesi@0
|
152 </body>
|
danielebarchiesi@0
|
153 </html>
|