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

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_othercommands.js
  14.  *  Definition of other commands that are not available internaly in the
  15.  *  browser (see FCKNamedCommand).
  16.  * 
  17.  * File Authors:
  18.  *  Frederico Caldeira Knabben (fredck@fckeditor.net)
  19.  */
  20. // ### General Dialog Box Commands.
  21. var FCKDialogCommand = function( name, title, url, width, height, getStateFunction, getStateParam )
  22. {
  23. this.Name = name ;
  24. this.Title = title ;
  25. this.Url = url ;
  26. this.Width = width ;
  27. this.Height = height ;
  28. this.GetStateFunction = getStateFunction ;
  29. this.GetStateParam = getStateParam ;
  30. }
  31. FCKDialogCommand.prototype.Execute = function()
  32. {
  33. FCKDialog.OpenDialog( 'FCKDialog_' + this.Name , this.Title, this.Url, this.Width, this.Height ) ;
  34. }
  35. FCKDialogCommand.prototype.GetState = function()
  36. {
  37. if ( this.GetStateFunction )
  38. return this.GetStateFunction( this.GetStateParam ) ;
  39. else
  40. return FCK_TRISTATE_OFF ;
  41. }
  42. // Generic Undefined command (usually used when a command is under development).
  43. var FCKUndefinedCommand = function()
  44. {
  45. this.Name = 'Undefined' ;
  46. }
  47. FCKUndefinedCommand.prototype.Execute = function()
  48. {
  49. alert( FCKLang.NotImplemented ) ;
  50. }
  51. FCKUndefinedCommand.prototype.GetState = function()
  52. {
  53. return FCK_TRISTATE_OFF ;
  54. }
  55. // ### FontName
  56. var FCKFontNameCommand = function()
  57. {
  58. this.Name = 'FontName' ;
  59. }
  60. FCKFontNameCommand.prototype.Execute = function( fontName )
  61. {
  62. if (fontName == null || fontName == "")
  63. {
  64. // TODO: Remove font name attribute.
  65. }
  66. else
  67. FCK.ExecuteNamedCommand( 'FontName', fontName ) ;
  68. }
  69. FCKFontNameCommand.prototype.GetState = function()
  70. {
  71. return FCK.GetNamedCommandValue( 'FontName' ) ;
  72. }
  73. // ### FontSize
  74. var FCKFontSizeCommand = function()
  75. {
  76. this.Name = 'FontSize' ;
  77. }
  78. FCKFontSizeCommand.prototype.Execute = function( fontSize )
  79. {
  80. if ( typeof( fontSize ) == 'string' ) fontSize = parseInt(fontSize) ;
  81. if ( fontSize == null || fontSize == '' )
  82. {
  83. // TODO: Remove font size attribute (Now it works with size 3. Will it work forever?)
  84. FCK.ExecuteNamedCommand( 'FontSize', 3 ) ;
  85. }
  86. else
  87. FCK.ExecuteNamedCommand( 'FontSize', fontSize ) ;
  88. }
  89. FCKFontSizeCommand.prototype.GetState = function()
  90. {
  91. return FCK.GetNamedCommandValue( 'FontSize' ) ;
  92. }
  93. // ### FormatBlock
  94. var FCKFormatBlockCommand = function()
  95. {
  96. this.Name = 'FormatBlock' ;
  97. }
  98. FCKFormatBlockCommand.prototype.Execute = function( formatName )
  99. {
  100. if ( formatName == null || formatName == '' )
  101. FCK.ExecuteNamedCommand( 'FormatBlock', '<P>' ) ;
  102. else if ( formatName == 'div' && FCKBrowserInfo.IsGecko )
  103. FCK.ExecuteNamedCommand( 'FormatBlock', 'div' ) ;
  104. else
  105. FCK.ExecuteNamedCommand( 'FormatBlock', '<' + formatName + '>' ) ;
  106. }
  107. FCKFormatBlockCommand.prototype.GetState = function()
  108. {
  109. return FCK.GetNamedCommandValue( 'FormatBlock' ) ;
  110. }
  111. // ### Preview
  112. var FCKPreviewCommand = function()
  113. {
  114. this.Name = 'Preview' ;
  115. }
  116. FCKPreviewCommand.prototype.Execute = function()
  117. {
  118.      FCK.Preview() ;
  119. }
  120. FCKPreviewCommand.prototype.GetState = function()
  121. {
  122. return FCK_TRISTATE_OFF ;
  123. }
  124. // ### Save
  125. var FCKSaveCommand = function()
  126. {
  127. this.Name = 'Save' ;
  128. }
  129. FCKSaveCommand.prototype.Execute = function()
  130. {
  131. // Get the linked field form.
  132. var oForm = FCK.LinkedField.form ;
  133. if ( typeof( oForm.onsubmit ) == 'function' )
  134. {
  135. var bRet = oForm.onsubmit() ;
  136. if ( bRet != null && bRet === false )
  137. return ;
  138. }
  139. // Submit the form.
  140. oForm.submit() ;
  141. }
  142. FCKSaveCommand.prototype.GetState = function()
  143. {
  144. return FCK_TRISTATE_OFF ;
  145. }
  146. // ### NewPage
  147. var FCKNewPageCommand = function()
  148. {
  149. this.Name = 'NewPage' ;
  150. }
  151. FCKNewPageCommand.prototype.Execute = function()
  152. {
  153. FCKUndo.SaveUndoStep() ;
  154. FCK.SetHTML( '' ) ;
  155. FCKUndo.Typing = true ;
  156. // FCK.SetHTML( FCKBrowserInfo.IsGecko ? '&nbsp;' : '' ) ;
  157. // FCK.SetHTML( FCKBrowserInfo.IsGecko ? GECKO_BOGUS : '' ) ;
  158. }
  159. FCKNewPageCommand.prototype.GetState = function()
  160. {
  161. return FCK_TRISTATE_OFF ;
  162. }
  163. // ### Source button
  164. var FCKSourceCommand = function()
  165. {
  166. this.Name = 'Source' ;
  167. }
  168. FCKSourceCommand.prototype.Execute = function()
  169. {
  170. if ( FCKConfig.SourcePopup ) // Until v2.2, it was mandatory for FCKBrowserInfo.IsGecko.
  171. {
  172. var iWidth = FCKConfig.ScreenWidth * 0.65 ;
  173. var iHeight = FCKConfig.ScreenHeight * 0.65 ;
  174. FCKDialog.OpenDialog( 'FCKDialog_Source', FCKLang.Source, 'dialog/fck_source.html', iWidth, iHeight, null, null, true ) ;
  175. }
  176. else
  177.     FCK.SwitchEditMode() ;
  178. }
  179. FCKSourceCommand.prototype.GetState = function()
  180. {
  181. return ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ? FCK_TRISTATE_OFF : FCK_TRISTATE_ON ) ;
  182. }
  183. // ### Undo
  184. var FCKUndoCommand = function()
  185. {
  186. this.Name = 'Undo' ;
  187. }
  188. FCKUndoCommand.prototype.Execute = function()
  189. {
  190. if ( FCKBrowserInfo.IsIE )
  191. FCKUndo.Undo() ;
  192. else
  193. FCK.ExecuteNamedCommand( 'Undo' ) ;
  194. }
  195. FCKUndoCommand.prototype.GetState = function()
  196. {
  197. if ( FCKBrowserInfo.IsIE )
  198. return ( FCKUndo.CheckUndoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ;
  199. else
  200. return FCK.GetNamedCommandState( 'Undo' ) ;
  201. }
  202. // ### Redo
  203. var FCKRedoCommand = function()
  204. {
  205. this.Name = 'Redo' ;
  206. }
  207. FCKRedoCommand.prototype.Execute = function()
  208. {
  209. if ( FCKBrowserInfo.IsIE )
  210. FCKUndo.Redo() ;
  211. else
  212. FCK.ExecuteNamedCommand( 'Redo' ) ;
  213. }
  214. FCKRedoCommand.prototype.GetState = function()
  215. {
  216. if ( FCKBrowserInfo.IsIE )
  217. return ( FCKUndo.CheckRedoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ;
  218. else
  219. return FCK.GetNamedCommandState( 'Redo' ) ;
  220. }
  221. // ### Page Break
  222. var FCKPageBreakCommand = function()
  223. {
  224. this.Name = 'PageBreak' ;
  225. }
  226. FCKPageBreakCommand.prototype.Execute = function()
  227. {
  228. // var e = FCK.EditorDocument.createElement( 'CENTER' ) ;
  229. // e.style.pageBreakAfter = 'always' ;
  230. // Tidy was removing the empty CENTER tags, so the following solution has 
  231. // been found. It also validates correctly as XHTML 1.0 Strict.
  232. var e = FCK.EditorDocument.createElement( 'DIV' ) ;
  233. e.style.pageBreakAfter = 'always' ;
  234. e.innerHTML = '<span style="DISPLAY:none">&nbsp;</span>' ;
  235. var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', e ) ;
  236. oFakeImage = FCK.InsertElement( oFakeImage ) ;
  237. }
  238. FCKPageBreakCommand.prototype.GetState = function()
  239. {
  240. return 0 ; // FCK_TRISTATE_OFF
  241. }
  242. // FCKUnlinkCommand - by Johnny Egeland (johnny@coretrek.com)
  243. var FCKUnlinkCommand = function()
  244. {
  245. this.Name = 'Unlink' ;
  246. }
  247. FCKUnlinkCommand.prototype.Execute = function()
  248. {
  249. if ( FCKBrowserInfo.IsGecko )
  250. {
  251. var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ;
  252. if ( oLink ) 
  253. FCK.Selection.SelectNode( oLink ) ;
  254. }
  255. FCK.ExecuteNamedCommand( this.Name ) ;
  256. if ( FCKBrowserInfo.IsGecko )
  257. FCK.Selection.Collapse( true ) ;
  258. }
  259. FCKUnlinkCommand.prototype.GetState = function()
  260. {
  261. return FCK.GetNamedCommandState( this.Name ) ;
  262. }