Commit d354a561 authored by bbaer's avatar bbaer
Browse files

History for undo redo added

parent 23b8b74d
Pipeline #1665 passed with stage
in 2 minutes and 13 seconds
/**
* @author Benjamin Baer <benjamin.baer@math.uzh.ch>
*/
/* global $ */
/**
* Qfq Namespace
*
* @namespace QfqNS
*/
var QfqNS = QfqNS || {};
(function (n) {
'use strict';
/**
* A custom history to use for undo and redo functionality.
**/
n.History = function() {
this.history = [];
this.pointer = 0;
};
n.History.prototype.put = function(object) {
if (this.pointerAtCurrent()) {
this._removeForwardHistory();
}
this.history.push(object);
this.pointer = this.history.length - 1;
};
n.History.prototype.back = function() {
if (this.canGoBack()) {
this.pointer--;
return this.history[this.pointer];
} else {
console.log("At the beginning of history");
return false;
}
};
n.History.prototype.forward = function() {
if (this.canGoForward()) {
this.pointer++;
return this.history[this.pointer];
} else {
console.log("At the end of history");
return false;
}
};
n.History.prototype.canGoBack = function() {
return this.pointer > 0;
};
n.History.prototype.canGoForward = function() {
return this.pointer < this.history.length - 1;
};
n.History.prototype.pointerAtCurrent = function() {
return this.pointer === this.history.length - 1;
};
n.History.prototype._removeForwardHistory = function() {
var tempPointer = this.history.length - 1;
while (tempPointer > this.pointer && this.history.length > 0) {
this.history.pop();
tempPointer--;
}
};
})(QfqNS);
\ No newline at end of file
......@@ -63,6 +63,7 @@ $(function (n) {
this.mouseInsideCanvas = false;
this.imageOutput = '';
this.localStore = new n.LocalStorage("fabric");
this.history = new n.History();
// Handles button states and generation of said buttons. Should be renamed.
function ModeSettings() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment