3

SequenceInspector

Objective
  • Responder
    • View
      • Inspector
        • SequenceInspector
Objective.js
I

Type in Hello! and press Enter. The length of the text is limited to 12 characters. Try entering <b>Bold</b>. HTML tags are escaped. Select a character font in the list. Check italic I to change the appearance of the text. NOTE: The fonts by Google are downloaded on demand.

In the console of the browser, lock the whole interface by blocking the inspector:

inspector.disable()

Unlock the interface:

inspector.enable()

Display the value of the inspector:

inspector.get()
Object { "font": "Open Sans", "text": "Objective.js", "italic": false }
  1. function SequenceInspector(inspectors) {
  2.     Inspector.call(this);
  3.  
  4.     for (let p in inspectors)
  5.         inspectors[p].addNextResponder(this);
  6.  
  7.     this._inspectors = inspectors;
  8. }
  9.  
  10. SequenceInspector.prototype = Object.create(Inspector.prototype);
  11.  
  12. Object.defineProperty(SequenceInspector.prototype, 'constructor', { value: SequenceInspector, enumerable: false, writable: true });
  13.  
  14. SequenceInspector.prototype.clone = function() {
  15.     let clone = Inspector.prototype.clone.call(this);
  16.  
  17.     for (let p in this._inspectors)
  18.         clone[p] = this._inspectors[p].clone();
  19.  
  20.     return clone;
  21. }
  22.  
  23. SequenceInspector.prototype.get = function() {
  24.     let value = {};
  25.  
  26.     for (let p in this._inspectors)
  27.         value[p] = this._inspectors[p].get();
  28.  
  29.     return value;
  30. }
  31.  
  32. SequenceInspector.prototype.set = function(val) {
  33.     for (let p in val)
  34.         if (! this._inspectors[p].set(val[p]))
  35.             return false;
  36.  
  37.     return true;
  38. }
  39.  
  40. SequenceInspector.prototype.reset = function() {
  41.     for (let p in this._inspectors)
  42.         if (! this._inspectors[p].reset())
  43.             return false;
  44.  
  45.     return true;
  46. }
  47.  
  48. SequenceInspector.prototype.disable = function() {
  49.     for (let p in this._inspectors)
  50.         this._inspectors[p].disable();
  51.  
  52.     return this;
  53. }
  54.  
  55. SequenceInspector.prototype.enable = function() {
  56.     for (let p in this._inspectors)
  57.         this._inspectors[p].enable();
  58.  
  59.     return this;
  60. }
  61.  
  62. SequenceInspector.prototype.inspectorFor = function(p) {
  63.     return this._inspectors[p];
  64. }
  65.  
  66. SequenceInspector.prototype.inspectorValueChanged = function(sender) {
  67.     this.nextRespondTo('inspectorValueChanged', this);
  68.  
  69.     return true;
  70. }
  71.  
  72. SequenceInspector.prototype.resetWidget = function() {
  73.     for (let p in this._inspectors)
  74.         this._inspectors[p].resetWidget();
  75.  
  76.     return this;
  77. }
  78.  
  79. SequenceInspector.prototype.setWidget = function(w) {
  80.     View.prototype.setWidget.call(this, w);
  81.  
  82.     return this;
  83. }
  84.  
  85. SequenceInspector.prototype.cloneWidget = function() {
  86.     for (let p in this._inspectors)
  87.         this._inspectors[p].cloneWidget();
  88.  
  89.     return View.prototype.cloneWidget.call(this);
  90. }
  91.  
  92. SequenceInspector.prototype.destroyWidget = function() {
  93.     for (let p in this._inspectors)
  94.         this._inspectors[p].destroyWidget();
  95.  
  96.     View.prototype.destroyWidget.call(this);
  97.  
  98.     return this;
  99. }
