This commit is contained in:
Ivan Smolin 2017-10-17 13:53:26 +03:00
parent 9d3f835e38
commit 34d5274b19
4 changed files with 17 additions and 29 deletions

View File

@ -1,7 +1,7 @@
<div class="header">
<div class="search-block">
<i class="icon-search"></i>
<input type="text" placeholder="Поиск" data-methods-path="{{ methodsPath }}" data-relative-to-root-path="{{ relativeToRootPath }}">
<input type="text" placeholder="Поиск" data-relative-to-root-path="{{ relativeToRootPath }}">
<div class="typeahead-container typeahead-container--hide"><div class="typeahead-content"></div></div>
</div>

View File

@ -1,2 +1,3 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script type="text/javascript" src="{{ jsFolderPath }}/main.js?v=1.02"></script>
<script type="text/javascript" src="{{ jsFolderPath }}/main.js?v=1.02"></script>
<script type="text/javascript" src="{{ jsFolderPath }}/searchItems.js?v=1.00"></script>

View File

@ -67,39 +67,25 @@ $(function () {
$(document).on('keyup', '.search-block input', function (e) {
var $searchInput = $(this);
var methodsUrl = $searchInput.data('methodsPath');
var relativeUrl = $searchInput.data('relativeToRootPath');
var $typeaheadContainer = $searchInput.closest('.search-block').find('.typeahead-container');
var $typeaheadContent = $typeaheadContainer.find('.typeahead-content');
$.ajax({
type: 'POST',
contentType: 'application/json',
dataType: 'json',
url: methodsUrl
var itemsLink = '';
searchItems
.filter(function (item) {
return item.name.toLowerCase().indexOf($searchInput.val().toLowerCase()) >= 0;
})
.done(
function (response) {
var itemsLink = '';
response
.filter(function (item) {
return item.name.toLowerCase().indexOf($searchInput.val().toLowerCase()) >= 0;
})
.forEach(function (item) {
itemsLink += '<a href="' + (relativeUrl ? relativeUrl + "/" : "") + item.url + '">' + item.name + '</a>'
});
$typeaheadContent.html(itemsLink);
.forEach(function (item) {
itemsLink += '<a href="' + (relativeUrl ? relativeUrl + "/" : "") + item.url + '">' + item.name + '</a>'
});
$typeaheadContent.html(itemsLink);
if (itemsLink != '') {
$typeaheadContainer.removeClass('typeahead-container--hide');
} else {
$typeaheadContainer.addClass('typeahead-container--hide');
}
})
.fail(
function () {
alert('Ошибка запроса.');
});
if (itemsLink != '') {
$typeaheadContainer.removeClass('typeahead-container--hide');
} else {
$typeaheadContainer.addClass('typeahead-container--hide');
}
});

View File

@ -0,0 +1 @@
const searchItems = {{ searchItems }};