[ Index ]
 

Code source de FCKeditor 2.4

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

title

Body

[fermer]

/editor/_source/internals/ -> fckundo_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: fckundo_ie.js
  22   *     IE specific implementation for the Undo/Redo system.
  23   * 
  24   * File Authors:
  25   *         Frederico Caldeira Knabben (www.fckeditor.net)
  26   */
  27  
  28  var FCKUndo = new Object() ;
  29  
  30  FCKUndo.SavedData = new Array() ;
  31  FCKUndo.CurrentIndex = -1 ;
  32  FCKUndo.TypesCount = FCKUndo.MaxTypes = 25 ;
  33  FCKUndo.Typing = false ;
  34  
  35  FCKUndo.SaveUndoStep = function()
  36  {
  37      if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
  38          return ;
  39  
  40      // Shrink the array to the current level.
  41      FCKUndo.SavedData = FCKUndo.SavedData.slice( 0, FCKUndo.CurrentIndex + 1 ) ;
  42  
  43      // Get the Actual HTML.
  44      var sHtml = FCK.EditorDocument.body.innerHTML ;
  45  
  46      // Cancel operation if the new step is identical to the previous one.
  47      if ( FCKUndo.CurrentIndex >= 0 && sHtml == FCKUndo.SavedData[ FCKUndo.CurrentIndex ][0] )
  48          return ;
  49  
  50      // If we reach the Maximun number of undo levels, we must remove the first
  51      // entry of the list shifting all elements.
  52      if ( FCKUndo.CurrentIndex + 1 >= FCKConfig.MaxUndoLevels )
  53          FCKUndo.SavedData.shift() ;
  54      else
  55          FCKUndo.CurrentIndex++ ;
  56  
  57      // Get the actual selection.
  58      var sBookmark ;
  59      if ( FCK.EditorDocument.selection.type == 'Text' )
  60          sBookmark = FCK.EditorDocument.selection.createRange().getBookmark() ;
  61  
  62      // Save the new level in front of the actual position.
  63      FCKUndo.SavedData[ FCKUndo.CurrentIndex ] = [ sHtml, sBookmark ] ;
  64  
  65      FCK.Events.FireEvent( "OnSelectionChange" ) ;
  66  }
  67  
  68  FCKUndo.CheckUndoState = function()
  69  {
  70      return ( FCKUndo.Typing || FCKUndo.CurrentIndex > 0 ) ;
  71  }
  72  
  73  FCKUndo.CheckRedoState = function()
  74  {
  75      return ( !FCKUndo.Typing && FCKUndo.CurrentIndex < ( FCKUndo.SavedData.length - 1 ) ) ;
  76  }
  77  
  78  FCKUndo.Undo = function()
  79  {
  80      if ( FCKUndo.CheckUndoState() )
  81      {
  82          // If it is the first step.
  83          if ( FCKUndo.CurrentIndex == ( FCKUndo.SavedData.length - 1 ) )
  84          {
  85              // Save the actual state for a possible "Redo" call.
  86              FCKUndo.SaveUndoStep() ;
  87          }
  88  
  89          // Go a step back.
  90          FCKUndo._ApplyUndoLevel( --FCKUndo.CurrentIndex ) ;
  91  
  92          FCK.Events.FireEvent( "OnSelectionChange" ) ;
  93      }
  94  }
  95  
  96  FCKUndo.Redo = function()
  97  {
  98      if ( FCKUndo.CheckRedoState() )
  99      {
 100          // Go a step forward.
 101          FCKUndo._ApplyUndoLevel( ++FCKUndo.CurrentIndex ) ;
 102  
 103          FCK.Events.FireEvent( "OnSelectionChange" ) ;
 104      }
 105  }
 106  
 107  FCKUndo._ApplyUndoLevel = function(level)
 108  {
 109      var oData = FCKUndo.SavedData[ level ] ;
 110      
 111      if ( !oData )
 112          return ;
 113  
 114      // Update the editor contents with that step data.
 115      FCK.SetInnerHtml( oData[0] ) ;
 116  //    FCK.EditorDocument.body.innerHTML = oData[0] ;
 117  
 118      if ( oData[1] ) 
 119      {
 120          var oRange = FCK.EditorDocument.selection.createRange() ;
 121          oRange.moveToBookmark( oData[1] ) ;
 122          oRange.select() ;
 123      }
 124      
 125      FCKUndo.TypesCount = 0 ; 
 126      FCKUndo.Typing = false ;
 127  }


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