Undopanel

Objective
  • Responder
    • View
      • Panel
        • UndoPanel
  1. function UndoPanel() {
  2.     Panel.call(this);
  3.  
  4.     this._undoWidget = null;
  5.     this._redoWidget = null;
  6. }
  7.  
  8. UndoPanel.prototype = Object.create(Panel.prototype);
  9.  
  10. Object.defineProperty(UndoPanel.prototype, 'constructor', { value: UndoPanel, enumerable: false, writable: true });
  11.  
  12. UndoPanel.prototype.disable = function() {
  13.     this.disableUndo();
  14.     this.disableRedo();
  15.  
  16.     return this;
  17. }
  18.  
  19. UndoPanel.prototype.enable = function() {
  20.     this.enableUndo();
  21.     this.enableRedo();
  22.  
  23.     return this;
  24. }
  25.  
  26. UndoPanel.prototype.resetWidget = function() {
  27.     this._undoWidget.disabled = true;
  28.     this._redoWidget.disabled = true;
  29.  
  30.     return this;
  31. }
  32.  
  33. UndoPanel.prototype.setWidget = function(w) {
  34.     let undo = w.children[0], redo = w.children[1];
  35.  
  36.     Panel.prototype.setWidget.call(this, w);
  37.  
  38.     if (undo) {
  39.         undo.addEventListener('click', () => {
  40.             this.respondTo('undo', this);
  41.         });
  42.     }
  43.  
  44.     this._undoWidget = undo;
  45.  
  46.     if (redo) {
  47.         redo.addEventListener('click', () => {
  48.             this.respondTo('redo', this);
  49.         });
  50.     }
  51.  
  52.     this._redoWidget = redo;
  53.  
  54.     return this;
  55. }
  56.  
  57. UndoPanel.prototype.enableUndo = function() {
  58.     if (this._undoWidget)
  59.         this._undoWidget.disabled = false;
  60.  
  61.     return this;
  62. }
  63.  
  64. UndoPanel.prototype.disableUndo = function() {
  65.     if (this._undoWidget)
  66.         this._undoWidget.disabled = true;
  67.  
  68.     return this;
  69. }
  70.  
  71. UndoPanel.prototype.enableRedo = function() {
  72.     if (this._redoWidget)
  73.         this._redoWidget.disabled = false;
  74.  
  75.     return this;
  76. }
  77.  
  78. UndoPanel.prototype.disableRedo = function() {
  79.     if (this._redoWidget)
  80.         this._redoWidget.disabled = true;
  81.  
  82.     return this;
  83. }
SEE ALSO

Panel, Undo, Editor

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].