[ Index ]
 

Code source de vtiger CRM 5.0.2

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

title

Body

[fermer]

/include/fckeditor/editor/_source/classes/ -> fckstyledef_ie.js (source)

   1  /*
   2   * FCKeditor - The text editor for internet
   3   * Copyright (C) 2003-2005 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_ie.js
  14   *     FCKStyleDef Class: represents a single stylke definition. (IE specific)
  15   * 
  16   * File Authors:
  17   *         Frederico Caldeira Knabben (fredck@fckeditor.net)
  18   */
  19  
  20  FCKStyleDef.prototype.ApplyToSelection = function()
  21  {
  22      var oSelection = FCK.EditorDocument.selection ;
  23      
  24      if ( oSelection.type == 'Text' )
  25      {
  26          var oRange = oSelection.createRange() ;
  27          
  28          // Create the main element.
  29          var e = document.createElement( this.Element ) ;
  30          e.innerHTML = oRange.htmlText ;
  31          
  32          // Set the attributes.
  33          this._AddAttributes( e ) ;
  34          
  35          // Remove the duplicated elements.
  36          this._RemoveDuplicates( e ) ;
  37          
  38          // Replace the selection with the resulting HTML.
  39          oRange.pasteHTML( e.outerHTML ) ;
  40      }
  41      else if ( oSelection.type == 'Control' )
  42      {
  43          var oControl = FCKSelection.GetSelectedElement() ;
  44          if ( oControl.tagName == this.Element )
  45              this._AddAttributes( oControl ) ;
  46      }
  47  }
  48  
  49  FCKStyleDef.prototype._AddAttributes = function( targetElement )
  50  {
  51      for ( var a in this.Attributes )
  52      {
  53          switch ( a.toLowerCase() )
  54          {
  55              case 'style' :
  56                  targetElement.style.cssText = this.Attributes[a] ;
  57                  break ;
  58                  
  59              case 'class' :
  60                  targetElement.setAttribute( 'className', this.Attributes[a], 0 ) ;
  61                  break ;
  62                  
  63              default :
  64                  targetElement.setAttribute( a, this.Attributes[a], 0 ) ;
  65          }
  66      }
  67  }
  68  
  69  FCKStyleDef.prototype._RemoveDuplicates = function( parent )
  70  {
  71      for ( var i = 0 ; i < parent.children.length ; i++ )
  72      {
  73          var oChild = parent.children[i] ;
  74          this._RemoveDuplicates( oChild ) ;
  75          
  76          if ( this.IsEqual( oChild ) )
  77              FCKTools.RemoveOuterTags( oChild ) ;
  78      }
  79  }
  80  
  81  FCKStyleDef.prototype.IsEqual = function( e )
  82  {
  83      if ( e.tagName != this.Element )
  84          return false ;
  85      
  86      for ( var a in this.Attributes )
  87      {
  88          switch ( a.toLowerCase() )
  89          {
  90              case 'style' :
  91                  if ( e.style.cssText.toLowerCase() != this.Attributes[a].toLowerCase() )
  92                      return false ;
  93                  break ;
  94              case 'class' :
  95                  if ( e.getAttribute( 'className', 0 ) != this.Attributes[a] )
  96                      return false ;
  97                  break ;
  98              default :
  99                  if ( e.getAttribute( a, 0 ) != this.Attributes[a] )
 100                      return false ;
 101          }
 102      }
 103      
 104      return true ;
 105  }
 106  
 107  FCKStyleDef.prototype._RemoveMe = function( elementToCheck )
 108  {
 109      if ( ! elementToCheck )
 110          return ;
 111  
 112      var oParent = elementToCheck.parentElement ;
 113  
 114      if ( this.IsEqual( elementToCheck ) )
 115      {
 116          if ( this.IsObjectElement )
 117          {
 118              for ( var a in this.Attributes )
 119              {
 120                  switch ( a.toLowerCase() )
 121                  {
 122                      case 'class' :
 123                          elementToCheck.removeAttribute( 'className', 0 ) ;
 124                          break ;
 125                      default :
 126                          elementToCheck.removeAttribute( a, 0 ) ;
 127                  }
 128              }
 129              return ;
 130          }
 131          else
 132              FCKTools.RemoveOuterTags( elementToCheck ) ;
 133      }
 134      
 135      this._RemoveMe( oParent ) ;
 136  }


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7