Skip to content

Commit

Permalink
Version 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chniter committed May 17, 2020
1 parent b7eb060 commit 45ff24d
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 51 deletions.
50 changes: 41 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ var tree = [
icon: "fa fa-folder",
nodes: [
{
id: "sub-node-1",
text: "Sub Child Node 1",
icon: "fa fa-folder",
class: "nav-level-3",
href: "#option/1.1.1"
href: "https://google.com"
},
{
text: "Sub Child Node 2",
Expand Down Expand Up @@ -122,13 +123,6 @@ This property `text` is required to display nodes.
}
```

Yes, we can make some options for bstreeview, i will explain them later :p

```javascript
{

```
### Node Properties

#### text
Expand All @@ -151,14 +145,52 @@ A custom `href` attribute value for a given node.

A class name or space separated list of class names to add to a given node.

#### id
`String` `Optional`

ID attribute value to assign to a given node.

## Options

#### data
`String` `Mandatory`

Json or string array of nodes.

#### expandIcon
`String` `Optional`

Expand icon class name, default is `fa fa-angle-down fa-fw`.

#### collapseIcon
`String` `Optional`

Collapse icon class name, default is `fa fa-angle-right fa-fw`.

#### indent
`number with decimals` `Optional`

Custom indent between node levels (rem), default is `1.25`.

#### parentsMarginLeft
`String` `Optional`

margin-left value of parent nodes, default is `1.25rem`.

#### openNodeLinkOnNewTab
`Boolean` `Optional`

Open node link on new browser Tab, default is `true`.

```javascript
// Example: initializing the bstreeview
$('#tree').treeview({
data: data // data is required
data: data,
expandIcon: 'fa fa-angle-down fa-fw',
collapseIcon: 'fa fa-angle-right fa-fw',
indent: 1.25,
parentsMarginLeft: '1.25rem',
openNodeLinkOnNewTab: true
});
```

Expand Down
11 changes: 10 additions & 1 deletion dist/css/bstreeview.min.css
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
.bstreeview{position:relative;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;min-width:0;word-wrap:break-word;background-color:#fff;background-clip:border-box;border:1px solid rgba(0,0,0,.125);border-radius:.25rem;padding:0;overflow:hidden}.bstreeview .list-group{margin-bottom:0}.bstreeview .list-group-item{border-radius:0;border-width:1px 0 0 0;padding-top:.5rem;padding-bottom:.5rem;cursor:pointer}.bstreeview .list-group-item:hover{background-color:#dee2e6}.bstreeview>.list-group-item:first-child{border-top-width:0}.bstreeview .state-icon{margin-right:8px}.bstreeview .item-icon{margin-right:5px}
/*
@preserve
bstreeview.css
Version: 1.2.0
Authors: Sami CHNITER <[email protected]>
Copyright 2020
License: Apache License 2.0
Project: https://github.com/chniter/bstreeview
*/
.bstreeview{position:relative;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;min-width:0;word-wrap:break-word;background-color:#fff;background-clip:border-box;border:1px solid rgba(0,0,0,.125);border-radius:.25rem;padding:0;overflow:hidden}.bstreeview .list-group{margin-bottom:0}.bstreeview .list-group-item{border-radius:0;border-width:1px 0 0 0;padding-top:.5rem;padding-bottom:.5rem;cursor:pointer}.bstreeview .list-group-item:hover{background-color:#dee2e6}.bstreeview>.list-group-item:first-child{border-top-width:0}.bstreeview .state-icon{margin-right:8px}.bstreeview .item-icon{margin-right:5px}
8 changes: 2 additions & 6 deletions dist/js/bstreeview.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "bstreeview",
"version": "1.0.0",
"version": "1.2.0",
"description": "Bootstrap 4 simple treeview.",
"main":"[\"./dist/css/bstreeview.css\",\"./dist/js/bstreeview.js\"]",
"main": "[\"./dist/css/bstreeview.min.css\",\"./dist/js/bstreeview.min.js\"]",
"dependencies": {},
"devDependencies": {},
"scripts": {
Expand Down Expand Up @@ -35,4 +35,4 @@
"url": "https://github.com/chniter/bstreeview/issues"
},
"homepage": "https://github.com/chniter/bstreeview#readme"
}
}
Binary file modified screeshots/bstreeview.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/css/bstreeview.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
@preserve
bstreeview.css
Version: 1.2.0
Authors: Sami CHNITER <[email protected]>
Copyright 2020
License: Apache License 2.0
Project: https://github.com/chniter/bstreeview
*/
.bstreeview {
position: relative;
display: -ms-flexbox;
Expand Down
53 changes: 34 additions & 19 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<html>

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>bstreeview</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"
integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<link href="css/bstreeview.css" rel="stylesheet">
</head>

Expand All @@ -21,10 +24,10 @@
</div>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>

<script src="js/bstreeview.js">
</script>
Expand All @@ -34,48 +37,60 @@
var json = [
{
text: "Inbox",
icon: "fa fa-inbox",
icon: "fa fa-inbox fa-fw",
nodes: [
{
text: "Office",
icon: "fa fa-inbox",
icon: "fa fa-inbox fa-fw",
nodes: [
{
icon: "fa fa-inbox",
icon: "fa fa-inbox fa-fw",
text: "Customers"
},
{
icon: "fa fa-inbox",
icon: "fa fa-inbox fa-fw",
text: "Co-Workers"
}
]
},
{
icon: "fa fa-inbox",
icon: "fa fa-inbox fa-fw",
text: "Others"
}
]
},
{
icon: "fa fa-archive",
icon: "fa fa-archive fa-fw",
text: "Drafts"
},
{
icon: "fa fa-calendar",
icon: "fa fa-calendar fa-fw",
text: "Calendar"
},
{
icon: "fa fa-address-book",
icon: "fa fa-address-book fa-fw",
text: "Contacts"
},
{
icon: "fa fa-trash",
icon: "fa fa-trash fa-fw",
text: "Deleted Items"
}
},
{
icon: "fa fa-globe fa-fw",
text: "Go to Google",
class: "text-info",
href: "https://google.com"
}
];

$('#tree').bstreeview({ data: json });

$('#tree').bstreeview({
data: json,
expandIcon: 'fa fa-angle-down fa-fw',
collapseIcon: 'fa fa-angle-right fa-fw',
indent: 1.25,
parentsMarginLeft: '1.25rem',
openNodeLinkOnNewTab: true
});
});
</script>
</body>
Expand Down
41 changes: 28 additions & 13 deletions src/js/bstreeview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! @preserve
* bstreeview.js
* Version: 1.0.0
* Version: 1.2.0
* Authors: Sami CHNITER <[email protected]>
* Copyright 2020
* License: Apache License 2.0
Expand All @@ -14,17 +14,20 @@
*/
var pluginName = "bstreeview",
defaults = {
expandIcon: 'fa fa-angle-down',
collapseIcon: 'fa fa-angle-right',
indent: 1.25
expandIcon: 'fa fa-angle-down fa-fw',
collapseIcon: 'fa fa-angle-right fa-fw',
indent: 1.25,
parentsMarginLeft: '1.25rem',
openNodeLinkOnNewTab: true

};
/**
* bstreeview HTML templates.
*/
var templates = {
treeview: '<div class="bstreeview"></div>',
treeviewItem: '<div href="#itemid" class="list-group-item" data-toggle="collapse"></div>',
treeviewGroupItem: '<div class="list-group collapse" id="itemid"></div>',
treeviewItem: '<div role="treeitem" class="list-group-item" data-toggle="collapse"></div>',
treeviewGroupItem: '<div role="group" class="list-group collapse" id="itemid"></div>',
treeviewItemStateIcon: '<i class="state-icon"></i>',
treeviewItemIcon: '<i class="item-icon"></i>'
};
Expand Down Expand Up @@ -64,10 +67,19 @@
var _this = this;
this.build($(this.element), this.tree, 0);
// Update angle icon on collapse
$(this.element).on('click', '.list-group-item', function () {
$(this.element).on('click', '.list-group-item', function (e) {
$('.state-icon', this)
.toggleClass(_this.settings.expandIcon)
.toggleClass(_this.settings.collapseIcon);
// navigate to href if present
if (e.target.hasAttribute('href')) {
if (_this.settings.openNodeLinkOnNewTab) {
window.open(e.target.getAttribute('href'), '_blank');
}
else {
window.location = e.target.getAttribute('href');
}
}
});
},
/**
Expand Down Expand Up @@ -98,7 +110,8 @@
build: function (parentElement, nodes, depth) {
var _this = this;
// Calculate item padding.
var leftPadding = "1.25rem;";
var leftPadding = _this.settings.parentsMarginLeft;

if (depth > 0) {
leftPadding = (_this.settings.indent + depth * _this.settings.indent).toString() + "rem;";
}
Expand All @@ -107,8 +120,9 @@
$.each(nodes, function addNodes(id, node) {
// Main node element.
var treeItem = $(templates.treeviewItem)
.attr('href', "#" + _this.itemIdPrefix + node.nodeId)
.attr('style', 'padding-left:' + leftPadding);
.attr('data-target', "#" + _this.itemIdPrefix + node.nodeId)
.attr('style', 'padding-left:' + leftPadding)
.attr('aria-level', depth);
// Set Expand and Collapse icones.
if (node.nodes) {
var treeItemStateIcon = $(templates.treeviewItemStateIcon)
Expand All @@ -123,17 +137,18 @@
}
// Set node Text.
treeItem.append(node.text);

// Reset node href if present
if (node.href) {
treeItem.attr('href', node.href);
}

// Add class to node if present
if (node.class) {
treeItem.addClass(node.class);
}

// Add custom id to node if present
if (node.id) {
treeItem.attr('id', node.id);
}
// Attach node to parent.
parentElement.append(treeItem);
// Build child nodes.
Expand Down

0 comments on commit 45ff24d

Please sign in to comment.