1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
2 | <!-- |
---|
3 | * FCKeditor - The text editor for internet |
---|
4 | * Copyright (C) 2003-2006 Frederico Caldeira Knabben |
---|
5 | * |
---|
6 | * Licensed under the terms of the GNU Lesser General Public License: |
---|
7 | * http://www.opensource.org/licenses/lgpl-license.php |
---|
8 | * |
---|
9 | * For further information visit: |
---|
10 | * http://www.fckeditor.net/ |
---|
11 | * |
---|
12 | * "Support Open Source software. What about a donation today?" |
---|
13 | * |
---|
14 | * File Name: sample08.html |
---|
15 | * Sample page. |
---|
16 | * |
---|
17 | * File Authors: |
---|
18 | * Frederico Caldeira Knabben (fredck@fckeditor.net) |
---|
19 | --> |
---|
20 | <html xmlns="http://www.w3.org/1999/xhtml"> |
---|
21 | <head> |
---|
22 | <title>FCKeditor - Sample</title> |
---|
23 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
---|
24 | <meta name="robots" content="noindex, nofollow" /> |
---|
25 | <link href="../sample.css" rel="stylesheet" type="text/css" /> |
---|
26 | <script type="text/javascript" src="../../fckeditor.js"></script> |
---|
27 | <script type="text/javascript"> |
---|
28 | |
---|
29 | // FCKeditor_OnComplete is a special function that is called when an editor |
---|
30 | // instance is loaded ad available to the API. It must be named exactly in |
---|
31 | // this way. |
---|
32 | function FCKeditor_OnComplete( editorInstance ) |
---|
33 | { |
---|
34 | // Show the editor name and description in the browser status bar. |
---|
35 | document.getElementById('eMessage').innerHTML = 'Instance "' + editorInstance.Name + '" loaded - ' + editorInstance.Description ; |
---|
36 | |
---|
37 | // Show this sample buttons. |
---|
38 | document.getElementById('eButtons').style.visibility = '' ; |
---|
39 | } |
---|
40 | |
---|
41 | function InsertHTML() |
---|
42 | { |
---|
43 | // Get the editor instance that we want to interact with. |
---|
44 | var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ; |
---|
45 | |
---|
46 | // Check the active editing mode. |
---|
47 | if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG ) |
---|
48 | { |
---|
49 | // Insert the desired HTML. |
---|
50 | oEditor.InsertHtml( '- This is some <a href="/Test1.html">sample</a> HTML -' ) ; |
---|
51 | } |
---|
52 | else |
---|
53 | alert( 'You must be on WYSIWYG mode!' ) ; |
---|
54 | } |
---|
55 | |
---|
56 | function SetContents() |
---|
57 | { |
---|
58 | // Get the editor instance that we want to interact with. |
---|
59 | var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ; |
---|
60 | |
---|
61 | // Set the editor contents (replace the actual one). |
---|
62 | oEditor.SetHTML( 'This is the <b>new content</b> I want in the editor.' ) ; |
---|
63 | } |
---|
64 | |
---|
65 | function GetContents() |
---|
66 | { |
---|
67 | // Get the editor instance that we want to interact with. |
---|
68 | var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ; |
---|
69 | |
---|
70 | // Get the editor contents in XHTML. |
---|
71 | alert( oEditor.GetXHTML( true ) ) ; // "true" means you want it formatted. |
---|
72 | } |
---|
73 | |
---|
74 | function ExecuteCommand( commandName ) |
---|
75 | { |
---|
76 | // Get the editor instance that we want to interact with. |
---|
77 | var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ; |
---|
78 | |
---|
79 | // Execute the command. |
---|
80 | oEditor.Commands.GetCommand( commandName ).Execute() ; |
---|
81 | } |
---|
82 | |
---|
83 | function GetLength() |
---|
84 | { |
---|
85 | // This functions shows that you can interact directly with the editor area |
---|
86 | // DOM. In this way you have the freedom to do anything you want with it. |
---|
87 | |
---|
88 | // Get the editor instance that we want to interact with. |
---|
89 | var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ; |
---|
90 | |
---|
91 | // Get the Editor Area DOM (Document object). |
---|
92 | var oDOM = oEditor.EditorDocument ; |
---|
93 | |
---|
94 | var iLength ; |
---|
95 | |
---|
96 | // The are two diffent ways to get the text (without HTML markups). |
---|
97 | // It is browser specific. |
---|
98 | |
---|
99 | if ( document.all ) // If Internet Explorer. |
---|
100 | { |
---|
101 | iLength = oDOM.body.innerText.length ; |
---|
102 | } |
---|
103 | else // If Gecko. |
---|
104 | { |
---|
105 | var r = oDOM.createRange() ; |
---|
106 | r.selectNodeContents( oDOM.body ) ; |
---|
107 | iLength = r.toString().length ; |
---|
108 | } |
---|
109 | |
---|
110 | alert( 'Actual text length (without HTML markups): ' + iLength + ' characters' ) ; |
---|
111 | } |
---|
112 | |
---|
113 | function GetInnerHTML() |
---|
114 | { |
---|
115 | // Get the editor instance that we want to interact with. |
---|
116 | var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ; |
---|
117 | |
---|
118 | alert( oEditor.EditorDocument.body.innerHTML ) ; |
---|
119 | } |
---|
120 | |
---|
121 | function CheckIsDirty() |
---|
122 | { |
---|
123 | // Get the editor instance that we want to interact with. |
---|
124 | var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ; |
---|
125 | alert( oEditor.IsDirty() ) ; |
---|
126 | } |
---|
127 | |
---|
128 | function ResetIsDirty() |
---|
129 | { |
---|
130 | // Get the editor instance that we want to interact with. |
---|
131 | var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ; |
---|
132 | oEditor.ResetIsDirty() ; |
---|
133 | alert( 'The "IsDirty" status has been reset' ) ; |
---|
134 | } |
---|
135 | |
---|
136 | </script> |
---|
137 | </head> |
---|
138 | <body> |
---|
139 | <h1> |
---|
140 | FCKeditor - JavaScript - Sample 8 |
---|
141 | </h1> |
---|
142 | <div> |
---|
143 | This sample shows how to use the FCKeditor JavaScript API to interact with the editor |
---|
144 | at runtime. |
---|
145 | </div> |
---|
146 | <hr /> |
---|
147 | <form action="sampleposteddata.asp" method="post" target="_blank"> |
---|
148 | <script type="text/javascript"> |
---|
149 | <!-- |
---|
150 | // Automatically calculates the editor base path based on the _samples directory. |
---|
151 | // This is usefull only for these samples. A real application should use something like this: |
---|
152 | // oFCKeditor.BasePath = '/fckeditor/' ; // '/fckeditor/' is the default value. |
---|
153 | var sBasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('_samples')) ; |
---|
154 | |
---|
155 | var oFCKeditor = new FCKeditor( 'FCKeditor1' ) ; |
---|
156 | oFCKeditor.BasePath = sBasePath ; |
---|
157 | oFCKeditor.Value = 'This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.' ; |
---|
158 | oFCKeditor.Create() ; |
---|
159 | //--> |
---|
160 | </script> |
---|
161 | <br /> |
---|
162 | <input type="submit" value="Submit" /> |
---|
163 | </form> |
---|
164 | <div> |
---|
165 | |
---|
166 | </div> |
---|
167 | <hr /> |
---|
168 | <div id="eMessage"> |
---|
169 | |
---|
170 | </div> |
---|
171 | <div> |
---|
172 | |
---|
173 | </div> |
---|
174 | <div id="eButtons" style="visibility: hidden"> |
---|
175 | <input type="button" value="Insert HTML" onclick="InsertHTML();" /> |
---|
176 | <input type="button" value="Set Editor Contents" onclick="SetContents();" /> |
---|
177 | <input type="button" value="Get Editor Contents (XHTML)" onclick="GetContents();" /> |
---|
178 | <br /> |
---|
179 | <br /> |
---|
180 | <input type="button" value='Execute "Bold" Command' onclick="ExecuteCommand('Bold');" /> |
---|
181 | <input type="button" value='Execute "Link" Command' onclick="ExecuteCommand('Link');" /> |
---|
182 | <br /> |
---|
183 | <br /> |
---|
184 | <input type="button" value="Interact with the Editor Area DOM" onclick="GetLength();" /> |
---|
185 | <input type="button" value="Get innerHTML" onclick="GetInnerHTML();" /> |
---|
186 | <br /> |
---|
187 | <br /> |
---|
188 | <input type="button" value="Check IsDirty()" onclick="CheckIsDirty();" /> |
---|
189 | <input type="button" value="Reset IsDirty()" onclick="ResetIsDirty();" /> |
---|
190 | </div> |
---|
191 | </body> |
---|
192 | </html> |
---|