|
1 | | -let forceShow = false; |
2 | | - |
3 | | -function setForceShow(val) { |
4 | | - forceShow = val; |
5 | | -} |
6 | | - |
7 | | -$.fn.liveUpdate = function(list) { |
8 | | - list = $(list); |
9 | | - if (list.length) { |
10 | | - var rows = list.children('a'), cache = rows.map(function () { |
11 | | - return jQuery(this).text().toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, ""); |
12 | | - }); |
13 | | - |
14 | | - this.keyup(filter).keyup().parents('form').submit(function () { |
15 | | - return false; |
16 | | - }); |
17 | | - } |
18 | | - return this; |
19 | | - |
20 | | - function filter() { |
21 | | - const searchTerm = $.trim($(this).val().toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, "")); |
22 | | - const scores = []; |
23 | | - rows.hide(); |
24 | | - showNoEntriesFound(false); |
25 | | - if (!searchTerm) { |
26 | | - setForceShow(false); |
27 | | - return; |
28 | | - } |
29 | | - cache.each(function (i) { |
30 | | - const score = this.score(searchTerm); |
31 | | - if (score > 0) { |
32 | | - scores.push([score, i]); |
33 | | - } |
34 | | - }); |
35 | | - if (scores.length === 0) { |
36 | | - showNoEntriesFound(true); |
37 | | - } else if (!forceShow && scores.length > 7) { |
38 | | - showWarningTooMuchEntries(true, scores.length + 1); |
39 | | - } else { |
40 | | - $.each( |
41 | | - scores.sort( |
42 | | - function(a, b) { return b[0] - a[0];}), |
43 | | - function() {$(rows[this[1]]).show(); |
44 | | - }); |
45 | | - } |
46 | | - } |
47 | | -}; |
48 | | - |
49 | | -function showWarningTooMuchEntries(show, cnt = 0) { |
| 1 | +function hideAll () { |
| 2 | + $("#list").hide(); |
50 | 3 | $('#no-entries').hide(); |
51 | | - if (show) { |
52 | | - $('#warning-entries').show(); |
53 | | - } else { |
54 | | - $('#warning-entries').hide(); |
55 | | - } |
56 | | - $('#results-cnt').text(cnt); |
| 4 | + $('#warning-entries').hide(); |
57 | 5 | } |
58 | 6 |
|
59 | | -function showNoEntriesFound(show) { |
60 | | - $('#warning-entries').hide(); |
61 | | - if (show) { |
62 | | - $('#no-entries').show(); |
| 7 | +$(document).ready(function() { |
| 8 | + if ($("#last-used-idp-wrap").length > 0) { |
| 9 | + $("#last-used-idp .metaentry").focus(); |
63 | 10 | } else { |
64 | | - $('#no-entries').hide(); |
| 11 | + $("#entries").show(); |
65 | 12 | } |
66 | | -} |
67 | 13 |
|
68 | | -$(document).ready(function() { |
69 | | - $("#query").liveUpdate("#list"); |
70 | 14 | $("#showEntries").click(function() { |
71 | 15 | $("#last-used-idp-wrap").hide(); |
72 | 16 | $("#entries").show(); |
73 | 17 | $("#showEntries").hide(); |
74 | 18 | }); |
75 | | - $("#showEntriesFromDropdown").click(function() { |
76 | | - $("#dropdown-entries").toggle(); |
| 19 | + |
| 20 | + let forceShow = false |
| 21 | + $('#query').keyup(function() { |
| 22 | + const filter = $(this).val().trim().toLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu, "") |
| 23 | + if (!filter) { |
| 24 | + hideAll(); |
| 25 | + forceShow = false; |
| 26 | + } else { |
| 27 | + let matches = []; |
| 28 | + $('#list a').each(function () { |
| 29 | + if ($(this).attr('data-search').indexOf(filter) >= 0) { |
| 30 | + matches.push(this); |
| 31 | + } else { |
| 32 | + $(this).hide(); |
| 33 | + } |
| 34 | + }); |
| 35 | + if (matches.length <= 0) { |
| 36 | + $('#no-entries').show(); |
| 37 | + $('#warning-entries').hide(); |
| 38 | + } else { |
| 39 | + $("#list").show(); |
| 40 | + $('#results-cnt').text(matches.length); |
| 41 | + $('#no-entries').hide(); |
| 42 | + if (matches.length > 10 && !forceShow) { |
| 43 | + matches.forEach(m => { |
| 44 | + $(m).hide(); |
| 45 | + }); |
| 46 | + $('#warning-entries').show(); |
| 47 | + } else { |
| 48 | + $('#warning-entries').hide(); |
| 49 | + matches.forEach(m => { |
| 50 | + $(m).show(); |
| 51 | + }); |
| 52 | + } |
| 53 | + } |
| 54 | + } |
77 | 55 | }); |
78 | | - if ($("#last-used-idp-wrap").length > 0) { |
79 | | - $("#last-used-idp .metaentry").focus(); |
80 | | - } else { |
81 | | - $("#entries").show(); |
82 | | - } |
83 | | - $('#warning-entries-btn-force-show').click(function() { |
84 | | - $('#query').trigger('keyup'); |
85 | | - showWarningTooMuchEntries(false); |
86 | | - showEntries(); |
| 56 | + |
| 57 | + $('#warning-entries-btn-force-show').click(function(event) { |
| 58 | + event.preventDefault(); |
| 59 | + forceShow = true; |
| 60 | + $('#warning-entries').hide(); |
| 61 | + $('#query').trigger('keyup').focus(); |
87 | 62 | }); |
88 | 63 | }); |
89 | | - |
90 | | -function showEntries() { |
91 | | - setForceShow(true); |
92 | | - $('#query').trigger('keyup'); |
93 | | -} |
0 commit comments