PageSourceSearch

https://www.ministryoftesting.com/assets/controllers/choices_contr…8d53a02cf3452193ef2e72a7ebb50655ea4bf050.js

js ministryoftesting.com collected 2026-09-24 17:15:05 UTC 4,012 bytes, 1 lines download raw bytes

1import{Controller}from"@hotwired/stimulus";const debounce=(e,t,s)=>{let i;return function(){let a=this,h=arguments;clearTimeout(i),s&&!i&&e.apply(a,h),i=setTimeout(function(){i=null,s||e.apply(a,h)},t)}};export default class extends Controller{static targets=["select","options"];static values={ready:Boolean};initialize(){this.element.choices=this,this.refresh=this.refresh.bind(this),this.add=this.add.bind(this),this.remove=this.remove.bind(this),this.search=debounce(this.search.bind(this),250),this.update=this.update.bind(this),this.filter=this.filter.bind(this),this.options=this.options.bind(this),this.optionsReducer=this.optionsReducer.bind(this),this.searchPath=this.element.dataset.searchPath,this.forceOption=this.element.dataset.forceOption||!0}connect(){setTimeout(this.setup.bind(this),5)}setup(){this.choices=new Choices(this.selectTarget,this.options()),this.input=this.element.querySelector("input"),this.refresh(),this.searchPath&&this.input.addEventListener("input",this.search),this.selectTarget.addEventListener("change",this.refresh),this.selectTarget.addEventListener("addItem",this.add),this.selectTarget.addEventListener("removeItem",this.remove),this.searchPath&&this.selectTarget.addEventListener("search",this.search),this.selectTarget.classList.contains("is-invalid")&&this.choices.containerOuter.element.classList.add("is-invalid"),this.readyValue=!0}disconnect(){this.readyValue=!1,this.searchPath&&this.input.removeEventListener("input",this.search),this.selectTarget.removeEventListener("change",this.refresh),this.selectTarget.removeEventListener("addItem",this.add),this.selectTarget.removeEventListener("removeItem",this.remove),this.searchPath&&this.selectTarget.removeEventListener("search",this.search);try{this.choices.destroy()}catch{}this.choices=void 0}refresh(){this.hasOptionsTarget&&(this.choices.setChoices([],"value","label",!0),[...this.optionsTarget.children].forEach(this.append.bind(this)))}append(e){[...this.selectTarget.options].some(t=>t.label===e.label)||this.choices.setChoices([e],"value","label",!1)}add(e){if(this.hasOptionsTarget){const t=[...this.optionsTarget.children].find(t=>t.label===e.detail.label);if(t)t.setAttribute("selected","");else{const t=document.createElement("option");t.setAttribute("label",e.detail.label),t.setAttribute("value",e.detail.value),t.setAttribute("selected",""),this.optionsTarget.appendChild(t)}}}remove(e){if(this.hasOptionsTarget){const t=[...this.optionsTarget.children].find(t=>t.label===e.detail.label);t&&(this.searchPath?t.remove():t.removeAttribute("selected"))}this.forceOption&&!this.selectTarget.options.length&&this.selectTarget.add(document.createElement("option"))}search(e){let t=this.choices._currentValue;t?fetch(this.searchPath+t,{headers:{"X-Requested-With":"XMLHttpRequest",Accept:"application/json"}}).then(function(e){return e.json()}).then(function(e){return e.map(function(e){return"full_name"in e?{value:e.id,label:`<img src="${e.url}" class="avatar avatar-sm avatar-image rounded-circle border border-2 border-white"/> ${e.full_name}`}:"email"in e?{value:e.id,label:`${e.name} - ${e.email}`}:"name"in e?{value:e.name,label:e.name}:"hashed_id"in e?{value:e.id,label:e.title}:void 0})}).then(this.update):this.refresh()}update(e){this.choices.setChoices(e,"value","label",!0)}filter(e){return![...this.selectTarget.options].some(t=>t.label===e.label)}options(){return"allowHTML silent renderChoiceLimit maxItemCount addItems addChoices removeItems removeItemButton editItems duplicateItemsAllowed delimiter paste searchEnabled searchChoices searchFloor searchResultLimit position resetScrollPosition addItemFilter shouldSort shouldSortItems placeholder placeholderValue searchPlaceholderValue prependValue appendValue renderSelectedChoices loadingText noResultsText noChoicesText itemSelectText addItemText maxItemText".split(" ").reduce(this.optionsReducer,{})}optionsReducer(e,t){return this.element.dataset[t]&&("false"===this.element.dataset[t]?e[t]=!1:e[t]=this.element.dataset[t]),e}}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.