0

I am using backbone undo js for undo and redo,I need to check whether undo or redo is available. is there any method like hasundo() and hasredo()

   View = Backbone.View.extend({
            initialize: function () {
                // If the model's value changes, update the view
                this.model.on("change:value", function (model, value, options) {
                    if (value != this.$el.html()) {
                        this.$el.html(value);
                        //need to check here,and add code for enable or disable my undo/redo buttons

                    }
                }, this);
            }
  })
Shijin TR
  • 7,516
  • 10
  • 55
  • 122

2 Answers2

1

You need to check this "manually" by seeing if the attribute exists and is of type "function".

See this answer: Javascript check if function exists

Community
  • 1
  • 1
David Sulc
  • 25,946
  • 3
  • 52
  • 54
  • Then what you should do is write a `hasUndo` function in your model, and only show the "undo" button in the view if `this.model.hasUndo()` is true. – David Sulc Apr 04 '14 at 09:23
1

There's an isAvailable function built right into Backbone.Undo.js specifically for your use case. Read the documentation here. You just need to write

if (myUndoManager.isAvailable("undo")) { /* doSomething */ }

As this question is almost four months old you probably already solved this problem somehow. However, I still wanted to drop the answer here for completeness' sake. Maybe it helps others who stumple upon this thread. :)