-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInputStack.js
53 lines (48 loc) · 1022 Bytes
/
InputStack.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// InputStack.js - InputStack...
// see: https://github.com/jzaefferer/undo
//
"use strict";
function InputStack() {
this.init();
}
InputStack.prototype = {
init: function () {
this.aInput = [];
this.iStackPosition = -1;
return this;
},
getInput: function () {
return this.aInput[this.iStackPosition];
},
clearRedo: function () {
this.aInput = this.aInput.slice(0, this.iStackPosition + 1);
return this;
},
save: function (sInput) {
this.clearRedo();
this.aInput.push(sInput);
this.iStackPosition += 1;
return this;
},
canUndo: function () {
return this.iStackPosition >= 0;
},
canUndoKeepOne: function () {
return this.iStackPosition > 0;
},
undo: function () {
this.iStackPosition -= 1;
return this.getInput();
},
canRedo: function () {
return this.iStackPosition < this.aInput.length - 1;
},
redo: function () {
this.iStackPosition += 1;
return this.getInput();
}
};
if (typeof module !== "undefined" && module.exports) {
module.exports = InputStack;
}
// end