YUI.add("moodle-atto_undo-button",function(t,e){t.namespace("M.atto_undo").Button=t.Base.create("button",t.M.editor_atto.EditorPlugin,[],{_maxUndos:40,_undoStack:null,_redoStack:null,initializer:function(){this._undoStack=[],this._redoStack=[],this.addButton({title:"undo",icon:"e/undo",callback:this._undoHandler,buttonName:"undo",keys:90}),this.addButton({title:"redo",icon:"e/redo",callback:this._redoHandler,buttonName:"redo",keys:89}),this.get("host").on("pluginsloaded",function(){this._addToUndo(this._getHTML()),this.get("host").on("atto:selectionchanged",this._changeListener,this)},this),this._updateButtonsStates()},_addToRedo:function(t){this._redoStack.push(t)},_addToUndo:function(t,e){for(void 0===e&&(e=!1),this._undoStack[this._undoStack.length-1]!==t&&(this._undoStack.push(t),e&&(this._redoStack=[]));this._undoStack.length>this._maxUndos;)this._undoStack.shift()},_getHTML:function(){return this.get("host").getCleanHTML()},_getRedo:function(){return this._redoStack.pop()},_getUndo:function(t){if(1===this._undoStack.length)return this._undoStack[0];var e=this._undoStack.pop();return e===t&&(e=this._undoStack.pop()),0===this._undoStack.length&&this._addToUndo(e),e},_restoreValue:function(t){this.editor.setHTML(t),this._addToUndo(t)},_updateButtonsStates:function(){1<this._undoStack.length?this.enableButtons("undo"):this.disableButtons("undo"),0<this._redoStack.length?this.enableButtons("redo"):this.disableButtons("redo")},_undoHandler:function(t){t.preventDefault();var e=this._getHTML(),o=this._getUndo(e);e!==o&&(this._restoreValue(o),this._addToRedo(e)),this._updateButtonsStates()},_redoHandler:function(t){if(t.preventDefault(),0!==this._redoStack.length){var e=this._getHTML(),o=this._getRedo();e!==o&&this._restoreValue(o),this._updateButtonsStates()}},_changeListener:function(t){t.event&&-1!==t.event.type.indexOf("key")&&39!==t.event.keyCode&&37!==t.event.keyCode&&40!==t.event.keyCode&&38!==t.event.keyCode||(this._addToUndo(this._getHTML(),!0),this._updateButtonsStates())}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]});