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

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: fckstyledef_gecko.js
  14.  *  FCKStyleDef Class: represents a single stylke definition. (Gecko specific)
  15.  * 
  16.  * File Authors:
  17.  *  Frederico Caldeira Knabben (fredck@fckeditor.net)
  18.  */
  19. FCKStyleDef.prototype.ApplyToSelection = function()
  20. {
  21. if ( FCKSelection.GetType() == 'Text' && !this.IsObjectElement )
  22. {
  23. var oSelection = FCK.ToolbarSet.CurrentInstance.EditorWindow.getSelection() ;
  24. // Create the main element.
  25. var e = FCK.ToolbarSet.CurrentInstance.EditorDocument.createElement( this.Element ) ;
  26. for ( var i = 0 ; i < oSelection.rangeCount ; i++ )
  27. {
  28. e.appendChild( oSelection.getRangeAt(i).extractContents() ) ;
  29. }
  30. // Set the attributes.
  31. this._AddAttributes( e ) ;
  32. // Remove the duplicated elements.
  33. this._RemoveDuplicates( e ) ;
  34. var oRange = oSelection.getRangeAt(0) ;
  35. oRange.insertNode( e ) ;
  36. }
  37. else
  38. {
  39. var oControl = FCK.ToolbarSet.CurrentInstance.Selection.GetSelectedElement() ;
  40. if ( oControl.tagName == this.Element )
  41. this._AddAttributes( oControl ) ;
  42. }
  43. }
  44. FCKStyleDef.prototype._AddAttributes = function( targetElement )
  45. {
  46. for ( var a in this.Attributes )
  47. {
  48. switch ( a.toLowerCase() )
  49. {
  50. case 'src' :
  51. targetElement.setAttribute( '_fcksavedurl', this.Attributes[a], 0 ) ;
  52. default :
  53. targetElement.setAttribute( a, this.Attributes[a], 0 ) ;
  54. }
  55. }
  56. }
  57. FCKStyleDef.prototype._RemoveDuplicates = function( parent )
  58. {
  59. for ( var i = 0 ; i < parent.childNodes.length ; i++ )
  60. {
  61. var oChild = parent.childNodes[i] ;
  62. if ( oChild.nodeType != 1 )
  63. continue ;
  64. this._RemoveDuplicates( oChild ) ;
  65. if ( this.IsEqual( oChild ) )
  66. FCKTools.RemoveOuterTags( oChild ) ;
  67. }
  68. }
  69. FCKStyleDef.prototype.IsEqual = function( e )
  70. {
  71. if ( e.tagName != this.Element )
  72. return false ;
  73. for ( var a in this.Attributes )
  74. {
  75. if ( e.getAttribute( a ) != this.Attributes[a] )
  76. return false ;
  77. }
  78. return true ;
  79. }
  80. FCKStyleDef.prototype._RemoveMe = function( elementToCheck )
  81. {
  82. if ( ! elementToCheck )
  83. return ;
  84. var oParent = elementToCheck.parentNode ;
  85. if ( elementToCheck.nodeType == 1 && this.IsEqual( elementToCheck ) )
  86. {
  87. if ( this.IsObjectElement )
  88. {
  89. for ( var a in this.Attributes )
  90. elementToCheck.removeAttribute( a, 0 ) ;
  91. return ;
  92. }
  93. else
  94. FCKTools.RemoveOuterTags( elementToCheck ) ;
  95. }
  96. this._RemoveMe( oParent ) ;
  97. }