Skip to content

Commit 599520b

Browse files
committed
improve speed of search operation
- group/reduce the dom changes to allow browser more easy optimization
1 parent f44c455 commit 599520b

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

views/index.html.twig

+4-9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<input type="text" id="search" autocomplete="off" autofocus />
3737

3838
{% for name, package in packages %}
39+
<div>
3940
<h3 id="{{ package.highest.name }}">{{ package.highest.name }}</h3>
4041
{% if package.highest.description %}
4142
<p>{{ package.highest.description }}</p>
@@ -95,6 +96,7 @@
9596
</td>
9697
</tr>
9798
</table>
99+
</div>
98100
{% endfor %}
99101
</div>
100102
</div>
@@ -107,12 +109,7 @@
107109
{% include 'jquery-2.0.0.js' %}
108110
{% include 'moment-2.4.0.js' %}
109111
$(function(){
110-
var packages = $('h3').each(function(){
111-
var desc = $(this).next('p'),
112-
info = desc.length ? desc.next('table') : $(this).next('table');
113-
$(this).data('desc', desc);
114-
$(this).data('info', info);
115-
});
112+
var packages = $('h3');
116113
var timer;
117114
$('input#search').keyup(function(){
118115
clearTimeout(timer);
@@ -121,9 +118,7 @@
121118
timer = setTimeout(function() {
122119
packages.each(function(){
123120
show = $(this).text().toLowerCase().indexOf(needle) != -1;
124-
$(this).toggle(show);
125-
$(this).data('desc').toggle(show);
126-
$(this).data('info').toggle(show);
121+
$(this).parent().toggle(show);
127122
});
128123
}, ms);
129124
}).focus();

0 commit comments

Comments
 (0)