Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly improve header accessibility #2301

Merged
merged 3 commits into from May 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/assets/javascripts/discourse/helpers/application_helpers.js
Expand Up @@ -407,3 +407,22 @@ Handlebars.registerHelper('link-domain', function(property, options) {
}
}
});

/**
Renders a font-awesome icon with an optional i18n string as hidden text for
screen readers.

@method icon
@for Handlebars
**/
Handlebars.registerHelper('icon', function(icon, options) {
var labelKey, html;
if (options.hash) { labelKey = options.hash.label; }
html = "<i class='fa fa-" + icon + "'";
if (labelKey) { html += " aria-hidden='true'"; }
html += "></i>";
if (labelKey) {
html += "<span class='sr-only'>" + I18n.t(labelKey) + "</span>";
}
return new Handlebars.SafeString(html);
});
48 changes: 25 additions & 23 deletions app/assets/javascripts/discourse/templates/header.js.handlebars
Expand Up @@ -11,7 +11,7 @@
{{/if}}
<h1>
{{#if topic.isPrivateMessage}}
<span class="private-message-glyph"><i class='fa fa-envelope'></i></span>
<span class="private-message-glyph">{{icon envelope}}</span>
{{/if}}
{{#if topic.category.parentCategory}}
{{boundCategoryLink topic.category.parentCategory}}
Expand All @@ -37,46 +37,50 @@
<div class='current-username'>
{{#if currentUser}}
<span class='username'><a {{bind-attr href="currentUser.path"}}>{{currentUser.displayName}}</a></span>
{{else}}
<button {{action showLogin}} class='btn btn-primary btn-small'>{{i18n log_in}}</button>
{{/if}}
</div>
{{/unless}}
<ul class='icons clearfix'>
<li class='notifications'>
{{#if currentUser}}
<a class='icon' href="#" {{action showNotifications target="view"}} data-notifications="notifications-dropdown" id='user-notifications' title='{{i18n notifications.title}}'><i class='fa fa-comment'></i></a>
{{#unless currentUser}}
<button {{action showLogin}} class='btn btn-primary btn-small login-button'>
{{icon user}} {{i18n log_in}}
</button>
{{/unless}}
<ul class='icons clearfix' role='navigation'>
{{#if currentUser}}
<li class='notifications'>
<a class='icon' href="#" {{action showNotifications target="view"}} data-notifications="notifications-dropdown" id='user-notifications' title='{{i18n notifications.title}}'>
{{icon comment label="notifications.title"}}
</a>
{{#if currentUser.unread_notifications}}
<a href='#' class='badge-notification unread-notifications'>{{currentUser.unread_notifications}}</a>
{{/if}}
{{#if currentUser.unread_private_messages}}
<a href='#' class='badge-notification unread-private-messages'>{{currentUser.unread_private_messages}}</a>
{{/if}}
{{else}}
<a class='icon' href="#" {{action showLogin}} title='{{i18n notifications.title}}'><i class='fa fa-comment'></i></a>
{{/if}}
</li>
</li>
{{/if}}
<li>
{{#if Discourse.loginRequired}}
<a id='search-button' class='icon expand' href='#' {{action showLogin}}>
<i class='fa fa-search'></i>
<a id='search-button' class='icon expand' href='#' aria-hidden="true" {{action showLogin}}>
{{icon search}}
</a>
{{else}}
<a id='search-button'
class='icon expand'
href='#'
data-dropdown="search-dropdown"
title='{{i18n search.title}}'>
<i class='fa fa-search'></i>
{{icon search label="search.title"}}
</a>
{{/if}}
</li>
<li class='categories dropdown'>
{{#if Discourse.loginRequired}}
<a class='icon'
href="#"
aria-hidden="true"
{{action showLogin}}>
<i class='fa fa-bars'></i>
{{icon bars}}
</a>
{{else}}
<a class='icon'
Expand All @@ -85,27 +89,25 @@
href="#"
title='{{i18n site_map}}'
id="site-map">
<i class='fa fa-bars'></i>
{{icon bars label="site_map"}}
</a>
{{/if}}
{{#if currentUser.site_flagged_posts_count}}
<a href='/admin/flags/active' title='{{i18n notifications.total_flagged}}' class='badge-notification flagged-posts'>{{currentUser.site_flagged_posts_count}}</a>
{{/if}}
</li>
<li class='current-user dropdown'>
{{#if currentUser}}
{{#if currentUser}}
<li class='current-user dropdown'>
<a class='icon'
data-dropdown="user-dropdown"
data-render="renderUserDropdown"
href="#"
title='{{i18n user.avatar.title}}'
id="current-user">
{{boundAvatar currentUser imageSize="medium" }}
{{boundAvatar currentUser imageSize="medium"}}
</a>
{{else}}
<div class="icon not-logged-in-avatar" {{action showLogin}}><i class='fa fa-user' title='{{i18n not_logged_in_user}}'></i></div>
{{/if}}
</li>
</li>
{{/if}}
</ul>

{{render "search"}}
Expand Down
11 changes: 11 additions & 0 deletions app/assets/stylesheets/common/foundation/helpers.scss
Expand Up @@ -29,6 +29,17 @@
visibility: hidden;
}

.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
border: 0;
}

// Affix
// --------------------------------------------------

Expand Down
9 changes: 6 additions & 3 deletions app/assets/stylesheets/desktop/header.scss
Expand Up @@ -47,9 +47,12 @@
display:block;
margin-top: 10px;
}
button {
margin-top: 9px;
}
}
button.login-button {
float: left;
margin-top: 7px;
padding: 6px 10px;
.fa { margin-right: 3px; }
}
.icons {
float: left;
Expand Down
11 changes: 7 additions & 4 deletions app/assets/stylesheets/mobile/header.scss
Expand Up @@ -51,14 +51,17 @@
font-size: 14px;
line-height: 40px;
}
button {
margin-top: 8px;
}
}
button.login-button {
float: left;
margin-top: 7px;
padding: 6px 10px;
.fa { margin-right: 3px; }
}
.icons {
float: left;
text-align: center;
margin: 0 0 0 15px;
margin: 0 0 0 5px;
list-style: none;
> li {
float: left;
Expand Down