diff --git a/build.sh b/build.sh
index a58e2a6..745a1b2 100755
--- a/build.sh
+++ b/build.sh
@@ -1,3 +1,3 @@
-wget --post-data="input=`cat hybrid-dropdown.js`" --output-document=min/hybrid-dropdown.min.js https://javascript-minifier.com/raw
+# wget --post-data="input=`cat hybrid-dropdown.js`" --output-document=min/hybrid-dropdown.min.js https://javascript-minifier.com/raw
#css
wget --post-data="input=`cat hybrid-dropdown.css`" --output-document=min/hybrid-dropdown.min.css https://cssminifier.com/raw
diff --git a/hybrid-dropdown.css b/hybrid-dropdown.css
index 3e9f9a7..247f716 100755
--- a/hybrid-dropdown.css
+++ b/hybrid-dropdown.css
@@ -14,7 +14,7 @@
cursor: pointer;
background:inherit;
}
-
+.hybrid-dropdown:focus {box-shadow: 1px 1px 3px}
.hybriddd-option::before, .hybriddd-group::before {
display: none !important;
content: none;
@@ -67,6 +67,8 @@
cursor: pointer;
min-width: 100%;
max-width: inherit;
+ display: inline-block;
+ z-index: 2;
}
.hybriddd-selected::after {
diff --git a/hybrid-dropdown.js b/hybrid-dropdown.js
index 5c90877..a964e8f 100755
--- a/hybrid-dropdown.js
+++ b/hybrid-dropdown.js
@@ -79,11 +79,19 @@ class HybridDDError extends Error {
break;
default:
_.isDS = true;// dateset source.
- try{
- cnfg['dataSet'] = JSON.parse(elm.querySelector('script').innerHTML);
- }catch(se){
- console.log(se.name+":"+se.message);
- console.log("Unable to Hybridise element, missing or malformed json dataset");
+ if(!settings['dataSet']){ //json object parsed or in HTML
+ let is = elm.querySelector('script');
+ if(is){
+ try{
+ cnfg['dataSet'] = JSON.parse(elm.querySelector('script').innerHTML);
+ }catch(se){
+ console.log(se.name+":"+se.message);
+ console.log("HybridDropdown ERROR: missing or malformed json dataset");
+ }
+ }else{
+ console.log("HybridDropdown ERROR: missing json dataset");
+ cnfg['dataSet'] = null;
+ }
}
if(!cnfg['id'] && cnfg['fieldName']) cnfg['id'] = cnfg['fieldName'];
elm.classList.add('hybriddd-custom'); //flag the element as custom.
@@ -94,6 +102,7 @@ class HybridDDError extends Error {
elm._hybriddd = _;
_.el = elm; //keep original element reference.
_.el.classList.add('hybridddised'); //flag the element as converted.
+ // let pl = _.el.closest('label');
// merge user setting with defaults
Object.keys(cnfg).forEach(k=>{
switch(k){
@@ -140,19 +149,19 @@ class HybridDDError extends Error {
);
//nake sure we have proper functions
['selectedLabel','optionLabel'].forEach(s=>{
- if(!_.opt[s] || !(_.opt[s] instanceof Function) && 1==_.opt[s].length){
+ if(!_.opt[s] || !(_.opt[s] instanceof Function) || 1!=_.opt[s].length){
throw new HybridDDError(`${s} setting must be a function with 1 argument.`);
}
});
if(_.opt.listOption ){ //check we have a function.
- if( !(_.opt.listOption instanceof Function && 2==_.opt.listOption.length) ){
+ if( !(_.opt.listOption instanceof Function) || 2!=_.opt.listOption.length ){
throw new HybridDDError("listOption setting must be a function with 2 arguments.");
}
}
if(_.opt.treeView && 1==_.opt.limitSelection) _.opt.limitSelection=-1; //by default
_.multi = (_.opt.limitSelection !=1); //flag multi select field.
//check if we have a field name.
- if(!_.opt.fieldName) _.opt.fieldName = _.opt.fieldId; //try to set it to id.
+ if(!_.opt.fieldId) _.opt.fieldId = _.opt.fieldName;
if(_.multi && _.opt.fieldName && _.opt.fieldName.indexOf('[]')<0) _.opt.fieldName +='[]';
//initialise the hybrid-dd.
@@ -177,6 +186,8 @@ class HybridDDError extends Error {
_.hdd.setAttribute('tabindex',_.opt.tabIndex);
}
_.hdd.setAttribute('id',_.opt.fieldId);
+ let pl = _.el.closest('label');
+ if(pl) pl.setAttribute('for',_.opt.fieldId);
_.hdd.setAttribute('class',_.opt.fieldClass);
_.hdd.classList.add('hybrid-dropdown');
// _.hdd.setAttribute('aria-hidden', true);//hide from readers.
@@ -373,11 +384,13 @@ class HybridDDError extends Error {
case 0===p && o[1] instanceof Array:
hasChildren = isGroup = true;
if(o[1]['label']){
+ isGroup = false;
val = o[0];
icl = 'hybridddis';
lbl = _.opt.optionLabel(o[1]['label']);
- kids = Object.entries(o[1]).slice(1);
- isGroup = false;
+ kids = Object.entries(o[1]);
+ kids.splice(Object.keys(o[1]).indexOf('label'));
+ hasChildren = (kids.length>0);
}else kids = Object.entries(o[1]);
break;
default:
diff --git a/min/hybrid-dropdown.min.css b/min/hybrid-dropdown.min.css
index 71dc653..c3dc6a1 100644
--- a/min/hybrid-dropdown.min.css
+++ b/min/hybrid-dropdown.min.css
@@ -1 +1 @@
-.hybrid-dropdown{position:relative;width:max-content;min-width:30px;min-height:2.5em;display:inline-block;vertical-align:baseline;font-size:1em;border:1px solid #6f6f6f;border-radius:.25em;padding:0 30px 0 18px;cursor:pointer;background:inherit}.hybriddd-group::before,.hybriddd-option::before{display:none!important;content:none;margin:0;padding:0}.hybridddised:disabled .hybrid-dropdown{background:#ccc;color:grey}.hybrid-dropdown.wide,.hybrid-dropdown.wide .hybriddd-options{min-width:100%}.hybrid-dropdown ul.hybriddd-options{position:absolute;min-width:max-content;border:1px solid #6f6f6f;border-radius:.25em;background-color:inherit;padding:0;list-style:none!important;display:none;z-index:1;margin:0;padding:0;left:-1px;max-height:43vh;overflow-y:auto;scrollbar-width:thin}.hybrid-dropdown.active>.hybriddd-options{display:block}.hybrid-dropdown *,.hybrid-dropdown .hybriddd-options .hybriddd-group,.hybrid-dropdown .hybriddd-options .hybriddd-group ul,.hybrid-dropdown .hybriddd-options .hybriddd-option,.hybrid-dropdown .hybriddd-options .hybriddd-option ul{box-sizing:border-box;cursor:default;margin:0}.hybriddd-selected{position:relative;width:max-content;height:100%;padding:.4em 3px;cursor:pointer;min-width:100%;max-width:inherit}.hybriddd-selected::after{border-bottom:2px solid #90a1b5;border-right:2px solid #90a1b5;content:'';display:block;height:5px;margin-top:-4px;pointer-events:none;position:absolute;right:-12px;top:50%;-webkit-transform-origin:66% 66%;-ms-transform-origin:66% 66%;transform-origin:66% 66%;-webkit-transform:rotate(45deg);-ms-transform:rotate(45deg);transform:rotate(45deg);-webkit-transition:all .15s ease-in-out;transition:all .15s ease-in-out;width:5px}.hybriddd-landscape .hybriddd-options>.hybriddd-group>ul>.hybriddd-option,.hybriddd-landscape .hybriddd-options>.hybriddd-option{display:inline-block}.hybriddd-landscape .hybriddd-options .hybridddl:dir(rtl){float:right}.hybriddd-landscape .hybriddd-options .hybriddd-group{clear:both;border-top:none;padding:0}.hybriddd-landscape .hybriddd-option>label{padding:.1em}ul.hybriddd-options::-webkit-scrollbar{width:6px}ul.hybriddd-options::-webkit-scrollbar-track{-webkit-box-shadow:inset 0 0 6px rgb(1 1 1 / 35%)}.hybriddd-options ul{list-style:none;padding:0}.hybriddd-group>span{font-weight:700}.hybriddd-l0{padding:0 .5em}.hybriddd-l1{padding:0 1em 0 1em}.hybriddd-l2{padding:0 1em 0 1.5em}.hybriddd-l3{padding:0 1em 0 2em}.hybriddd-l4{padding:0 1em 0 2.5em}.hybriddd-l5{padding:0 1em 0 3em}.hybriddd-group>span{padding:0 .5em}.hybriddd-options ul .hybriddd-group>span{padding:0 1em}.hybriddd-option label{user-select:none;-ms-user-select:none;-moz-user-select:none;-webkit-user-select:none;display:block}.hybriddd-option label>*{display:inline-block}.hybridddcb{width:0;height:0;vertical-align:middle;display:inline-block;visibility:hidden}.hybrid-dropdown.show-cb .hybridddcb{visibility:visible;width:16px;height:16px;border:solid 1px;margin:0 3px 3px 2px}.hybriddd-option>label>input{opacity:0;width:0;height:0}.hybridddcb::before{content:'';display:block;width:10px;height:10px;margin:2px auto}.hybriddd-option input[type=radio] .hybridddcb{border-radius:50%}.hybriddd-option input:checked .hybridddcb::before{border:solid 3px;padding:1px}.hybriddd-option.active>label{background:#0466ff;color:#fff}input:checked .hybridddcb::before{background:#fff}.hybriddd-option.partial>label .hybridddcb::before{background:#a5a5a5}
\ No newline at end of file
+.hybrid-dropdown{position:relative;width:max-content;min-width:30px;min-height:2.5em;display:inline-block;vertical-align:baseline;font-size:1em;border:1px solid #6f6f6f;border-radius:.25em;padding:0 30px 0 18px;cursor:pointer;background:inherit}.hybrid-dropdown:focus{box-shadow:1px 1px 3px}.hybriddd-group::before,.hybriddd-option::before{display:none!important;content:none;margin:0;padding:0}.hybridddised:disabled .hybrid-dropdown{background:#ccc;color:grey}.hybrid-dropdown.wide,.hybrid-dropdown.wide .hybriddd-options{min-width:100%}.hybrid-dropdown ul.hybriddd-options{position:absolute;min-width:max-content;border:1px solid #6f6f6f;border-radius:.25em;background-color:inherit;padding:0;list-style:none!important;display:none;z-index:1;margin:0;padding:0;left:-1px;max-height:43vh;overflow-y:auto;scrollbar-width:thin}.hybrid-dropdown.active>.hybriddd-options{display:block}.hybrid-dropdown *,.hybrid-dropdown .hybriddd-options .hybriddd-group,.hybrid-dropdown .hybriddd-options .hybriddd-group ul,.hybrid-dropdown .hybriddd-options .hybriddd-option,.hybrid-dropdown .hybriddd-options .hybriddd-option ul{box-sizing:border-box;cursor:default;margin:0}.hybriddd-selected{position:relative;width:max-content;height:100%;padding:.4em 3px;cursor:pointer;min-width:100%;max-width:inherit;display:inline-block;z-index:2}.hybriddd-selected::after{border-bottom:2px solid #90a1b5;border-right:2px solid #90a1b5;content:'';display:block;height:5px;margin-top:-4px;pointer-events:none;position:absolute;right:-12px;top:50%;-webkit-transform-origin:66% 66%;-ms-transform-origin:66% 66%;transform-origin:66% 66%;-webkit-transform:rotate(45deg);-ms-transform:rotate(45deg);transform:rotate(45deg);-webkit-transition:all .15s ease-in-out;transition:all .15s ease-in-out;width:5px}.hybriddd-landscape .hybriddd-options>.hybriddd-group>ul>.hybriddd-option,.hybriddd-landscape .hybriddd-options>.hybriddd-option{display:inline-block}.hybriddd-landscape .hybriddd-options .hybridddl:dir(rtl){float:right}.hybriddd-landscape .hybriddd-options .hybriddd-group{clear:both;border-top:none;padding:0}.hybriddd-landscape .hybriddd-option>label{padding:.1em}ul.hybriddd-options::-webkit-scrollbar{width:6px}ul.hybriddd-options::-webkit-scrollbar-track{-webkit-box-shadow:inset 0 0 6px rgb(1 1 1 / 35%)}.hybriddd-options ul{list-style:none;padding:0}.hybriddd-group>span{font-weight:700}.hybriddd-l0{padding:0 .5em}.hybriddd-l1{padding:0 1em 0 1em}.hybriddd-l2{padding:0 1em 0 1.5em}.hybriddd-l3{padding:0 1em 0 2em}.hybriddd-l4{padding:0 1em 0 2.5em}.hybriddd-l5{padding:0 1em 0 3em}.hybriddd-group>span{padding:0 .5em}.hybriddd-options ul .hybriddd-group>span{padding:0 1em}.hybriddd-option label{user-select:none;-ms-user-select:none;-moz-user-select:none;-webkit-user-select:none;display:block}.hybriddd-option label>*{display:inline-block}.hybridddcb{width:0;height:0;vertical-align:middle;display:inline-block;visibility:hidden}.hybrid-dropdown.show-cb .hybridddcb{visibility:visible;width:16px;height:16px;border:solid 1px;margin:0 3px 3px 2px}.hybriddd-option>label>input{opacity:0;width:0;height:0}.hybridddcb::before{content:'';display:block;width:10px;height:10px;margin:2px auto}.hybriddd-option input[type=radio] .hybridddcb{border-radius:50%}.hybriddd-option input:checked .hybridddcb::before{border:solid 3px;padding:1px}.hybriddd-option.active>label{background:#0466ff;color:#fff}input:checked .hybridddcb::before{background:#fff}.hybriddd-option.partial>label .hybridddcb::before{background:#a5a5a5}
diff --git a/min/hybrid-dropdown.min.js b/min/hybrid-dropdown.min.js
index 81a7905..e85ce90 100644
--- a/min/hybrid-dropdown.min.js
+++ b/min/hybrid-dropdown.min.js
@@ -1 +1 @@
-class HybridDDError extends Error{constructor(e){super(e),this.name="HybridDropdownError"}}!function(e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e():e()}(function(){let e="undefined"!=typeof window?window:this,t=e.HybridDropdown=function(e,t){if(!(e&&e instanceof Element))throw new HybridDDError("HybridDropdown requires a DOM element to intialise.");if(e.classList.contains("hybridddised")&&e._hybriddd)return console.log("WARNING: attempting instantiate element already converted to Hybrid Dropdown"),e._hybriddd;if(e.classList.contains("hybrid-dropdown"))return console.log("WARNING: attempting instantiate Hybrid Dropdown element."),e;let i=this,d=1,o=!0,l=e.getAttribute("tabindex");switch(i.isDS=!1,cnfg=Object.assign({},e.dataset),["class","id","name"].forEach(t=>{if(e.hasAttribute(t)){let i="field"+t.charAt(0).toUpperCase()+t.slice(1);cnfg[i]=e.getAttribute(t),e.removeAttribute(t)}}),!0){case"SELECT"===e.nodeName:e.multiple&&(d=-1),e.style="visibility:hidden",o=!1;break;default:i.isDS=!0;try{cnfg.dataSet=JSON.parse(e.querySelector("script").innerHTML)}catch(e){console.log(e.name+":"+e.message),console.log("Unable to Hybridise element, missing or malformed json dataset")}!cnfg.id&&cnfg.fieldName&&(cnfg.id=cnfg.fieldName),e.classList.add("hybriddd-custom")}if(cnfg&&(e._hybriddd=i),i.el=e,i.el.classList.add("hybridddised"),Object.keys(cnfg).forEach(e=>{switch(e){case"limitSelection":cnfg[e]=parseInt(cnfg[e]);break;case"treeView":case"negative":case"colourise":case"checkboxes":cnfg[e]="true"==cnfg[e]}}),i.opt=Object.assign({},{dropdown:"vertical",limitSelection:d,optionLabel:function(e){return""+e+""},selectedLabel:function(e){let t=Object.keys(e);return e[t[0]]+(t.length>1?"[...]":"")},defaultText:"---",treeView:!1,treeGlue:"/",fieldName:"hybriddd",backgroundColor:"",color:"",negative:!1,colourise:!0,checkboxes:o,tabIndex:l||0,listOption:null,selectedValues:[],fieldId:"",fieldClass:""},t,cnfg),["selectedLabel","optionLabel"].forEach(e=>{if(!i.opt[e]||!(i.opt[e]instanceof Function)&&1==i.opt[e].length)throw new HybridDDError(`${e} setting must be a function with 1 argument.`)}),i.opt.listOption&&!(i.opt.listOption instanceof Function&&2==i.opt.listOption.length))throw new HybridDDError("listOption setting must be a function with 2 arguments.");return i.opt.treeView&&1==i.opt.limitSelection&&(i.opt.limitSelection=-1),i.multi=1!=i.opt.limitSelection,i.opt.fieldName||(i.opt.fieldName=i.opt.fieldId),i.multi&&i.opt.fieldName&&i.opt.fieldName.indexOf("[]")<0&&(i.opt.fieldName+="[]"),i.init(!0,!0,!0),i},i=t.prototype;return i.init=function(e,t,i){let d=this;if(e&&(d.hdd=null,d.isDS?(d.hdd=d.el,d.el.hasAttribute("tabindex")||d.hdd.setAttribute("tabindex",d.opt.tabIndex)):(d.hdd=document.createElement("div"),d.el.parentNode.insertBefore(d.hdd,d.el.nextSibling),d.hdd.style["margin-left"]="-"+d.el.getBoundingClientRect().width+"px",d.hdd.setAttribute("tabindex",d.opt.tabIndex)),d.hdd.setAttribute("id",d.opt.fieldId),d.hdd.setAttribute("class",d.opt.fieldClass),d.hdd.classList.add("hybrid-dropdown"),d.hdd.selected=document.createElement("div"),d.hdd.appendChild(d.hdd.selected),d.hdd.selected.classList.add("hybriddd-selected"),d.hdd.ddlist=document.createElement("ul"),d.hdd.appendChild(d.hdd.ddlist),d.hdd.ddlist.classList.add("hybriddd-options"),d.listenForBulk=!1,d.listenModClick=!1,d.hdd.classList.add("hybriddd-"+d.opt.dropdown)),t){let e=null;d.hdd.options={},d.hindex=[],d.sindex=[],d.value={};try{d.isDS?(d.hdd.classList.add("hybriddd-custom"),d.opt.dataSet?e=d.buildOptionList(Object.entries(d.opt.dataSet),0):(d.hdd.selected.innerHTML="json error",e=[])):e=d.buildOptionList(d.el.children,0),d.hdd.ddlist.replaceChildren(...e)}catch(e){if(!(e instanceof HybridDDError))throw e;console.log(e.name+":"+e.message),d.hdd.selected.innerHTML="json error"}}e&&(d.isDS||d.event(d.el,"add",{change:d.updateFromOriginal.bind(d),focus:d.originalElementFocus.bind(d)}),d.change=d.inputChange.bind(d),d.event(d.hdd.ddlist,"add",{change:d.change}),d.open=d.openSelect.bind(d),d.event(d.hdd,"add",{click:d.open}),d.close=d.closeSelect.bind(d,!0),d.blur=d.blurField.bind(d),d.hover=d.optionHover.bind(d),d.keyNav=d.keyboardNavigate.bind(d),d.event(d.hdd,"add",{keydown:d.keyNav}),d.refresh=d.refreshHybrid.bind(d),d.modClick=d.optionModClick.bind(d),d.emit("hybrid-dd-init")),d.opt.checkboxes&&d.hdd.classList.add("show-cb"),i&&d.colourise()},i.colourise=function(){let t=this,i=!1;if(!t.opt.colourise)return;if(!(e.hdd||t.opt.backgroundColor&&t.opt.color)){let d,o=!1,l=t.hdd;for(e.hdd={};!o&&l;){if(d=e.getComputedStyle(l,null),!e.hdd.bgColor&&!t.opt.backgroundColor)switch(d["background-color"]){case"transparent":case"":case"rgba(0, 0, 0, 0)":l=l.parentElement;break;default:e.hdd.bgColor=d["background-color"]}if(!e.hdd.color&&!t.opt.color)switch(d.color){case"transparent":case"":case"rgba(0, 0, 0, 0)":l=l.parentElement;break;default:e.hdd.color=d.color}e.hdd.bgColor&&e.hdd.color&&(o=!0),i=!0}o||(e.hdd.color||(e.hdd.color="#fff"),e.hdd.bgColor&&(e.hdd.bgColor="#5d5d5d"))}let d=t.opt.backgroundColor?t.opt.backgroundColor:e.hdd.bgColor,o=t.opt.color?t.opt.color:e.hdd.color;if(t.hdd.style["background-color"]=t.opt.negative?o:d,t.hdd.style.color=t.opt.negative?d:o,i){let e=document.createElement("style");e.setAttribute("id","hybriddd-colours"),e.type="text/css",e.innerText=`.hybriddd-option.active > label:hover,.hybriddd-option.hover > label,.hybriddd-option > label:hover{color:${d};background-color:${o}}:hover > input:checked + .hybridddl > .hybridddcb::before {color:${o}}ul.hybriddd-options::-webkit-scrollbar-track {background:${d}} ul.hybriddd-options::-webkit-scrollbar-thumb, ul.hybriddd-options::-webkit-scrollbar{background:${o}}`,document.head.appendChild(e)}if(t.opt.backgroundColor||t.opt.color||t.opt.negative){if(t.opt.negative){let e=d;d=o,o=e}let e=document.createElement("style"),i=t.hdd.getAttribute("id");e.setAttribute("id",i+"-css"),e.type="text/css",e.innerText=`#${i} .hybriddd-option.active > label:hover,#${i} .hybriddd-option.hover > label,#${i} .hybriddd-option > label:hover{color:${d};background-color:${o}}#${i} :hover > input:checked + .hybridddl > .hybridddcb::before {color:${o}} #${i} ul.hybriddd-options::-webkit-scrollbar-track {background:${d}} #${i} ul.hybriddd-options::-webkit-scrollbar-thumb,#${i} ul.hybriddd-options::-webkit-scrollbar{background:${o}}`,document.head.appendChild(e)}},i.refreshHybrid=function(e={}){let t=this,i=!1,d=!1;if(e.hasOwnProperty("negative")||e.hasOwnProperty("colourise")||e.color||e.backgroundColor){d=!0;let e=t.el.getAttribute("id"),i=document.querySelector("style#"+e+"-css");i&&i.remove()}e.listOption&&(i=!0,e.listOption instanceof Function&&2==e.listOption.length||(console.log("Hybriddd refresh error: listOption setting must be a function with 2 arguments."),e.listOption=null)),t.opt=Object.assign({},t.opt,e),t.init(!1,i,d)},i.buildOptionList=function(e,t,i=""){let d=this,o=[],l=d.multi?"checkbox":"radio",n=d.opt.fieldName?' name="'+d.opt.fieldName+'"':"";if([].forEach.call(e,(e,s)=>{if(d.opt.listOption&&!0!==d.opt.listOption(e,s))return;let r,c,a=document.createElement("li"),h=!1,u=!1,p=!1,b=[],f="",y="";if(d.isDS)switch(r=e[0],c=null,!0){case e[1]instanceof Object&&!e[1].length:case 0===t&&e[1]instanceof Array:p=h=!0,e[1].label?(c=e[0],f="hybridddis",r=d.opt.optionLabel(e[1].label),b=Object.entries(e[1]).slice(1),h=!1):b=Object.entries(e[1]);break;default:f="hybridddis",c=e[0],r=d.opt.optionLabel(e[1]),u=d.opt.selectedValues.indexOf(c)>=0}else switch(e.nodeName){case"OPTGROUP":p=h=!0,r=e.label,b=e.children;break;default:f="hybridddin",r=e.text,c=e.value,u=e.selected}switch(h){case!0:a.innerHTML=""+r+"",a.classList.add("hybriddd-group");break;default:if(y="",u&&(d.value[c]=r,d.sindex.push(c),y=" checked"),a.setAttribute("tabindex","-1"),a.innerHTML=``,a.classList.value="hybriddd-option"+(u?" active":""),d.isDS||(a.classList.value+=` ${e.classList.value}`),d.hdd.options[i+c])throw new HybridDDError("Option list has duplicate value: "+c);d.hdd.options[i+c]=a}if(p){d.opt.treeView&&c&&(i+=c+d.opt.treeGlue);let e=d.buildOptionList(b,t+1,i),o=document.createElement("ul");o.replaceChildren(...e),a.appendChild(o)}o[o.length]=a}),0==t){d.empty()&&d.reset();let e=Object.keys(d.value);e.length>1&&e.indexOf("")>=0&&delete d.value[""],d.hdd.selected.innerHTML=d.opt.selectedLabel(d.value)}return o},i.empty=function(){let e=this;for(let t in e.value)return!1;return!0},i.reset=function(){let e=this;e.sindex=[],e.hdd.options[""]?(e.hdd.options[""].classList.add("active"),e.value[""]=e.hdd.options[""].querySelector(".hybridddl").innerHTML,e.hdd.options[""].querySelector("input").checked=!0,e.sindex.push("")):e.value[""]=e.opt.defaultText},i.event=function(e,t,i){var d=e[t+"EventListener"].bind(e);Object.keys(i).forEach(function(e){["mouseenter","mouseleave"].indexOf(e)>=0?d(e,i[e],!0):d(e,i[e])})},i.updateFromOriginal=function(){let e=this,t=[];if(!e.isDS){if(e.multi){let i=!0;for(let d=0;d0?t.indexOf(e[e.length-1]):-1;return i0?t.indexOf(e[0]):t.length;return i>=0&&i--,i<0&&(i=t.length-1),t[i]},i.keyboardNavigate=function(){let e,t=this,i=arguments[0];if(!t.el.disabled&&i&&i.keyCode)switch(i.preventDefault(),!0){case 40==i.keyCode&&"keydown"==i.type:t.hdd.classList.contains("active")?((t.hindex.length>0&&!t.multi||!i.shiftKey)&&t.clearClass("hover"),e=t.nextOption(t.hindex),t.hdd.options[e].classList.add("hover"),t.scroll(e,"down"),t.multi&&i.shiftKey?(t.hindex.push(e),t.opt.limitSelection>0&&(t.hindex=t.hindex.slice(-1*t.opt.limitSelection))):t.hindex[0]=e):1==t.opt.limitSelection?(e=t.nextOption(t.sindex),t.toggleValue([e],!0)):(t.hdd.classList.remove("focus"),t.open());break;case 38==i.keyCode&&"keydown"==i.type:if(t.hdd.classList.contains("active"))(t.hindex.length>0&&!t.multi||!i.shiftKey)&&t.clearClass("hover"),e=t.prevOption(t.hindex),t.hdd.options[e].classList.add("hover"),t.scroll(e,"up"),t.multi&&i.shiftKey?(t.hindex.push(e),t.opt.limitSelection>0&&(t.hindex=t.hindex.slice(-1*t.opt.limitSelection))):t.hindex[0]=e;else if(1==t.opt.limitSelection){let e=t.prevOption(t.sindex);t.toggleValue([e],!0)}else t.hdd.classList.remove("focus"),t.open();break;case 13==i.keyCode&&"keydown"==i.type:case 32==i.keyCode&&"keydown"==i.type:!1===t.hdd.classList.contains("active")?(t.hdd.classList.remove("focus"),t.open()):(t.hindex.length>0&&t.toggleValue(t.hindex,!0),t.closeSelect(!1),t.hdd.classList.add("focus"));break;case 27==i.keyCode&&"keydown"==i.type:t.hdd.classList.contains("active")&&t.closeSelect(!1),t.blurField();break;case 9==i.keyCode&&"keydown"==i.type:t.hdd.classList.contains("active")&&t.closeSelect(!1),t.blurField();let d,o,l=1*t.el.getAttribute("tabindex"),n=t.el.closest("form");if(null===n&&(n=document),null!=l&&""!=l)l+=1,d=n.querySelector('[tabindex="'+l+'"]');else if(n!==document)for(l in o=t.el,t.isDS&&(l=(o=Object.keys(t.hdd.options))[o.length-1],o=t.hdd.options[l].querySelector("input")),n.elements)if(n.elements[l]===o){do{l++}while(lo.bottom)switch(t){case"up":o.top>d.top?i.hdd.ddlist.scrollTop-=d.height:o.bottomd.top&&(i.hdd.ddlist.scrollTop=0)}},i.inputChange=function(){let e=this,t=arguments[0],i=[],d=!1;if(t&&t.target){if(d=t.target.classList.contains("mod-ctrl"),"change"==t.type&&d)return t.target.classList.remove("mod-ctrl"),!1;if(e.hindex.length>0&&(i=[...e.hindex]),t.target.checked&&""==t.target.value)d||e.removeValue([...e.sindex],!0);else if(e.opt.treeView&&(e.opt.limitSelection<0||e.opt.limitSelection>e.sindex.length)){let o,l,n=!0,s=t.target.closest(".hybriddd-option"),r=s.querySelectorAll("input");for(l of r.values())l.checked=t.target.checked,d||(t.target.checked?i.push(l.value):e.removeValue([l.value])),l.closest(".hybriddd-option").classList.remove("partial");for(;s;)l=s.querySelector("input"),n||l.checked||s.querySelectorAll("label input").length-s.querySelectorAll("label input:checked").length!=1||(l.checked=!0,i.push(l.value),s.classList.remove("partial")),r=s.querySelectorAll("input:checked"),o=s.querySelectorAll("input"),l.checked&&1==r.length&&o.length>1?(s.classList.remove("partial"),l.checked=!1,d||e.removeValue([l.value])):r.length>0&&o.length!=r.length?(s.classList.add("partial"),d||e.removeValue([l.value])):s.classList.remove("partial"),s=s.parentNode.closest(".hybriddd-option"),n=!1;d||e.addValue(i,!0)}else d||(i.push(t.target.value),t.target.checked?e.addValue(i,!0):e.removeValue(i,!0));switch(!0){case"hybrid-ddi-change"==t.type:case t.shiftKey&&1==t.shiftKey:break;default:e.closeSelect(!1)}}},i.toggleValue=function(e,t){let i=this;i.hdd.options[e[0]].querySelector("input").checked?i.removeValue(e,t):i.addValue(e,t)},i.addValue=function(e,t=!1){let i=this;switch(i.opt.limitSelection){case 1:i.sindex.length>0&&i.hdd.options[i.sindex[0]].classList.remove("active"),i.sindex=e;break;default:if(1==i.sindex.length&&0==i.sindex[0].length?(i.hdd.options[""].classList.remove("active"),i.hdd.options[""].querySelector("input").checked=!1,i.sindex=e):i.sindex=i.sindex.concat(e),i.opt.limitSelection>0){for(let e=i.opt.limitSelection;e{i.value[e]=i.hdd.options[e].querySelector(".hybridddl").innerHTML,i.hdd.options[e].querySelector("input").checked=!0,i.hdd.options[e].classList.add("active")}),i.empty()&&i.reset(),i.isDS||i.updateOriginal(),i.hdd.selected.innerHTML=i.opt.selectedLabel(i.value),t&&i.emit("change")},i.removeValue=function(e,t=!1){let i,d=this;e.forEach(e=>{d.hdd.options[e].classList.remove("active"),d.hdd.options[e].querySelector("input").checked=!1,(i=d.sindex.indexOf(e))>=0&&(d.sindex.splice(i,1),delete d.value[e])}),0==d.sindex.length&&(d.hdd.options[""]?(d.sindex=[""],d.value={"":d.hdd.options[""].querySelector(".hybridddl").innerHTML},d.hdd.options[""].querySelector("input").checked=!0,d.hdd.options[""].classList.add("active")):d.value={"":d.opt.defaultText}),d.empty()&&d.reset(),d.isDS||d.updateOriginal(),d.hdd.selected.innerHTML=d.opt.selectedLabel(d.value),t&&d.emit("change")},i.updateOriginal=function(){let e=this;Object.keys(e.value).forEach(t=>{e.el.selectedIndex=-1,e.el.querySelector('option[value="'+t+'"]').selected=!0})},i.optionHover=function(){let e,t,i=this,d=arguments[0];if(d.shiftKey){if(t=d.target.classList.contains("hybriddd-option")?d.target:d.target.closest(".hybriddd-option")){switch(e=t.querySelector("input").value,d.type){case"mouseleave":i.event(i.hdd.ddlist,"remove",{mouseleave:i.hover}),e&&(i.hindex=[e]);break;case"mouseenter":i.hindex.includes(e)?(e=i.hindex[i.hindex.length-1],i.hindex=i.hindex.slice(0,-1)):e&&i.hindex.push(e),i.opt.limitSelection>0&&(i.hindex=i.hindex.slice(0,i.opt.limitSelection))}e&&!i.sindex.includes(e)&&i.hdd.options[e].classList.add("hover")}}else i.hindex.length>0&&(i.clearClass("hover"),i.hindex=[])},i.clearClass=function(e){let t=this;"string"==typeof e&&e.length>0&&t.hdd.querySelectorAll("."+e).forEach(t=>{t.classList.remove(e)})},i.openSelect=function(){let e=this,t=arguments[0];if(!e.el.disabled){if(t&&t.target){if(t.target.classList.contains("hybriddd-options")||t.target.closest(".hybriddd-options"))return;t.stopPropagation(),e.emit("hybrid-dd-"+t.type)}e.hdd.classList.contains("active")?e.closeSelect():(e.hdd.classList.add("active"),e.hdd.ddlist.style["min-width"]||(e.hdd.ddlist.style["min-width"]=e.hdd.ddlist.offsetWidth+12+"px"),e.event(document,"add",{click:e.close}),e.event(e.hdd,"add",{keyup:e.keyNav}),e.event(document,"add",{"hybrid-dd-click":e.close}))}},i.closeSelect=function(e){let t=this,i=arguments[0],d=arguments[1];if(!(i&&i.target&&i.target.classList.contains("hybriddd-option"))){if(d){if(d.target.isSameNode(t.el))return;if(t.multi&&(d.ctrlKey||d.shiftKey))return;if(d.target.parentNode.classList&&d.target.parentNode.classList.contains("hybriddd-group"))return;if(d.target.closest(".hybriddd-option"))return}t.hdd.classList.remove("active"),t.clearClass("hover"),t.hindex=[],t.event(document,"remove",{click:t.close}),t.event(document,"remove",{"hybrid-dd-click":t.close}),t.event(t.hdd,"remove",{keyup:t.keyNav}),t.listenForBulk&&(t.event(t.hdd.ddlist,"remove",{mouseenter:t.hover}),t.listenForBulk=!1),e&&t.blur()}},t});
+class HybridDDError extends Error{constructor(e){super(e),this.name="HybridDropdownError"}}!function(e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e():e()}(function(){let e="undefined"!=typeof window?window:this,t=e.HybridDropdown=function(e,t){if(!(e&&e instanceof Element))throw new HybridDDError("HybridDropdown requires a DOM element to intialise.");if(e.classList.contains("hybridddised")&&e._hybriddd)return console.log("WARNING: attempting instantiate element already converted to Hybrid Dropdown"),e._hybriddd;if(e.classList.contains("hybrid-dropdown"))return console.log("WARNING: attempting instantiate Hybrid Dropdown element."),e;let i=this,d=1,o=!0,l=e.getAttribute("tabindex");switch(i.isDS=!1,cnfg=Object.assign({},e.dataset),["class","id","name"].forEach(t=>{if(e.hasAttribute(t)){let i="field"+t.charAt(0).toUpperCase()+t.slice(1);cnfg[i]=e.getAttribute(t),e.removeAttribute(t)}}),!0){case"SELECT"===e.nodeName:e.multiple&&(d=-1),e.style="visibility:hidden",o=!1;break;default:if(i.isDS=!0,!t.dataSet){if(e.querySelector("script"))try{cnfg.dataSet=JSON.parse(e.querySelector("script").innerHTML)}catch(e){console.log(e.name+":"+e.message),console.log("HybridDropdown ERROR: missing or malformed json dataset")}else console.log("HybridDropdown ERROR: missing json dataset"),cnfg.dataSet=null}!cnfg.id&&cnfg.fieldName&&(cnfg.id=cnfg.fieldName),e.classList.add("hybriddd-custom")}if(cnfg&&(e._hybriddd=i),i.el=e,i.el.classList.add("hybridddised"),Object.keys(cnfg).forEach(e=>{switch(e){case"limitSelection":cnfg[e]=parseInt(cnfg[e]);break;case"treeView":case"negative":case"colourise":case"checkboxes":cnfg[e]="true"==cnfg[e]}}),i.opt=Object.assign({},{dropdown:"vertical",limitSelection:d,optionLabel:function(e){return""+e+""},selectedLabel:function(e){let t=Object.keys(e);return e[t[0]]+(t.length>1?"[...]":"")},defaultText:"---",treeView:!1,treeGlue:"/",fieldName:"hybriddd",backgroundColor:"",color:"",negative:!1,colourise:!0,checkboxes:o,tabIndex:l||0,listOption:null,selectedValues:[],fieldId:"",fieldClass:""},t,cnfg),["selectedLabel","optionLabel"].forEach(e=>{if(!(i.opt[e]&&i.opt[e]instanceof Function&&1==i.opt[e].length))throw new HybridDDError(`${e} setting must be a function with 1 argument.`)}),i.opt.listOption&&(!(i.opt.listOption instanceof Function)||2!=i.opt.listOption.length))throw new HybridDDError("listOption setting must be a function with 2 arguments.");return i.opt.treeView&&1==i.opt.limitSelection&&(i.opt.limitSelection=-1),i.multi=1!=i.opt.limitSelection,i.opt.fieldId||(i.opt.fieldId=i.opt.fieldName),i.multi&&i.opt.fieldName&&i.opt.fieldName.indexOf("[]")<0&&(i.opt.fieldName+="[]"),i.init(!0,!0,!0),i},i=t.prototype;return i.init=function(e,t,i){let d=this;if(e){d.hdd=null,d.isDS?(d.hdd=d.el,d.el.hasAttribute("tabindex")||d.hdd.setAttribute("tabindex",d.opt.tabIndex)):(d.hdd=document.createElement("div"),d.el.parentNode.insertBefore(d.hdd,d.el.nextSibling),d.hdd.style["margin-left"]="-"+d.el.getBoundingClientRect().width+"px",d.hdd.setAttribute("tabindex",d.opt.tabIndex)),d.hdd.setAttribute("id",d.opt.fieldId);let e=d.el.closest("label");e&&e.setAttribute("for",d.opt.fieldId),d.hdd.setAttribute("class",d.opt.fieldClass),d.hdd.classList.add("hybrid-dropdown"),d.hdd.selected=document.createElement("div"),d.hdd.appendChild(d.hdd.selected),d.hdd.selected.classList.add("hybriddd-selected"),d.hdd.ddlist=document.createElement("ul"),d.hdd.appendChild(d.hdd.ddlist),d.hdd.ddlist.classList.add("hybriddd-options"),d.listenForBulk=!1,d.listenModClick=!1,d.hdd.classList.add("hybriddd-"+d.opt.dropdown)}if(t){let e=null;d.hdd.options={},d.hindex=[],d.sindex=[],d.value={};try{d.isDS?(d.hdd.classList.add("hybriddd-custom"),d.opt.dataSet?e=d.buildOptionList(Object.entries(d.opt.dataSet),0):(d.hdd.selected.innerHTML="json error",e=[])):e=d.buildOptionList(d.el.children,0),d.hdd.ddlist.replaceChildren(...e)}catch(e){if(!(e instanceof HybridDDError))throw e;console.log(e.name+":"+e.message),d.hdd.selected.innerHTML="json error"}}e&&(d.isDS||d.event(d.el,"add",{change:d.updateFromOriginal.bind(d),focus:d.originalElementFocus.bind(d)}),d.change=d.inputChange.bind(d),d.event(d.hdd.ddlist,"add",{change:d.change}),d.open=d.openSelect.bind(d),d.event(d.hdd,"add",{click:d.open}),d.close=d.closeSelect.bind(d,!0),d.blur=d.blurField.bind(d),d.hover=d.optionHover.bind(d),d.keyNav=d.keyboardNavigate.bind(d),d.event(d.hdd,"add",{keydown:d.keyNav}),d.refresh=d.refreshHybrid.bind(d),d.modClick=d.optionModClick.bind(d),d.emit("hybrid-dd-init")),d.opt.checkboxes&&d.hdd.classList.add("show-cb"),i&&d.colourise()},i.colourise=function(){let t=this,i=!1;if(!t.opt.colourise)return;if(!(e.hdd||t.opt.backgroundColor&&t.opt.color)){let d,o=!1,l=t.hdd;for(e.hdd={};!o&&l;){if(d=e.getComputedStyle(l,null),!e.hdd.bgColor&&!t.opt.backgroundColor)switch(d["background-color"]){case"transparent":case"":case"rgba(0, 0, 0, 0)":l=l.parentElement;break;default:e.hdd.bgColor=d["background-color"]}if(!e.hdd.color&&!t.opt.color)switch(d.color){case"transparent":case"":case"rgba(0, 0, 0, 0)":l=l.parentElement;break;default:e.hdd.color=d.color}e.hdd.bgColor&&e.hdd.color&&(o=!0),i=!0}o||(e.hdd.color||(e.hdd.color="#fff"),e.hdd.bgColor&&(e.hdd.bgColor="#5d5d5d"))}let d=t.opt.backgroundColor?t.opt.backgroundColor:e.hdd.bgColor,o=t.opt.color?t.opt.color:e.hdd.color;if(t.hdd.style["background-color"]=t.opt.negative?o:d,t.hdd.style.color=t.opt.negative?d:o,i){let e=document.createElement("style");e.setAttribute("id","hybriddd-colours"),e.type="text/css",e.innerText=`.hybriddd-option.active > label:hover,.hybriddd-option.hover > label,.hybriddd-option > label:hover{color:${d};background-color:${o}}:hover > input:checked + .hybridddl > .hybridddcb::before {color:${o}}ul.hybriddd-options::-webkit-scrollbar-track {background:${d}} ul.hybriddd-options::-webkit-scrollbar-thumb, ul.hybriddd-options::-webkit-scrollbar{background:${o}}`,document.head.appendChild(e)}if(t.opt.backgroundColor||t.opt.color||t.opt.negative){if(t.opt.negative){let e=d;d=o,o=e}let e=document.createElement("style"),i=t.hdd.getAttribute("id");e.setAttribute("id",i+"-css"),e.type="text/css",e.innerText=`#${i} .hybriddd-option.active > label:hover,#${i} .hybriddd-option.hover > label,#${i} .hybriddd-option > label:hover{color:${d};background-color:${o}}#${i} :hover > input:checked + .hybridddl > .hybridddcb::before {color:${o}} #${i} ul.hybriddd-options::-webkit-scrollbar-track {background:${d}} #${i} ul.hybriddd-options::-webkit-scrollbar-thumb,#${i} ul.hybriddd-options::-webkit-scrollbar{background:${o}}`,document.head.appendChild(e)}},i.refreshHybrid=function(e={}){let t=this,i=!1,d=!1;if(e.hasOwnProperty("negative")||e.hasOwnProperty("colourise")||e.color||e.backgroundColor){d=!0;let e=t.el.getAttribute("id"),i=document.querySelector("style#"+e+"-css");i&&i.remove()}e.listOption&&(i=!0,e.listOption instanceof Function&&2==e.listOption.length||(console.log("Hybriddd refresh error: listOption setting must be a function with 2 arguments."),e.listOption=null)),t.opt=Object.assign({},t.opt,e),t.init(!1,i,d)},i.buildOptionList=function(e,t,i=""){let d=this,o=[],l=d.multi?"checkbox":"radio",n=d.opt.fieldName?' name="'+d.opt.fieldName+'"':"";if([].forEach.call(e,(e,s)=>{if(d.opt.listOption&&!0!==d.opt.listOption(e,s))return;let r,c,a=document.createElement("li"),h=!1,u=!1,p=!1,b=[],f="",y="";if(d.isDS)switch(r=e[0],c=null,!0){case e[1]instanceof Object&&!e[1].length:case 0===t&&e[1]instanceof Array:p=h=!0,e[1].label?(h=!1,c=e[0],f="hybridddis",r=d.opt.optionLabel(e[1].label),(b=Object.entries(e[1])).splice(Object.keys(e[1]).indexOf("label")),p=b.length>0):b=Object.entries(e[1]);break;default:f="hybridddis",c=e[0],r=d.opt.optionLabel(e[1]),u=d.opt.selectedValues.indexOf(c)>=0}else switch(e.nodeName){case"OPTGROUP":p=h=!0,r=e.label,b=e.children;break;default:f="hybridddin",r=e.text,c=e.value,u=e.selected}switch(h){case!0:a.innerHTML=""+r+"",a.classList.add("hybriddd-group");break;default:if(y="",u&&(d.value[c]=r,d.sindex.push(c),y=" checked"),a.setAttribute("tabindex","-1"),a.innerHTML=``,a.classList.value="hybriddd-option"+(u?" active":""),d.isDS||(a.classList.value+=` ${e.classList.value}`),d.hdd.options[i+c])throw new HybridDDError("Option list has duplicate value: "+c);d.hdd.options[i+c]=a}if(p){d.opt.treeView&&c&&(i+=c+d.opt.treeGlue);let e=d.buildOptionList(b,t+1,i),o=document.createElement("ul");o.replaceChildren(...e),a.appendChild(o)}o[o.length]=a}),0==t){d.empty()&&d.reset();let e=Object.keys(d.value);e.length>1&&e.indexOf("")>=0&&delete d.value[""],d.hdd.selected.innerHTML=d.opt.selectedLabel(d.value)}return o},i.empty=function(){let e=this;for(let t in e.value)return!1;return!0},i.reset=function(){let e=this;e.sindex=[],e.hdd.options[""]?(e.hdd.options[""].classList.add("active"),e.value[""]=e.hdd.options[""].querySelector(".hybridddl").innerHTML,e.hdd.options[""].querySelector("input").checked=!0,e.sindex.push("")):e.value[""]=e.opt.defaultText},i.event=function(e,t,i){var d=e[t+"EventListener"].bind(e);Object.keys(i).forEach(function(e){["mouseenter","mouseleave"].indexOf(e)>=0?d(e,i[e],!0):d(e,i[e])})},i.updateFromOriginal=function(){let e=this,t=[];if(!e.isDS){if(e.multi){let i=!0;for(let d=0;d0?t.indexOf(e[e.length-1]):-1;return i0?t.indexOf(e[0]):t.length;return i>=0&&i--,i<0&&(i=t.length-1),t[i]},i.keyboardNavigate=function(){let e,t=this,i=arguments[0];if(!t.el.disabled&&i&&i.keyCode)switch(i.preventDefault(),!0){case 40==i.keyCode&&"keydown"==i.type:t.hdd.classList.contains("active")?((t.hindex.length>0&&!t.multi||!i.shiftKey)&&t.clearClass("hover"),e=t.nextOption(t.hindex),t.hdd.options[e].classList.add("hover"),t.scroll(e,"down"),t.multi&&i.shiftKey?(t.hindex.push(e),t.opt.limitSelection>0&&(t.hindex=t.hindex.slice(-1*t.opt.limitSelection))):t.hindex[0]=e):1==t.opt.limitSelection?(e=t.nextOption(t.sindex),t.toggleValue([e],!0)):(t.hdd.classList.remove("focus"),t.open());break;case 38==i.keyCode&&"keydown"==i.type:if(t.hdd.classList.contains("active"))(t.hindex.length>0&&!t.multi||!i.shiftKey)&&t.clearClass("hover"),e=t.prevOption(t.hindex),t.hdd.options[e].classList.add("hover"),t.scroll(e,"up"),t.multi&&i.shiftKey?(t.hindex.push(e),t.opt.limitSelection>0&&(t.hindex=t.hindex.slice(-1*t.opt.limitSelection))):t.hindex[0]=e;else if(1==t.opt.limitSelection){let e=t.prevOption(t.sindex);t.toggleValue([e],!0)}else t.hdd.classList.remove("focus"),t.open();break;case 13==i.keyCode&&"keydown"==i.type:case 32==i.keyCode&&"keydown"==i.type:!1===t.hdd.classList.contains("active")?(t.hdd.classList.remove("focus"),t.open()):(t.hindex.length>0&&t.toggleValue(t.hindex,!0),t.closeSelect(!1),t.hdd.classList.add("focus"));break;case 27==i.keyCode&&"keydown"==i.type:t.hdd.classList.contains("active")&&t.closeSelect(!1),t.blurField();break;case 9==i.keyCode&&"keydown"==i.type:t.hdd.classList.contains("active")&&t.closeSelect(!1),t.blurField();let d,o,l=1*t.el.getAttribute("tabindex"),n=t.el.closest("form");if(null===n&&(n=document),null!=l&&""!=l)l+=1,d=n.querySelector('[tabindex="'+l+'"]');else if(n!==document)for(l in o=t.el,t.isDS&&(l=(o=Object.keys(t.hdd.options))[o.length-1],o=t.hdd.options[l].querySelector("input")),n.elements)if(n.elements[l]===o){do{l++}while(lo.bottom)switch(t){case"up":o.top>d.top?i.hdd.ddlist.scrollTop-=d.height:o.bottomd.top&&(i.hdd.ddlist.scrollTop=0)}},i.inputChange=function(){let e=this,t=arguments[0],i=[],d=!1;if(t&&t.target){if(d=t.target.classList.contains("mod-ctrl"),"change"==t.type&&d)return t.target.classList.remove("mod-ctrl"),!1;if(e.hindex.length>0&&(i=[...e.hindex]),t.target.checked&&""==t.target.value)d||e.removeValue([...e.sindex],!0);else if(e.opt.treeView&&(e.opt.limitSelection<0||e.opt.limitSelection>e.sindex.length)){let o,l,n=!0,s=t.target.closest(".hybriddd-option"),r=s.querySelectorAll("input");for(l of r.values())l.checked=t.target.checked,d||(t.target.checked?i.push(l.value):e.removeValue([l.value])),l.closest(".hybriddd-option").classList.remove("partial");for(;s;)l=s.querySelector("input"),n||l.checked||s.querySelectorAll("label input").length-s.querySelectorAll("label input:checked").length!=1||(l.checked=!0,i.push(l.value),s.classList.remove("partial")),r=s.querySelectorAll("input:checked"),o=s.querySelectorAll("input"),l.checked&&1==r.length&&o.length>1?(s.classList.remove("partial"),l.checked=!1,d||e.removeValue([l.value])):r.length>0&&o.length!=r.length?(s.classList.add("partial"),d||e.removeValue([l.value])):s.classList.remove("partial"),s=s.parentNode.closest(".hybriddd-option"),n=!1;d||e.addValue(i,!0)}else d||(i.push(t.target.value),t.target.checked?e.addValue(i,!0):e.removeValue(i,!0));switch(!0){case"hybrid-ddi-change"==t.type:case t.shiftKey&&1==t.shiftKey:break;default:e.closeSelect(!1)}}},i.toggleValue=function(e,t){let i=this;i.hdd.options[e[0]].querySelector("input").checked?i.removeValue(e,t):i.addValue(e,t)},i.addValue=function(e,t=!1){let i=this;switch(i.opt.limitSelection){case 1:i.sindex.length>0&&i.hdd.options[i.sindex[0]].classList.remove("active"),i.sindex=e;break;default:if(1==i.sindex.length&&0==i.sindex[0].length?(i.hdd.options[""].classList.remove("active"),i.hdd.options[""].querySelector("input").checked=!1,i.sindex=e):i.sindex=i.sindex.concat(e),i.opt.limitSelection>0){for(let e=i.opt.limitSelection;e{i.value[e]=i.hdd.options[e].querySelector(".hybridddl").innerHTML,i.hdd.options[e].querySelector("input").checked=!0,i.hdd.options[e].classList.add("active")}),i.empty()&&i.reset(),i.isDS||i.updateOriginal(),i.hdd.selected.innerHTML=i.opt.selectedLabel(i.value),t&&i.emit("change")},i.removeValue=function(e,t=!1){let i,d=this;e.forEach(e=>{d.hdd.options[e].classList.remove("active"),d.hdd.options[e].querySelector("input").checked=!1,(i=d.sindex.indexOf(e))>=0&&(d.sindex.splice(i,1),delete d.value[e])}),0==d.sindex.length&&(d.hdd.options[""]?(d.sindex=[""],d.value={"":d.hdd.options[""].querySelector(".hybridddl").innerHTML},d.hdd.options[""].querySelector("input").checked=!0,d.hdd.options[""].classList.add("active")):d.value={"":d.opt.defaultText}),d.empty()&&d.reset(),d.isDS||d.updateOriginal(),d.hdd.selected.innerHTML=d.opt.selectedLabel(d.value),t&&d.emit("change")},i.updateOriginal=function(){let e=this;Object.keys(e.value).forEach(t=>{e.el.selectedIndex=-1,e.el.querySelector('option[value="'+t+'"]').selected=!0})},i.optionHover=function(){let e,t,i=this,d=arguments[0];if(d.shiftKey){if(t=d.target.classList.contains("hybriddd-option")?d.target:d.target.closest(".hybriddd-option")){switch(e=t.querySelector("input").value,d.type){case"mouseleave":i.event(i.hdd.ddlist,"remove",{mouseleave:i.hover}),e&&(i.hindex=[e]);break;case"mouseenter":i.hindex.includes(e)?(e=i.hindex[i.hindex.length-1],i.hindex=i.hindex.slice(0,-1)):e&&i.hindex.push(e),i.opt.limitSelection>0&&(i.hindex=i.hindex.slice(0,i.opt.limitSelection))}e&&!i.sindex.includes(e)&&i.hdd.options[e].classList.add("hover")}}else i.hindex.length>0&&(i.clearClass("hover"),i.hindex=[])},i.clearClass=function(e){let t=this;"string"==typeof e&&e.length>0&&t.hdd.querySelectorAll("."+e).forEach(t=>{t.classList.remove(e)})},i.openSelect=function(){let e=this,t=arguments[0];if(!e.el.disabled){if(t&&t.target){if(t.target.classList.contains("hybriddd-options")||t.target.closest(".hybriddd-options"))return;t.stopPropagation(),e.emit("hybrid-dd-"+t.type)}e.hdd.classList.contains("active")?e.closeSelect():(e.hdd.classList.add("active"),e.hdd.ddlist.style["min-width"]||(e.hdd.ddlist.style["min-width"]=e.hdd.ddlist.offsetWidth+12+"px"),e.event(document,"add",{click:e.close}),e.event(e.hdd,"add",{keyup:e.keyNav}),e.event(document,"add",{"hybrid-dd-click":e.close}))}},i.closeSelect=function(e){let t=this,i=arguments[0],d=arguments[1];if(!(i&&i.target&&i.target.classList.contains("hybriddd-option"))){if(d){if(d.target.isSameNode(t.el))return;if(t.multi&&(d.ctrlKey||d.shiftKey))return;if(d.target.parentNode.classList&&d.target.parentNode.classList.contains("hybriddd-group"))return;if(d.target.closest(".hybriddd-option"))return}t.hdd.classList.remove("active"),t.clearClass("hover"),t.hindex=[],t.event(document,"remove",{click:t.close}),t.event(document,"remove",{"hybrid-dd-click":t.close}),t.event(t.hdd,"remove",{keyup:t.keyNav}),t.listenForBulk&&(t.event(t.hdd.ddlist,"remove",{mouseenter:t.hover}),t.listenForBulk=!1),e&&t.blur()}},t});