fck_2_gecko.js
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:5k
源码类别:

OA系统

开发平台:

C#

  1. /*
  2.  * FCKeditor - The text editor for internet
  3.  * Copyright (C) 2003-2006 Frederico Caldeira Knabben
  4.  * 
  5.  * Licensed under the terms of the GNU Lesser General Public License:
  6.  *  http://www.opensource.org/licenses/lgpl-license.php
  7.  * 
  8.  * For further information visit:
  9.  *  http://www.fckeditor.net/
  10.  * 
  11.  * "Support Open Source software. What about a donation today?"
  12.  * 
  13.  * File Name: fck_2_gecko.js
  14.  *  This is the second part of the "FCK" object creation. This is the main
  15.  *  object that represents an editor instance.
  16.  *  (Gecko specific implementations)
  17.  * 
  18.  * File Authors:
  19.  *  Frederico Caldeira Knabben (fredck@fckeditor.net)
  20.  */
  21. // GetNamedCommandState overload for Gecko.
  22. FCK._BaseGetNamedCommandState = FCK.GetNamedCommandState ;
  23. FCK.GetNamedCommandState = function( commandName )
  24. {
  25. switch ( commandName )
  26. {
  27. case 'Unlink' :
  28. return FCKSelection.HasAncestorNode('A') ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ;
  29. default :
  30. return FCK._BaseGetNamedCommandState( commandName ) ;
  31. }
  32. }
  33. // Named commands to be handled by this browsers specific implementation.
  34. FCK.RedirectNamedCommands = 
  35. {
  36. Print : true,
  37. Paste : true,
  38. Cut : true,
  39. Copy : true
  40. }
  41. // ExecuteNamedCommand overload for Gecko.
  42. FCK.ExecuteRedirectedNamedCommand = function( commandName, commandParameter )
  43. {
  44. switch ( commandName )
  45. {
  46. case 'Print' :
  47. FCK.EditorWindow.print() ;
  48. break ;
  49. case 'Paste' :
  50. try { if ( FCK.Paste() ) FCK.ExecuteNamedCommand( 'Paste', null, true ) ; }
  51. catch (e) { alert(FCKLang.PasteErrorPaste) ; }
  52. break ;
  53. case 'Cut' :
  54. try { FCK.ExecuteNamedCommand( 'Cut', null, true ) ; }
  55. catch (e) { alert(FCKLang.PasteErrorCut) ; }
  56. break ;
  57. case 'Copy' :
  58. try { FCK.ExecuteNamedCommand( 'Copy', null, true ) ; }
  59. catch (e) { alert(FCKLang.PasteErrorCopy) ; }
  60. break ;
  61. default :
  62. FCK.ExecuteNamedCommand( commandName, commandParameter ) ;
  63. }
  64. }
  65. FCK.AttachToOnSelectionChange = function( functionPointer )
  66. {
  67. this.Events.AttachEvent( 'OnSelectionChange', functionPointer ) ;
  68. }
  69. FCK.Paste = function()
  70. {
  71. if ( FCKConfig.ForcePasteAsPlainText )
  72. {
  73. FCK.PasteAsPlainText() ;
  74. return false ;
  75. }
  76. /* For now, the AutoDetectPasteFromWord feature is IE only.
  77. else if ( FCKConfig.AutoDetectPasteFromWord )
  78. {
  79. var sHTML = FCK.GetClipboardHTML() ;
  80. var re = /<w[^>]* class="?MsoNormal"?/gi ;
  81. if ( re.test( sHTML ) )
  82. {
  83. if ( confirm( FCKLang["PasteWordConfirm"] ) )
  84. {
  85. FCK.PasteFromWord() ;
  86. return false ;
  87. }
  88. }
  89. }
  90. */
  91. else
  92. return true ;
  93. }
  94. //**
  95. // FCK.InsertHtml: Inserts HTML at the current cursor location. Deletes the
  96. // selected content if any.
  97. FCK.InsertHtml = function( html )
  98. {
  99. html = FCKConfig.ProtectedSource.Protect( html ) ;
  100. html = FCK.ProtectUrls( html ) ;
  101. // Delete the actual selection.
  102. var oSel = FCKSelection.Delete() ;
  103. // Get the first available range.
  104. var oRange = oSel.getRangeAt(0) ;
  105. // Create a fragment with the input HTML.
  106. var oFragment = oRange.createContextualFragment( html ) ;
  107. // Get the last available node.
  108. var oLastNode = oFragment.lastChild ;
  109. // Insert the fragment in the range.
  110. oRange.insertNode(oFragment) ;
  111. // Set the cursor after the inserted fragment.
  112. FCKSelection.SelectNode( oLastNode ) ;
  113. FCKSelection.Collapse( false ) ;
  114. this.Focus() ;
  115. }
  116. FCK.InsertElement = function( element )
  117. {
  118. // Deletes the actual selection.
  119. var oSel = FCKSelection.Delete() ;
  120. // Gets the first available range.
  121. var oRange = oSel.getRangeAt(0) ;
  122. // Inserts the element in the range.
  123. oRange.insertNode( element ) ;
  124. // Set the cursor after the inserted fragment.
  125. FCKSelection.SelectNode( element ) ;
  126. FCKSelection.Collapse( false ) ;
  127. this.Focus() ;
  128. }
  129. FCK.PasteAsPlainText = function()
  130. {
  131. // TODO: Implement the "Paste as Plain Text" code.
  132. FCKDialog.OpenDialog( 'FCKDialog_Paste', FCKLang.PasteAsText, 'dialog/fck_paste.html', 400, 330, 'PlainText' ) ;
  133. /*
  134. var sText = FCKTools.HTMLEncode( clipboardData.getData("Text") ) ;
  135. sText = sText.replace( /n/g, '<BR>' ) ;
  136. this.InsertHtml( sText ) ;
  137. */
  138. }
  139. /*
  140. FCK.PasteFromWord = function()
  141. {
  142. // TODO: Implement the "Paste as Plain Text" code.
  143. FCKDialog.OpenDialog( 'FCKDialog_Paste', FCKLang.PasteFromWord, 'dialog/fck_paste.html', 400, 330, 'Word' ) ;
  144. // FCK.CleanAndPaste( FCK.GetClipboardHTML() ) ;
  145. }
  146. */
  147. FCK.GetClipboardHTML = function()
  148. {
  149. return '' ;
  150. }
  151. FCK.CreateLink = function( url )
  152. {
  153. FCK.ExecuteNamedCommand( 'Unlink' ) ;
  154. if ( url.length > 0 )
  155. {
  156. // Generate a temporary name for the link.
  157. var sTempUrl = 'javascript:void(0);/*' + ( new Date().getTime() ) + '*/' ;
  158. // Use the internal "CreateLink" command to create the link.
  159. FCK.ExecuteNamedCommand( 'CreateLink', sTempUrl ) ;
  160. // Retrieve the just created link using XPath.
  161. var oLink = document.evaluate("//a[@href='" + sTempUrl + "']", this.EditorDocument.body, null, 9, null).singleNodeValue ;
  162. if ( oLink )
  163. {
  164. oLink.href = url ;
  165. return oLink ;
  166. }
  167. }
  168. }