From 31d54403fbab5c299be4538c1d53ad04d6aadac6 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Sat, 3 Aug 2013 13:58:36 +0000 Subject: [PATCH] add Ox.History --- source/Ox.UI/js/Core/History.js | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 source/Ox.UI/js/Core/History.js diff --git a/source/Ox.UI/js/Core/History.js b/source/Ox.UI/js/Core/History.js new file mode 100644 index 00000000..61fb93f9 --- /dev/null +++ b/source/Ox.UI/js/Core/History.js @@ -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]); + } + } + }; + +};