I’m trying to use backbone.undo.js to implement undo and redo function into my html/javascript web app.
I understand that I need to do this
//Instantiate your UndoManager
var undoManager = new Backbone.UndoManager({
register: object,
track: true
})
But I do not know what the object is.
I have already created the undo buttons as follows
$(document).on("click", ".UNDO", function() {
//UNDO ONE STEP
undoManager.undo();
});
$(document).on("click", ".REDO", function() {
//REDO LAST ACTION
undoManager.redo();
});
I believe that this does not work because I have not configured "object" correctly. But the tutorial video did not go into that.
What step am I missing?
update 05/02
I think the step I am missing looks something like this
var sitebody = $('body');
var bodyModel = new Backbone.Model();
bodyModel.setElement(sitebody);
I just want to get undo working on my entire page so it seems logical that I would register the body. What am I missing?
This code does not work.
2
Answers
I ended up writing my own undo redo script. It was a lot easier than I thought it would be.
Pro tip: video tutorials are nice, but make sure to always read the written documentation as well. It tends to include details that videos will omit for brevity.
In this case, the writing under the video explains that
register
should be a model, a collection or an array of models and collections.