WIP: JS Tree

* simplifies js for single-select radio tree
This commit is contained in:
mpeltriaux 2022-05-11 08:41:37 +02:00
parent a5d24e6db5
commit 5fe27e02ec

View File

@ -12,24 +12,16 @@
element = $(element); element = $(element);
var cssClass = "badge rlp-r" var cssClass = "badge rlp-r"
var directParent = element.closest(".tree-element-children") // Find all already tagged input elements and reset them to be untagged
var root = element.parents(".tree-element-children") var allTaggedInputs = $("#tree-root").find(".badge.rlp-r")
allTaggedInputs.removeClass(cssClass)
var otherCheckedInputsOfParent = directParent.find('.tree-input:checked'); // Find all parents of selected element
var otherCheckedInputsOfRoot = root.find('.tree-input:checked'); var parentElements = element.parents(".tree-element-children")
if(otherCheckedInputsOfParent.length == 0){
var parentLabel = directParent.siblings(".tree-label");
parentLabel.removeClass(cssClass)
if(otherCheckedInputsOfRoot.length == 0){
var rootLabel = root.siblings(".tree-label")
rootLabel.removeClass(cssClass)
}
}else{
var rootAndParentLabel = root.siblings(".tree-label");
rootAndParentLabel.addClass(cssClass);
}
// Tag parents of element
var parentLabels = parentElements.siblings(".tree-label");
parentLabels.addClass(cssClass);
} }
function changeHandler(event){ function changeHandler(event){