[ Index ]
 

Code source de FCKeditor 2.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/editor/_source/classes/ -> fckstyledef_gecko.js (source)

   1  /*
   2   * FCKeditor - The text editor for Internet - http://www.fckeditor.net
   3   * Copyright (C) 2003-2007 Frederico Caldeira Knabben
   4   * 
   5   * == BEGIN LICENSE ==
   6   * 
   7   * Licensed under the terms of any of the following licenses at your
   8   * choice:
   9   * 
  10   *  - GNU General Public License Version 2 or later (the "GPL")
  11   *    http://www.gnu.org/licenses/gpl.html
  12   * 
  13   *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  14   *    http://www.gnu.org/licenses/lgpl.html
  15   * 
  16   *  - Mozilla Public License Version 1.1 or later (the "MPL")
  17   *    http://www.mozilla.org/MPL/MPL-1.1.html
  18   * 
  19   * == END LICENSE ==
  20   * 
  21   * File Name: fckstyledef_gecko.js
  22   *     FCKStyleDef Class: represents a single stylke definition. (Gecko specific)
  23   * 
  24   * File Authors:
  25   *         Frederico Caldeira Knabben (www.fckeditor.net)
  26   */
  27  
  28  FCKStyleDef.prototype.ApplyToSelection = function()
  29  {
  30      if ( FCKSelection.GetType() == 'Text' && !this.IsObjectElement )
  31      {
  32          var oSelection = FCK.ToolbarSet.CurrentInstance.EditorWindow.getSelection() ;
  33          
  34          // Create the main element.
  35          var e = FCK.ToolbarSet.CurrentInstance.EditorDocument.createElement( this.Element ) ;
  36          
  37          for ( var i = 0 ; i < oSelection.rangeCount ; i++ )
  38          {
  39              e.appendChild( oSelection.getRangeAt(i).extractContents() ) ;
  40          }
  41          
  42          // Set the attributes.
  43          this._AddAttributes( e ) ;
  44          
  45          // Remove the duplicated elements.
  46          this._RemoveDuplicates( e ) ;
  47  
  48          var oRange = oSelection.getRangeAt(0) ;        
  49          oRange.insertNode( e ) ;
  50      }
  51      else
  52      {
  53          var oControl = FCK.ToolbarSet.CurrentInstance.Selection.GetSelectedElement() ;
  54          if ( oControl.tagName == this.Element )
  55              this._AddAttributes( oControl ) ;
  56      }
  57  }
  58  
  59  FCKStyleDef.prototype._AddAttributes = function( targetElement )
  60  {
  61      for ( var a in this.Attributes )
  62      {
  63          switch ( a.toLowerCase() )
  64          {
  65              case 'src' :
  66                  targetElement.setAttribute( '_fcksavedurl', this.Attributes[a], 0 ) ;
  67              default :
  68                  targetElement.setAttribute( a, this.Attributes[a], 0 ) ;
  69          }
  70      }
  71  }
  72  
  73  FCKStyleDef.prototype._RemoveDuplicates = function( parent )
  74  {
  75      for ( var i = 0 ; i < parent.childNodes.length ; i++ )
  76      {
  77          var oChild = parent.childNodes[i] ;
  78          
  79          if ( oChild.nodeType != 1 )
  80              continue ;
  81          
  82          this._RemoveDuplicates( oChild ) ;
  83          
  84          if ( this.IsEqual( oChild ) )
  85              FCKTools.RemoveOuterTags( oChild ) ;
  86      }
  87  }
  88  
  89  FCKStyleDef.prototype.IsEqual = function( e )
  90  {
  91      if ( e.tagName != this.Element )
  92          return false ;
  93      
  94      for ( var a in this.Attributes )
  95      {
  96          if ( e.getAttribute( a ) != this.Attributes[a] )
  97              return false ;
  98      }
  99      
 100      return true ;
 101  }
 102  
 103  FCKStyleDef.prototype._RemoveMe = function( elementToCheck )
 104  {
 105      if ( ! elementToCheck )
 106          return ;
 107  
 108      var oParent = elementToCheck.parentNode ;
 109  
 110      if ( elementToCheck.nodeType == 1 && this.IsEqual( elementToCheck ) )
 111      {
 112          if ( this.IsObjectElement )
 113          {
 114              for ( var a in this.Attributes )
 115                  elementToCheck.removeAttribute( a, 0 ) ;
 116              return ;
 117          }
 118          else
 119              FCKTools.RemoveOuterTags( elementToCheck ) ;
 120      }
 121      
 122      this._RemoveMe( oParent ) ;
 123  }


Généré le : Sun Feb 25 15:28:05 2007 par Balluche grâce à PHPXref 0.7