12 |
- // chronology.js v0.4 - Copyright (c) 2013 Wout Fierens - Licensed under the MIT license
- (function(){var e=function(e){this.settings={limit:20,call:true};this.set(e);this.clear()};e.prototype.set=function(e){for(var t in e)this.settings[t]=e[t];return this};e.prototype.add=function(t){this.redos=[];if(!t instanceof e.Occurence)t=new e.Occurence(t);this.undos.unshift(t);if(t.call===true||typeof t.call=="undefined"&&this.settings.call===true)t.up();if(this.settings.limit)this.undos.splice(this.settings.limit);if(typeof this.settings.onAdd=="function")this.settings.onAdd(t);return this};e.prototype.clear=function(){this.redos=[];this.undos=[];if(typeof this.settings.onClear=="function")this.settings.onClear();return this};e.prototype.revert=function(){var e;while(e=this.undos.shift())e.down();return this.clear()};e.prototype.undo=function(){var e;if(e=this.undos.shift()){this.redos.unshift(e);e.down();if(typeof this.settings.onUndo=="function")this.settings.onUndo(e);if(this.undos.length==0&&typeof this.settings.onBegin=="function")this.settings.onBegin(e)}return this};e.prototype.redo=function(){var e;if(e=this.redos.shift()){this.undos.unshift(e);e.up();if(typeof this.settings.onRedo=="function")this.settings.onRedo(e);if(this.redos.length==0&&typeof this.settings.onEnd=="function")this.settings.onEnd(e)}return this};e.Occurence=function(e){e=e||{};this.up=e.up||function(){};this.down=e.down||function(){}};if(typeof define==="function"&&define.amd)define(function(){return e});else if(typeof exports!=="undefined")exports.Chronology=e;else this.Chronology=e}).call(this)
|