dikplhd/public/assets/js/pages/form-choises.min.js

1 line
6.6 KiB
JavaScript

document.addEventListener("DOMContentLoaded",function(){var e=document.querySelectorAll("[data-trigger]");for(i=0;i<e.length;++i){var t=e[i];new Choices(t,{allowHTML:!0,placeholderValue:"placeholder set config",searchPlaceholderValue:"This is a search placeholder"})}new Choices(document.getElementById("choices-text-remove-button"),{allowHTML:!0,delimiter:",",editItems:!0,maxItemCount:5,removeItemButton:!0}),new Choices("#choices-text-unique-values",{allowHTML:!0,paste:!1,duplicateItemsAllowed:!1,editItems:!0}),new Choices("#choices-text-i18n",{allowHTML:!0,paste:!1,duplicateItemsAllowed:!1,editItems:!0,maxItemCount:5,addItemText:function(e){return'Appuyez sur Entrée pour ajouter <b>"'+String(e)+'"</b>'},maxItemText:function(e){return String(e)+"valeurs peuvent être ajoutées"},uniqueItemText:"Cette valeur est déjà présente"}),new Choices("#choices-text-email-filter",{allowHTML:!0,editItems:!0,addItemFilter:function(e){if(!e)return!1;const t=new RegExp(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.source,"i");return t.test(e)}}).setValue(["joe@bloggs.com"]),new Choices("#choices-text-disabled",{allowHTML:!0,addItems:!1,removeItems:!1}).disable(),new Choices("#choices-text-prepend-append-value",{allowHTML:!0,prependValue:"item-",appendValue:"-"+Date.now()}).removeActiveItems(),new Choices("#choices-text-preset-values",{allowHTML:!0,items:["Josh Johnson",{value:"joe@bloggs.co.uk",label:"Joe Bloggs",customProperties:{description:"Joe Blogg is such a generic name"}}]}),new Choices(document.getElementById("choices-multiple-groups"),{allowHTML:!0}),new Choices("#choices-multiple-remote-fetch",{allowHTML:!1,placeholder:!0,placeholderValue:"Pick an Strokes record",maxItemCount:5}).setChoices(function(){return fetch("https://api.discogs.com/artists/55980/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW").then(function(e){return e.json()}).then(function(e){return e.releases.map(function(e){return{value:e.title,label:e.title}})})}),new Choices("#choices-multiple-remove-button",{allowHTML:!0,removeItemButton:!0});var l=new Choices("#choices-multiple-labels",{allowHTML:!0,removeItemButton:!0,choices:[{value:"One",label:"Label One"},{value:"Two",label:"Label Two",disabled:!0},{value:"Three",label:"Label Three"}]}).setChoices([{value:"Four",label:"Label Four",disabled:!0},{value:"Five",label:"Label Five"},{value:"Six",label:"Label Six",selected:!0}],"value","label",!1),l=(l.passedElement.element.addEventListener("addItem",function(e){document.getElementById("message").innerHTML='You just added "'+e.detail.label+'"'}),l.passedElement.element.addEventListener("removeItem",function(e){document.getElementById("message").innerHTML='You just removed "'+e.detail.label+'"'}),new Choices("#choices-single-remote-fetch",{allowHTML:!1,searchPlaceholderValue:"Search for an Arctic Monkeys record"}).setChoices(function(){return fetch("https://api.discogs.com/artists/391170/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW").then(function(e){return e.json()}).then(function(e){return e.releases.map(function(e){return{label:e.title,value:e.title}})})}).then(function(e){e.setChoiceByValue("Fake Tales Of San Francisco")}),new Choices("#choices-single-remove-xhr",{allowHTML:!0,removeItemButton:!0,searchPlaceholderValue:"Search for a Smiths' record"}).setChoices(function(e){return fetch("https://api.discogs.com/artists/83080/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW").then(function(e){return e.json()}).then(function(e){return e.releases.map(function(e){return{label:e.title,value:e.title}})})}),new Choices("#choices-single-no-search",{allowHTML:!0,searchEnabled:!1,removeItemButton:!0,choices:[{value:"One",label:"Label One"},{value:"Two",label:"Label Two",disabled:!0},{value:"Three",label:"Label Three"}]}).setChoices([{value:"Four",label:"Label Four",disabled:!0},{value:"Five",label:"Label Five"},{value:"Six",label:"Label Six",selected:!0}],"value","label",!1),new Choices("#choices-single-preset-options",{allowHTML:!0,placeholder:!0}).setChoices([{label:"Group one",id:1,disabled:!1,choices:[{value:"Child One",label:"Child One",selected:!0},{value:"Child Two",label:"Child Two",disabled:!0},{value:"Child Three",label:"Child Three"}]},{label:"Group two",id:2,disabled:!1,choices:[{value:"Child Four",label:"Child Four",disabled:!0},{value:"Child Five",label:"Child Five"},{value:"Child Six",label:"Child Six"}]}],"value","label"),new Choices("#choices-single-selected-option",{allowHTML:!0,searchFields:["label","value","customProperties.description"],choices:[{value:"One",label:"Label One",selected:!0},{value:"Two",label:"Label Two",disabled:!0},{value:"Three",label:"Label Three",customProperties:{description:"This option is fantastic"}}]}).setChoiceByValue("Two"),new Choices("#choices-with-custom-props-via-html",{allowHTML:!0,searchFields:["label","value","customProperties"]}),new Choices("#choices-single-no-sorting",{allowHTML:!0,shouldSort:!1,labelId:"choices-single-no-sorting-label"}),new Choices(document.getElementById("cities"),{allowHTML:!0})),a=new Choices(document.getElementById("tube-stations"),{allowHTML:!0}).disable();l.passedElement.element.addEventListener("change",function(e){"London"===e.detail.value?a.enable():a.disable()}),new Choices(document.getElementById("choices-single-custom-templates"),{allowHTML:!0,callbackOnCreateTemplates:function(l){this.config.classNames;var a=this.config.itemSelectText;return{item:function({classNames:e},t){return l(' <div class="'+String(e.item)+" "+String(t.highlighted?e.highlightedState:e.itemSelectable)+'" data-item data-id="'+String(t.id)+'" data-value="'+String(t.value)+'" '+String(t.active?'aria-selected="true"':"")+" "+String(t.disabled?'aria-disabled="true"':"")+' > <span style="margin-right:10px;">🎉</span> '+String(t.label)+" </div> ")},choice:function({classNames:e},t){return l(' <div class="'+String(e.item)+" "+String(e.itemChoice)+" "+String(t.disabled?e.itemDisabled:e.itemSelectable)+'" data-select-text="'+String(a)+'" data-choice '+String(t.disabled?'data-choice-disabled aria-disabled="true"':"data-choice-selectable")+' data-id="'+String(t.id)+'" data-value="'+String(t.value)+'" '+String(0<t.groupId?'role="treeitem"':'role="option"')+' > <span style="margin-right:10px;">👉🏽</span> '+String(t.label)+" </div> ")}}}}),new Choices(document.getElementById("reset-simple"),{allowHTML:!0}),new Choices("#reset-multiple",{allowHTML:!0,removeItemButton:!0})});