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

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: fckstylecommand.js
  14.  *  FCKStyleCommand Class: represents the "Style" command.
  15.  * 
  16.  * File Authors:
  17.  *  Frederico Caldeira Knabben (fredck@fckeditor.net)
  18.  */
  19. var FCKStyleCommand = function()
  20. {
  21. this.Name = 'Style' ;
  22. // Load the Styles defined in the XML file.
  23. this.StylesLoader = new FCKStylesLoader() ;
  24. this.StylesLoader.Load( FCKConfig.StylesXmlPath ) ;
  25. this.Styles = this.StylesLoader.Styles ;
  26. }
  27. FCKStyleCommand.prototype.Execute = function( styleName, styleComboItem )
  28. {
  29. FCKUndo.SaveUndoStep() ;
  30. if ( styleComboItem.Selected )
  31. styleComboItem.Style.RemoveFromSelection() ;
  32. else
  33. styleComboItem.Style.ApplyToSelection() ;
  34. FCKUndo.SaveUndoStep() ;
  35. FCK.Focus() ;
  36. FCK.Events.FireEvent( "OnSelectionChange" ) ;
  37. }
  38. FCKStyleCommand.prototype.GetState = function()
  39. {
  40. if ( !FCK.EditorDocument )
  41. return FCK_TRISTATE_DISABLED ;
  42. var oSelection = FCK.EditorDocument.selection ;
  43. if ( FCKSelection.GetType() == 'Control' )
  44. {
  45. var e = FCKSelection.GetSelectedElement() ;
  46. if ( e )
  47. return this.StylesLoader.StyleGroups[ e.tagName ] ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ;
  48. }
  49. return FCK_TRISTATE_OFF ;
  50. }
  51. FCKStyleCommand.prototype.GetActiveStyles = function()
  52. {
  53. var aActiveStyles = new Array() ;
  54. if ( FCKSelection.GetType() == 'Control' )
  55. this._CheckStyle( FCKSelection.GetSelectedElement(), aActiveStyles, false ) ;
  56. else
  57. this._CheckStyle( FCKSelection.GetParentElement(), aActiveStyles, true ) ;
  58. return aActiveStyles ;
  59. }
  60. FCKStyleCommand.prototype._CheckStyle = function( element, targetArray, checkParent )
  61. {
  62. if ( ! element )
  63. return ;
  64. if ( element.nodeType == 1 )
  65. {
  66. var aStyleGroup = this.StylesLoader.StyleGroups[ element.tagName ] ;
  67. if ( aStyleGroup )
  68. {
  69. for ( var i = 0 ; i < aStyleGroup.length ; i++ )
  70. {
  71. if ( aStyleGroup[i].IsEqual( element ) )
  72. targetArray[ targetArray.length ] = aStyleGroup[i] ;
  73. }
  74. }
  75. }
  76. if ( checkParent )
  77. this._CheckStyle( element.parentNode, targetArray, checkParent ) ;
  78. }