Skip to content

Commit 043df08

Browse files
committed
Issue #692 - Fix highlighting of menu items
Replace hardcoded HTML <li> tag with their ternary check to add a CSS class by a closure that generates the link in an heredoc variable. This way we are sure we don't have typos and if we need to change the HTML output, it's not duplicated.
1 parent a73a977 commit 043df08

File tree

1 file changed

+45
-18
lines changed

1 file changed

+45
-18
lines changed

app/views/templates/base.php

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,68 @@
2121
$css_include = $base_css;
2222
}
2323

24-
$links = '
24+
/*
25+
This is a closure to build a list item containing the
26+
link to the page. The page we are on gets a CSS class
27+
of selected_view added.
28+
*/
29+
$li_link = function ($page, $title, $text) use ($url, $urls) {
30+
$link = array_search($page, $urls);
31+
32+
if ($link != '/') {
33+
$link = "/{$link}/";
34+
}
35+
36+
return '<li><a ' . ($url['path'] == $link ? 'class="selected_view" ' : '')
37+
. 'href="' . $link . '" '
38+
. 'title="' . $title . '">'
39+
. $text . '</a></li>';
40+
};
41+
42+
/*
43+
The t2t page is a legacy page without an entry in the $urls array.
44+
*/
45+
$li_t2t = '<li><a ' . (isset($_GET['t2t']) ? 'class="selected_view" ' : '')
46+
. 'href="/?sourcelocale=' . $source_locale . '&locale=' . $locale
47+
. '&repo=' . $check['repo'] . '&t2t=t2t&recherche='
48+
. Utils::secureText($initial_search)
49+
. '" title="Search in the Glossary">Glossary</a></li>';
50+
51+
$links = <<<EOT
2552
<div class="linkscolumn">
2653
<h3>Main Views</h3>
2754
<ul>
28-
<li><a href="/" title="Main search">Home</a></li>
29-
<li><a ' . (isset($_GET['t2t']) ? 'class="selected_view" ' : '') . 'href="/?sourcelocale=' . $source_locale . '&locale=' . $locale . '&repo=' . $check['repo'] . '&t2t=t2t&recherche=' . Utils::secureText($initial_search) . '" title="Search in the Glossary">Glossary</a></li>
30-
<li><a ' . ($url['path'] == '3locales' ? 'class="selected_view" ' : '') . 'href="/3locales/" title="Search with 3 locales">3 locales</a></li>
31-
<li><a ' . ($url['path'] == 'downloads' ? 'class="selected_view" ' : '') . 'href="/downloads/" title="Download TMX files">TMX Download</a></li>
55+
{$li_link('root', 'Main search', 'Home')}
56+
{$li_link('3locales', 'Search with 3 locales', '3 locales')}
57+
{$li_t2t}
58+
{$li_link('downloads', 'Download TMX files', 'TMX Download')}
3259
</ul>
3360
</div>
3461
<div class="linkscolumn" id="qa_column">
3562
<h3>QA Views</h3>
3663
<ul>
37-
<li><a ' . ($url['path'] == 'accesskeys' ? 'class="selected_view" ' : '') . 'href="/accesskeys/" title="Check your access keys">Access Keys</a></li>
38-
<li><a ' . ($url['path'] == 'variables' ? 'class="selected_view" ' : '') . 'href="/variables/" title="Check what variable differences there are from English">Check Variables</a></li>
39-
<li><a ' . ($url['path'] == 'consistency' ? 'class="selected_view" ' : '') . 'href="/consistency/" title="Translation Consistency">Translation Consistency</a></li>
40-
<li><a ' . ($url['path'] == 'unchanged_strings' ? 'class="selected_view" ' : '') . 'href="/unchanged/" title="Display all strings identical to English">Unchanged Strings</a></li>
41-
<li><a ' . ($url['path'] == 'unlocalized_words' ? 'class="selected_view" ' : '') . 'href="/unlocalized/" title="Display common words remaining in English">Unlocalized Words</a></li>
64+
{$li_link('keys', 'Check your access keys', 'Access Keys')}
65+
{$li_link('checkvariables', 'Check what variable differences there are from English', 'Check Variables')}
66+
{$li_link('consistency', 'Translation Consistency', 'Translation Consistency')}
67+
{$li_link('unchangedstrings', 'Display all strings identical to English', 'Unchanged Strings')}
68+
{$li_link('unlocalized', 'Display common words remaining in English', 'Unlocalized Words')}
4269
</ul>
4370
<ul>
44-
<li><a ' . ($url['path'] == 'channelcomparison' ? 'class="selected_view" ' : '') . 'href="/channelcomparison/" title="Compare strings from channel to channel">Channel Comparison</a></li>
45-
<li><a ' . ($url['path'] == 'gaia' ? 'class="selected_view" ' : '') . 'href="/gaia/" title="Compare strings across Gaia channels">Gaia Comparison</a></li>
46-
<li><a ' . ($url['path'] == 'showrepos' ? 'class="selected_view" ' : '') . 'href="/showrepos/" title="Check the health status of locales">Health Status Overview</a></li>
47-
<li><a ' . ($url['path'] == 'productization' ? 'class="selected_view" ' : '') . 'href="/productization/" title="Show productization aspects">Productization</a></li>
71+
{$li_link('channelcomp', 'Compare strings betwen channels', 'Channel Comparison')}
72+
{$li_link('gaia', 'Compare strings across Gaia channels', 'Gaia Comparison')}
73+
{$li_link('showrepos', 'Check the health status of locales', 'Health Status Overview')}
74+
{$li_link('productization', 'Show productization aspects', 'Productization')}
4875
</ul>
4976
</div>
5077
<div class="linkscolumn">
5178
<h3>About Transvision</h3>
5279
<ul>
53-
<li><a ' . ($url['path'] == 'credits' ? 'class="selected_view" ' : '') . 'href="/credits/" title="Transvision Credits page">Credits</a></li>
54-
<li><a ' . ($url['path'] == 'news' ? 'class="selected_view" ' : '') . 'href="/news/" title="Changelog">Release Notes</a></li>
55-
<li><a ' . ($url['path'] == 'stats' ? 'class="selected_view" ' : '') . 'href="/stats/" title="Light usage statistics">Statistics</a></li>
80+
{$li_link('credits', 'Transvision Credits page', 'Credits')}
81+
{$li_link('changelog', 'Release Notes', 'Release Notes')}
82+
{$li_link('stats', 'Light usage statistics', 'Statistics')}
5683
</ul>
5784
</div>
58-
';
85+
EOT;
5986

6087
$title_productname = BETA_VERSION ? 'Transvision Beta' : 'Transvision';
6188

0 commit comments

Comments
 (0)