1
var FCKUndo = new Object() ;
3
FCKUndo.SavedData = new Array() ;
4
FCKUndo.CurrentIndex = -1 ;
5
FCKUndo.TypesCount = FCKUndo.MaxTypes = 25 ;
6
FCKUndo.Typing = false ;
8
FCKUndo.SaveUndoStep = function()
10
// Shrink the array to the current level.
11
FCKUndo.SavedData = FCKUndo.SavedData.slice( 0, FCKUndo.CurrentIndex + 1 ) ;
13
// Get the Actual HTML.
14
var sHtml = FCK.EditorDocument.body.innerHTML ;
16
// Cancel operation if the new step is identical to the previous one.
17
if ( FCKUndo.CurrentIndex >= 0 && sHtml == FCKUndo.SavedData[ FCKUndo.CurrentIndex ][0] )
20
// If we reach the Maximun number of undo levels, we must remove the first
21
// entry of the list shifting all elements.
22
if ( FCKUndo.CurrentIndex + 1 >= FCKConfig.MaxUndoLevels )
23
FCKUndo.SavedData.shift() ;
25
FCKUndo.CurrentIndex++ ;
27
// Get the actual selection.
29
if ( FCK.EditorDocument.selection.type == 'Text' )
30
sBookmark = FCK.EditorDocument.selection.createRange().getBookmark() ;
32
// Save the new level in front of the actual position.
33
FCKUndo.SavedData[ FCKUndo.CurrentIndex ] = [ sHtml, sBookmark ] ;
35
FCK.Events.FireEvent( "OnSelectionChange" ) ;
38
FCKUndo.CheckUndoState = function()
40
return ( FCKUndo.Typing || FCKUndo.CurrentIndex > 0 ) ;
43
FCKUndo.CheckRedoState = function()
45
return ( !FCKUndo.Typing && FCKUndo.CurrentIndex < ( FCKUndo.SavedData.length - 1 ) ) ;
48
FCKUndo.Undo = function()
50
if ( FCKUndo.CheckUndoState() )
52
// If it is the first step.
53
if ( FCKUndo.CurrentIndex == ( FCKUndo.SavedData.length - 1 ) )
55
// Save the actual state for a possible "Redo" call.
56
FCKUndo.SaveUndoStep() ;
60
FCKUndo._ApplyUndoLevel( --FCKUndo.CurrentIndex ) ;
62
FCK.Events.FireEvent( "OnSelectionChange" ) ;
66
FCKUndo.Redo = function()
68
if ( FCKUndo.CheckRedoState() )
71
FCKUndo._ApplyUndoLevel( ++FCKUndo.CurrentIndex ) ;
73
FCK.Events.FireEvent( "OnSelectionChange" ) ;
77
FCKUndo._ApplyUndoLevel = function(level)
79
var oData = FCKUndo.SavedData[ level ] ;
84
// Update the editor contents with that step data.
85
FCK.SetInnerHtml( oData[0] ) ;
86
// FCK.EditorDocument.body.innerHTML = oData[0] ;
90
var oRange = FCK.EditorDocument.selection.createRange() ;
91
oRange.moveToBookmark( oData[1] ) ;
95
FCKUndo.TypesCount = 0 ;
96
FCKUndo.Typing = false ;
b'\\ No newline at end of file'