Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 1 | % if (param 'q') { |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 2 | % content 'main' => begin |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 3 | % unless (param 'snippet') { |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 4 | <div style="clear: both"> |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 5 | % my $url = url_with->query(['p' => '{page}']); |
Nils Diewald | 2fef6c6 | 2014-11-11 17:48:59 +0000 | [diff] [blame] | 6 | % my $pages; |
| 7 | % $pages = stash('search.totalResults') == -1 ? -1 : (stash('search.totalResults') / (stash('search.itemsPerPage') || 1)); |
Nils Diewald | 44a7278 | 2014-06-20 16:03:21 +0000 | [diff] [blame] | 8 | <div id="pagination"><%= pagination(stash('search.startPage'), $pages, $url) =%></div> |
| 9 | <p class="found">Found |
Nils Diewald | 432356a | 2014-11-11 12:52:13 +0000 | [diff] [blame] | 10 | % my $found = stash('search.totalResults'); |
| 11 | % if ($found == -1) { |
| 12 | % $found = 'unknown amount of'; |
| 13 | % } elsif (stash('search.timeExceeded')) { |
| 14 | % $found = 'more than ' . $found; |
| 15 | % }; |
| 16 | <span id="total-results"><%= $found %> matches</span> |
Nils Diewald | 2ef057e | 2014-11-04 16:04:17 +0000 | [diff] [blame] | 17 | <% if (stash 'search.benchmark') { %> in <%= stash 'search.benchmark' %><% } %> |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 18 | </p> |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 19 | </div> |
Nils Diewald | 02df991 | 2014-06-03 16:08:07 +0000 | [diff] [blame] | 20 | %= include 'query' |
Nils Diewald | 1d2903f | 2014-11-03 22:31:20 +0000 | [diff] [blame] | 21 | %= include 'api-communication' |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 22 | % }; |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 23 | |
Nils Diewald | 432356a | 2014-11-11 12:52:13 +0000 | [diff] [blame] | 24 | % if (stash('search.totalResults') != 0 && scalar @{stash('search.hits')}) { |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 25 | <div id="search"> |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame] | 26 | <ol class="align-left"> |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 27 | %= search_hits begin |
| 28 | %= include 'match', match => $_ |
| 29 | % end |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 30 | </ol> |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 31 | </div> |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 32 | % }; |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 33 | % end |
Nils Diewald | 44a7278 | 2014-06-20 16:03:21 +0000 | [diff] [blame] | 34 | |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 35 | % content 'javascript' => begin |
| 36 | %= javascript begin |
| 37 | |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame] | 38 | var openLi = function (e) { |
| 39 | this.classList.add("active"); |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 40 | e.stopPropagation(); |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame] | 41 | }; |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 42 | |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame] | 43 | var closeLi = function (e) { |
| 44 | this.parentNode.parentNode.classList.remove("active"); |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 45 | e.stopPropagation(); |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | var inactiveLi = document.querySelectorAll("#search > ol > li:not(.active)"); |
| 49 | for (var i = 0; i < inactiveLi.length; i++) { |
| 50 | inactiveLi[i].addEventListener("click", openLi, false); |
| 51 | inactiveLi[i].getElementsByClassName("close")[0].addEventListener("click", closeLi, false); |
| 52 | }; |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 53 | |
| 54 | % end |
| 55 | % end |
Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 56 | % }; |