|
135 | 135 | }); |
136 | 136 | }; |
137 | 137 |
|
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 | | - |
148 | 138 | // Switch category and jump to its first benchmark |
149 | 139 | showCategory('#{category_benchmarks.keys.first.downcase}'); |
150 | 140 | $('.category_switch').on('click', function() { |
151 | 141 | var category = $(this).data('category'); |
152 | 142 | 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'); |
156 | 146 | } |
157 | 147 | }); |
158 | 148 |
|
| 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 | +
|
159 | 156 | // Load rubies first |
160 | 157 | $.get('https://raw.githubusercontent.com/rubybench/rubybench-data/master/rubies.yml').done(function (data) { |
161 | 158 | 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(); |
174 | 160 | }); |
175 | 161 | }); |
0 commit comments