Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

32
LINES

< > BotCompany Repo | #1032454 // HSlider - HTML range slider

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5586L/32K).

1  
sclass HSlider {
2  
  S id = aGlobalID(), name, label, unit;
3  
  double min, max, value, step = 1;
4  
  bool useWebSocket = true;
5  
  
6  
  !include #1028121 // setField + change()
7  
8  
  bool requiresWebSocket() { true; }
9  
  
10  
  // ID of numerical value display
11  
  S valueID() { ret id + "_value"; }
12  
13  
  S html() {
14  
    ret div(span(str(value), id := valueID())
15  
      + prependSpaceIfNempty(unit), style := "width: 8ch; display: inline-block; text-align: right")
16  
      + " " + tag input("", type := "range", +id, +name, +min, +max, +value, +step,
17  
      oninput := !useWebSocket ? null : jsDollarVars([[
18  
        document.getElementById($valueID).innerHTML = this.value;
19  
        if (typeof wsSend !== 'undefined')
20  
          wsSend(JSON.stringify({sliderValue: {id: $id, value: this.value}}));
21  
      ]], +id, +valueID()))
22  
      + " " + hlabelFor(id, label);
23  
  }
24  
  
25  
  void onWebSocketJSON(Map map) {
26  
    Map map2 = optCast Map(map.get("sliderValue")), ret if null;
27  
    S id = cast map2.get("id");
28  
    if (!eq(id, this.id)) ret;
29  
    Number value = cast map2.get("value");
30  
    setField(value := toDouble(value));
31  
  }
32  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032454
Snippet name: HSlider - HTML range slider
Eternal ID of this version: #1032454/21
Text MD5: 82c0cd3e024b4f7f9350d2b6ff438878
Transpilation MD5: 5dec1d692c2e84217fe9fdd393a0be15
Author: stefan
Category: javax / html
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-24 15:53:46
Source code size: 1122 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 131 / 280
Version history: 20 change(s)
Referenced in: [show references]