Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undo/redo exception when there are no stored elements #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions djaodjin-annotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ MIT License
'</div></div>';
} else {
self.$tool = '<div id="" style="display:inline-block">' +
'<button id="undoaction">UNDO</button>';
'<button id="undoaction" class="annotate-undo">UNDO</button>';
if (self.options.unselectTool) {
self.$tool += '<input type="radio" name="' + self.toolOptionId +
'" data-tool="null">NO TOOL SELECTED';
Expand All @@ -128,7 +128,7 @@ MIT License
'<input type="radio" name="' + self.toolOptionId +
'" data-tool="arrow">ARROW<input type="radio" name="' +
self.toolOptionId + '" data-tool="pen">PEN' +
'<button id="redoaction"' +
'<button id="redoaction" class="annotate-redo"' +
'title="Redo the last undone annotation">REDO</button>' +
'</div>';
}
Expand Down Expand Up @@ -339,26 +339,37 @@ MIT License
},
checkUndoRedo: function() {
var self = this;
self.$tool.children('.annotate-redo').attr('disabled', self.storedUndo
.length === 0);
self.$tool.children('.annotate-undo').attr('disabled', self.storedElement
.length === 0);
self.$tool.find('.annotate-redo').attr(
'disabled',
self.storedUndo.length === 0
);
self.$tool.find('.annotate-undo').attr(
'disabled',
self.storedElement.length === 0
);
},
undoaction: function(event) {
event.preventDefault();
var self = this;
self.storedUndo.push(self.storedElement[self.storedElement.length -
1]);
self.storedElement.pop();
var action = self.storedElement.pop();

if (action) {
self.storedUndo.push(action);
}

self.checkUndoRedo();
self.clear();
self.redraw();
},
redoaction: function(event) {
event.preventDefault();
var self = this;
self.storedElement.push(self.storedUndo[self.storedUndo.length - 1]);
self.storedUndo.pop();
var action = self.storedUndo.pop();

if (action) {
self.storedElement.push(action);
}

self.checkUndoRedo();
self.clear();
self.redraw();
Expand Down