/** * Search Navbar */ 'use strict'; // ! Removed following code if you do't wish to use jQuery. Remember that navbar search functionality will stop working on removal. if (typeof $ !== 'undefined') { $(function () { // ! TODO: Required to load after DOM is ready, did this now with jQuery ready. window.Helpers.initSidebarToggle(); // Toggle Universal Sidebar // Navbar Search with autosuggest (typeahead) // ? You can remove the following JS if you don't want to use search functionality. //---------------------------------------------------------------------------------- var searchToggler = $('.search-toggler'), searchInputWrapper = $('.search-input-wrapper'), searchInput = $('.search-input'), contentBackdrop = $('.content-backdrop'); // Open search input on click of search icon if (searchToggler.length) { searchToggler.on('click', function () { if (searchInputWrapper.length) { searchInputWrapper.toggleClass('d-none'); searchInput.focus(); } }); } // Open search on 'CTRL+/' $(document).on('keydown', function (event) { let ctrlKey = event.ctrlKey, slashKey = event.which === 191; if (ctrlKey && slashKey) { if (searchInputWrapper.length) { searchInputWrapper.toggleClass('d-none'); searchInput.focus(); } } }); // Note: Following code is required to update container class of typeahead dropdown width on focus of search input. setTimeout is required to allow time to initiate Typeahead UI. setTimeout(function () { var twitterTypeahead = $('.twitter-typeahead'); searchInput.on('focus', function () { if (searchInputWrapper.hasClass('container-xxl')) { searchInputWrapper.find(twitterTypeahead).addClass('container-xxl'); twitterTypeahead.removeClass('container-fluid'); } else if (searchInputWrapper.hasClass('container-fluid')) { searchInputWrapper.find(twitterTypeahead).addClass('container-fluid'); twitterTypeahead.removeClass('container-xxl'); } }); }, 10); if (searchInput.length) { // Filter config var filterConfig = function (data) { return function findMatches(q, cb) { let matches; matches = []; data.filter(function (i) { if (i.name.toLowerCase().startsWith(q.toLowerCase())) { matches.push(i); } else if ( !i.name.toLowerCase().startsWith(q.toLowerCase()) && i.name.toLowerCase().includes(q.toLowerCase()) ) { matches.push(i); matches.sort(function (a, b) { return b.name < a.name ? 1 : -1; }); } else { return []; } }); cb(matches); }; }; // Search JSON var searchJson = 'search-navbar'; // For vertical layout if ($('#layout-menu').hasClass('menu-horizontal')) { var searchJson = 'search-navbar'; // For vertical layout } // Search API AJAX call var searchData = $.ajax({ url: assetsPath + '../../admin/navbar/' + searchJson, //? Use your own search api instead dataType: 'json', async: false }).responseJSON; // Init typeahead on searchInput searchInput.each(function () { var $this = $(this); searchInput .typeahead( { hint: false, classNames: { menu: 'tt-menu navbar-search-suggestion', cursor: 'active', suggestion: 'suggestion d-flex justify-content-between px-4 py-2 w-100' } }, // ? Add/Update blocks as per need // Pages { name: 'pages', display: 'name', limit: 6, source: filterConfig(searchData.pages), templates: { header: '
No se encontro resultados
' + 'No se encontro resultados
' + 'No se encontro resultados
' + 'No se encontro resultados
' + '