From 61b11f3d7ec426f99f2543f093bc95585ccbc6e0 Mon Sep 17 00:00:00 2001 From: aurovrata Date: Fri, 17 Sep 2021 15:15:09 +0530 Subject: [PATCH] v2.0.6 --- README.md | 2 +- min/hybrid-dropdown.min.css | 2 +- min/hybrid-dropdown.min.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index eb647bd..93e2bb4 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# hybrid-html-dropdown 2.0 +# hybrid-html-dropdown 2 A hybrid HTML select fully customisable and emulating all navigational functions of a select element based on an initial [idea](https://css-tricks.com/striking-a-balance-between-native-and-custom-select-elements/) by @sandrina-p ## Demo diff --git a/min/hybrid-dropdown.min.css b/min/hybrid-dropdown.min.css index 4bfb2b1..9c42c1c 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}select.hybridddised{visibility:hidden!important;width:0!important;height:0!important}.hybrid-dropdown:focus{box-shadow:1px 1px 3px}.hybriddd-option::before,.hybriddd-group::before{display:none!important;content:none;margin:0;padding:0}.hybridddised:disabled+.hybrid-dropdown{background:#ccc;color:grey}.hybrid-dropdown .hybriddd-wrapper{overflow:hidden;z-index:7777;position:absolute;left:0;max-height:34vh;min-width:max-content;display:none;background-color:inherit}.hybrid-dropdown ul.hybriddd-options{border:1px solid #6f6f6f;border-radius:.25em;list-style:none!important;margin:0!important;padding:0!important;overflow-y:auto;scrollbar-width:thin;height:100%;background-color:inherit;overscroll-behavior:contain}.hybrid-dropdown.active>.hybriddd-wrapper{display:block}.hybrid-dropdown *,.hybrid-dropdown .hybriddd-options .hybriddd-option,.hybrid-dropdown .hybriddd-options .hybriddd-option ul,.hybrid-dropdown .hybriddd-options .hybriddd-group,.hybrid-dropdown .hybriddd-options .hybriddd-group 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:7}.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 0.15s ease-in-out;transition:all 0.15s ease-in-out;width:5px}.hybriddd-landscape .hybriddd-options>.hybriddd-option,.hybriddd-landscape .hybriddd-options>.hybriddd-group>ul>.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} +.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}select.hybridddised{visibility:hidden!important;width:0!important;height:0!important}.hybrid-dropdown:focus{box-shadow:1px 1px 3px}.hybriddd-option::before,.hybriddd-group::before{display:none!important;content:none;margin:0;padding:0}.hybridddised:disabled+.hybrid-dropdown{background:#ccc;color:grey}.hybrid-dropdown .hybriddd-wrapper{overflow:hidden;z-index:7777;position:absolute;left:0;max-height:34vh;min-width:max-content;display:none;background-color:inherit}.hybrid-dropdown.hybriddd-top .hybriddd-wrapper{bottom:var(--hybriddd-top)}.hybrid-dropdown.hybriddd-right .hybriddd-wrapper{right:0;left:auto}.hybrid-dropdown ul.hybriddd-options{border:1px solid #6f6f6f;border-radius:.25em;list-style:none!important;margin:0!important;padding:0!important;overflow-y:auto;scrollbar-width:thin;height:100%;background-color:inherit;overscroll-behavior:contain}.hybrid-dropdown.active>.hybriddd-wrapper{display:block}.hybrid-dropdown *,.hybrid-dropdown .hybriddd-options .hybriddd-option,.hybrid-dropdown .hybriddd-options .hybriddd-option ul,.hybrid-dropdown .hybriddd-options .hybriddd-group,.hybrid-dropdown .hybriddd-options .hybriddd-group 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:7}.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 0.15s ease-in-out;transition:all 0.15s ease-in-out;width:5px}.hybriddd-landscape .hybriddd-options>.hybriddd-option,.hybriddd-landscape .hybriddd-options>.hybriddd-group>ul>.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 d00c67e..5247eec 100644 --- a/min/hybrid-dropdown.min.js +++ b/min/hybrid-dropdown.min.js @@ -1,8 +1,8 @@ /* Hybrid Dropdown JavaScript plugin insprired from an original idea by Sandrina Pereira (twitter:@a_sandrina_p) -Version: 2.0.5 +Version: 2.0.6 Authors: Aurovrata Venet Twitter: @aurovrata GitHub: https://github.com/aurovrata/hybrid-html-dropdown */ -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 d=this,i=1,l=!0,o=e.getAttribute("tabindex");switch(d.isDS=!1,cnfg=Object.assign({},e.dataset),["class","id","name"].forEach(t=>{if(e.hasAttribute(t)){let d="field"+t.charAt(0).toUpperCase()+t.slice(1);switch(cnfg[d]=e.getAttribute(t),t){case"name":e.removeAttribute(t)}}}),!0){case"SELECT"===e.nodeName:e.multiple&&(i=-1),l=!1,!cnfg.fieldName&&cnfg.fieldId&&(cnfg.fieldName=cnfg.fieldId),cnfg.fieldId&&(cnfg.fieldId+="-hdd");break;default:if(d.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.fieldName&&cnfg.fieldId&&(cnfg.fieldName=cnfg.fieldId),e.classList.add("hybriddd-custom")}if(e._hybriddd=d,d.el=e,d.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"multiple":case"checkboxes":cnfg[e]="true"==cnfg[e];break;case"selectedValues":cnfg[e].indexOf("[")>=0?cnfg[e]=JSON.parse(cnfg[e]):cnfg[e]=[cnfg[e]]}}),d.opt=Object.assign({},{dropdown:"vertical",limitSelection:i,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:l,tabIndex:o||0,listOption:null,selectedValues:[],fieldId:"",fieldClass:""},t,cnfg),d.opt.selectedValues.length>0&&(d.opt.selectedValues=d.opt.selectedValues.map(String)),["selectedLabel","optionLabel"].forEach(e=>{if(!(d.opt[e]&&d.opt[e]instanceof Function&&1==d.opt[e].length))throw new HybridDDError(`${e} setting must be a function with 1 argument.`)}),d.opt.listOption&&(!(d.opt.listOption instanceof Function)||2!=d.opt.listOption.length))throw new HybridDDError("listOption setting must be a function with 2 arguments.");return(d.opt.treeView||d.opt.multiple)&&d.opt.limitSelection<2&&(d.opt.limitSelection=-1),d.multi=1!=d.opt.limitSelection,d.multi&&d.opt.fieldName&&d.opt.fieldName.indexOf("[]")<0&&(d.opt.fieldName+="[]"),d.init(!0,!0,!0),d},d=t.prototype;return d.init=function(e,t,d){let i=this;if(e){i.hdd=null,i.isDS?(i.hdd=i.el,i.el.hasAttribute("tabindex")||i.hdd.setAttribute("tabindex",i.opt.tabIndex)):(i.hdd=document.createElement("div"),i.el.parentNode.insertBefore(i.hdd,i.el.nextSibling),i.hdd.style["margin-left"]="-"+i.el.getBoundingClientRect().width+"px",i.hdd.setAttribute("tabindex",i.opt.tabIndex)),i.hdd.setAttribute("id",i.opt.fieldId);let e=i.el.closest("label");e&&e.setAttribute("for",i.opt.fieldId),i.hdd.setAttribute("class",i.opt.fieldClass),i.hdd.classList.add("hybrid-dropdown"),i.hdd.selected=document.createElement("div"),i.hdd.appendChild(i.hdd.selected),i.hdd.selected.classList.add("hybriddd-selected"),i.hdd.listwrap=document.createElement("div"),i.hdd.appendChild(i.hdd.listwrap),i.hdd.ddlist=document.createElement("ul"),i.hdd.listwrap.appendChild(i.hdd.ddlist),i.hdd.listwrap.classList.add("hybriddd-wrapper"),i.hdd.ddlist.classList.add("hybriddd-options"),i.listenForBulk=!1,i.listenModClick=!1,i.hdd.classList.add("hybriddd-"+i.opt.dropdown)}if(t){let e=null;i.hdd.options={},i.hindex=[],i.sindex=[],i.value={};try{i.isDS?(i.hdd.classList.add("hybriddd-custom"),i.opt.dataSet?e=i.buildOptionList(Object.entries(i.opt.dataSet),0):(i.hdd.selected.innerHTML="json error",e=[])):e=i.buildOptionList(i.el.children,0),i.hdd.ddlist.replaceChildren(...e)}catch(e){if(!(e instanceof HybridDDError))throw e;console.log(e.name+":"+e.message),i.hdd.selected.innerHTML="json error"}}if(e){i.isDS||i.event(i.el,"add",{change:i.updateFromOriginal.bind(i),focus:i.originalElementFocus.bind(i)}),i.change=i.inputChange.bind(i),i.event(i.hdd.ddlist,"add",{change:i.change}),i.open=i.openSelect.bind(i),i.event(i.hdd,"add",{click:i.open});let e=i.el.closest("form");e&&i.event(e,"add",{reset:i.reset.bind(i)}),i.close=i.closeSelect.bind(i,!0),i.blur=i.blurField.bind(i),i.hover=i.optionHover.bind(i),i.keyNav=i.keyboardNavigate.bind(i),i.event(i.hdd,"add",{keydown:i.keyNav}),i.refresh=i.refreshHybrid.bind(i),i.modClick=i.optionModClick.bind(i),i.emit("hybrid-dd-init")}i.opt.checkboxes&&i.hdd.classList.add("show-cb"),d&&i.colourise()},d.colourise=function(){let t=this,d=!1;if(!t.opt.colourise)return;if(!(e.hdd||t.opt.backgroundColor&&t.opt.color)){let i,l=!1,o=t.hdd;for(e.hdd={};!l&&o;){if(i=e.getComputedStyle(o,null),!e.hdd.bgColor&&!t.opt.backgroundColor)switch(i["background-color"]){case"transparent":case"":case"rgba(0, 0, 0, 0)":o=o.parentElement;break;default:e.hdd.bgColor=i["background-color"]}if(!e.hdd.color&&!t.opt.color)switch(i.color){case"transparent":case"":case"rgba(0, 0, 0, 0)":o=o.parentElement;break;default:e.hdd.color=i.color}e.hdd.bgColor&&e.hdd.color&&(l=!0),d=!0}l||(e.hdd.color||(e.hdd.color="#fff"),e.hdd.bgColor&&(e.hdd.bgColor="#5d5d5d"))}let i=t.opt.backgroundColor?t.opt.backgroundColor:e.hdd.bgColor,l=t.opt.color?t.opt.color:e.hdd.color;if(t.hdd.style["background-color"]=t.opt.negative?l:i,t.hdd.style.color=t.opt.negative?i:l,d){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:${i};background-color:${l}}:hover > input:checked+.hybridddcb::before {background-color:${i}}ul.hybriddd-options::-webkit-scrollbar-track {background:${i}} ul.hybriddd-options::-webkit-scrollbar-thumb, ul.hybriddd-options::-webkit-scrollbar{background:${l}} ul.hybriddd-options{scrollbar-color:${l} ${i}}`,document.head.appendChild(e)}if(t.opt.backgroundColor||t.opt.color||t.opt.negative){if(t.opt.negative){let e=i;i=l,l=e}let e=document.createElement("style"),d=t.hdd.getAttribute("id");e.setAttribute("id",d+"-css"),e.type="text/css",e.innerText=`#${d} .hybriddd-option.active > label:hover,#${d} .hybriddd-option.hover > label,#${d} .hybriddd-option > label:hover{color:${i};background-color:${l}}#${d} :hover > input:checked + .hybridddl > .hybridddcb::before {color:${l}} #${d} ul.hybriddd-options::-webkit-scrollbar-track {background:${i}} #${d} ul.hybriddd-options::-webkit-scrollbar-thumb,#${d} ul.hybriddd-options::-webkit-scrollbar{background:${l}} #${d} ul.hybriddd-options{scrollbar-color:${l} ${i};`,document.head.appendChild(e)}},d.refreshHybrid=function(e={}){let t=this,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&&(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,!0,d)},d.buildOptionList=function(e,t,d=""){let i=this,l=[],o=i.multi?"checkbox":"radio",n=i.opt.fieldName?' name="'+i.opt.fieldName+'"':"";if([].forEach.call(e,(e,s)=>{if(i.opt.listOption&&!0!==i.opt.listOption(e,s))return;let r,c,a=document.createElement("li"),h=!1,u=!1,p=!1,b=[],f="",y="";if(i.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=i.opt.optionLabel(e[1].label),(b=Object.entries(e[1])).splice(Object.keys(e[1]).indexOf("label"),1),p=b.length>0,u=i.opt.selectedValues.indexOf(c)>=0):b=Object.entries(e[1]);break;default:f="hybridddis",c=e[0],r=i.opt.optionLabel(e[1]),u=i.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&&(i.value[c]=r,i.sindex.push(c),y=" checked"),a.setAttribute("tabindex","-1"),a.innerHTML=``,a.classList.value="hybriddd-option"+(u?" active":""),i.isDS||(a.classList.value+=` ${e.classList.value}`),i.hdd.options[d+c])throw new HybridDDError("Option list has duplicate value: "+c);i.hdd.options[d+c]=a}if(p){i.opt.treeView&&c&&(d+=c+i.opt.treeGlue);let e=i.buildOptionList(b,t+1,d),l=document.createElement("ul");l.replaceChildren(...e),a.appendChild(l)}l[l.length]=a}),0==t){i.empty()&&i.reset();let e=Object.keys(i.value);e.length>1&&e.indexOf("")>=0&&delete i.value[""],i.hdd.selected.innerHTML=i.opt.selectedLabel(i.value)}return l},d.empty=function(){let e=this;for(let t in e.value)return!1;return!0},d.reset=function(){let e=this;e.sindex=[],e.value={},e.clearClass("active"),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,e.hdd.selected.innerHTML=e.opt.selectedLabel(e.value)},d.event=function(e,t,d){var i=e[t+"EventListener"].bind(e);Object.keys(d).forEach(function(e){["mouseenter","mouseleave"].indexOf(e)>=0?i(e,d[e],!0):i(e,d[e])})},d.updateFromOriginal=function(){let e=this,t=[];if(!e.isDS){if(e.multi){let d=!0;for(let i=0;i0?t.indexOf(e[e.length-1]):-1;return d0?t.indexOf(e[0]):t.length;return d>=0&&d--,d<0&&(d=t.length-1),t[d]},d.keyboardNavigate=function(){let e,t=this,d=arguments[0];if(!t.el.disabled&&d&&d.keyCode)switch(d.preventDefault(),!0){case 40==d.keyCode&&"keydown"==d.type:t.hdd.classList.contains("active")?((t.hindex.length>0&&!t.multi||!d.shiftKey)&&t.clearClass("hover"),e=t.nextOption(t.hindex),t.hdd.options[e].classList.add("hover"),t.scroll(e,"down"),t.multi&&d.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==d.keyCode&&"keydown"==d.type:if(t.hdd.classList.contains("active"))(t.hindex.length>0&&!t.multi||!d.shiftKey)&&t.clearClass("hover"),e=t.prevOption(t.hindex),t.hdd.options[e].classList.add("hover"),t.scroll(e,"up"),t.multi&&d.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==d.keyCode&&"keydown"==d.type:case 32==d.keyCode&&"keydown"==d.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==d.keyCode&&"keydown"==d.type:t.hdd.classList.contains("active")&&t.closeSelect(!1),t.blurField();break;case 9==d.keyCode&&"keydown"==d.type:t.hdd.classList.contains("active")&&t.closeSelect(!1),t.blurField();let i,l,o=1*t.el.getAttribute("tabindex"),n=t.el.closest("form");if(null===n&&(n=document),null!=o&&""!=o)o+=1,i=n.querySelector('[tabindex="'+o+'"]');else if(n!==document)for(o in l=t.el,t.isDS&&(o=(l=Object.keys(t.hdd.options))[l.length-1],l=t.hdd.options[o].querySelector("input")),n.elements)if(n.elements[o]===l){do{o++}while(ol.bottom)switch(t){case"up":l.top>i.top?d.hdd.ddlist.scrollTop-=i.height:l.bottomi.top&&(d.hdd.ddlist.scrollTop=0)}},d.inputChange=function(){let e=this,t=arguments[0],d=[],i=!1;if(t&&t.target){if(i=t.target.classList.contains("mod-ctrl"),"change"==t.type&&i)return t.target.classList.remove("mod-ctrl"),!1;if(e.hindex.length>0&&(d=[...e.hindex]),t.target.checked&&""==t.target.value)i||e.removeValue([...e.sindex],!0);else if(e.opt.treeView&&(e.opt.limitSelection<0||e.opt.limitSelection>e.sindex.length)){let l,o,n=!0,s=t.target.closest(".hybriddd-option"),r=s.querySelectorAll("input");for(o of r.values())o.checked=t.target.checked,i||(t.target.checked?d.push(o.value):e.removeValue([o.value])),o.closest(".hybriddd-option").classList.remove("partial");for(;s;)o=s.querySelector("input"),n||o.checked||s.querySelectorAll("label input").length-s.querySelectorAll("label input:checked").length!=1||(o.checked=!0,d.push(o.value),s.classList.remove("partial")),r=s.querySelectorAll("input:checked"),l=s.querySelectorAll("input"),o.checked&&1==r.length&&l.length>1?(s.classList.remove("partial"),o.checked=!1,i||e.removeValue([o.value])):r.length>0&&l.length!=r.length?(s.classList.add("partial"),i||e.removeValue([o.value])):s.classList.remove("partial"),s=s.parentNode.closest(".hybriddd-option"),n=!1;i||e.addValue(d,!0)}else i||(d.push(t.target.value),t.target.checked?e.addValue(d,!0):e.removeValue(d,!0));switch(!0){case"hybrid-ddi-change"==t.type:case t.shiftKey&&1==t.shiftKey:break;default:e.closeSelect(!1)}}},d.toggleValue=function(e,t){let d=this;d.hdd.options[e[0]].querySelector("input").checked?d.removeValue(e,t):d.addValue(e,t)},d.addValue=function(e,t=!1){let d=this;switch(d.opt.limitSelection){case 1:d.sindex.length>0&&d.hdd.options[d.sindex[0]].classList.remove("active"),d.sindex=e;break;default:if(1==d.sindex.length&&0==d.sindex[0].length?(d.hdd.options[""].classList.remove("active"),d.hdd.options[""].querySelector("input").checked=!1,d.sindex=e):d.sindex=d.sindex.concat(e),d.opt.limitSelection>0){for(let e=d.opt.limitSelection;e{d.value[e]=d.hdd.options[e].querySelector(".hybridddl").innerHTML,d.hdd.options[e].querySelector("input").checked=!0,d.hdd.options[e].classList.add("active")}),d.empty()&&d.reset(),d.isDS||d.updateOriginal(),d.hdd.selected.innerHTML=d.opt.selectedLabel(d.value),t&&d.emit("change")},d.removeValue=function(e,t=!1){let d,i=this;e.forEach(e=>{i.hdd.options[e].classList.remove("active"),i.hdd.options[e].querySelector("input").checked=!1,(d=i.sindex.indexOf(e))>=0&&(i.sindex.splice(d,1),delete i.value[e])}),0==i.sindex.length&&(i.hdd.options[""]?(i.sindex=[""],i.value={"":i.hdd.options[""].querySelector(".hybridddl").innerHTML},i.hdd.options[""].querySelector("input").checked=!0,i.hdd.options[""].classList.add("active")):i.value={"":i.opt.defaultText}),i.empty()&&i.reset(),i.isDS||i.updateOriginal(),i.hdd.selected.innerHTML=i.opt.selectedLabel(i.value),t&&i.emit("change")},d.updateOriginal=function(){let e=this;Object.keys(e.value).forEach(t=>{e.el.selectedIndex=-1,e.el.querySelector('option[value="'+t+'"]').selected=!0})},d.optionHover=function(){let e,t,d=this,i=arguments[0];if(i.shiftKey){if(t=i.target.classList.contains("hybriddd-option")?i.target:i.target.closest(".hybriddd-option")){switch(e=t.querySelector("input").value,i.type){case"mouseleave":d.event(d.hdd.ddlist,"remove",{mouseleave:d.hover}),e&&(d.hindex=[e]);break;case"mouseenter":d.hindex.includes(e)?(e=d.hindex[d.hindex.length-1],d.hindex=d.hindex.slice(0,-1)):e&&d.hindex.push(e),d.opt.limitSelection>0&&(d.hindex=d.hindex.slice(0,d.opt.limitSelection))}e&&!d.sindex.includes(e)&&d.hdd.options[e].classList.add("hover")}}else d.hindex.length>0&&(d.clearClass("hover"),d.hindex=[])},d.clearClass=function(e){let t=this;"string"==typeof e&&e.length>0&&t.hdd.querySelectorAll("."+e).forEach(t=>{t.classList.remove(e)})},d.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.hdd.listwrap.style.height||(e.hdd.listwrap.style.height=e.hdd.ddlist.offsetHeight+"px",e.hdd.listwrap.style.width="100%"),e.event(document,"add",{click:e.close}),e.event(e.hdd,"add",{keyup:e.keyNav}),e.event(document,"add",{"hybrid-dd-click":e.close}))}},d.closeSelect=function(e){let t=this,d=arguments[0],i=arguments[1];if(!(d&&d.target&&d.target.classList.contains("hybriddd-option"))){if(i){if(i.target.isSameNode(t.el))return;if(t.multi&&(i.ctrlKey||i.shiftKey))return;if(i.target.parentNode.classList&&i.target.parentNode.classList.contains("hybriddd-group"))return;if(i.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 d=this,i=1,l=!0,o=e.getAttribute("tabindex");switch(d.isDS=!1,cnfg=Object.assign({},e.dataset),["class","id","name"].forEach(t=>{if(e.hasAttribute(t)){let d="field"+t.charAt(0).toUpperCase()+t.slice(1);switch(cnfg[d]=e.getAttribute(t),t){case"name":e.removeAttribute(t)}}}),!0){case"SELECT"===e.nodeName:e.multiple&&(i=-1),l=!1,!cnfg.fieldName&&cnfg.fieldId&&(cnfg.fieldName=cnfg.fieldId),cnfg.fieldId&&(cnfg.fieldId+="-hdd");break;default:if(d.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.fieldName&&cnfg.fieldId&&(cnfg.fieldName=cnfg.fieldId),e.classList.add("hybriddd-custom")}if(e._hybriddd=d,d.el=e,d.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"multiple":case"checkboxes":cnfg[e]="true"==cnfg[e];break;case"selectedValues":cnfg[e].indexOf("[")>=0?cnfg[e]=JSON.parse(cnfg[e]):cnfg[e]=[cnfg[e]]}}),d.opt=Object.assign({},{dropdown:"vertical",limitSelection:i,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:l,tabIndex:o||0,listOption:null,selectedValues:[],fieldId:"",fieldClass:""},t,cnfg),d.opt.selectedValues.length>0&&(d.opt.selectedValues=d.opt.selectedValues.map(String)),["selectedLabel","optionLabel"].forEach(e=>{if(!(d.opt[e]&&d.opt[e]instanceof Function&&1==d.opt[e].length))throw new HybridDDError(`${e} setting must be a function with 1 argument.`)}),d.opt.listOption&&(!(d.opt.listOption instanceof Function)||2!=d.opt.listOption.length))throw new HybridDDError("listOption setting must be a function with 2 arguments.");return(d.opt.treeView||d.opt.multiple)&&d.opt.limitSelection<2&&(d.opt.limitSelection=-1),d.multi=1!=d.opt.limitSelection,d.multi&&d.opt.fieldName&&d.opt.fieldName.indexOf("[]")<0&&(d.opt.fieldName+="[]"),d.init(!0,!0,!0),d},d=t.prototype;return d.init=function(e,t,d){let i=this;if(e){i.hdd=null,i.isDS?(i.hdd=i.el,i.el.hasAttribute("tabindex")||i.hdd.setAttribute("tabindex",i.opt.tabIndex)):(i.hdd=document.createElement("div"),i.el.parentNode.insertBefore(i.hdd,i.el.nextSibling),i.hdd.style["margin-left"]="-"+i.el.getBoundingClientRect().width+"px",i.hdd.setAttribute("tabindex",i.opt.tabIndex)),i.hdd.setAttribute("id",i.opt.fieldId);let e=i.el.closest("label");e&&e.setAttribute("for",i.opt.fieldId),i.hdd.setAttribute("class",i.opt.fieldClass),i.hdd.classList.add("hybrid-dropdown"),i.hdd.selected=document.createElement("div"),i.hdd.appendChild(i.hdd.selected),i.hdd.selected.classList.add("hybriddd-selected"),i.hdd.listwrap=document.createElement("div"),i.hdd.appendChild(i.hdd.listwrap),i.hdd.ddlist=document.createElement("ul"),i.hdd.listwrap.appendChild(i.hdd.ddlist),i.hdd.listwrap.classList.add("hybriddd-wrapper"),i.hdd.ddlist.classList.add("hybriddd-options"),i.listenForBulk=!1,i.listenModClick=!1,i.hdd.classList.add("hybriddd-"+i.opt.dropdown)}if(t){let e=null;i.hdd.options={},i.hindex=[],i.sindex=[],i.value={};try{i.isDS?(i.hdd.classList.add("hybriddd-custom"),i.opt.dataSet?e=i.buildOptionList(Object.entries(i.opt.dataSet),0):(i.hdd.selected.innerHTML="json error",e=[])):e=i.buildOptionList(i.el.children,0),i.hdd.ddlist.replaceChildren(...e)}catch(e){if(!(e instanceof HybridDDError))throw e;console.log(e.name+":"+e.message),i.hdd.selected.innerHTML="json error"}}if(e){i.isDS||i.event(i.el,"add",{change:i.updateFromOriginal.bind(i),focus:i.originalElementFocus.bind(i)}),i.change=i.inputChange.bind(i),i.event(i.hdd.ddlist,"add",{change:i.change}),i.open=i.openSelect.bind(i),i.event(i.hdd,"add",{click:i.open});let e=i.el.closest("form");e&&i.event(e,"add",{reset:i.reset.bind(i)}),i.close=i.closeSelect.bind(i,!0),i.blur=i.blurField.bind(i),i.hover=i.optionHover.bind(i),i.keyNav=i.keyboardNavigate.bind(i),i.event(i.hdd,"add",{keydown:i.keyNav}),i.refresh=i.refreshHybrid.bind(i),i.modClick=i.optionModClick.bind(i),i.emit("hybrid-dd-init")}i.opt.checkboxes&&i.hdd.classList.add("show-cb"),d&&i.colourise()},d.colourise=function(){let t=this,d=!1;if(!t.opt.colourise)return;if(!(e.hdd||t.opt.backgroundColor&&t.opt.color)){let i,l=!1,o=t.hdd;for(e.hdd={};!l&&o;){if(i=e.getComputedStyle(o,null),!e.hdd.bgColor&&!t.opt.backgroundColor)switch(i["background-color"]){case"transparent":case"":case"rgba(0, 0, 0, 0)":o=o.parentElement;break;default:e.hdd.bgColor=i["background-color"]}if(!e.hdd.color&&!t.opt.color)switch(i.color){case"transparent":case"":case"rgba(0, 0, 0, 0)":o=o.parentElement;break;default:e.hdd.color=i.color}e.hdd.bgColor&&e.hdd.color&&(l=!0),d=!0}l||(e.hdd.color||(e.hdd.color="#fff"),e.hdd.bgColor&&(e.hdd.bgColor="#5d5d5d"))}let i=t.opt.backgroundColor?t.opt.backgroundColor:e.hdd.bgColor,l=t.opt.color?t.opt.color:e.hdd.color;if(t.hdd.style["background-color"]=t.opt.negative?l:i,t.hdd.style.color=t.opt.negative?i:l,d){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:${i};background-color:${l}}:hover > input:checked+.hybridddcb::before {background-color:${i}}ul.hybriddd-options::-webkit-scrollbar-track {background:${i}} ul.hybriddd-options::-webkit-scrollbar-thumb, ul.hybriddd-options::-webkit-scrollbar{background:${l}} ul.hybriddd-options{scrollbar-color:${l} ${i}}`,document.head.appendChild(e)}if(t.opt.backgroundColor||t.opt.color||t.opt.negative){if(t.opt.negative){let e=i;i=l,l=e}let e=document.createElement("style"),d=t.hdd.getAttribute("id");e.setAttribute("id",d+"-css"),e.type="text/css",e.innerText=`#${d} .hybriddd-option.active > label:hover,#${d} .hybriddd-option.hover > label,#${d} .hybriddd-option > label:hover{color:${i};background-color:${l}}#${d} :hover > input:checked + .hybridddl > .hybridddcb::before {color:${l}} #${d} ul.hybriddd-options::-webkit-scrollbar-track {background:${i}} #${d} ul.hybriddd-options::-webkit-scrollbar-thumb,#${d} ul.hybriddd-options::-webkit-scrollbar{background:${l}} #${d} ul.hybriddd-options{scrollbar-color:${l} ${i};`,document.head.appendChild(e)}},d.refreshHybrid=function(e={}){let t=this,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&&(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,!0,d)},d.buildOptionList=function(e,t,d=""){let i=this,l=[],o=i.multi?"checkbox":"radio",n=i.opt.fieldName?' name="'+i.opt.fieldName+'"':"";if([].forEach.call(e,(e,s)=>{if(i.opt.listOption&&!0!==i.opt.listOption(e,s))return;let r,c,a=document.createElement("li"),h=!1,u=!1,p=!1,b=[],f="",y="";if(i.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=i.opt.optionLabel(e[1].label),(b=Object.entries(e[1])).splice(Object.keys(e[1]).indexOf("label"),1),p=b.length>0,u=i.opt.selectedValues.indexOf(c)>=0):b=Object.entries(e[1]);break;default:f="hybridddis",c=e[0],r=i.opt.optionLabel(e[1]),u=i.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&&(i.value[c]=r,i.sindex.push(c),y=" checked"),a.setAttribute("tabindex","-1"),a.innerHTML=``,a.classList.value="hybriddd-option"+(u?" active":""),i.isDS||(a.classList.value+=` ${e.classList.value}`),i.hdd.options[d+c])throw new HybridDDError("Option list has duplicate value: "+c);i.hdd.options[d+c]=a}if(p){i.opt.treeView&&c&&(d+=c+i.opt.treeGlue);let e=i.buildOptionList(b,t+1,d),l=document.createElement("ul");l.replaceChildren(...e),a.appendChild(l)}l[l.length]=a}),0==t){i.empty()&&i.reset();let e=Object.keys(i.value);e.length>1&&e.indexOf("")>=0&&delete i.value[""],i.hdd.selected.innerHTML=i.opt.selectedLabel(i.value)}return l},d.empty=function(){let e=this;for(let t in e.value)return!1;return!0},d.reset=function(){let e=this;e.sindex=[],e.value={},e.clearClass("active"),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,e.hdd.selected.innerHTML=e.opt.selectedLabel(e.value)},d.event=function(e,t,d){var i=e[t+"EventListener"].bind(e);Object.keys(d).forEach(function(e){["mouseenter","mouseleave"].indexOf(e)>=0?i(e,d[e],!0):i(e,d[e])})},d.updateFromOriginal=function(){let e=this,t=[];if(!e.isDS){if(e.multi){let d=!0;for(let i=0;i0?t.indexOf(e[e.length-1]):-1;return d0?t.indexOf(e[0]):t.length;return d>=0&&d--,d<0&&(d=t.length-1),t[d]},d.keyboardNavigate=function(){let e,t=this,d=arguments[0];if(!t.el.disabled&&d&&d.keyCode)switch(d.preventDefault(),!0){case 40==d.keyCode&&"keydown"==d.type:t.hdd.classList.contains("active")?((t.hindex.length>0&&!t.multi||!d.shiftKey)&&t.clearClass("hover"),e=t.nextOption(t.hindex),t.hdd.options[e].classList.add("hover"),t.scroll(e,"down"),t.multi&&d.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==d.keyCode&&"keydown"==d.type:if(t.hdd.classList.contains("active"))(t.hindex.length>0&&!t.multi||!d.shiftKey)&&t.clearClass("hover"),e=t.prevOption(t.hindex),t.hdd.options[e].classList.add("hover"),t.scroll(e,"up"),t.multi&&d.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==d.keyCode&&"keydown"==d.type:case 32==d.keyCode&&"keydown"==d.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==d.keyCode&&"keydown"==d.type:t.hdd.classList.contains("active")&&t.closeSelect(!1),t.blurField();break;case 9==d.keyCode&&"keydown"==d.type:t.hdd.classList.contains("active")&&t.closeSelect(!1),t.blurField();let i,l,o=1*t.el.getAttribute("tabindex"),n=t.el.closest("form");if(null===n&&(n=document),null!=o&&""!=o)o+=1,i=n.querySelector('[tabindex="'+o+'"]');else if(n!==document)for(o in l=t.el,t.isDS&&(o=(l=Object.keys(t.hdd.options))[l.length-1],l=t.hdd.options[o].querySelector("input")),n.elements)if(n.elements[o]===l){do{o++}while(ol.bottom)switch(t){case"up":l.top>i.top?d.hdd.ddlist.scrollTop-=i.height:l.bottomi.top&&(d.hdd.ddlist.scrollTop=0)}},d.inputChange=function(){let e=this,t=arguments[0],d=[],i=!1;if(t&&t.target){if(i=t.target.classList.contains("mod-ctrl"),"change"==t.type&&i)return t.target.classList.remove("mod-ctrl"),!1;if(e.hindex.length>0&&(d=[...e.hindex]),t.target.checked&&""==t.target.value)i||e.removeValue([...e.sindex],!0);else if(e.opt.treeView&&(e.opt.limitSelection<0||e.opt.limitSelection>e.sindex.length)){let l,o,n=!0,s=t.target.closest(".hybriddd-option"),r=s.querySelectorAll("input");for(o of r.values())o.checked=t.target.checked,i||(t.target.checked?d.push(o.value):e.removeValue([o.value])),o.closest(".hybriddd-option").classList.remove("partial");for(;s;)o=s.querySelector("input"),n||o.checked||s.querySelectorAll("label input").length-s.querySelectorAll("label input:checked").length!=1||(o.checked=!0,d.push(o.value),s.classList.remove("partial")),r=s.querySelectorAll("input:checked"),l=s.querySelectorAll("input"),o.checked&&1==r.length&&l.length>1?(s.classList.remove("partial"),o.checked=!1,i||e.removeValue([o.value])):r.length>0&&l.length!=r.length?(s.classList.add("partial"),i||e.removeValue([o.value])):s.classList.remove("partial"),s=s.parentNode.closest(".hybriddd-option"),n=!1;i||e.addValue(d,!0)}else i||(d.push(t.target.value),t.target.checked?e.addValue(d,!0):e.removeValue(d,!0));switch(!0){case"hybrid-ddi-change"==t.type:case t.shiftKey&&1==t.shiftKey:break;default:e.closeSelect(!1)}}},d.toggleValue=function(e,t){let d=this;d.hdd.options[e[0]].querySelector("input").checked?d.removeValue(e,t):d.addValue(e,t)},d.addValue=function(e,t=!1){let d=this;switch(d.opt.limitSelection){case 1:d.sindex.length>0&&d.hdd.options[d.sindex[0]].classList.remove("active"),d.sindex=e;break;default:if(1==d.sindex.length&&0==d.sindex[0].length?(d.hdd.options[""].classList.remove("active"),d.hdd.options[""].querySelector("input").checked=!1,d.sindex=e):d.sindex=d.sindex.concat(e),d.opt.limitSelection>0){for(let e=d.opt.limitSelection;e{d.value[e]=d.hdd.options[e].querySelector(".hybridddl").innerHTML,d.hdd.options[e].querySelector("input").checked=!0,d.hdd.options[e].classList.add("active")}),d.empty()&&d.reset(),d.isDS||d.updateOriginal(),d.hdd.selected.innerHTML=d.opt.selectedLabel(d.value),t&&d.emit("change")},d.removeValue=function(e,t=!1){let d,i=this;e.forEach(e=>{i.hdd.options[e].classList.remove("active"),i.hdd.options[e].querySelector("input").checked=!1,(d=i.sindex.indexOf(e))>=0&&(i.sindex.splice(d,1),delete i.value[e])}),0==i.sindex.length&&(i.hdd.options[""]?(i.sindex=[""],i.value={"":i.hdd.options[""].querySelector(".hybridddl").innerHTML},i.hdd.options[""].querySelector("input").checked=!0,i.hdd.options[""].classList.add("active")):i.value={"":i.opt.defaultText}),i.empty()&&i.reset(),i.isDS||i.updateOriginal(),i.hdd.selected.innerHTML=i.opt.selectedLabel(i.value),t&&i.emit("change")},d.updateOriginal=function(){let e=this;Object.keys(e.value).forEach(t=>{e.el.selectedIndex=-1,e.el.querySelector('option[value="'+t+'"]').selected=!0})},d.optionHover=function(){let e,t,d=this,i=arguments[0];if(i.shiftKey){if(t=i.target.classList.contains("hybriddd-option")?i.target:i.target.closest(".hybriddd-option")){switch(e=t.querySelector("input").value,i.type){case"mouseleave":d.event(d.hdd.ddlist,"remove",{mouseleave:d.hover}),e&&(d.hindex=[e]);break;case"mouseenter":d.hindex.includes(e)?(e=d.hindex[d.hindex.length-1],d.hindex=d.hindex.slice(0,-1)):e&&d.hindex.push(e),d.opt.limitSelection>0&&(d.hindex=d.hindex.slice(0,d.opt.limitSelection))}e&&!d.sindex.includes(e)&&d.hdd.options[e].classList.add("hover")}}else d.hindex.length>0&&(d.clearClass("hover"),d.hindex=[])},d.clearClass=function(e){let t=this;"string"==typeof e&&e.length>0&&t.hdd.querySelectorAll("."+e).forEach(t=>{t.classList.remove(e)})},d.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.listwrap.style.setProperty("--hybriddd-top",e.hdd.offsetHeight+"px"),e.hdd.classList.add("active"),e.hdd.ddlist.style["min-width"]||(e.hdd.ddlist.style["min-width"]=e.hdd.ddlist.offsetWidth+12+"px"),e.hdd.listwrap.style.height||(e.hdd.listwrap.style.height=e.hdd.ddlist.offsetHeight+"px",e.hdd.listwrap.style.width="100%"),e.event(document,"add",{click:e.close}),e.event(e.hdd,"add",{keyup:e.keyNav}),e.event(document,"add",{"hybrid-dd-click":e.close}))}},d.closeSelect=function(e){let t=this,d=arguments[0],i=arguments[1];if(!(d&&d.target&&d.target.classList.contains("hybriddd-option"))){if(i){if(i.target.isSameNode(t.el))return;if(t.multi&&(i.ctrlKey||i.shiftKey))return;if(i.target.parentNode.classList&&i.target.parentNode.classList.contains("hybriddd-group"))return;if(i.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});