1 // FCKeditor_OnComplete is a special function that is called when an editor
2 // instance is loaded ad available to the API. It must be named exactly in
3 // this way.
4 function FCKeditor_OnComplete( editorInstance )
5 {
6 // Show the editor name and description in the browser status bar.
7 document.getElementById('eMessage').innerHTML = 'Instance "' + editorInstance.Name + '" loaded - ' + editorInstance.Description ;
8
9 // Show this sample buttons.
10 document.getElementById('eButtons').style.visibility = '' ;
11 }
12
13 function InsertHTML()
14 {
15 // Get the editor instance that we want to interact with.
16 var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
17
18 // Check the active editing mode.
19 if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
20 {
21 // Insert the desired HTML.
22 oEditor.InsertHtml( '- This is some sample HTML -' ) ;
23 }
24 else
25 alert( 'You must be on WYSIWYG mode!' ) ;
26 }
27
28 function SetContents()
29 {
30 // Get the editor instance that we want to interact with.
31 var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
32
33 // Set the editor contents (replace the actual one).
34 oEditor.SetHTML( 'This is the I want new contentin the editor.' ) ;
35 }
36
37 function GetContents()
38 {
39 // Get the editor instance that we want to interact with.
40 var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
41
42 // Get the editor contents in XHTML.
43 alert( oEditor.GetXHTML( true ) ) ; // "true" means you want it formatted.
44 }
45
46 function ExecuteCommand( commandName )
47 {
48 // Get the editor instance that we want to interact with.
49 var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
50
51 // Execute the command.
52 oEditor.Commands.GetCommand( commandName ).Execute() ;
53 }
54
55 function GetLength()
56 {
57 // This functions shows that you can interact directly with the editor area
58 // DOM. In this way you have the freedom to do anything you want with it.
59
60 // Get the editor instance that we want to interact with.
61 var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
62
63 // Get the Editor Area DOM (Document object).
64 var oDOM = oEditor.EditorDocument ;
65
66 var iLength ;
67
68 // The are two diffent ways to get the text (without HTML markups).
69 // It is browser specific.
70
71 if ( document.all ) // If Internet Explorer.
72 {
73 iLength = oDOM.body.innerText.length ;
74 }
75 else // If Gecko.
76 {
77 var r = oDOM.createRange() ;
78 r.selectNodeContents( oDOM.body ) ;
79 iLength = r.toString().length ;
80 }
81
82 alert( 'Actual text length (without HTML markups): ' + iLength + ' characters' ) ;
83 }
84
85 function GetInnerHTML()
86 {
87 // Get the editor instance that we want to interact with.
88 var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
89
90 alert( oEditor.EditorDocument.body.innerHTML ) ;
91 }
92
93 function CheckIsDirty()
94 {
95 // Get the editor instance that we want to interact with.
96 var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
97 alert( oEditor.IsDirty() ) ;
98 }
99
100 function ResetIsDirty()
101 {
102 // Get the editor instance that we want to interact with.
103 var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
104 oEditor.ResetIsDirty() ;
105 alert( 'The "IsDirty" status has been reset' ) ;
106 }
107
阅读(1541) | 评论(0) | 转发(0) |