add Ox.History
This commit is contained in:
parent
20137da742
commit
31d54403fb
1 changed files with 57 additions and 0 deletions
57
source/Ox.UI/js/Core/History.js
Normal file
57
source/Ox.UI/js/Core/History.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
'use strict';
|
||||
|
||||
Ox.History = function(options) {
|
||||
|
||||
options = Ox.extend({
|
||||
text: function(item) {
|
||||
return item.text;
|
||||
}
|
||||
}, options || {});
|
||||
|
||||
var history = [],
|
||||
position = 0;
|
||||
|
||||
return {
|
||||
_print: function() {
|
||||
Ox.print(JSON.stringify({history: history, position: position}));
|
||||
},
|
||||
add: function(items) {
|
||||
items = Ox.makeArray(items);
|
||||
history = history.slice(0, position).concat(items);
|
||||
position += items.length;
|
||||
return history.length;
|
||||
},
|
||||
clear: function() {
|
||||
history = [];
|
||||
position = 0;
|
||||
return history.length;
|
||||
},
|
||||
items: function() {
|
||||
return history.length;
|
||||
},
|
||||
redo: function() {
|
||||
if (position < history.length) {
|
||||
return history[position++];
|
||||
}
|
||||
},
|
||||
redoText: function() {
|
||||
if (position < history.length) {
|
||||
return options.text(history[position]);
|
||||
}
|
||||
},
|
||||
remove: function(test) {
|
||||
|
||||
},
|
||||
undo: function() {
|
||||
if (position > 0) {
|
||||
return history[--position];
|
||||
}
|
||||
},
|
||||
undoText: function() {
|
||||
if (position > 0) {
|
||||
return options.text(history[position - 1]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
};
|
Loading…
Reference in a new issue