[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/public_html/fckeditor/editor/_source/internals/ -> fckselection_ie.js (source)

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


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics