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

43
LINES

< > BotCompany Repo | #1030832 // HTMLTree

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

Libraryless. Click here for Pure Java version (3342L/20K).

1  
// super-simple HTML tree with expandable/collapsible nodes
2  
sclass HTMLTree {
3  
  S headStuff() {
4  
    ret loadJQuery2() + hcss([[
5  
      .tree-toggler {
6  
        display: inline-block;
7  
        height: 1.3em;
8  
        width: 0.7em;
9  
        background: cornflowerblue;
10  
        padding-left: 0.5em;
11  
        padding-right: 0.5em;
12  
        /*line-height: 50px; */
13  
        text-align: center;
14  
      }
15  
      
16  
      .tree-toggler a {
17  
        text-decoration: none;
18  
      }
19  
    ]]) + hjs([[
20  
      function tree_expandCollapse(id) {
21  
        var children = $("#" + id);
22  
        children.toggle();
23  
        var vis = children.is(':visible');
24  
        $("#" + id + "_toggle a").html(vis ? "&ndash;" : "+");
25  
      }
26  
    ]]);
27  
  }
28  
  
29  
  S root(S contents) {
30  
    ret ul(contents);
31  
  }
32  
  
33  
  S node(S nodeHTML, S... children) {
34  
    S id = aGlobalID();
35  
    ret div(
36  
      ahref_javascript(
37  
        "tree_expandCollapse(" + jsQuote(id) + ");",
38  
        "+"),
39  
        class := "tree-toggler", id := id + "_toggle")
40  
      + " " + nodeHTML
41  
      + ul(asList(children), +id, style := "display: none");
42  
  }
43  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 5 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030832
Snippet name: HTMLTree
Eternal ID of this version: #1030832/2
Text MD5: 43f27219935356f599911c87b33374c0
Transpilation MD5: cd2b2e0d0e6aab43f7440777bcd066e9
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-04-01 16:06:49
Source code size: 1114 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 131 / 310
Version history: 1 change(s)
Referenced in: [show references]