Clickago.js is a lightweight framework for implementing Undo/Redo functionality on a web page.
Use this method to register events.
Example:
var message, tracker;
tracker = new Clickago();
message = function (text) {
alert(text);
};
tracker.register({
method: message,
thisArg: window,
arguments: ["You're fired!"]
}, {
method: message,
thisArg: window,
arguments: ["My bad. You can keep your job."]
});
message("You're fired!"); // Alerts "You're fired!"
This method will get the newest rollbackOptions
and evaluate it.
Example:
tracker.undo(); // Alerts "My bad. You can keep your job."
This method will get the newest actionOptions
and evaluate it.
Example:
tracker.redo(); // Alerts "You're fired!"
Boolean values indicating whether you can use .undo()
and/or .redo()
.
Disables .undo()
and .redo()
methods (you can still register new actions).
Example:
tracker.disable();
tracker.undo(); // returns undefined;
trakcer.canUndo; // false
tracker.canRedo; // false
Enables .undo()
and .redo()
.
Example:
tracker.enable();
tracker.undo(); // Alerts "My bad. You can keep your job."
(function () {
"use strict";
var tracker, comments;
// Initialise Clickago class.
tracker = new Clickago();
comments = [];
// Inserting comments to the collection.
function insertComment (comment) {
comments[comments.length] = comment;
};
// Removing comments from the collection.
function removeComment (index) {
comments.splice(index, 1);
};
// Wraper function around `insertComment` which registers the events.
function addComment (comment) {
tracker.register({
method: insertComment,
thisArg: null,
arguments: [comment]
}, {
method: removeComment,
thisArg: null,
arguments: [comments.length]
});
insertComment(comment);
}
// Wraper function around `insertComment` which registers the events.
function deleteComment (index) {
tracker.register({
method: removeComment,
thisArg: null,
arguments: [index]
}, {
method: insertComment,
thisArg: null,
arguments: [comments[index]]
});
removeComment(index);
};
addComment("Comment 1");
console.log(comments); // Logs ["Comment 1"]
addComment("Comment 2");
console.log(comments); // Logs ["Comment 1", "Comment 2"]
addComment("Comment 3");
console.log(comments); // Logs ["Comment 1", "Comment 2", "Comment 3"]
deleteComment(2);
console.log(comments); // Logs ["Comment 1", "Comment 2"]
tracker.undo();
console.log(comments); // Logs ["Comment 1", "Comment 2", "Comment 3"]
tracker.redo();
console.log(comments); // Logs ["Comment 1", "Comment 2"]
tracker.undo();
console.log(comments); // Logs ["Comment 1", "Comment 2", "Comment 3"]
tracker.undo();
console.log(comments); // Logs ["Comment 1", "Comment 2"]
tracker.undo();
console.log(comments); // Logs ["Comment 1"]
tracker.undo();
console.log(comments); // Logs []
})();