fix methods search. closes https://github.com/TouchInstinct/api-generator/issues/43
This commit is contained in:
parent
9d3f835e38
commit
34d5274b19
|
|
@ -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>
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -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');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
const searchItems = {{ searchItems }};
|
||||
Loading…
Reference in New Issue