source: branches/1.2/workflow/js/fckeditor/editor/_source/internals/fckundo_ie.js @ 1349

Revision 1349, 3.1 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

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