2
* FCKeditor - The text editor for internet
3
* Copyright (C) 2003-2005 Frederico Caldeira Knabben
5
* Licensed under the terms of the GNU Lesser General Public License:
6
* http://www.opensource.org/licenses/lgpl-license.php
8
* For further information visit:
9
* http://www.fckeditor.net/
11
* "Support Open Source software. What about a donation today?"
13
* File Name: sample08.html
17
* Frederico Caldeira Knabben (fredck@fckeditor.net)
19
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
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">
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
32
function FCKeditor_OnComplete( editorInstance )
34
// Show the editor name and description in the browser status bar.
35
document.getElementById('eMessage').innerHTML = 'Instance "' + editorInstance.Name + '" loaded - ' + editorInstance.Description ;
37
// Show this sample buttons.
38
document.getElementById('eButtons').style.visibility = '' ;
43
// Get the editor instance that we want to interact with.
44
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
46
// Check the active editing mode.
47
if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
49
// Insert the desired HTML.
50
oEditor.InsertHtml( '- This is some <a href="/Test1.html">sample</a> HTML -' ) ;
53
alert( 'You must be on WYSIWYG mode!' ) ;
56
function SetContents()
58
// Get the editor instance that we want to interact with.
59
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
61
// Set the editor contents (replace the actual one).
62
oEditor.SetHTML( 'This is the <b>new content</b> I want in the editor.' ) ;
65
function GetContents()
67
// Get the editor instance that we want to interact with.
68
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
70
// Get the editor contents in XHTML.
71
alert( oEditor.GetXHTML( true ) ) ; // "true" means you want it formatted.
74
function ExecuteCommand( commandName )
76
// Get the editor instance that we want to interact with.
77
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
79
// Execute the command.
80
oEditor.Commands.GetCommand( commandName ).Execute() ;
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.
88
// Get the editor instance that we want to interact with.
89
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
91
// Get the Editor Area DOM (Document object).
92
var oDOM = oEditor.EditorDocument ;
96
// The are two diffent ways to get the text (without HTML markups).
97
// It is browser specific.
99
if ( document.all ) // If Internet Explorer.
101
iLength = oDOM.body.innerText.length ;
105
var r = oDOM.createRange() ;
106
r.selectNodeContents( oDOM.body ) ;
107
iLength = r.toString().length ;
110
alert( 'Actual text length (without HTML markups): ' + iLength + ' characters' ) ;
113
function GetInnerHTML()
115
// Get the editor instance that we want to interact with.
116
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
118
alert( oEditor.EditorDocument.body.innerHTML ) ;
121
function CheckIsDirty()
123
// Get the editor instance that we want to interact with.
124
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
125
alert( oEditor.IsDirty() ) ;
128
function ResetIsDirty()
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' ) ;
139
<h1>FCKeditor - Javascript - Sample 8</h1>
140
This sample shows how to use the FCKeditor Javascript API to interact with the
143
<form action="sampleposteddata.asp" method="post" target="_blank">
144
<script type="text/javascript">
146
// Automatically calculates the editor base path based on the _samples directory.
147
// This is usefull only for these samples. A real application should use something like this:
148
// oFCKeditor.BasePath = '/fckeditor/' ; // '/fckeditor/' is the default value.
149
var sBasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('_samples')) ;
151
var oFCKeditor = new FCKeditor( 'FCKeditor1' ) ;
152
oFCKeditor.BasePath = sBasePath ;
153
oFCKeditor.Value = 'This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.' ;
154
oFCKeditor.Create() ;
158
<input type="submit" value="Submit">
162
<div id="eMessage"> </div>
164
<div id="eButtons" style="VISIBILITY: hidden">
165
<input type="button" value="Insert HTML" onclick="InsertHTML();">
166
<input type="button" value="Set Editor Contents" onclick="SetContents();">
167
<input type="button" value="Get Editor Contents (XHTML)" onclick="GetContents();">
170
<input type="button" value='Execute "Bold" Command' onclick="ExecuteCommand('Bold');">
171
<input type="button" value='Execute "Link" Command' onclick="ExecuteCommand('Link');">
174
<input type="button" value="Interact with the Editor Area DOM" onclick="GetLength();">
175
<input type="button" value="Get innerHTML" onclick="GetInnerHTML();">
178
<input type="button" value="Check IsDirty()" onclick="CheckIsDirty();">
179
<input type="button" value="Reset IsDirty()" onclick="ResetIsDirty();">