{"version":3,"file":"searchinput.min.js","sources":["https:\/\/kundenportal.comm-unity.at\/local\/wb_faq\/amd\/src\/searchinput.js"],"sourcesContent":["\n\/\/ This file is part of Moodle - http:\/\/moodle.org\/\n\/\/\n\/\/ Moodle is free software: you can redistribute it and\/or modify\n\/\/ it under the terms of the GNU General Public License as published by\n\/\/ the Free Software Foundation, either version 3 of the License, or\n\/\/ (at your option) any later version.\n\/\/\n\/\/ Moodle is distributed in the hope that it will be useful,\n\/\/ but WITHOUT ANY WARRANTY; without even the implied warranty of\n\/\/ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\/\/ GNU General Public License for more details.\n\/\/\n\/\/ You should have received a copy of the GNU General Public License\n\/\/ along with Moodle. If not, see .\n\n\/*\n * @package local_wunderbyte_table\n * @copyright Wunderbyte GmbH \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\nimport Templates from 'core\/templates';\nimport {get_string as getString} from 'core\/str';\nimport {increaseCounter} from \"local_wb_faq\/faqnavbar\";\n\nvar searcharray = [];\n\nexport const searchInput = (inputClass, elementToHide, elementToSearch) => {\n\n let input, filter, li, a, i, txtValue;\n input = document.querySelector(inputClass);\n filter = input.value.toUpperCase();\n li = document.querySelectorAll(elementToHide);\n for (i = 0; i < li.length; i++) {\n a = li[i].querySelector(elementToSearch);\n txtValue = a.textContent || a.innerText;\n\n if (txtValue.toUpperCase().indexOf(filter) > -1) {\n li[i].style.display = \"\";\n } else {\n li[i].style.display = \"none\";\n }\n }\n};\n\nexport const searchJSON = (listContainer, inputClass, json) => {\n let arr = [];\n \/\/ Select Container\n let container = document.querySelector(listContainer);\n let searchVal = document.querySelector(inputClass).value.toUpperCase();\n\n \/\/ Make sure we have parsed json.\n if (typeof json === 'string') {\n json = JSON.parse(json);\n }\n\n if (searchVal.length > 3) {\n let i = 0;\n Object.values(json).forEach(e=>{\n if ((e.content && e.content.toUpperCase().indexOf(searchVal) > -1)\n || (e.title && e.title.toUpperCase().indexOf(searchVal) > -1)) {\n arr[i] = e;\n if (e.type == 0) {\n arr[i].iscategory = true;\n }\n i++;\n }\n });\n\n for (let i = 0; i < arr.length; i++) {\n\n if (typeof searcharray[i] === 'undefined') {\n render(arr, container);\n break;\n }\n\n if (arr[i].id != searcharray[i].id) {\n\n render(arr, container);\n break;\n }\n }\n searcharray = arr;\n\n if (searcharray.length < 1) {\n getString('noresult', 'local_wb_faq').then(value => {\n\n container.innerHTML = value;\n return;\n }).catch(e => {\n \/\/ eslint-disable-next-line no-console\n console.log(e);\n });\n \/\/ If we didn't find anything, we just increase the counter.\n \/\/ User might need to search a few times.\n increaseCounter();\n } else {\n \/\/ If we had a valid input, we allow to continue to the input form.\n increaseCounter(true);\n }\n\n } else if (searchVal.length == 0) {\n\n container.innerHTML = '';\n searcharray = [];\n\n } else {\n\n getString('stringtooshort', 'local_wb_faq').then(value => {\n\n container.innerHTML = value;\n return;\n }).catch(e => {\n \/\/ eslint-disable-next-line no-console\n console.log(e);\n });\n\n searcharray = [];\n\n }\n};\n\nexport const init = (searchInputID, listContainer, elementToHide, elementToSearch, json = null) => {\n\n const searchInputElement = document.querySelector(searchInputID);\n\n if (searchInputElement) {\n searchInputElement.addEventListener('keyup', function() {\n searchJSON(listContainer, searchInputID, json);\n });\n }\n};\n\n\nexport const render = (data, container) => {\n \/\/ Render\n\n Templates.renderForPromise('local_wb_faq\/searchbox', data).then(({html}) => {\n container.innerHTML = \"\";\n container.insertAdjacentHTML('afterbegin', html);\n return;\n }).catch(e => {\n \/\/ eslint-disable-next-line no-console\n console.log(e);\n });\n};"],"names":["searcharray","inputClass","elementToHide","elementToSearch","input","filter","li","a","i","txtValue","document","querySelector","value","toUpperCase","querySelectorAll","length","textContent","innerText","indexOf","style","display","searchJSON","listContainer","json","arr","container","searchVal","JSON","parse","Object","values","forEach","e","content","title","type","iscategory","render","id","then","innerHTML","catch","console","log","searchInputID","searchInputElement","addEventListener","data","renderForPromise","_ref","html","insertAdjacentHTML"],"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