Collapsible Folder Tree With Pure JavaScript – jslists

Category: Javascript | October 21, 2018
Author: TheTechy
Views Total: 3,104
Official Page: Go to website
Last Update: October 21, 2018
License: MIT

Preview:

Collapsible Folder Tree With Pure JavaScript – jslists

Description:

jslists is a standalone JavaScript plugin that converts nested HTML lists into a collapsible, multi-level tree list.

How to use it:

Create the tree list from nested html lists as displayed below:

<ul id="simple_list">
  <li>
    <i class="fa fa-folder-o" aria-hidden="true"></i>
    <b>Folder One</b>
    <ul>
      <li id="aa1"><i class="fa fa-file-text-o" aria-hidden="true"></i> Click Me</li>
      <a href="https://www.google.com"><li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item Two</li></a>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item Three</li>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item Four</li>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item Five</li>
    </ul>
  </li>
  <li>
    <i class="fa fa-folder-o" aria-hidden="true"></i>
    <b><a href="#">Folder Two</a></b>
    <ul>
      <li><i class="fa fa-folder-o" aria-hidden="true"></i> Item One
        <ul>
          <li><i class="fa fa-file-text-o" aria-hidden="true"></i><a href="#"> A</a></li>
          <li><i class="fa fa-file-text-o" aria-hidden="true"></i> B</li>
          <li><i class="fa fa-file-text-o" aria-hidden="true"></i> C</li>
        </ul>
      </li>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item Two</li>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item Three</li>
      <li>
        <i class="fa fa-folder-o" aria-hidden="true"></i> Item Four
                        <ul>
          <li><i class="fa fa-file-text-o" aria-hidden="true"></i><a href="#"> A</a></li>
          <li><i class="fa fa-file-text-o" aria-hidden="true"></i> B</li>
          <li><i class="fa fa-folder-o" aria-hidden="true"></i> C
            <ul>
              <li><i class="fa fa-file-text-o" aria-hidden="true"></i><a href="#"> A</a></li>
              <li><i class="fa fa-folder-o" aria-hidden="true"></i> B
                <ul>
                  <li><i class="fa fa-file-text-o" aria-hidden="true"></i><a href="#"> A</a></li>
                  <li><i class="fa fa-file-text-o" aria-hidden="true"></i> B</li>
                  <li><i class="fa fa-folder-o" aria-hidden="true"></i> C
                    <ul>
                      <li><i class="fa fa-file-text-o" aria-hidden="true"></i><a href="#"> A</a></li>
                      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> B</li>
                      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> C</li>
                    </ul>
                  </li>
                </ul>
              </li>
              <li><i class="fa fa-file-text-o" aria-hidden="true"></i> C</li>
            </ul>
          </li>
        </ul>
      </li>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item Five</li>
    </ul>
  </li>
  <li>
    <i class="fa fa-folder-o" aria-hidden="true"></i>
    <b>Folder Three</b>
    <ul>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item One</li>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item Two</li>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item Three</li>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item Four</li>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item Five</li>
    </ul>
  </li>
  <li>
    <i class="fa fa-folder-o" aria-hidden="true"></i>
    <b>Folder Four</b>
    <ul>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item One</li>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item Two</li>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item Three</li>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item Four</li>
      <li><i class="fa fa-file-text-o" aria-hidden="true"></i> Item Five</li>
    </ul>
  </li>
  <li>
    <i class="fa fa-folder-o" aria-hidden="true"></i>
    <b>Folder Five</b>
    <ul>
      <li>Item One</li>
      <li>Item Two</li>
      <li>Item Three</li>
      <li>Item Four</li>
      <li>Item Five</li>
    </ul>
  </li>
</ul>

In this example, we use Font Awesome for the folder icons.

<link rel="stylesheet" href="font-awesome.min.css">

Place the jslists’ JavaScript at the bottom of the web page.

<script src="jsLists.min.js"></script>

Initialize the tree list.

JSLists.applyToList('simple_list', 'ALL');

Changelog:

10/21/2018

  • Updating to include bullet point

You Might Be Interested In:


Leave a Reply