diff --git a/bbtreeview.js b/bbtreeview.js
deleted file mode 100644
index fa5bb92..0000000
--- a/bbtreeview.js
+++ /dev/null
@@ -1,392 +0,0 @@
-/**
- * BBTreeview
- * @version v0.1.1.006 (2023/09/27 2218)
- */
-function BBTreeview(options)
-{
- const a = this;
-
- a.initialise(options);
-};
-
-BBTreeview.prototype.AddItem = function(options) {
- const a = this;
- const _options = a.getOptions(options);
-
- // Don't add duplicate
- if (a.Find(_options.ID) != null) {
- return false;
- }
-
- // Check parent exists
- let parentNode = null;
- if (_options.ParentID != null) {
- parentNode = a.Find(_options.ParentID);
- if (parentNode == null) {
- return false;
- }
- }
-
- if (parentNode == null) {
- parentNode = a.Container;
- } else {
- parentNode = parentNode.GetChildNode();
- }
-
- const nodeHtml = a.generateNodeHtml(_options);
-
- // Add node
- a.appendHtml(parentNode, nodeHtml);
-
- const node = a.Find(_options.ID);
-
- // Setup events
- node.SetupEvents();
-
- return true;
-};
-
-BBTreeview.prototype.Remove = function(id) {
- const a = this;
-
- const node = a.Find(id);
- if (node == null) {
- return false;
- }
-
- node.Remove();
-
- return true;
-};
-
-BBTreeview.prototype.Default = function() {
- return {
- TreeviewOptions: {
- ID: null,
- ShowCheckbox: false,
- ShowSelection: true,
- EnablePullUp: false,
- ShowIcon: true
- },
- TreeNodeOptions: {
- ID: null,
- ParentID: null,
- Name: "",
- Hint: "",
- Value: "",
- Icon: "folder",
- Checked: false,
- Tag: null
- }
- };
-};
-
-BBTreeview.prototype.Clear = function() {
- const a = this;
-
- a.initialise(a.Options);
-};
-
-BBTreeview.prototype.CollapseAll = function() {
- const a = this;
-
- a.GetAllNodes().forEach(function(e) {
- e.Collapse();
- });
-};
-
-BBTreeview.prototype.ExpandAll = function() {
- const a = this;
-
- a.GetAllNodes().forEach(function(e) {
- e.Expand();
- });
-};
-
-BBTreeview.prototype.CheckAll = function(value) {
- const a = this;
-
- if (!a.Options.ShowCheckbox) {
- return;
- }
-
- a.GetAllNodes().forEach(function(e) {
- e.Check(value);
- });
-};
-
-BBTreeview.prototype.Find = function(id) {
- const a = this;
-
- if (a.Container == null){
- console.log("BBTreeview container not found");
- return;
- }
-
- const node = a.Container.querySelectorAll("li[data-bbtv-id='" + id + "']");
- if (node.length <= 0) {
- return null;
- }
-
- let treenode = new BBTreeviewNode(this);
- treenode.Load(node[0]);
-
- // console.log(treenode);
-
- return treenode;
-};
-
-BBTreeview.prototype.FindByName = function(value) {
- const a = this;
-
- let response = [];
- a.GetAllNodes().forEach(function(e) {
- if (e.Name != value) {
- return;
- }
-
- response.push(e);
- });
-
- return response;
-};
-
-BBTreeview.prototype.FindByValue = function(value) {
- const a = this;
-
- let response = [];
- a.GetAllNodes().forEach(function(e) {
- if (e.Value != value) {
- return;
- }
-
- response.push(e);
- });
-
- return response;
-};
-
-BBTreeview.prototype.GetAllNodes = function() {
- const a = this;
-
- const node = a.Container.querySelectorAll("li");
- if (node.length <= 0) {
- return [];
- }
-
- let response = [];
- node.forEach(function(e) {
- const id = e.getAttribute("data-bbtv-id");
- if (a.isNullOrWhitespace(id)) {
- return;
- }
-
- const myNode = a.Find(id);
- if (myNode == null) {
- return;
- }
-
- response.push(myNode);
- });
-
- return response;
-};
-
-BBTreeview.prototype.GetCheckedNodes = function() {
- const a = this;
-
- let response = [];
- a.GetAllNodes().forEach(function(e) {
- if (!e.Checked) {
- return;
- }
-
- response.push(e);
- });
-
- return response;
-};
-
-BBTreeview.prototype.GetCheckedValues = function() {
- const a = this;
-
- let response = [];
- a.GetCheckedNodes().map(function(e) {
- response.push(e.Value);
- });
-
- return response;
-};
-
-
-BBTreeview.prototype.GetCheckedTags = function() {
- const a = this;
-
- let response = [];
- a.GetCheckedNodes().map(function(e) {
- response.push(e.Tag);
- });
-
- return response;
-};
-
-BBTreeview.prototype.GetSelectedNode = function() {
- const a = this;
-
- let response = null;
- a.GetAllNodes().forEach(function(e) {
- if (e.Highlighted) {
- response = e;
-
- return false;
- }
- });
-
- return response;
-};
-
-BBTreeview.prototype.initialise = function(options) {
- var a = this;
-
- a.Options = Object.assign(a.Default().TreeviewOptions, options);
-
- a.Container = null;
-
- let treeview = document.getElementsByTagName("body")[0].querySelectorAll(a.Options.ID);
- if (treeview.length <= 0) {
- return;
- }
-
- if (treeview[0] == null) {
- return;
- }
-
- a.Container = treeview[0];
-
- a.Container.innerHTML = "
";
-
- a.Container = a.Container.querySelectorAll("ul.bbtreeview")[0];
-};
-
-BBTreeview.prototype.appendHtml = function(el, html) {
- let node = document.createElement('template');
- node.innerHTML = html;
-
- node = node.content.firstChild;
-
- el.appendChild(node);
-};
-
-BBTreeview.prototype.generateID = function() {
- return "treeviewItem" + (Math.floor(Math.random() * 1000001) + 100).toString();
-};
-
-BBTreeview.prototype.generateNodeHtml = function(options) {
- const a = this;
-
- let tag = "";
- if (!a.isNullOrWhitespace(options.Tag)) {
- tag = encodeURIComponent(JSON.stringify(options.Tag));
- }
-
- let html = '';
- html += ''
-
- if (a.Options.ShowCheckbox) {
- html += '
';
- }
-
- if (a.Options.ShowIcon) {
- html += '
';
- html += '
' + options.Name + '';
- } else {
- html += '
' + options.Name + '';
- }
-
- html += '
';
- html += '';
- html += '';
-
- return html;
-};
-
-BBTreeview.prototype.getNode = function(el) {
- const a = this;
-
- let node = null;
- if (a.isTag(el, "li")) {
- node = el;
- } else {
- node = a.parentsUntilTagName(el, "li");
- }
-
- const id = node.getAttribute("data-bbtv-id");
-
- if (a.isNullOrWhitespace(id)) {
- return null;
- }
-
- return a.Find(id);
-};
-
-BBTreeview.prototype.getOptions = function(options) {
- const a = this;
-
- let _options = Object.assign(a.Default().TreeNodeOptions, options);
-
- if (_options.ID == null) {
- _options.ID = a.generateID();
- }
-
- if (_options.Tag == null) {
- _options.Tag = "";
- }
-
- return _options;
-};
-
-BBTreeview.prototype.isNullOrWhitespace = function(value) {
- if (typeof (value) == "undefined") {
- return true;
- }
-
- if (value == null) {
- return true;
- }
-
- return (value.toString().trim().length <= 0);
-};
-
-BBTreeview.prototype.isTag = function(el, tagName) {
- return (el.tagName.toLowerCase() == tagName);
-};
-
-BBTreeview.prototype.parentsUntilTagName = function(el, tagName) {
- const a = this;
-
- let node = el;
-
- while (true) {
- if (typeof(node.parentNode) == "undefined") {
- break;
- }
-
- node = node.parentNode;
-
- if (typeof(node) == "undefined") {
- break;
- }
-
- if (a.isTag(node, "ul")) {
- if (node.classList.contains("bbtreeview")) {
- return null;
- }
- }
-
- if (a.isTag(node, tagName)) {
- break;
- }
- }
-
- return node;
-};
diff --git a/bbtreeview.min.js b/bbtreeview.min.js
deleted file mode 100644
index 2731a75..0000000
--- a/bbtreeview.min.js
+++ /dev/null
@@ -1,7 +0,0 @@
-/**
- * BBTreeview
- * @version v0.1.1.006 (2023/09/27 2218)
- */
-function BBTreeview(options){const a=undefined;this.initialise(options)}BBTreeview.prototype.AddItem=function(options){const a=this,_options=a.getOptions(options);if(null!=a.Find(_options.ID))return!1;let parentNode=null;if(null!=_options.ParentID&&(parentNode=a.Find(_options.ParentID),null==parentNode))return!1;parentNode=null==parentNode?a.Container:parentNode.GetChildNode();const nodeHtml=a.generateNodeHtml(_options);a.appendHtml(parentNode,nodeHtml);const node=undefined;return a.Find(_options.ID).SetupEvents(),!0},BBTreeview.prototype.Remove=function(id){const a=undefined,node=this.Find(id);return null!=node&&(node.Remove(),!0)},BBTreeview.prototype.Default=function(){return{TreeviewOptions:{ID:null,ShowCheckbox:!1,ShowSelection:!0,EnablePullUp:!1,ShowIcon:!0},TreeNodeOptions:{ID:null,ParentID:null,Name:"",Hint:"",Value:"",Icon:"folder",Checked:!1,Tag:null}}},BBTreeview.prototype.Clear=function(){const a=this;a.initialise(a.Options)},BBTreeview.prototype.CollapseAll=function(){const a=undefined;this.GetAllNodes().forEach((function(e){e.Collapse()}))},BBTreeview.prototype.ExpandAll=function(){const a=undefined;this.GetAllNodes().forEach((function(e){e.Expand()}))},BBTreeview.prototype.CheckAll=function(value){const a=this;a.Options.ShowCheckbox&&a.GetAllNodes().forEach((function(e){e.Check(value)}))},BBTreeview.prototype.Find=function(id){const a=this;if(null==a.Container)return void console.log("BBTreeview container not found");const node=a.Container.querySelectorAll("li[data-bbtv-id='"+id+"']");if(node.length<=0)return null;let treenode=new BBTreeviewNode(this);return treenode.Load(node[0]),treenode},BBTreeview.prototype.FindByName=function(value){const a=undefined;let response=[];return this.GetAllNodes().forEach((function(e){e.Name==value&&response.push(e)})),response},BBTreeview.prototype.FindByValue=function(value){const a=undefined;let response=[];return this.GetAllNodes().forEach((function(e){e.Value==value&&response.push(e)})),response},BBTreeview.prototype.GetAllNodes=function(){const a=this,node=a.Container.querySelectorAll("li");if(node.length<=0)return[];let response=[];return node.forEach((function(e){const id=e.getAttribute("data-bbtv-id");if(a.isNullOrWhitespace(id))return;const myNode=a.Find(id);null!=myNode&&response.push(myNode)})),response},BBTreeview.prototype.GetCheckedNodes=function(){const a=undefined;let response=[];return this.GetAllNodes().forEach((function(e){e.Checked&&response.push(e)})),response},BBTreeview.prototype.GetCheckedValues=function(){const a=undefined;let response=[];return this.GetCheckedNodes().map((function(e){response.push(e.Value)})),response},BBTreeview.prototype.GetCheckedTags=function(){const a=undefined;let response=[];return this.GetCheckedNodes().map((function(e){response.push(e.Tag)})),response},BBTreeview.prototype.GetSelectedNode=function(){const a=undefined;let response=null;return this.GetAllNodes().forEach((function(e){if(e.Highlighted)return response=e,!1})),response},BBTreeview.prototype.initialise=function(options){var a=this;a.Options=Object.assign(a.Default().TreeviewOptions,options),a.Container=null;let treeview=document.getElementsByTagName("body")[0].querySelectorAll(a.Options.ID);treeview.length<=0||null!=treeview[0]&&(a.Container=treeview[0],a.Container.innerHTML='',a.Container=a.Container.querySelectorAll("ul.bbtreeview")[0])},BBTreeview.prototype.appendHtml=function(el,html){let node=document.createElement("template");node.innerHTML=html,node=node.content.firstChild,el.appendChild(node)},BBTreeview.prototype.generateID=function(){return"treeviewItem"+(Math.floor(1000001*Math.random())+100).toString()},BBTreeview.prototype.generateNodeHtml=function(options){const a=this;let tag="";a.isNullOrWhitespace(options.Tag)||(tag=encodeURIComponent(JSON.stringify(options.Tag)));let html='';return html+='',a.Options.ShowCheckbox&&(html+='
'),a.Options.ShowIcon?(html+='
',html+='
'+options.Name+""):html+='
'+options.Name+"",html+="
",html+="",html+="",html},BBTreeview.prototype.getNode=function(el){const a=this;let node=null;node=a.isTag(el,"li")?el:a.parentsUntilTagName(el,"li");const id=node.getAttribute("data-bbtv-id");return a.isNullOrWhitespace(id)?null:a.Find(id)},BBTreeview.prototype.getOptions=function(options){const a=this;let _options=Object.assign(a.Default().TreeNodeOptions,options);return null==_options.ID&&(_options.ID=a.generateID()),null==_options.Tag&&(_options.Tag=""),_options},BBTreeview.prototype.isNullOrWhitespace=function(value){return void 0===value||(null==value||value.toString().trim().length<=0)},BBTreeview.prototype.isTag=function(el,tagName){return el.tagName.toLowerCase()==tagName},BBTreeview.prototype.parentsUntilTagName=function(el,tagName){const a=this;let node=el;for(;void 0!==node.parentNode&&(node=node.parentNode,void 0!==node);){if(a.isTag(node,"ul")&&node.classList.contains("bbtreeview"))return null;if(a.isTag(node,tagName))break}return node};
-
-function BBTreeviewNode(treeview){const a=this;a.Treeview=treeview,a.initialise()}BBTreeviewNode.prototype.Load=function(node){const a=this;a.ID=node.getAttribute("data-bbtv-id"),a.Node=node,a.Container=node.querySelectorAll("div.li")[0],a.Label=node.querySelectorAll("span")[0],a.Value=node.getAttribute("data-bbtv-value"),a.Name=a.Label.textContent,a.Hint=a.Label.getAttribute("title"),a.ParentID=a.GetParentID(),a.Checked=a.IsChecked(),a.Highlighted=a.IsHighlighted(),a.Tag=a.GetTag()},BBTreeviewNode.prototype.Check=function(value){const a=this;a.setCheckbox(a.Node,value),a.Node.querySelectorAll("li").forEach((function(e){a.setCheckbox(e,value)}));let parentNode=a.GetParentNode();if(null!=parentNode)if(a.Treeview.Options.EnablePullUp)for(;;){const parentChecked=parentNode.querySelectorAll("li.x").length>0;if(a.setCheckbox(parentNode,parentChecked),parentNode=a.Treeview.getNode(parentNode),parentNode=parentNode.GetParentNode(),null==parentNode)break}else{let uncheckedCount=0;parentNode.querySelectorAll("li").forEach((function(e){e.classList.contains("x")||uncheckedCount++})),a.setCheckbox(parentNode,uncheckedCount<=0)}},BBTreeviewNode.prototype.Collapse=function(){const a=this;a.Node.classList.contains("e")&&(a.Node.classList.remove("e"),a.Node.classList.add("c")),a.GetChildNodes().forEach((function(e){e.classList.add("hidden")}))},BBTreeviewNode.prototype.Expand=function(){const a=this;a.Node.classList.contains("c")&&(a.Node.classList.remove("c"),a.Node.classList.add("e")),a.GetChildNodes().forEach((function(e){e.classList.remove("hidden")}))},BBTreeviewNode.prototype.GetCheckbox=function(){const a=this;if(!a.Treeview.Options.ShowCheckbox)return null;const checkboxes=a.Node.querySelectorAll("div.icon.checkbox");return void 0===checkboxes?null:checkboxes[0]},BBTreeviewNode.prototype.GetChildNode=function(){const a=undefined;let result=this.Node.querySelectorAll("ul");return result.length<=0?null:result[0]},BBTreeviewNode.prototype.GetChildNodes=function(){const a=undefined,childNode=this.GetChildNode();if(null==childNode)return[];let nodes=childNode.querySelectorAll("li");if(nodes.length<=0)return[];let result=[];return nodes.forEach((function(e){void 0!==e.parentNode&&e.parentNode==childNode&&result.push(e)})),result},BBTreeviewNode.prototype.GetTag=function(){const a=this;let tag=a.Node.getAttribute("data-bbtv-tag");return a.Treeview.isNullOrWhitespace(tag)?null:JSON.parse(decodeURIComponent(tag))},BBTreeviewNode.prototype.GetParentID=function(){const a=undefined,parentNode=this.GetParentNode();return null==parentNode?null:parentNode.getAttribute("data-bbtv-id")},BBTreeviewNode.prototype.GetParentNode=function(){const a=this;return a.parentsUntilTagName(a.Node,"li")},BBTreeviewNode.prototype.IsChecked=function(){const a=this;return!!a.Treeview.Options.ShowCheckbox&&a.Node.classList.contains("x")},BBTreeviewNode.prototype.IsExpanded=function(){const a=this;return!!a.Node.classList.contains("e")||!a.Node.classList.contains("c")&&null},BBTreeviewNode.prototype.IsHighlighted=function(){const a=undefined;return this.Container.classList.contains("highlighted")},BBTreeviewNode.prototype.Remove=function(){const a=this;null!=a.GetParentNode()&&(a.GetParentNode().classList.contains("e")&&a.GetParentNode().classList.remove("e"),a.GetParentNode().classList.contains("c")&&a.GetParentNode().classList.remove("c")),a.Node.parentNode.removeChild(a.Node)},BBTreeviewNode.prototype.SetupEvents=function(){const a=this;a.Node.addEventListener("click",(function(e){if(e.stopPropagation(),e.preventDefault(),!a.isTag(e.target,"li"))return;if(e.offsetX<0||e.offsetX>16||e.offsetY<0||e.offsetY>16)return;const myNode=a.Treeview.getNode(e.target);null!=myNode&&myNode.Toggle()})),a.Container.addEventListener("dblclick",(function(e){e.stopPropagation(),e.preventDefault();const myNode=a.Treeview.getNode(e.target);null!=myNode&&myNode.Toggle()})),a.Treeview.Options.ShowCheckbox&&(a.GetCheckbox().addEventListener("mousedown",(function(e){e.stopPropagation(),e.preventDefault(),a.Check(!a.IsChecked())})),a.GetCheckbox().addEventListener("click",(function(e){e.stopPropagation(),e.preventDefault()})),a.GetCheckbox().addEventListener("dblclick",(function(e){e.stopPropagation(),e.preventDefault()}))),a.Container.addEventListener("mousedown",(function(e){e.stopPropagation(),e.preventDefault();const myNode=a.Treeview.getNode(e.target);null!=myNode&&(a.Treeview.Container.querySelectorAll("div.highlighted").forEach((function(e){e.classList.remove("highlighted")})),a.Treeview.Options.ShowSelection&&myNode.Container.classList.add("highlighted"))})),a.invalidateCollapsible()},BBTreeviewNode.prototype.Toggle=function(){const a=this;switch(a.IsExpanded()){case!0:a.Collapse();break;case!1:a.Expand()}},BBTreeviewNode.prototype.initialise=function(){const a=this},BBTreeviewNode.prototype.invalidateCollapsible=function(){const a=this;null!=a.GetParentNode()&&(a.GetParentNode().classList.contains("c")?a.Node.classList.add("hidden"):(a.GetParentNode().classList.contains("e")||a.GetParentNode().classList.add("e"),a.Node.classList.remove("hidden")))},BBTreeviewNode.prototype.isTag=function(el,tagName){return el.tagName.toLowerCase()==tagName},BBTreeviewNode.prototype.parentsUntilTagName=function(el,tagName){const a=this;let node=el;for(;void 0!==node.parentNode&&(node=node.parentNode,void 0!==node);){if(a.isTag(node,"ul")&&node.classList.contains("bbtreeview"))return null;if(a.isTag(node,tagName))break}return node},BBTreeviewNode.prototype.setCheckbox=function(el,value){value?el.classList.contains("x")||el.classList.add("x"):el.classList.contains("x")&&el.classList.remove("x")};
\ No newline at end of file
diff --git a/bbtreeviewnode.js b/bbtreeviewnode.js
deleted file mode 100644
index 62c1916..0000000
--- a/bbtreeviewnode.js
+++ /dev/null
@@ -1,408 +0,0 @@
-/**
- * BBTreeview
- * @version v0.1.0.244 (2023/09/11 2327)
- */
-function BBTreeviewNode(treeview)
-{
- const a = this;
-
- a.Treeview = treeview;
-
- a.initialise();
-};
-
-
-BBTreeviewNode.prototype.Load = function(node) {
- const a = this;
-
- a.ID = node.getAttribute("data-bbtv-id");
- a.Node = node;
-
- a.Container = node.querySelectorAll("div.li")[0];
- a.Label = node.querySelectorAll("span")[0];
- a.Value = node.getAttribute("data-bbtv-value");
-
- a.Name = a.Label.textContent;
- a.Hint = a.Label.getAttribute("title");
-
- a.ParentID = a.GetParentID();
- a.Checked = a.IsChecked();
- a.Highlighted = a.IsHighlighted();
- a.Tag = a.GetTag();
-};
-
-
-BBTreeviewNode.prototype.Check = function(value) {
- const a = this;
-
- a.setCheckbox(a.Node, value);
-
- // Update children
- a.Node.querySelectorAll("li").forEach(function(e) {
- a.setCheckbox(e, value);
- });
-
- // Update parent state
- let parentNode = a.GetParentNode();
- if (parentNode == null) {
- return;
- }
-
- // Handle pull-ups
- if (a.Treeview.Options.EnablePullUp) {
- while (true) {
- const parentChecked = (parentNode.querySelectorAll("li.x").length > 0);
-
- a.setCheckbox(parentNode, parentChecked);
-
- parentNode = a.Treeview.getNode(parentNode);
- parentNode = parentNode.GetParentNode();
-
- if (parentNode == null) {
- break;
- }
- }
- } else {
- let uncheckedCount = 0;
-
- parentNode.querySelectorAll("li").forEach(function(e) {
- if (e.classList.contains("x")) {
- return;
- }
-
- uncheckedCount++;
- });
-
- a.setCheckbox(parentNode, (uncheckedCount <= 0));
- }
-};
-
-BBTreeviewNode.prototype.Collapse = function() {
- const a = this;
-
- if (a.Node.classList.contains("e")) {
- a.Node.classList.remove("e");
- a.Node.classList.add("c");
- }
-
- a.GetChildNodes().forEach(function(e) {
- e.classList.add("hidden");
- });
-};
-
-BBTreeviewNode.prototype.Expand = function() {
- const a = this;
-
- if (a.Node.classList.contains("c")) {
- a.Node.classList.remove("c");
- a.Node.classList.add("e");
- }
-
- a.GetChildNodes().forEach(function(e) {
- e.classList.remove("hidden");
- });
-};
-
-BBTreeviewNode.prototype.GetCheckbox = function() {
- const a = this;
-
- if (!a.Treeview.Options.ShowCheckbox) {
- return null;
- }
-
- const checkboxes = a.Node.querySelectorAll("div.icon.checkbox");
- if (typeof(checkboxes) == "undefined") {
- return null;
- }
-
- return checkboxes[0];
-};
-
-BBTreeviewNode.prototype.GetChildNode = function() {
- const a = this;
-
- let result = a.Node.querySelectorAll("ul");
- if (result.length <= 0) {
- return null;
- }
-
- return result[0];
-};
-
-BBTreeviewNode.prototype.GetChildNodes = function() {
- const a = this;
-
- const childNode = a.GetChildNode();
- if (childNode == null) {
- return [];
- }
-
- let nodes = childNode.querySelectorAll("li");
- if (nodes.length <= 0) {
- return [];
- }
-
- let result = [];
- nodes.forEach(function(e) {
- if (typeof(e.parentNode) == "undefined") {
- return;
- }
-
- if (e.parentNode != childNode) {
- return;
- }
-
- result.push(e);
- });
-
- return result;
-};
-
-BBTreeviewNode.prototype.GetTag = function() {
- const a = this;
-
- let tag = a.Node.getAttribute("data-bbtv-tag");
- if (a.Treeview.isNullOrWhitespace(tag)) {
- return null;
- }
-
- return JSON.parse(decodeURIComponent(tag));
-};
-BBTreeviewNode.prototype.GetParentID = function() {
- const a = this;
-
- const parentNode = a.GetParentNode();
- if (parentNode == null) {
- return null;
- }
-
- return parentNode.getAttribute("data-bbtv-id");
-};
-
-BBTreeviewNode.prototype.GetParentNode = function() {
- const a = this;
-
- return a.parentsUntilTagName(a.Node, "li");
-};
-
-BBTreeviewNode.prototype.IsChecked = function() {
- const a = this;
-
- if (!a.Treeview.Options.ShowCheckbox) {
- return false;
- }
-
- return a.Node.classList.contains("x");
-};
-
-BBTreeviewNode.prototype.IsExpanded = function() {
- const a = this;
-
- if (a.Node.classList.contains("e")) {
- return true;
- }
-
- if (a.Node.classList.contains("c")) {
- return false;
- }
-
- return null;
-};
-
-BBTreeviewNode.prototype.IsHighlighted = function() {
- const a = this;
-
- return (a.Container.classList.contains("highlighted"));
-};
-
-BBTreeviewNode.prototype.Remove = function() {
- const a = this;
-
- if (a.GetParentNode() != null) {
- if (a.GetParentNode().classList.contains("e")) {
- a.GetParentNode().classList.remove("e");
- }
-
- if (a.GetParentNode().classList.contains("c")) {
- a.GetParentNode().classList.remove("c");
- }
- }
-
- a.Node.parentNode.removeChild(a.Node);
-};
-
-BBTreeviewNode.prototype.SetupEvents = function() {
- const a = this;
-
- // collapsible icon behaviour
- a.Node.addEventListener("click", function(e){
- e.stopPropagation();
- e.preventDefault();
-
- if (!a.isTag(e.target, "li")) {
- return;
- }
-
- if ((e.offsetX < 0) || (e.offsetX > 16) || (e.offsetY < 0) || (e.offsetY > 16)) {
- return;
- }
-
- const myNode = a.Treeview.getNode(e.target);
- if (myNode == null) {
- return;
- }
-
- myNode.Toggle();
- });
-
- // collapsible label behaviour
- a.Container.addEventListener("dblclick", function(e){
- e.stopPropagation();
- e.preventDefault();
-
- const myNode = a.Treeview.getNode(e.target);
- if (myNode == null) {
- return;
- }
-
- myNode.Toggle();
- });
-
- // checkbox behaviour
- if (a.Treeview.Options.ShowCheckbox) {
- a.GetCheckbox().addEventListener("mousedown", function(e){
- e.stopPropagation();
- e.preventDefault();
-
- a.Check(!a.IsChecked());
- });
-
- a.GetCheckbox().addEventListener("click", function(e){
- e.stopPropagation();
- e.preventDefault();
-
- // do nothing
- });
-
- a.GetCheckbox().addEventListener("dblclick", function(e){
- e.stopPropagation();
- e.preventDefault();
-
- // do nothing
- });
- }
-
- // highlighting
- a.Container.addEventListener("mousedown", function(e){
- e.stopPropagation();
- e.preventDefault();
-
- const myNode = a.Treeview.getNode(e.target);
- if (myNode == null) {
- return;
- }
-
- a.Treeview.Container.querySelectorAll("div.highlighted").forEach(function(e) {
- e.classList.remove("highlighted");
- });
-
- // Don't show selection
- if (!a.Treeview.Options.ShowSelection) {
- return;
- }
-
- myNode.Container.classList.add("highlighted");
- });
-
- a.invalidateCollapsible();
-};
-
-BBTreeviewNode.prototype.Toggle = function() {
- const a = this;
-
- switch (a.IsExpanded()) {
- case true:
- a.Collapse();
- break;
- case false:
- a.Expand();
- break;
- default: break;
- }
-};
-
-BBTreeviewNode.prototype.initialise = function() {
- const a = this;
-
-// a.ID = null;
-// a.ParentID = null;
-// a.Name = "";
-// a.Hint = "";
-// a.Value = "";
-// a.Icon = "folder";
-// a.Checked = false;
-};
-
-BBTreeviewNode.prototype.invalidateCollapsible = function() {
- const a = this;
-
- // Invalidate state
- if (a.GetParentNode() == null) {
- return;
- }
-
- if (a.GetParentNode().classList.contains("c")) {
- a.Node.classList.add("hidden");
- } else if (a.GetParentNode().classList.contains("e")) {
- a.Node.classList.remove("hidden");
- } else {
- a.GetParentNode().classList.add("e");
- a.Node.classList.remove("hidden");
- }
-};
-
-BBTreeviewNode.prototype.isTag = function(el, tagName) {
- return (el.tagName.toLowerCase() == tagName);
-};
-
-BBTreeviewNode.prototype.parentsUntilTagName = function(el, tagName) {
- const a = this;
-
- let node = el;
-
- while (true) {
- if (typeof(node.parentNode) == "undefined") {
- break;
- }
-
- node = node.parentNode;
-
- if (typeof(node) == "undefined") {
- break;
- }
-
- if (a.isTag(node, "ul")) {
- if (node.classList.contains("bbtreeview")) {
- return null;
- }
- }
-
- if (a.isTag(node, tagName)) {
- break;
- }
- }
-
- return node;
-};
-
-BBTreeviewNode.prototype.setCheckbox = function(el, value) {
- if (value) {
- if (!el.classList.contains("x")) {
- el.classList.add("x");
- }
- } else {
- if (el.classList.contains("x")) {
- el.classList.remove("x");
- }
- }
-};
\ No newline at end of file
diff --git a/build.bat b/build.bat
new file mode 100644
index 0000000..e8ed8f6
--- /dev/null
+++ b/build.bat
@@ -0,0 +1,22 @@
+del bbtreeview.min.js
+del bbtreeview.min.tmp
+del build/bbtreeview.min.js
+
+cd src
+
+type version.txt >> ../bbtreeview.min.js
+
+@REM "C:\B\Portable Files (dev)\Google Closure Compiler\closure-compiler-v20231112.jar" --js *.js --js_output_file ../bbtreeview.min.tmp
+@REM npx google-closure-compiler --compilation_level=ADVANCED --js=*.js --js_output_file=../bbtreeview.min.tmp
+@REM npx google-closure-compiler --compilation_level=ADVANCED --warning_level=VERBOSE --js=*.js --js_output_file=bbtreeview.min.tmp
+@REM npx google-closure-compiler --warning_level=VERBOSE --js=*.js --js_output_file=bbtreeview.min.tmp
+
+move bbtreeview.min.tmp ../bbtreeview.min.tmp
+
+cd..
+
+type bbtreeview.min.tmp >> bbtreeview.min.js
+
+move bbtreeview.min.js build/bbtreeview.min.js
+
+del bbtreeview.min.tmp
diff --git a/bbtreeview.min.css b/build/bbtreeview.min.css
similarity index 100%
rename from bbtreeview.min.css
rename to build/bbtreeview.min.css
diff --git a/build/bbtreeview.min.js b/build/bbtreeview.min.js
new file mode 100644
index 0000000..6c4f307
--- /dev/null
+++ b/build/bbtreeview.min.js
@@ -0,0 +1,18 @@
+/**
+ * BBTreeview
+ * @version v0.1.2.044 (2024/01/09 2118)
+ */
+class BBTreeview{constructor(a){this.Options={};this.initialiseComponents(a)}initialiseComponents(a){this.Options=Object.assign({ID:null,ShowCheckbox:!1,ShowSelection:!0,EnablePullUp:!1,ShowIcon:!0},a);this.createTreeview()}get Container(){return this.getTreeview()}AddItem(a){a=Object.assign({ID:null,ParentID:null,Name:"",Hint:"",Value:"",Icon:"folder",Checked:!1,Tag:null},a);null==a.ID&&(a.ID=this.generateID());null==a.Tag&&(a.Tag="");if(null!=this.Find(a.ID))return!1;let b=null;if(null!=a.ParentID&&
+(b=this.Find(a.ParentID),null==b))return!1;b=null==b?this.Container:b.ChildNode;const c=this.generateNodeHtml(a);this.appendHtml(b,c);this.Find(a.ID).InvalidateEvents();return!0}Remove(a){a=this.Find(a);if(null==a)return!1;a.Remove();return!0}Clear(){this.initialiseComponents(this.Options)}CollapseAll(){this.GetAllNodes().forEach(function(a){a.Collapse()})}ExpandAll(){this.GetAllNodes().forEach(function(a){a.Expand()})}CheckAll(a){this.Options.ShowCheckbox&&this.GetAllNodes().forEach(function(b){b.Check(a)})}Find(a){if(null==
+this.Container)console.log("BBTreeview container not found");else return a=this.Container.querySelectorAll("li[data-bbtv-id='"+a+"']"),0>=a.length?null:new BBTreeviewNode(this,a[0])}FindByName(a){let b=[];this.GetAllNodes().forEach(function(c){c.Name==a&&b.push(c)});return b}FindByValue(a){let b=[];this.GetAllNodes().forEach(function(c){c.Value==a&&b.push(c)});return b}GetAllNodes(){const a=this,b=a.Container.querySelectorAll("li");if(0>=b.length)return[];let c=[];b.forEach(function(d){d=d.getAttribute("data-bbtv-id");
+a.isNullOrWhitespace(d)||(d=a.Find(d),null!=d&&c.push(d))});return c}GetCheckedNodes(){let a=[];this.GetAllNodes().forEach(function(b){b.IsChecked&&a.push(b)});return a}GetCheckedValues(){let a=[];this.GetCheckedNodes().map(function(b){a.push(b.Value)});return a}GetCheckedTags(){let a=[];this.GetCheckedNodes().map(function(b){a.push(b.Tag)});return a}GetSelectedNode(){let a=null;this.GetAllNodes().forEach(function(b){if(b.IsHighlighted)return a=b,!1});return a}appendHtml(a,b){let c=document.createElement("template");
+c.innerHTML=b;c=c.content.firstChild;a.appendChild(c)}createTreeview(){let a=this.getContainer();null!=a&&(a.innerHTML='')}generateID(){return"treeviewItem"+(Math.floor(1000001*Math.random())+100).toString()}generateNodeHtml(a){var b="";this.isNullOrWhitespace(a.Tag)||(b=encodeURIComponent(JSON.stringify(a.Tag)));b='';b+='';this.Options.ShowCheckbox&&(b+='
');
+this.Options.ShowIcon?(b+='
',b+='
'+a.Name+""):b+='
'+a.Name+"";return b+"
"}getContainer(){let a=document.getElementsByTagName("body");if(!(0>=a.length||(a=a[0],a=a.querySelectorAll(this.Options.ID),0>=a.length)))return a=a[0]}getNode(a){a=(this.isTag(a,"li")?a:this.parentsUntilTagName(a,"li")).getAttribute("data-bbtv-id");return this.isNullOrWhitespace(a)?null:this.Find(a)}getTreeview(){let a=
+this.getContainer();if(null!=a&&(a=a.querySelectorAll("ul.bbtreeview"),!(0>=a.length)))return a=a[0]}isNullOrWhitespace(a){return"undefined"==typeof a||null==a?!0:0>=a.toString().trim().length}isTag(a,b){return a.tagName.toLowerCase()==b}parentsUntilTagName(a,b){for(;"undefined"!=typeof a.parentNode;){a=a.parentNode;if("undefined"==typeof a)break;if(this.isTag(a,"ul")&&a.classList.contains("bbtreeview"))return null;if(this.isTag(a,b))break}return a}};class BBTreeviewNode{constructor(a,b){this.Treeview=a;this.Node=b}get Checkbox(){if(!this.Treeview.Options.ShowCheckbox)return null;const a=this.Node.querySelectorAll("div.icon.checkbox");return"undefined"==typeof a?null:a[0]}get ChildNode(){let a=this.Node.querySelectorAll("ul");return 0>=a.length?null:a[0]}get ChildNodes(){const a=this.ChildNode;if(null==a)return[];let b=a.querySelectorAll("li");if(0>=b.length)return[];let c=[];b.forEach(function(d){"undefined"!=typeof d.parentNode&&d.parentNode==
+a&&c.push(d)});return c}get IsChecked(){return this.Treeview.Options.ShowCheckbox?this.Node.classList.contains("x"):!1}get Container(){return this.Node.querySelectorAll("div.li")[0]}get Hint(){return this.Label.getAttribute("title")}get ID(){return this.Node.getAttribute("data-bbtv-id")}get IsExpanded(){return this.Node.classList.contains("e")?!0:this.Node.classList.contains("c")?!1:null}get IsHighlighted(){return this.Container.classList.contains("highlighted")}get Label(){return this.Node.querySelectorAll("span")[0]}get Name(){return this.Label.textContent}get ParentID(){const a=
+this.ParentNode;return null==a?null:a.getAttribute("data-bbtv-id")}get ParentNode(){return this.parentsUntilTagName(this.Node,"li")}get Tag(){let a=this.Node.getAttribute("data-bbtv-tag");return this.Treeview.isNullOrWhitespace(a)?null:JSON.parse(decodeURIComponent(a))}get Value(){return this.Node.getAttribute("data-bbtv-value")}Check(a){const b=this;b.setCheckbox(b.Node,a);b.Node.querySelectorAll("li").forEach(function(d){b.setCheckbox(d,a)});let c=b.ParentNode;if(null!=c)if(b.Treeview.Options.EnablePullUp)for(;;){const d=
+0=d)}}Collapse(){this.Node.classList.contains("e")&&(this.Node.classList.remove("e"),this.Node.classList.add("c"));this.ChildNodes.forEach(function(a){a.classList.add("hidden")})}Expand(){this.Node.classList.contains("c")&&(this.Node.classList.remove("c"),this.Node.classList.add("e"));
+this.ChildNodes.forEach(function(a){a.classList.remove("hidden")})}Remove(){null!=this.ParentNode&&(this.ParentNode.classList.contains("e")&&this.ParentNode.classList.remove("e"),this.ParentNode.classList.contains("c")&&this.ParentNode.classList.remove("c"));this.Node.parentNode.removeChild(this.Node)}InvalidateEvents(){const a=this;a.Node.addEventListener("click",function(b){b.stopPropagation();b.preventDefault();!a.isTag(b.target,"li")||0>b.offsetX||16b.offsetY||16 -->
-
-
-
+
+
+
+
+
diff --git a/src/UCkji.png b/src/UCkji.png
deleted file mode 100644
index 5853d67..0000000
Binary files a/src/UCkji.png and /dev/null differ
diff --git a/bbtreeview.css b/src/bbtreeview.css
similarity index 100%
rename from bbtreeview.css
rename to src/bbtreeview.css
diff --git a/src/bbtreeview.js b/src/bbtreeview.js
new file mode 100644
index 0000000..b7670de
--- /dev/null
+++ b/src/bbtreeview.js
@@ -0,0 +1,412 @@
+class BBTreeview {
+ constructor(options) {
+ this.Options = {};
+
+ this.initialiseComponents(options);
+ }
+
+ initialiseComponents(options) {
+ var a = this;
+
+ a.Options = Object.assign({
+ ID: null,
+ ShowCheckbox: false,
+ ShowSelection: true,
+ EnablePullUp: false,
+ ShowIcon: true
+ }, options);
+
+ // Replace treeview
+ a.createTreeview();
+
+ // a.Container = a.getTreeview();
+ }
+
+
+ get Container() {
+ return this.getTreeview();
+ }
+
+
+ AddItem(options) {
+ const a = this;
+ const _options = Object.assign({
+ ID: null,
+ ParentID: null,
+ Name: "",
+ Hint: "",
+ Value: "",
+ Icon: "folder",
+ Checked: false,
+ Tag: null
+ }, options);
+
+ if (_options.ID == null) _options.ID = a.generateID();
+ if (_options.Tag == null) _options.Tag = "";
+
+ // Don't add duplicate
+ if (a.Find(_options.ID) != null) {
+ return false;
+ }
+
+ // Check parent exists
+ let parentNode = null;
+ if (_options.ParentID != null) {
+ parentNode = a.Find(_options.ParentID);
+ if (parentNode == null) {
+ return false;
+ }
+ }
+
+ if (parentNode == null) {
+ parentNode = a.Container;
+ } else {
+ parentNode = parentNode.ChildNode;
+ }
+
+ const nodeHtml = a.generateNodeHtml(_options);
+
+ // Add node
+ a.appendHtml(parentNode, nodeHtml);
+
+ const node = a.Find(_options.ID);
+
+ // Setup events
+ node.InvalidateEvents();
+
+ return true;
+ }
+
+ Remove(id) {
+ const a = this;
+
+ const node = a.Find(id);
+ if (node == null) {
+ return false;
+ }
+
+ node.Remove();
+
+ return true;
+ }
+
+ Clear() {
+ const a = this;
+
+ a.initialiseComponents(a.Options);
+ }
+
+ CollapseAll() {
+ const a = this;
+
+ a.GetAllNodes().forEach(function(e) {
+ e.Collapse();
+ });
+ }
+
+ ExpandAll() {
+ const a = this;
+
+ a.GetAllNodes().forEach(function(e) {
+ e.Expand();
+ });
+ }
+
+ CheckAll(value) {
+ const a = this;
+
+ if (!a.Options.ShowCheckbox) {
+ return;
+ }
+
+ a.GetAllNodes().forEach(function(e) {
+ e.Check(value);
+ });
+ }
+
+ Find(id) {
+ const a = this;
+
+ if (a.Container == null){
+ console.log("BBTreeview container not found");
+ return;
+ }
+
+ const node = a.Container.querySelectorAll("li[data-bbtv-id='" + id + "']");
+ if (node.length <= 0) {
+ return null;
+ }
+
+ const treenode = new BBTreeviewNode(this, node[0]);
+
+ return treenode;
+ }
+
+ FindByName(value) {
+ const a = this;
+
+ let response = [];
+ a.GetAllNodes().forEach(function(e) {
+ if (e.Name != value) {
+ return;
+ }
+
+ response.push(e);
+ });
+
+ return response;
+ }
+
+ FindByValue(value) {
+ const a = this;
+
+ let response = [];
+ a.GetAllNodes().forEach(function(e) {
+ if (e.Value != value) {
+ return;
+ }
+
+ response.push(e);
+ });
+
+ return response;
+ }
+
+ GetAllNodes() {
+ const a = this;
+
+ const node = a.Container.querySelectorAll("li");
+ if (node.length <= 0) {
+ return [];
+ }
+
+ let response = [];
+ node.forEach(function(e) {
+ const id = e.getAttribute("data-bbtv-id");
+ if (a.isNullOrWhitespace(id)) {
+ return;
+ }
+
+ const myNode = a.Find(id);
+ if (myNode == null) {
+ return;
+ }
+
+ response.push(myNode);
+ });
+
+ return response;
+ }
+
+ GetCheckedNodes() {
+ const a = this;
+
+ let response = [];
+ a.GetAllNodes().forEach(function(e) {
+ if (!e.IsChecked) {
+ return;
+ }
+
+ response.push(e);
+ });
+
+ return response;
+ }
+
+ GetCheckedValues() {
+ const a = this;
+
+ let response = [];
+ a.GetCheckedNodes().map(function(e) {
+ response.push(e.Value);
+ });
+
+ return response;
+ }
+
+ GetCheckedTags() {
+ const a = this;
+
+ let response = [];
+ a.GetCheckedNodes().map(function(e) {
+ response.push(e.Tag);
+ });
+
+ return response;
+ }
+
+ GetSelectedNode() {
+ const a = this;
+
+ let response = null;
+ a.GetAllNodes().forEach(function(e) {
+ if (e.IsHighlighted) {
+ response = e;
+
+ return false;
+ }
+ });
+
+ return response;
+ }
+
+
+ appendHtml(el, html) {
+ let node = document.createElement('template');
+ node.innerHTML = html;
+
+ node = node.content.firstChild;
+
+ el.appendChild(node);
+ }
+
+ createTreeview() {
+ const a = this;
+
+ let container = a.getContainer();
+ if (container != null) {
+ container.innerHTML = "";
+ }
+ }
+
+ generateID() {
+ return "treeviewItem" + (Math.floor(Math.random() * 1000001) + 100).toString();
+ }
+
+ generateNodeHtml(options) {
+ const a = this;
+
+ let tag = "";
+ if (!a.isNullOrWhitespace(options.Tag)) {
+ tag = encodeURIComponent(JSON.stringify(options.Tag));
+ }
+
+ let html = '';
+ html += ''
+
+ if (a.Options.ShowCheckbox) {
+ html += '
';
+ }
+
+ if (a.Options.ShowIcon) {
+ html += '
';
+ html += '
' + options.Name + '';
+ } else {
+ html += '
' + options.Name + '';
+ }
+
+ html += '
';
+ html += '';
+ html += '';
+
+ return html;
+ }
+
+ getContainer() {
+ const a = this;
+
+ let result = document.getElementsByTagName("body");
+ if (result.length <= 0) {
+ return;
+ }
+
+ result = result[0];
+
+ result = result.querySelectorAll(a.Options.ID);
+ if (result.length <= 0) {
+ return;
+ }
+
+ result = result[0];
+
+ return result;
+ }
+
+ getNode(el) {
+ const a = this;
+
+ let node = null;
+ if (a.isTag(el, "li")) {
+ node = el;
+ } else {
+ node = a.parentsUntilTagName(el, "li");
+ }
+
+ const id = node.getAttribute("data-bbtv-id");
+
+ if (a.isNullOrWhitespace(id)) {
+ return null;
+ }
+
+ return a.Find(id);
+ }
+
+ getTreeview() {
+ const a = this;
+
+ let container = a.getContainer();
+ if (container == null) {
+ return;
+ }
+
+ // if (container.querySelectorAll("ul.bbtreeview").length <= 0) {
+ // container.innerHTML = "";
+ // }
+
+ container = container.querySelectorAll("ul.bbtreeview");
+ if (container.length <= 0) {
+ return;
+ }
+
+ container = container[0];
+
+ return container;
+ }
+
+ isNullOrWhitespace(value) {
+ if (typeof (value) == "undefined") {
+ return true;
+ }
+
+ if (value == null) {
+ return true;
+ }
+
+ return (value.toString().trim().length <= 0);
+ }
+
+ isTag(el, tagName) {
+ return (el.tagName.toLowerCase() == tagName);
+ }
+
+ parentsUntilTagName(el, tagName) {
+ const a = this;
+
+ let node = el;
+
+ while (true) {
+ if (typeof(node.parentNode) == "undefined") {
+ break;
+ }
+
+ node = node.parentNode;
+
+ if (typeof(node) == "undefined") {
+ break;
+ }
+
+ if (a.isTag(node, "ul")) {
+ if (node.classList.contains("bbtreeview")) {
+ return null;
+ }
+ }
+
+ if (a.isTag(node, tagName)) {
+ break;
+ }
+ }
+
+ return node;
+ }
+
+}
\ No newline at end of file
diff --git a/src/bbtreeviewnode.js b/src/bbtreeviewnode.js
new file mode 100644
index 0000000..1c8a64e
--- /dev/null
+++ b/src/bbtreeviewnode.js
@@ -0,0 +1,405 @@
+class BBTreeviewNode {
+ constructor(treeview, node) {
+ this.Treeview = treeview;
+ this.Node = node;
+
+ // this.initialiseComponents();
+ }
+
+ // initialiseComponents() {
+ // const a = this;
+
+ // }
+
+
+ get Checkbox() {
+ const a = this;
+
+ if (!a.Treeview.Options.ShowCheckbox) {
+ return null;
+ }
+
+ const checkboxes = a.Node.querySelectorAll("div.icon.checkbox");
+ if (typeof(checkboxes) == "undefined") {
+ return null;
+ }
+
+ return checkboxes[0];
+ }
+
+ get ChildNode() {
+ const a = this;
+
+ let result = a.Node.querySelectorAll("ul");
+ if (result.length <= 0) {
+ return null;
+ }
+
+ return result[0];
+ }
+
+ get ChildNodes() {
+ const a = this;
+
+ const childNode = a.ChildNode;
+ if (childNode == null) {
+ return [];
+ }
+
+ let nodes = childNode.querySelectorAll("li");
+ if (nodes.length <= 0) {
+ return [];
+ }
+
+ let result = [];
+ nodes.forEach(function(e) {
+ if (typeof(e.parentNode) == "undefined") {
+ return;
+ }
+
+ if (e.parentNode != childNode) {
+ return;
+ }
+
+ result.push(e);
+ });
+
+ return result;
+ }
+
+ get IsChecked() {
+ const a = this;
+
+ if (!a.Treeview.Options.ShowCheckbox) {
+ return false;
+ }
+
+ return a.Node.classList.contains("x");
+ }
+
+ get Container() {
+ return this.Node.querySelectorAll("div.li")[0];
+ }
+
+ get Hint() {
+ return this.Label.getAttribute("title");
+ }
+
+ get ID() {
+ return this.Node.getAttribute("data-bbtv-id");
+ }
+
+ get IsExpanded() {
+ const a = this;
+
+ if (a.Node.classList.contains("e")) {
+ return true;
+ }
+
+ if (a.Node.classList.contains("c")) {
+ return false;
+ }
+
+ return null;
+ }
+
+ get IsHighlighted() {
+ const a = this;
+
+ return a.Container.classList.contains("highlighted");
+ }
+
+ get Label() {
+ return this.Node.querySelectorAll("span")[0];
+ }
+
+ get Name() {
+ return this.Label.textContent;
+ }
+
+ get ParentID() {
+ const a = this;
+
+ const parentNode = a.ParentNode;
+ if (parentNode == null) {
+ return null;
+ }
+
+ return parentNode.getAttribute("data-bbtv-id");
+ }
+
+ get ParentNode() {
+ const a = this;
+
+ return a.parentsUntilTagName(a.Node, "li");
+ }
+
+ get Tag() {
+ const a = this;
+
+ let tag = a.Node.getAttribute("data-bbtv-tag");
+ if (a.Treeview.isNullOrWhitespace(tag)) {
+ return null;
+ }
+
+ return JSON.parse(decodeURIComponent(tag));
+ }
+
+ get Value() {
+ return this.Node.getAttribute("data-bbtv-value");
+ }
+
+
+ Check(value) {
+ const a = this;
+
+ a.setCheckbox(a.Node, value);
+
+ // Update children
+ a.Node.querySelectorAll("li").forEach(function(e) {
+ a.setCheckbox(e, value);
+ });
+
+ // Update parent state
+ let parentNode = a.ParentNode;
+ if (parentNode == null) {
+ return;
+ }
+
+ // Handle pull-ups
+ if (a.Treeview.Options.EnablePullUp) {
+ while (true) {
+ const parentChecked = (parentNode.querySelectorAll("li.x").length > 0);
+
+ a.setCheckbox(parentNode, parentChecked);
+
+ parentNode = a.Treeview.getNode(parentNode);
+ parentNode = parentNode.ParentNode;
+
+ if (parentNode == null) {
+ break;
+ }
+ }
+ } else {
+ let uncheckedCount = 0;
+
+ parentNode.querySelectorAll("li").forEach(function(e) {
+ if (e.classList.contains("x")) {
+ return;
+ }
+
+ uncheckedCount++;
+ });
+
+ a.setCheckbox(parentNode, (uncheckedCount <= 0));
+ }
+ }
+
+ Collapse() {
+ const a = this;
+
+ if (a.Node.classList.contains("e")) {
+ a.Node.classList.remove("e");
+ a.Node.classList.add("c");
+ }
+
+ a.ChildNodes.forEach(function(e) {
+ e.classList.add("hidden");
+ });
+ }
+
+ Expand() {
+ const a = this;
+
+ if (a.Node.classList.contains("c")) {
+ a.Node.classList.remove("c");
+ a.Node.classList.add("e");
+ }
+
+ a.ChildNodes.forEach(function(e) {
+ e.classList.remove("hidden");
+ });
+ }
+
+ Remove() {
+ const a = this;
+
+ if (a.ParentNode != null) {
+ if (a.ParentNode.classList.contains("e")) {
+ a.ParentNode.classList.remove("e");
+ }
+
+ if (a.ParentNode.classList.contains("c")) {
+ a.ParentNode.classList.remove("c");
+ }
+ }
+
+ a.Node.parentNode.removeChild(a.Node);
+ }
+
+ InvalidateEvents() {
+ const a = this;
+
+ // collapsible icon behaviour
+ a.Node.addEventListener("click", function(e){
+ e.stopPropagation();
+ e.preventDefault();
+
+ if (!a.isTag(e.target, "li")) {
+ return;
+ }
+
+ if ((e.offsetX < 0) || (e.offsetX > 16) || (e.offsetY < 0) || (e.offsetY > 16)) {
+ return;
+ }
+
+ const myNode = a.Treeview.getNode(e.target);
+ if (myNode == null) {
+ return;
+ }
+
+ myNode.Toggle();
+ });
+
+ // collapsible label behaviour
+ a.Container.addEventListener("dblclick", function(e){
+ e.stopPropagation();
+ e.preventDefault();
+
+ const myNode = a.Treeview.getNode(e.target);
+ if (myNode == null) {
+ return;
+ }
+
+ myNode.Toggle();
+ });
+
+ // checkbox behaviour
+ if (a.Treeview.Options.ShowCheckbox) {
+ a.Checkbox.addEventListener("mousedown", function(e){
+ e.stopPropagation();
+ e.preventDefault();
+
+ a.Check(!a.IsChecked);
+ });
+
+ a.Checkbox.addEventListener("click", function(e){
+ e.stopPropagation();
+ e.preventDefault();
+
+ // do nothing
+ });
+
+ a.Checkbox.addEventListener("dblclick", function(e){
+ e.stopPropagation();
+ e.preventDefault();
+
+ // do nothing
+ });
+ }
+
+ // highlighting
+ a.Container.addEventListener("mousedown", function(e){
+ e.stopPropagation();
+ e.preventDefault();
+
+ const myNode = a.Treeview.getNode(e.target);
+ if (myNode == null) {
+ return;
+ }
+
+ a.Treeview.Container.querySelectorAll("div.highlighted").forEach(function(e) {
+ e.classList.remove("highlighted");
+ });
+
+ // Don't show selection
+ if (!a.Treeview.Options.ShowSelection) {
+ return;
+ }
+
+ myNode.Container.classList.add("highlighted");
+ });
+
+ a.invalidateCollapsible();
+ }
+
+ Toggle() {
+ const a = this;
+
+ switch (a.IsExpanded) {
+ case true:
+ a.Collapse();
+ break;
+ case false:
+ a.Expand();
+ break;
+ default: break;
+ }
+ }
+
+
+ invalidateCollapsible() {
+ const a = this;
+
+ // Invalidate state
+ if (a.ParentNode == null) {
+ return;
+ }
+
+ if (a.ParentNode.classList.contains("c")) {
+ a.Node.classList.add("hidden");
+ } else if (a.ParentNode.classList.contains("e")) {
+ a.Node.classList.remove("hidden");
+ } else {
+ a.ParentNode.classList.add("e");
+ a.Node.classList.remove("hidden");
+ }
+ }
+
+ isTag(el, tagName) {
+ return (el.tagName.toLowerCase() == tagName);
+ }
+
+ parentsUntilTagName(el, tagName) {
+ const a = this;
+
+ let node = el;
+
+ while (true) {
+ if (typeof(node.parentNode) == "undefined") {
+ break;
+ }
+
+ node = node.parentNode;
+
+ if (typeof(node) == "undefined") {
+ break;
+ }
+
+ if (a.isTag(node, "ul")) {
+ if (node.classList.contains("bbtreeview")) {
+ return null;
+ }
+ }
+
+ if (a.isTag(node, tagName)) {
+ break;
+ }
+ }
+
+ return node;
+ }
+
+ setCheckbox(el, value) {
+ if (value) {
+ if (!el.classList.contains("x")) {
+ el.classList.add("x");
+ }
+ } else {
+ if (el.classList.contains("x")) {
+ el.classList.remove("x");
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/checkbox.png b/src/checkbox.png
new file mode 100644
index 0000000..d561510
Binary files /dev/null and b/src/checkbox.png differ
diff --git a/src/collapse.png b/src/collapse.png
index 9307b79..d8328c3 100644
Binary files a/src/collapse.png and b/src/collapse.png differ
diff --git a/src/expand.png b/src/expand.png
index 8d92b45..72f7767 100644
Binary files a/src/expand.png and b/src/expand.png differ
diff --git a/src/folder.png b/src/folder.png
new file mode 100644
index 0000000..8527862
Binary files /dev/null and b/src/folder.png differ
diff --git a/src/line.png b/src/line.png
new file mode 100644
index 0000000..7deb6c7
Binary files /dev/null and b/src/line.png differ
diff --git a/src/treeview-check-boxes12231.png b/src/treeview-check-boxes12231.png
deleted file mode 100644
index 6809043..0000000
Binary files a/src/treeview-check-boxes12231.png and /dev/null differ
diff --git a/src/uncheckbox.png b/src/uncheckbox.png
new file mode 100644
index 0000000..8b6fd10
Binary files /dev/null and b/src/uncheckbox.png differ
diff --git a/src/version.txt b/src/version.txt
new file mode 100644
index 0000000..c126fb0
--- /dev/null
+++ b/src/version.txt
@@ -0,0 +1,4 @@
+/**
+ * BBTreeview
+ * @version v0.1.2.044 (2024/01/09 2118)
+ */