1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
\r
3 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
\r
4 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 <html xmlns="http://www.w3.org/1999/xhtml">
\r
8 <title>Adding Event Handlers — CKEditor Sample</title>
\r
9 <meta content="text/html; charset=utf-8" http-equiv="content-type"/>
\r
10 <link href="../sample.css" rel="stylesheet" type="text/css"/>
\r
13 <h1 class="samples">
\r
14 CKEditor Sample — Adding Event Handlers
\r
16 <div class="description">
\r
18 This sample shows how to add event handlers to CKEditor with PHP.
\r
21 A snippet of the configuration code can be seen below; check the source code of this page for
\r
22 the full definition:
\r
24 <pre class="samples"><?php
\r
25 // Include the CKEditor class.
\r
26 include("ckeditor/ckeditor.php");
\r
28 // Create a class instance.
\r
29 $CKEditor = new CKEditor();
\r
31 // Path to the CKEditor directory.
\r
32 $CKEditor->basePath = '/ckeditor/';
\r
34 // The initial value to be displayed in the editor.
\r
35 $initialValue = 'This is some sample text.';
\r
37 // Add event handler, <em>instanceReady</em> is fired when editor is loaded.
\r
38 $CKEditor-><strong>addEventHandler</strong>('instanceReady', 'function (evt) {
\r
39 alert("Loaded editor: " + evt.editor.name);
\r
42 // Create an editor instance.
\r
43 $CKEditor->editor("editor1", $initialValue);
\r
46 <!-- This <div> holds alert messages to be display in the sample page. -->
\r
50 <strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript
\r
51 support, like yours, you should still see the contents (HTML data) and you should
\r
52 be able to edit it normally, without a rich editor interface.
\r
56 <form action="../sample_posteddata.php" method="post">
\r
57 <label>Editor 1:</label>
\r
61 * Adds a global event, will hide the "Target" tab in the "Link" dialog window in all instances.
\r
63 function CKEditorHideLinkTargetTab(&$CKEditor) {
\r
65 $function = 'function (ev) {
\r
66 // Take the dialog window name and its definition from the event data.
\r
67 var dialogName = ev.data.name;
\r
68 var dialogDefinition = ev.data.definition;
\r
70 // Check if the definition comes from the "Link" dialog window.
\r
71 if ( dialogName == "link" )
\r
72 dialogDefinition.removeContents("target")
\r
75 $CKEditor->addGlobalEventHandler('dialogDefinition', $function);
\r
79 * Adds a global event, will notify about an open dialog window.
\r
81 function CKEditorNotifyAboutOpenedDialog(&$CKEditor) {
\r
82 $function = 'function (evt) {
\r
83 alert("Loading a dialog window: " + evt.data.name);
\r
86 $CKEditor->addGlobalEventHandler('dialogDefinition', $function);
\r
89 // Include the CKEditor class.
\r
90 include("../../ckeditor.php");
\r
92 // Create a class instance.
\r
93 $CKEditor = new CKEditor();
\r
95 // Set a configuration option for all editors.
\r
96 $CKEditor->config['width'] = 750;
\r
98 // Path to the CKEditor directory, ideally use an absolute path instead of a relative dir.
\r
99 // $CKEditor->basePath = '/ckeditor/'
\r
100 // If not set, CKEditor will try to detect the correct path.
\r
101 $CKEditor->basePath = '../../';
\r
103 // The initial value to be displayed in the editor.
\r
104 $initialValue = '<p>This is some <strong>sample text</strong>. You are using <a href="http://ckeditor.com/">CKEditor</a>.</p>';
\r
106 // Event that will be handled only by the first editor.
\r
107 $CKEditor->addEventHandler('instanceReady', 'function (evt) {
\r
108 alert("Loaded editor: " + evt.editor.name);
\r
111 // Create the first instance.
\r
112 $CKEditor->editor("editor1", $initialValue);
\r
114 // Clear event handlers. Instances that will be created later will not have
\r
115 // the 'instanceReady' listener defined a couple of lines above.
\r
116 $CKEditor->clearEventHandlers();
\r
119 <label>Editor 2:</label>
\r
121 // Configuration that will only be used by the second editor.
\r
122 $config['width'] = '600';
\r
123 $config['toolbar'] = 'Basic';
\r
125 // Add some global event handlers (for all editors).
\r
126 CKEditorHideLinkTargetTab($CKEditor);
\r
127 CKEditorNotifyAboutOpenedDialog($CKEditor);
\r
129 // Event that will only be handled by the second editor.
\r
130 // Instead of calling addEventHandler(), events may be passed as an argument.
\r
131 $events['instanceReady'] = 'function (evt) {
\r
132 alert("Loaded second editor: " + evt.editor.name);
\r
135 // Create the second instance.
\r
136 $CKEditor->editor("editor2", $initialValue, $config, $events);
\r
139 <input type="submit" value="Submit"/>
\r
145 CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
\r
148 Copyright © 2003-2011, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
\r
149 Knabben. All rights reserved.
\r