16

Undopanel

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