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