65

Inspector

Objective
  • Responder
    • View
      • Inspector
  1. function Inspector() {
  2.     View.call(this);
  3. }
  4.  
  5. Inspector.prototype = Object.create(View.prototype);
  6.  
  7. Object.defineProperty(Inspector.prototype, 'constructor', { value: Inspector, enumerable: false, writable: true });
  8.  
  9. Inspector.prototype.validate = function(val) {
  10.     return true;
  11. };
  12.  
  13. Inspector.prototype.normalize = function(val) {
  14.     return val;
  15. };
  16.  
  17. Inspector.prototype.get = function() {
  18.     return this._value;
  19. };
  20.  
  21. Inspector.prototype.set = function(val) {
  22.     if (!this.validate(val))
  23.         return false;
  24.  
  25.     val = this.normalize(val);
  26.  
  27.     if (this._value !== val) {
  28.         this._value = val;
  29.  
  30.         if (this.interfaced())
  31.             this.resetWidget();
  32.     }
  33.  
  34.     return true;
  35. };
  36.  
  37. Inspector.prototype.reset = function() {
  38.     if (!this._widget)
  39.         return false;
  40.  
  41.     let val = this._widget.value;
  42.  
  43.     if (!this.validate(val))
  44.         return false;
  45.  
  46.     this._value = this.normalize(val);
  47.  
  48.     return true;
  49. };
  50.  
  51. Inspector.prototype.changeCallback = function(e) {
  52.     let val = e.target.value;
  53.  
  54.     if (this.validate(val)) {
  55.         val = this.normalize(val);
  56.  
  57.         if (this._value !== val) {
  58.             this._value = val;
  59.  
  60.             this.respondTo('inspectorValueChanged', this);
  61.         }
  62.     }
  63. };
  64.  
  65. Inspector.prototype.resetWidget = function() {
  66.     if (this._widget)
  67.         this._widget.value = this._value;
  68.  
  69.     return this;
  70. };
  71.  
  72. Inspector.prototype.setWidget = function(w) {
  73.     w.addEventListener('change', (e) => this.changeCallback(e));
  74.  
  75.     View.prototype.setWidget.call(this, w);
  76.  
  77.     return this;
  78. };
SEE ALSO

View, BooleanInspector, NumberInspector, StringInspector, SelectInspector, OptionInspector, SelectionInspector, ImageInspector, ColorInspector, RangeInspector, DimensionInspector

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].