Test
  1. <?php $text='Objective.js'; ?>
  2. <?php $fontlist=array('Acme', 'Fugaz One', 'Inconsolata', 'Lobster', 'Long Cang', 'Modak', 'Open Sans', 'Play', 'Slackey'); ?>
  3. <?php $font='Open Sans'; ?>
  4. <?php $fontSize=32; ?>
  5. <?php $color='#333'; ?>
  6. <?php $bg='#fd1'; ?>
  7. <?php $minlen=2; ?>
  8. <?php $maxlen=12; ?>
  1. <?php foreach($fontlist as $f): ?><?php head('font', $f); ?><?php endforeach; ?>
  1. <?php $id=uniqid('id'); ?>
  1. .test_display {
  2.     width: 240px;
  3.     height: 135px;
  4.     display: flex;
  5.     align-items: center;
  6.     justify-content: center;
  7.     background: <?php echo $bg; ?>;
  8.     color: <?php echo $color; ?>;
  9.     font-family: "<?php echo $font; ?>", sans-serif;
  10.     font-size: <?php echo $fontSize; ?>px;
  11.     margin-bottom: 10px;
  12.     border-radius: 3px;
  13. }
  1. <div id="<?php echo $id; ?>" class="noprint">
  2. <div class="test_display"><?php echo $text; ?></div>
  3. <div class="ojs">
  4. <div>
  5. <span>
  6. <input id="text_input" type="text" size="10" maxlength="<?php echo $maxlen; ?>" spellcheck="false"/>
  7. <select id="text_font" size="1">
  8. <?php foreach($fontlist as $f): ?>
  9. <option value="<?php echo $f; ?>"<?php if ($f == $font): ?> selected="selected"<?php  endif; ?>><?php echo $f; ?></option>
  10. <?php endforeach; ?>
  11. </select>
  12. <span class="nowrap"><input id="text_italic" type="checkbox"/><span class="btn_edit btn_i">I</span></span>
  13. </span>
  14. </div>
  15. </div>
  16. </div>
  1. <?php head('javascript', '/objectivejs/Objective.js'); ?>
  2. <?php head('javascript', '/objectivejs/Responder.js'); ?>
  3. <?php head('javascript', '/objectivejs/View.js'); ?>
  4. <?php head('javascript', '/objectivejs/Inspector.js'); ?>
  5. <?php head('javascript', '/objectivejs/SelectInspector.js'); ?>
  6. <?php head('javascript', '/objectivejs/StringInspector.js'); ?>
  7. <?php head('javascript', '/objectivejs/BooleanInspector.js'); ?>
  8. <?php head('javascript', '/objectivejs/SequenceInspector.js'); ?>
  1. function Tester(display, inspector) {
  2.     Responder.call(this);
  3.  
  4.     this._display = display;
  5.  
  6.     inspector.addNextResponder(this);
  7.  
  8.     this._inspector = inspector;
  9. }
  10.  
  11. Tester.prototype = Object.create(Responder.prototype);
  12.  
  13. Object.defineProperty(Tester.prototype, 'constructor', { value: Tester, enumerable: false, writable: true });
  14.  
  15. Tester.prototype.inspectorValueChanged = function(sender) {
  16.     if (sender === this._inspector) {
  17.         const {font, text, italic} = sender.get();
  18.  
  19.         this._display.style.fontStyle = italic ? 'italic' : 'normal';
  20.         this._display.style.fontFamily = `"${font}", sans-serif`;
  21.         this._display.innerHTML = `<span>${text}</span>`;
  22.     }
  23.  
  24.     return true;
  25. }
  1. const fontnames = [<?php echo implode(',', array_map(function($s) { return "'$s'"; }, $fontlist)); ?>];
  2.  
  3. const fontInspector = new SelectInspector('<?php echo $font; ?>', { tags: fontnames });
  4.  
  5. const textInspector = new StringInspector('<?php echo $text; ?>', { min: <?php echo $minlen; ?>, max: <?php echo $maxlen; ?>, trim: true, required: true, escapeHTML: true });
  6.  
  7. const italicInspector = new BooleanInspector();
  8.  
  9. const container = document.querySelector('#<?php echo $id; ?>');
  10.  
  11. const display = container.querySelector('.test_display');
  12.  
  13. fontInspector.setManagedWidget(container.querySelector('#text_font')).resetWidget();
  14. textInspector.setManagedWidget(container.querySelector('#text_input')).resetWidget();
  15. italicInspector.setManagedWidget(container.querySelector('#text_italic')).resetWidget();
  16.  
  17. const inspector = new SequenceInspector({ font: fontInspector, text: textInspector, italic: italicInspector });
  18.  
  19. inspector.setManagedWidget(container.querySelector('.ojs > div'));
SEE ALSO

Inspector, NumberInspector, StringInspector, SelectInspector, SetOfInspector

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