{"version":3,"file":"uppsala.groupable-autocomplete.min.js","names":["define","$","autoCompleteOnChangeCallback","groupableAutocompleteSelector","expandedClass","inputSelector","optionClassName","activeOptionSelector","activeClass","currentUserInput","unsetTrap","groupableAutocomplete","clickTrap","off","keyTrap","event","preventDefault","$target","target","unset","$autocompleteElement","length","hasClass","parents","$clickedOption","closest","clickedOptionText","data","insertOptionToSearchField","populateHiddenFields","close","$autocompleteOptions","$autoCompleteElement","preventDefaultEvent","keyCode","$selectedOption","selectedOptionText","movePrevious","moveNext","$options","nextElement","$focusedElement","removeActiveOption","indexOfFocused","index","undefined","val","setActiveOption","innerText","setFocusOnActive","id","prevElement","$element","value","addClass","attr","removeClass","$optionIdHiddenInput","$optionTextHiddenInput","$optionLayerTypeHiddenInput","$optionDiarienrHiddenInput","$optionAktbetecknHiddenInput","optiontext","layerType","diarienr","aktbeteckn","setAutoCompleteOptionsAsNonFocusable","currentElement","currentAnchorElement","find","removeAttr","focus","init","endpoint","callbackOnChange","staticTextInList","debounceFunction","$groupableAutocompleteElement","on","clearTimeout","setTimeout","query","get","remove","htmlString","itemsAdded","each","arrayIndex","Suggestions","DisplayName","innerArrayIndex","innerValue","Id","Text","Diarienummer","Aktbeteckning","LayerType","html","groupableAutoCompleteResponseHandler","open","$baseElement","$input","resetInput","empty"],"sources":["components/uppsala.groupable-autocomplete.js"],"mappings":"AAAAA,OAAO,CAAC,WAAW,SAAUC,GAEzB,IAWIC,EAXAC,EAAgC,6BAChCC,EAAgB,WAChBC,EAAgB,uCAMhBC,EAAkB,yBAClBC,EAAuB,iCACvBC,EAAc,SASdC,EAAmB,GAcnBC,EAAY,WACRC,EAAsBC,YACtBD,EAAsBC,UAAY,KAClCX,EAAE,QAAQY,IAAI,QAASD,IAEvBD,EAAsBG,UACtBH,EAAsBG,QAAU,KAChCb,EAAE,QAAQY,IAAI,UAAWC,GAEjC,EAEIF,EAAY,SAAUG,GACtBA,EAAMC,iBACN,IAAIC,EAAUhB,EAAEc,EAAMG,QA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WK,UAAY,IAAML,EAAWC,GAAK,2CAA6CtF,EAAkB,sHAAwHqF,EAAWE,KAAO,iBAG1hB,IAEAT,GAAc,aACdC,GAAa,EAErB,IAEIA,EACArD,EAAqBiE,KAAKb,GAG1BpD,EAAqBiE,KAAK,wFAhCD,CAkCjC,CA2BoBC,CAAqCvE,EAAMgD,GAC3ChE,EAAsBwF,KAAKtB,EAC/B,GAAG,OAEP,GAAG,IACP,GACJ,EAEAsB,KAAM,SAAUC,GACZA,EAAa5C,YAAY,kBACzB6C,OAASpG,EAAEI,GACXgG,OAAO/C,SAASlD,GArRfO,EAAsBC,YACvBD,EAAsBC,UAAYA,EAClCX,EAAE,QAAQ6E,GAAG,QAASlE,IAGrBD,EAAsBG,UACvBH,EAAsBG,QAAUA,EAChCb,EAAE,QAAQ6E,GAAG,UAAWhE,GAgR5B,EAEAgB,MAAO,SAAUsE,EAAcE,GAC3BpC,IACAkC,EAAaG,QACbH,EAAa9C,SAAS,kBACtB+C,OAASpG,EAAEI,GACXgG,OAAO7C,YAAYpD,GAEfkG,GACAD,OAAOvD,IAAIrC,EAEnB,GAGJ,OAAOE,CACX","ignoreList":[],"sourcesContent":["define([\"jquery\"], function ($) {\n\n var groupableAutocompleteSelector = \".js-groupable-autocomplete\";\n var expandedClass = \"expanded\";\n var inputSelector = \"#js-localplanlist-autocomplete-input\";\n var hiddenInputIdSelector = \"#js-selectedautocompleteoption-id\";\n var hiddenInputTextSelector = \"#js-selectedautocompleteoption-text\";\n var hiddenInputDiarieNrSelector = \"#js-selectedautocompleteoption-diarienr\";\n var hiddenInputAktbtcknSelector = \"#js-selectedautocompleteoption-aktbeteckning\";\n var hiddenInputLayerTypeSelector = \"#js-selectedautocompleteoption-layertype\";\n var optionClassName = \"js-autocomplete-option\";\n var activeOptionSelector = \".js-autocomplete-option.active\";\n var activeClass = \"active\";\n var autoCompleteOnChangeCallback;\n\n var UP_keycode = 38;\n var DOWN_keycode = 40;\n var ESC_keycode = 27;\n var TAB_keycode = 9;\n var ENTER_keycode = 13;\n\n var currentUserInput = \"\";\n\n var setTrap = function () {\n if (!groupableAutocomplete.clickTrap) {\n groupableAutocomplete.clickTrap = clickTrap;\n $(\"body\").on(\"click\", clickTrap);\n }\n\n if (!groupableAutocomplete.keyTrap) {\n groupableAutocomplete.keyTrap = keyTrap;\n $(\"body\").on(\"keydown\", keyTrap);\n }\n }\n\n var unsetTrap = function () {\n if (groupableAutocomplete.clickTrap) {\n groupableAutocomplete.clickTrap = null;\n $(\"body\").off(\"click\", clickTrap);\n }\n if (groupableAutocomplete.keyTrap) {\n groupableAutocomplete.keyTrap = null;\n $(\"body\").off(\"keydown\", keyTrap);\n }\n }\n\n var clickTrap = function (event) {\n event.preventDefault();\n var $target = $(event.target);\n var unset = false;\n\n var $autocompleteElement = $(groupableAutocompleteSelector);\n var $autocompleteOptions = $(\".\" + optionClassName);\n if ($autocompleteOptions.length > 0) {\n\n var targetIsAutocompleteOption = $target.hasClass(optionClassName) || $target.parents(\".\" + optionClassName).length > 0;\n if (targetIsAutocompleteOption) {\n //if link or span is clicked, get li parent where data attributes are stored\n $clickedOption = $target.closest(\".\" + optionClassName);\n var clickedOptionText = $clickedOption.data('optiontext');\n insertOptionToSearchField(clickedOptionText);\n populateHiddenFields($clickedOption);\n groupableAutocomplete.close($autocompleteElement, false);\n autoCompleteOnChangeCallback();\n unset = true;\n }\n //klickat target är utanför autocomplete-element\n else if (!$target.parents(groupableAutocompleteSelector).length > 0) {\n groupableAutocomplete.close($autocompleteElement, false);\n unset = true;\n }\n }\n\n if (unset) {\n unsetTrap();\n }\n }\n\n var keyTrap = function (event) {\n var unset = false;\n var $autocompleteOptions = $(\".\" + optionClassName);\n var $autoCompleteElement = $(groupableAutocompleteSelector);\n var preventDefaultEvent = false;\n\n if (event.keyCode == ENTER_keycode) {\n //if autocomplete option is selected\n if ($autocompleteOptions.length > 0 && $(activeOptionSelector)[0]) {\n var $selectedOption = $(activeOptionSelector);\n var selectedOptionText = $selectedOption.data('optiontext');\n populateHiddenFields($selectedOption);\n insertOptionToSearchField(selectedOptionText);\n var $autocompleteElement = $(groupableAutocompleteSelector);\n groupableAutocomplete.close($autocompleteElement, false);\n autoCompleteOnChangeCallback();\n }\n preventDefaultEvent = true;\n }\n\n if ($autocompleteOptions.length > 0) {\n switch (event.keyCode) {\n case ESC_keycode:\n groupableAutocomplete.close($autoCompleteElement, true);\n unset = true;\n preventDefaultEvent = true;\n break;\n case TAB_keycode:\n groupableAutocomplete.close($autoCompleteElement, false);\n preventDefaultEvent = false;\n unset = true;\n break;\n case UP_keycode:\n movePrevious($autocompleteOptions);\n preventDefaultEvent = true;\n break;\n case DOWN_keycode:\n moveNext($autocompleteOptions);\n preventDefaultEvent = true;\n break;\n }\n }\n if (preventDefaultEvent) {\n event.preventDefault();\n }\n if (unset) {\n unsetTrap();\n }\n }\n\n var moveNext = function ($options) {\n\n var nextElement;\n var $focusedElement = $(activeOptionSelector);\n\n if ($focusedElement.length > 0) {\n removeActiveOption($focusedElement);\n var indexOfFocused = $options.index($focusedElement);\n nextElement = $options[indexOfFocused + 1];\n\n if (nextElement === undefined) {\n $(inputSelector).val(currentUserInput);\n return;\n }\n\n }\n else {\n var indexToFocusOn = 0;\n nextElement = $options[indexToFocusOn];\n }\n setActiveOption($(nextElement), nextElement.innerText);\n setFocusOnActive(nextElement.id);\n }\n\n var movePrevious = function ($options) {\n var prevElement;\n var $focusedElement = $(activeOptionSelector);\n\n if ($focusedElement.length > 0) {\n removeActiveOption($focusedElement);\n var indexOfFocused = $options.index($focusedElement);\n prevElement = $options[indexOfFocused - 1];\n\n if (prevElement === undefined) {\n $(inputSelector).val(currentUserInput);\n return;\n }\n }\n else {\n var indexToFocusOn = $options.length - 1;\n prevElement = $options[indexToFocusOn];\n }\n setActiveOption($(prevElement), prevElement.innerText);\n setFocusOnActive(prevElement.id);\n }\n\n var setActiveOption = function ($element, value) {\n $element.addClass(activeClass);\n $element.attr(\"aria-selected\", \"true\");\n }\n\n var removeActiveOption = function ($element) {\n $element.removeClass(activeClass);\n $element.attr(\"aria-selected\", \"false\");\n }\n\n var insertOptionToSearchField = function (value) {\n var $inputElement = $(inputSelector);\n $inputElement.val(value);\n }\n\n var populateHiddenFields = function ($selectedOption) {\n\n var $optionIdHiddenInput = $(hiddenInputIdSelector);\n var $optionTextHiddenInput = $(hiddenInputTextSelector);\n var $optionLayerTypeHiddenInput = $(hiddenInputLayerTypeSelector);\n var $optionDiarienrHiddenInput = $(hiddenInputDiarieNrSelector);\n var $optionAktbetecknHiddenInput = $(hiddenInputAktbtcknSelector);\n\n var id = $selectedOption.data('objectid');\n var optiontext = $selectedOption.data('optiontext');\n var layerType = $selectedOption.data('layertype');\n var diarienr = $selectedOption.data('diarienr');\n var aktbeteckn = $selectedOption.data('aktbeteckn');\n\n $optionIdHiddenInput.val(id);\n $optionTextHiddenInput.val(optiontext);\n $optionLayerTypeHiddenInput.val(layerType);\n $optionAktbetecknHiddenInput.val(aktbeteckn);\n $optionDiarienrHiddenInput.val(diarienr);\n }\n\n //autocomplete should not be able to tab into. thats why we've set tabindex=\"-1\"\n //however, for the scroll to work we need to focus the selected element when navigating with the arrow keys\n var setFocusOnActive = function (id) {\n\n setAutoCompleteOptionsAsNonFocusable();\n var currentElement = $(\"#\" + id);\n currentAnchorElement = currentElement.find(\"a\");\n currentAnchorElement.removeAttr(\"tabindex\");\n currentAnchorElement.focus();\n }\n\n var setAutoCompleteOptionsAsNonFocusable = function () {\n\n var anchorsWithoutTabIndex = $(groupableAutocompleteSelector + \" a:not([tabindex])\");\n anchorsWithoutTabIndex.attr(\"tabindex\", \"-1\");\n }\n\n var groupableAutoCompleteResponseHandler = function (data, staticTextInList) {\n\n if (data === null) { return; }\n\n var $autoCompleteElement = $(groupableAutocompleteSelector);\n $autoCompleteElement.find(\"li\").remove();\n var htmlString = \"\";\n var itemsAdded = false;\n\n if (staticTextInList !== \"\") {\n htmlString = '
  • ' + staticTextInList + '
  • '\n }\n\n $.each(data, function (arrayIndex, value) {\n if (value.Suggestions !== undefined && value.Suggestions.length > 0) {\n\n htmlString += '
  • ' + value.DisplayName + '
  • ';\n itemsAdded = true;\n }\n });\n\n if (itemsAdded) {\n $autoCompleteElement.html(htmlString);\n }\n else {\n $autoCompleteElement.html('
    Inga sökförslag kunde hittas
    ');\n }\n }\n\n var groupableAutocomplete = {\n init: function (endpoint, callbackOnChange, staticTextInList) {\n\n var $groupableAutocompleteElement = $(groupableAutocompleteSelector);\n autoCompleteOnChangeCallback = callbackOnChange;\n\n // Register event listener to trigger request for autocomplete options\n // setTimeout to limit number of times it runs\n var debounceFunction;\n\n $(inputSelector).on(\"input focus\", function () {\n\n clearTimeout(debounceFunction);\n debounceFunction = setTimeout(function () {\n\n currentUserInput = $(inputSelector).val();\n\n if (currentUserInput == \"\" || currentUserInput == null || currentUserInput.length < 3) {\n groupableAutocomplete.close($groupableAutocompleteElement, false);\n return false;\n }\n\n var query = \"?searchTerm=\" + currentUserInput;\n\n $.get(endpoint + query, function (data) {\n groupableAutoCompleteResponseHandler(data, staticTextInList);\n groupableAutocomplete.open($groupableAutocompleteElement);\n }, \"json\");\n\n }, 600);\n });\n },\n\n open: function ($baseElement) {\n $baseElement.removeClass(\"visuallyhidden\");\n $input = $(inputSelector);\n $input.addClass(expandedClass);\n setTrap();\n },\n\n close: function ($baseElement, resetInput) {\n setAutoCompleteOptionsAsNonFocusable();\n $baseElement.empty();\n $baseElement.addClass(\"visuallyhidden\");\n $input = $(inputSelector);\n $input.removeClass(expandedClass);\n\n if (resetInput) {\n $input.val(currentUserInput);\n }\n },\n };\n\n return groupableAutocomplete;\n});"]}