[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 var FCKUndo = new Object() ; 2 3 FCKUndo.SavedData = new Array() ; 4 FCKUndo.CurrentIndex = -1 ; 5 FCKUndo.TypesCount = FCKUndo.MaxTypes = 25 ; 6 FCKUndo.Typing = false ; 7 8 FCKUndo.SaveUndoStep = function() 9 { 10 // Shrink the array to the current level. 11 FCKUndo.SavedData = FCKUndo.SavedData.slice( 0, FCKUndo.CurrentIndex + 1 ) ; 12 13 // Get the Actual HTML. 14 var sHtml = FCK.EditorDocument.body.innerHTML ; 15 16 // Cancel operation if the new step is identical to the previous one. 17 if ( FCKUndo.CurrentIndex >= 0 && sHtml == FCKUndo.SavedData[ FCKUndo.CurrentIndex ][0] ) 18 return ; 19 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() ; 24 else 25 FCKUndo.CurrentIndex++ ; 26 27 // Get the actual selection. 28 var sBookmark ; 29 if ( FCK.EditorDocument.selection.type == 'Text' ) 30 sBookmark = FCK.EditorDocument.selection.createRange().getBookmark() ; 31 32 // Save the new level in front of the actual position. 33 FCKUndo.SavedData[ FCKUndo.CurrentIndex ] = [ sHtml, sBookmark ] ; 34 35 FCK.Events.FireEvent( "OnSelectionChange" ) ; 36 } 37 38 FCKUndo.CheckUndoState = function() 39 { 40 return ( FCKUndo.Typing || FCKUndo.CurrentIndex > 0 ) ; 41 } 42 43 FCKUndo.CheckRedoState = function() 44 { 45 return ( !FCKUndo.Typing && FCKUndo.CurrentIndex < ( FCKUndo.SavedData.length - 1 ) ) ; 46 } 47 48 FCKUndo.Undo = function() 49 { 50 if ( FCKUndo.CheckUndoState() ) 51 { 52 // If it is the first step. 53 if ( FCKUndo.CurrentIndex == ( FCKUndo.SavedData.length - 1 ) ) 54 { 55 // Save the actual state for a possible "Redo" call. 56 FCKUndo.SaveUndoStep() ; 57 } 58 59 // Go a step back. 60 FCKUndo._ApplyUndoLevel( --FCKUndo.CurrentIndex ) ; 61 62 FCK.Events.FireEvent( "OnSelectionChange" ) ; 63 } 64 } 65 66 FCKUndo.Redo = function() 67 { 68 if ( FCKUndo.CheckRedoState() ) 69 { 70 // Go a step forward. 71 FCKUndo._ApplyUndoLevel( ++FCKUndo.CurrentIndex ) ; 72 73 FCK.Events.FireEvent( "OnSelectionChange" ) ; 74 } 75 } 76 77 FCKUndo._ApplyUndoLevel = function(level) 78 { 79 var oData = FCKUndo.SavedData[ level ] ; 80 81 if ( !oData ) 82 return ; 83 84 // Update the editor contents with that step data. 85 FCK.SetInnerHtml( oData[0] ) ; 86 // FCK.EditorDocument.body.innerHTML = oData[0] ; 87 88 if ( oData[1] ) 89 { 90 var oRange = FCK.EditorDocument.selection.createRange() ; 91 oRange.moveToBookmark( oData[1] ) ; 92 oRange.select() ; 93 } 94 95 FCKUndo.TypesCount = 0 ; 96 FCKUndo.Typing = false ; 97 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |