templates/includes/side-navigation/search-form.html.twig line 1

Open in your IDE?
  1. <form method="get" id="searchform" autocomplete="off" onsubmit="return false;" class="search-bar">
  2.     <div id="searchContainer" class="search-result-wrp">
  3.         <!--                        <div class="page_navigation"></div>-->
  4.         <div id="searchResult" data-search-result></div>
  5.         <div id="pagination" class="pagination"></div>
  6.     </div>
  7.     <label>
  8.         <input type="search" placeholder="Suche" class="input-input font-light searchtext" name="s" type="text"/>
  9.     </label>
  10.     <div class="autocomplete-suggestions"></div>
  11. </form>
  12. <img src="/bundles/app/static/frontend/images/icons/lupe_neg.svg" alt="Lupe" class="lupe"/>
  13. <script type="text/javascript">
  14.     (function () {
  15.         var moduleName = 'main_module'; // naming convention XXX_module
  16.         if (typeof selt === 'undefined') {
  17.             selt = {
  18.                 modules: {}
  19.             };
  20.         } else if (!selt.modules) {
  21.             selt.modules = {};
  22.         }
  23.         selt.modules[moduleName] = {
  24.             name: moduleName,
  25.             init: function () {
  26.                 initSearchBar();
  27.                 paginage();
  28.                 initSearch();
  29.             }
  30.         };
  31.         function initSearchBar() {
  32.             var searchBarInput = $('[type="search"], .search-bar'),
  33.                 searchBar = $('.lupe'),
  34.                 searchContainer = $('main #searchContainer'),
  35.                 searchContainer2 = $('aside #searchContainer');
  36.             searchBar.on('click', function (e) {
  37.                 searchBarInput.toggleClass('focus');
  38.                 e.stopImmediatePropagation();
  39.             });
  40.         }
  41.         function initSearch() {
  42.             // get status modifier element
  43.             var searchResult = $('main #searchResult'),
  44.                 searchResult2 = $('aside #searchResult'),
  45.                 searchContainer = $('main #searchContainer'),
  46.                 searchContainer2 = $('aside #searchContainer'),
  47.                 searchform = $('main #searchform'),
  48.                 searchform2 = $('aside #searchform'),
  49.                 searchtext = searchform.find('.searchtext'),
  50.                 searchtext2 = searchform2.find('.searchtext');
  51.             // searchtext.on('keyup', function (e) {
  52.             //     instantSearch('keyupEvent', this.value);
  53.             // });
  54.             searchform.on('submit', function (e) {
  55.                 instantSearch('submit');
  56.             });
  57.             searchform2.on('submit', function (e) {
  58.                 instantSearch2('submit');
  59.             });
  60.             // auto complete
  61.             var xhr;
  62.             var ac = new autoComplete({
  63.                 selector: 'input[name="s"]',
  64.                 minChars: 2,
  65.                 source: function (term, response) {
  66.                     try {
  67.                         xhr.abort();
  68.                     } catch (e) {
  69.                     }
  70.                     xhr = $.getJSON('/search/autocomplete?render=1', {q: term}, function (data) {
  71.                         response(data);
  72.                     });
  73.                 },
  74.                 onSelect: function (e, term, item) {
  75.                     instantSearch('submit');
  76.                 },
  77.                 onSuggest: function () {
  78.                     searchContainer.stop(true, true).fadeOut();
  79.                 }
  80.             });
  81.             function instantSearch(welchesEvent, keyword) {
  82.                 var ausgabe = true;
  83.                 if (welchesEvent === 'submit') {
  84.                     keyword = searchtext.val();
  85.                 }
  86.                 searchContainer.stop(true, true).fadeIn();
  87.                 ac.hide();
  88.                 // Falls bereits eine Suche ausgeführt wurde oder noch läuft wird die Anzeige zurück auf
  89.                 // animierte punkte gesetzt
  90.                 searchResult.html('<svg version="1.1" id="L4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 52 12" width="50">\n' +
  91.                     '  <circle fill="#000" stroke="none" cx="6" cy="6" r="6">\n' +
  92.                     '    <animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.1"></animate>\n' +
  93.                     '  </circle>\n' +
  94.                     '    <circle fill="#000" stroke="none" cx="26" cy="6" r="6">\n' +
  95.                     '    <animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.2"></animate>\n' +
  96.                     '  </circle>\n' +
  97.                     '    <circle fill="#000" stroke="none" cx="46" cy="6" r="6">\n' +
  98.                     '    <animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.3"></animate>\n' +
  99.                     '  </circle>\n' +
  100.                     '</svg>');
  101.                 // In diesem nächsten Schritt erzeugen wir ein jQuery Get Objekt
  102.                 // und übermitteln die Such-Keywords
  103.                 var searchServiceUrl = '/search/list?q=' + keyword + '&render=1&lang='+$('html').attr('data-language');
  104.                 $.get(searchServiceUrl, function (data, success) {
  105.                     // Wenn der Parameter success auch success zurück gibt
  106.                     // wurde die GET Anfrage erfolgreich übertragen und Werte zurück geliefert
  107.                     if (success == 'success') {
  108.                         console.log(data);
  109.                         if (data.indexOf('search-result-item') >= 0) {
  110.                             searchResult.html(data);
  111.                             paginage();
  112.                         } else {
  113.                             searchContainer.stop(true, true).fadeOut();
  114.                         }
  115.                     }
  116.                 });
  117.             }
  118.             function instantSearch2(welchesEvent, keyword) {
  119.                 var ausgabe = true;
  120.                 if (welchesEvent === 'submit') {
  121.                     keyword = searchtext2.val();
  122.                 }
  123.                 searchContainer2.stop(true, true).fadeIn();
  124.                 ac.hide();
  125.                 // Falls bereits eine Suche ausgeführt wurde oder noch läuft wird die Anzeige zurück auf
  126.                 // animierte punkte gesetzt
  127.                 searchResult2.html('<svg version="1.1" id="L4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 52 12" width="50">\n' +
  128.                     '  <circle fill="#000" stroke="none" cx="6" cy="6" r="6">\n' +
  129.                     '    <animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.1"></animate>\n' +
  130.                     '  </circle>\n' +
  131.                     '    <circle fill="#000" stroke="none" cx="26" cy="6" r="6">\n' +
  132.                     '    <animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.2"></animate>\n' +
  133.                     '  </circle>\n' +
  134.                     '    <circle fill="#000" stroke="none" cx="46" cy="6" r="6">\n' +
  135.                     '    <animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.3"></animate>\n' +
  136.                     '  </circle>\n' +
  137.                     '</svg>');
  138.                 // In diesem nächsten Schritt erzeugen wir ein jQuery Get Objekt
  139.                 // und übermitteln die Such-Keywords
  140.                 var searchServiceUrl = '/search/list?q=' + keyword + '&render=1&lang='+$('html').attr('data-language');
  141.                 $.get(searchServiceUrl, function (data, success) {
  142.                     // Wenn der Parameter success auch success zurück gibt
  143.                     // wurde die GET Anfrage erfolgreich übertragen und Werte zurück geliefert
  144.                     if (success == 'success') {
  145.                         console.log(data);
  146.                         if (data.indexOf('search-result-item') >= 0) {
  147.                             searchResult2.html(data);
  148.                             paginage();
  149.                         } else {
  150.                             searchContainer2.stop(true, true).fadeOut();
  151.                         }
  152.                     }
  153.                 });
  154.             }
  155.         }
  156.         function paginage() {
  157.             var searchResultCollection = document.querySelectorAll('main #searchResult li'),
  158.                 searchResultCollection2 = document.querySelectorAll('aside #searchResult li'),
  159.                 itemsPerPage = 10,
  160.                 numberOfItems = searchResultCollection.length,
  161.                 pageCountFloat = numberOfItems / itemsPerPage,
  162.                 pageCount = Math.ceil(pageCountFloat),
  163.                 paginationCell = document.querySelector('main #pagination');
  164.                 paginationCell2 = document.querySelector('aside #pagination');
  165.             function updateResult() {
  166.                 var showFrom = (this.page - 1) * itemsPerPage,
  167.                     showTo = showFrom + itemsPerPage;
  168.                 searchResultCollection.forEach(function (item, index) {
  169.                     item.classList.remove('show');
  170.                     if (index >= showFrom && index < showTo) {
  171.                         item.classList.add('show');
  172.                     }
  173.                 });
  174.                 searchResultCollection2.forEach(function (item, index) {
  175.                     item.classList.remove('show');
  176.                     if (index >= showFrom && index < showTo) {
  177.                         item.classList.add('show');
  178.                     }
  179.                 });
  180.                 paginationCell.classList.add('hide');
  181.                 if (pageCount > 1) {
  182.                     paginationCell.classList.remove('hide');
  183.                 }
  184.                 paginationCell2.classList.add('hide');
  185.                 if (pageCount > 1) {
  186.                     paginationCell.classList.remove('hide');
  187.                 }
  188.             }
  189.             selt.pagination.Init(document.querySelector('main #pagination'), {
  190.                 size: pageCount
  191.             }, updateResult);
  192.             selt.pagination.Init(document.querySelector('aside #pagination'), {
  193.                 size: pageCount
  194.             }, updateResult);
  195.         }
  196.     }());//EOS
  197. </script>