JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.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">\r
2 <!--\r
3 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
4 For licensing, see LICENSE.html or http://ckeditor.com/license\r
5 -->\r
6 <html xmlns="http://www.w3.org/1999/xhtml">\r
7 <head>\r
8         <title>Sample - CKEditor</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
11 </head>\r
12 <body>\r
13         <h1>\r
14                 CKEditor Sample\r
15         </h1>\r
16         <!-- This <div> holds alert messages to be display in the sample page. -->\r
17         <div id="alerts">\r
18                 <noscript>\r
19                         <p>\r
20                                 <strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript\r
21                                 support, like yours, you should still see the contents (HTML data) and you should\r
22                                 be able to edit it normally, without a rich editor interface.\r
23                         </p>\r
24                 </noscript>\r
25         </div>\r
26         <!-- This <fieldset> holds the HTML that you will usually find in your pages. -->\r
27         <fieldset title="Output">\r
28                 <legend>Output</legend>\r
29                 <form action="../sample_posteddata.php" method="post">\r
30                         <p>\r
31                                 <label>Editor 1:</label><br/>\r
32                         </p>\r
33 <?php\r
34 \r
35 /**\r
36  * Adds global event, will hide "Target" tab in Link dialog in all instances.\r
37  */\r
38 function CKEditorHideLinkTargetTab(&$CKEditor) {\r
39 \r
40         $function = 'function (ev) {\r
41                 // Take the dialog name and its definition from the event data\r
42                 var dialogName = ev.data.name;\r
43                 var dialogDefinition = ev.data.definition;\r
44 \r
45                 // Check if the definition is from the Link dialog.\r
46                 if ( dialogName == "link" )\r
47                         dialogDefinition.removeContents("target")\r
48         }';\r
49 \r
50         $CKEditor->addGlobalEventHandler('dialogDefinition', $function);\r
51 }\r
52 \r
53 /**\r
54  * Adds global event, will notify about opened dialog.\r
55  */\r
56 function CKEditorNotifyAboutOpenedDialog(&$CKEditor) {\r
57         $function = 'function (evt) {\r
58                 alert("Loading dialog: " + evt.data.name);\r
59         }';\r
60 \r
61         $CKEditor->addGlobalEventHandler('dialogDefinition', $function);\r
62 }\r
63 \r
64 // Include CKEditor class.\r
65 include("../../ckeditor.php");\r
66 \r
67 // Create class instance.\r
68 $CKEditor = new CKEditor();\r
69 \r
70 // Set configuration option for all editors.\r
71 $CKEditor->config['width'] = 750;\r
72 \r
73 // Path to CKEditor directory, ideally instead of relative dir, use an absolute path:\r
74 //   $CKEditor->basePath = '/ckeditor/'\r
75 // If not set, CKEditor will try to detect the correct path.\r
76 $CKEditor->basePath = '../../';\r
77 \r
78 // The initial value to be displayed in the editor.\r
79 $initialValue = '<p>This is some <strong>sample text</strong>. You are using <a href="http://ckeditor.com/">CKEditor</a>.</p>';\r
80 \r
81 // Event that will be handled only by the first editor.\r
82 $CKEditor->addEventHandler('instanceReady', 'function (evt) {\r
83         alert("Loaded editor: " + evt.editor.name);\r
84 }');\r
85 \r
86 // Create first instance.\r
87 $CKEditor->editor("editor1", $initialValue);\r
88 \r
89 // Clear event handlers, instances that will be created later will not have\r
90 // the 'instanceReady' listener defined a couple of lines above.\r
91 $CKEditor->clearEventHandlers();\r
92 ?>\r
93                         <p>\r
94                                 <label>Editor 2:</label><br/>\r
95                         </p>\r
96 <?php\r
97 // Configuration that will be used only by the second editor.\r
98 $config['width'] = '600';\r
99 $config['toolbar'] = 'Basic';\r
100 \r
101 // Add some global event handlers (for all editors).\r
102 CKEditorHideLinkTargetTab($CKEditor);\r
103 CKEditorNotifyAboutOpenedDialog($CKEditor);\r
104 \r
105 // Event that will be handled only by the second editor.\r
106 // Instead of calling addEventHandler(), events may be passed as an argument.\r
107 $events['instanceReady'] = 'function (evt) {\r
108         alert("Loaded second editor: " + evt.editor.name);\r
109 }';\r
110 \r
111 // Create second instance.\r
112 $CKEditor->editor("editor2", $initialValue, $config, $events);\r
113 ?>\r
114                                 <input type="submit" value="Submit"/>\r
115                         </p>\r
116                 </form>\r
117         </fieldset>\r
118         <div id="footer">\r
119                 <hr />\r
120                 <p>\r
121                         CKEditor - The text editor for Internet - <a href="http://ckeditor.com/">http://ckeditor.com</a>\r
122                 </p>\r
123                 <p id="copy">\r
124                         Copyright &copy; 2003-2010, <a href="http://cksource.com/">CKSource</a> - Frederico\r
125                         Knabben. All rights reserved.\r
126                 </p>\r
127         </div>\r
128 </body>\r
129 </html>\r