Skip to content

Commit 28ad3ae

Browse files
committed
Use the shared navigation helper on the ruby/ruby page
The page marked the <li> as active instead of the .nav-link, so Bootstrap never painted the active pill. Switch to RubyBench.setupBenchmarkNavigation like the ruby-bench page, which fixes the highlight and adds arrow-key navigation.
1 parent b927361 commit 28ad3ae

1 file changed

Lines changed: 11 additions & 25 deletions

File tree

‎source/benchmarks/ruby.html.haml‎

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -135,41 +135,27 @@
135135
});
136136
};
137137
138-
$('.activate-chart').on('click', function(event) {
139-
event.preventDefault();
140-
$('.benchmark_navbar li').removeClass('active');
141-
$(this).closest('li').addClass('active');
142-
var id = $(this).data('id');
143-
var graphElement = $("#" + id);
144-
activateChart(graphElement);
145-
window.location.hash = id;
146-
});
147-
148138
// Switch category and jump to its first benchmark
149139
showCategory('#{category_benchmarks.keys.first.downcase}');
150140
$('.category_switch').on('click', function() {
151141
var category = $(this).data('category');
152142
showCategory(category);
153-
var active = $('.benchmark_navbar li.active');
154-
if (active.data('category') !== category) {
155-
$('.benchmark_navbar .nav-item[data-category="' + category + '"] .activate-chart').first().trigger('click');
143+
var active = $('.benchmark_navbar .nav-link.active');
144+
if (active.closest('.nav-item').data('category') !== category) {
145+
$('.benchmark_navbar .nav-item[data-category="' + category + '"] .nav-link').first().trigger('click');
156146
}
157147
});
158148
149+
// Setup navigation
150+
var navigation = RubyBench.setupBenchmarkNavigation({
151+
activateChart: activateChart,
152+
defaultBenchmark: $('.benchmark_graph##{category_benchmarks.values.flatten.first}'),
153+
enableKeyboardNavigation: true
154+
});
155+
159156
// Load rubies first
160157
$.get('https://raw.githubusercontent.com/rubybench/rubybench-data/master/rubies.yml').done(function (data) {
161158
rubies = jsyaml.load(data);
162-
163-
// Activate a benchmark result
164-
var url = document.location.toString();
165-
if (url.match('#')) {
166-
var id = url.split('#')[1];
167-
$('.benchmark_navbar li').removeClass('active');
168-
activateChart($('.benchmark_graph#' + id));
169-
$('.activate-chart[data-id=' + id + ']').closest('li').addClass('active');
170-
}
171-
else {
172-
activateChart($('.benchmark_graph##{category_benchmarks.values.flatten.first}'));
173-
}
159+
navigation.handleHashNavigation();
174160
});
175161
});

0 commit comments

Comments
 (0)