[ Index ]
 

Code source de FCKeditor 2.4

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

title

Body

[fermer]

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


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