-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
132 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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>' | ||
}; | ||
|
@@ -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'); | ||
} | ||
} | ||
}); | ||
}, | ||
/** | ||
|
@@ -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;"; | ||
} | ||
|
@@ -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) | ||
|
@@ -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. | ||
|