Implement javascript and php undo and redo functions

I want to implement the functionality of Undo and Redo not only on the client side, but also on the server side. For insatnce, I have a div containing the image and I can rotate the size and rewrite it. All basic operations for generating images. And all operations update data and image. you can say that my image is being updated and the database is being updated after every action.

Now I need to implement the functionality of Undo and Redo. I also did some research. I need the best approach to accomplish the required task. I was thinking of supporting every action of a "log-type thing" or processing it using a database or with javascript arrays, including HTML or what else?

What is the best approach to achieve my goal.

Thank,

+5
source share
2 answers

At a basic level, you will need two things:

  • an operational stack (array) that tracks the operations being performed. When the user performs the operation, you create an object that describes the operation and add it to the array. When the user removes the undo, you can remove the last element from the array.

  • each type of operation needs a save method and a cancel method. This may seem complicated, because some methods of “cancellation” are similar to methods of “preservation” (i.e., to cancel a horizontal flip, which you simply do with another flip), while others do not have such symmetry (i.e., to cancel the crop) which you will need to save the image data, as it was before the start of the crop).

"", . , , . "", .

Command (http://en.wikipedia.org/wiki/Command_pattern), Undo.

+18

All Articles