Skip to content

Commit 96b158f

Browse files
authored
Refine "other versions" behavior (#1538)
When you click the "other versions" option it used to take you to the version link farm page. While it is nice to get all the versions this loses the one of the nice behaviors of the versions drop down, namely that it checks if the page you are on exists in the target version and drops you right on that page if it does. This change stops it from sending you to the link farm and instead un-hides another drop down that contains *all* of the versions. Relates to #1419 and #1536.
1 parent 59ca39b commit 96b158f

File tree

5 files changed

+56
-26
lines changed

5 files changed

+56
-26
lines changed

integtest/spec/all_books_spec.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,17 @@ def self.setup_example(repo, lang, hash)
624624
<meta name="robots" content="noindex,nofollow" />
625625
HTML
626626
end
627-
context 'the version drop down' do
627+
context 'the live versions drop down' do
628628
it 'contains only the live branch' do
629629
expect(body).to include(<<~HTML.strip)
630-
<select><option value="master" selected>master (current)</option><option value="other">other versions</option></select>
630+
<select id="live_versions"><option value="master" selected>master (current)</option><option value="other">other versions</option></select>
631+
HTML
632+
end
633+
end
634+
context 'the other versions drop down' do
635+
it 'contains all branches' do
636+
expect(body).to include(<<~HTML.strip)
637+
<span id="other_versions">other versions: <select><option value="master" selected>master (current)</option><option value="nonlive">nonlive</option></select>
631638
HTML
632639
end
633640
end
@@ -646,13 +653,17 @@ def self.setup_example(repo, lang, hash)
646653
<meta name="robots" content="noindex,nofollow" />
647654
HTML
648655
end
649-
context 'the version drop down' do
656+
context 'the live versions drop down' do
650657
it 'contains the deprecated branch' do
651658
expect(body).to include(<<~HTML.strip)
652-
<select><option value="master">master (current)</option><option value="nonlive" selected>nonlive (out of date)</option></select>
659+
<select id="live_versions"><option value="master">master (current)</option><option value="nonlive" selected>nonlive (out of date)</option></select>
653660
HTML
654661
end
655662
end
663+
it "it doesn't contain the other versions drop down" do
664+
# *because* there aren't any versions filtered from the list
665+
expect(body).not_to include 'id="other_versions"'
666+
end
656667
end
657668
page_context "the dead branch's chapter",
658669
'html/test/nonlive/chapter.html' do

lib/ES/Book.pm

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ sub _update_title_and_version_drop_downs {
329329
#===================================
330330
my ( $self, $branch_dir, $branch ) = @_;
331331

332-
my $title = '<li id="book_title"><span>' . $self->title . ': <select>';
332+
my $title = '<li id="book_title"><span>' . $self->title . ': ';
333+
$title .= '<select id="live_versions">';
333334
my $removed_any = 0;
334335
for my $b ( @{ $self->branches } ) {
335336
my $live = grep( /^$b$/, @{ $self->{live_branches} } );
@@ -346,7 +347,19 @@ sub _update_title_and_version_drop_downs {
346347
$title .= '</option>';
347348
}
348349
$title .= '<option value="other">other versions</option>' if $removed_any;
349-
$title .= '</select></span></li>';
350+
$title .= '</select>';
351+
if ( $removed_any ) {
352+
$title .= '<span id="other_versions">other versions: <select>';
353+
for my $b ( @{ $self->branches } ) {
354+
$title .= '<option value="' . $b . '"';
355+
$title .= ' selected' if $branch eq $b;
356+
$title .= '>' . $self->branch_title($b);
357+
$title .= ' (current)' if $self->current eq $b;
358+
$title .= '</option>';
359+
}
360+
$title .= '</select>';
361+
}
362+
$title .= '</span></li>';
350363
for ( 'toc.html', 'index.html' ) {
351364
my $file = $branch_dir->file($_);
352365
# Ignore missing files because the books haven't been built yet. This

resources/web/docs_js/index.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,19 @@ function init_toc(lang_strings) {
128128
var v_selected = title.find('select option:selected');
129129
title
130130
.find('select')
131-
.change(function() {
132-
var version = title.find('option:selected').val();
133-
utils.get_current_page_in_version(version).fail(function() {
134-
v_selected.attr('selected', 'selected');
135-
alert(lang_strings('This page is not available in the docs for version:')
136-
+ version);
137-
});
138-
});
131+
.change(function(e) {
132+
var version = $(e.target).find('option:selected').val();
133+
if (version === "other") {
134+
$("#other_versions").show();
135+
$("#live_versions").hide();
136+
return;
137+
}
138+
utils.get_current_page_in_version(version).fail(function() {
139+
v_selected.attr('selected', 'selected');
140+
alert(lang_strings('This page is not available in the docs for version:')
141+
+ version);
142+
});
143+
});
139144
}
140145

141146
// Main function, runs on DOM ready

resources/web/docs_js/utils.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ export function get_base_url(href) {
77

88
const VERSION_REGEX = /[^\/]+\/+([^\/]+\.html)/;
99
export function get_current_page_in_version(version) {
10-
if (version === "other") {
11-
location.href = location.href.replace(VERSION_REGEX, "index.html");
12-
return;
13-
}
1410
var url = location.href.replace(VERSION_REGEX, version + "/$1");
1511
return $.get(url).done(function() {
1612
location.href = url

resources/web/style/toc.pcss

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,19 @@
105105
}
106106
}
107107

108-
/* Right hand TOC */
109108
#book_title {
110-
color: #2b4590;
109+
color: #2b4590;
111110

112-
select {
113-
background-color: #fcfcfc;
114-
border: none;
115-
margin-left: 1px;
116-
color: #2b4590;
117-
}
111+
select {
112+
background-color: #fcfcfc;
113+
border: none;
114+
margin-left: 1px;
115+
color: #2b4590;
116+
width: 150px;
117+
}
118+
#other_versions {
119+
/* We'll show it if you click "other versions". */
120+
display: none;
121+
}
118122
}
123+

0 commit comments

Comments
 (0)