[ Index ]
 

Code source de FCKeditor 2.4

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

title

Body

[fermer]

/editor/_source/internals/ -> fckselection_ie.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: fckselection_ie.js
  22   *     Active selection functions. (IE specific implementation)
  23   * 
  24   * File Authors:
  25   *         Frederico Caldeira Knabben (www.fckeditor.net)
  26   */
  27  
  28  // Get the selection type.
  29  FCKSelection.GetType = function()
  30  {
  31      return FCK.EditorDocument.selection.type ;
  32  }
  33  
  34  // Retrieves the selected element (if any), just in the case that a single
  35  // element (object like and image or a table) is selected.
  36  FCKSelection.GetSelectedElement = function()
  37  {
  38      if ( this.GetType() == 'Control' )
  39      {
  40          var oRange = FCK.EditorDocument.selection.createRange() ;
  41  
  42          if ( oRange && oRange.item )
  43              return FCK.EditorDocument.selection.createRange().item(0) ;
  44      }
  45  }
  46  
  47  FCKSelection.GetParentElement = function()
  48  {
  49      switch ( this.GetType() )
  50      {
  51          case 'Control' :
  52              return FCKSelection.GetSelectedElement().parentElement ;
  53          case 'None' :
  54              return null ;
  55          default :
  56              return FCK.EditorDocument.selection.createRange().parentElement() ;
  57      }
  58  }
  59  
  60  FCKSelection.SelectNode = function( node )
  61  {
  62      FCK.Focus() ;
  63      FCK.EditorDocument.selection.empty() ;
  64      var oRange ;
  65      try 
  66      {
  67          // Try to select the node as a control.
  68          oRange = FCK.EditorDocument.body.createControlRange() ;
  69          oRange.addElement( node ) ;
  70      } 
  71      catch(e) 
  72      {
  73          // If failed, select it as a text range.
  74          oRange = FCK.EditorDocument.selection.createRange() ;
  75          oRange.moveToElementText( node ) ;
  76      }
  77  
  78      oRange.select() ;
  79  }
  80  
  81  FCKSelection.Collapse = function( toStart )
  82  {
  83      FCK.Focus() ;
  84      if ( this.GetType() == 'Text' )
  85      {
  86          var oRange = FCK.EditorDocument.selection.createRange() ;
  87          oRange.collapse( toStart == null || toStart === true ) ;
  88          oRange.select() ;
  89      }
  90  }
  91  
  92  // The "nodeTagName" parameter must be Upper Case.
  93  FCKSelection.HasAncestorNode = function( nodeTagName )
  94  {
  95      var oContainer ;
  96  
  97      if ( FCK.EditorDocument.selection.type == "Control" )
  98      {
  99          oContainer = this.GetSelectedElement() ;
 100      }
 101      else
 102      {
 103          var oRange  = FCK.EditorDocument.selection.createRange() ;
 104          oContainer = oRange.parentElement() ;
 105      }
 106  
 107      while ( oContainer )
 108      {
 109          if ( oContainer.tagName == nodeTagName ) return true ;
 110          oContainer = oContainer.parentNode ;
 111      }
 112  
 113      return false ;
 114  }
 115  
 116  // The "nodeTagName" parameter must be UPPER CASE.
 117  FCKSelection.MoveToAncestorNode = function( nodeTagName )
 118  {
 119      var oNode, oRange ;
 120  
 121      if ( ! FCK.EditorDocument )
 122          return null ;
 123  
 124      if ( FCK.EditorDocument.selection.type == "Control" )
 125      {
 126          oRange = FCK.EditorDocument.selection.createRange() ;
 127          for ( i = 0 ; i < oRange.length ; i++ )
 128          {
 129              if (oRange(i).parentNode)
 130              {
 131                  oNode = oRange(i).parentNode ;
 132                  break ;
 133              }
 134          }
 135      }
 136      else
 137      {
 138          oRange  = FCK.EditorDocument.selection.createRange() ;
 139          oNode = oRange.parentElement() ;
 140      }
 141  
 142      while ( oNode && oNode.nodeName != nodeTagName )
 143          oNode = oNode.parentNode ;
 144  
 145      return oNode ;
 146  }
 147  
 148  FCKSelection.Delete = function()
 149  {
 150      // Gets the actual selection.
 151      var oSel = FCK.EditorDocument.selection ;
 152  
 153      // Deletes the actual selection contents.
 154      if ( oSel.type.toLowerCase() != "none" )
 155      {
 156          oSel.clear() ;
 157      }
 158  
 159      return oSel ;
 160  }
 161  
 162  


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