From 34d5274b19bbfe2cd7003c3803871a59d2cf46e3 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Tue, 17 Oct 2017 13:53:26 +0300 Subject: [PATCH] fix methods search. closes https://github.com/TouchInstinct/api-generator/issues/43 --- Web-documentation/blocks/header.html.twig | 2 +- Web-documentation/blocks/scripts.html.twig | 3 +- Web-documentation/js/main.js | 40 +++++++--------------- Web-documentation/searchItems.js.twig | 1 + 4 files changed, 17 insertions(+), 29 deletions(-) create mode 100644 Web-documentation/searchItems.js.twig diff --git a/Web-documentation/blocks/header.html.twig b/Web-documentation/blocks/header.html.twig index f72818c..a317891 100644 --- a/Web-documentation/blocks/header.html.twig +++ b/Web-documentation/blocks/header.html.twig @@ -1,7 +1,7 @@
- +
diff --git a/Web-documentation/blocks/scripts.html.twig b/Web-documentation/blocks/scripts.html.twig index 737f78d..cea75c5 100644 --- a/Web-documentation/blocks/scripts.html.twig +++ b/Web-documentation/blocks/scripts.html.twig @@ -1,2 +1,3 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/Web-documentation/js/main.js b/Web-documentation/js/main.js index 5701972..b499a22 100644 --- a/Web-documentation/js/main.js +++ b/Web-documentation/js/main.js @@ -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 += '' + item.name + '' - }); - $typeaheadContent.html(itemsLink); + .forEach(function (item) { + itemsLink += '' + item.name + '' + }); + $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'); + } }); diff --git a/Web-documentation/searchItems.js.twig b/Web-documentation/searchItems.js.twig new file mode 100644 index 0000000..a5a4eb1 --- /dev/null +++ b/Web-documentation/searchItems.js.twig @@ -0,0 +1 @@ +const searchItems = {{ searchItems }}; \ No newline at end of file