09-02
17
FCKeditor JS API
作者:Java伴侣 日期:2009-02-17
<script type="text/javascript" src="../../fckeditor.js"></script>
复制内容到剪贴板 程序代码
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.
4function 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
13function 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 <a href="/Test1.html">sample</a> HTML -' ) ;
23 }
24 else
25 alert( 'You must be on WYSIWYG mode!' ) ;
26}
27
28function 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 <b>new content</b> I want in the editor.' ) ;
35}
36
37function 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
46function 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
55function 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
85function 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
93function 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
100function 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
2// instance is loaded ad available to the API. It must be named exactly in
3// this way.
4function 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
13function 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 <a href="/Test1.html">sample</a> HTML -' ) ;
23 }
24 else
25 alert( 'You must be on WYSIWYG mode!' ) ;
26}
27
28function 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 <b>new content</b> I want in the editor.' ) ;
35}
36
37function 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
46function 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
55function 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
85function 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
93function 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
100function 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
评论: 1 | 引用: 0 | 查看次数: 567
回复john[2009-04-16 07:40 PM | ]
留下联系方式可以吗?我的QQ是:54243115,联系我或你,谢谢
发表评论