Project

General

Profile

Patch #21805 » 0001-Improve-accessibility-for-icon-only-links.patch

Daniel Ritz, 2016-01-23 18:54

View differences:

app/helpers/application_helper.rb
User.current.allowed_to?({:controller => controller, :action => action}, @project)
end
# Creates a link with only an icon, without visible text. A hidden <span> is added
# using the :title attribute for accessibility
#
# @param [String or Hash] url
# @param [Hash] html_options Options passed to link_to
def icon_link(url, options = {})
link_to(icon_link_content(options), url, options)
end
# Like link_to_function for icon only links, similar to icon_link
#
# @param [String] funct The function
# @param [Hash] html_options Options passed to link_to
def icon_link_to_function(funct, options)
link_to_function(icon_link_content(options), options)
end
# Display an icon-only link if user is authorized
#
# @param [Hash] options Hash params. This will checked by authorize_for to see if the user is authorized
# @param [optional, Hash] html_options Options passed to link_to
# @param [optional, Hash] parameters_for_method_reference Extra parameters for link_to
def icon_link_if_authorized(options = {}, html_options = nil, *parameters_for_method_reference)
if authorize_for(options[:controller] || params[:controller], options[:action])
link_to(icon_link_content(html_options), options, html_options, *parameters_for_method_reference)
end
end
# Display a link if user is authorized
#
# @param [String] name Anchor text (passed to link_to)
......
end
def reorder_links(name, url, method = :post)
link_to('',
url.merge({"#{name}[move_to]" => 'highest'}), :method => method,
:title => l(:label_sort_highest), :class => 'icon-only icon-move-top') +
link_to('',
url.merge({"#{name}[move_to]" => 'higher'}), :method => method,
:title => l(:label_sort_higher), :class => 'icon-only icon-move-up') +
link_to('',
url.merge({"#{name}[move_to]" => 'lower'}), :method => method,
:title => l(:label_sort_lower), :class => 'icon-only icon-move-down') +
link_to('',
url.merge({"#{name}[move_to]" => 'lowest'}), :method => method,
:title => l(:label_sort_lowest), :class => 'icon-only icon-move-bottom')
icon_link(url.merge({"#{name}[move_to]" => 'highest'}), :method => method,
:title => l(:label_sort_highest), :class => 'icon-only icon-move-top') +
icon_link(url.merge({"#{name}[move_to]" => 'higher'}), :method => method,
:title => l(:label_sort_higher), :class => 'icon-only icon-move-up') +
icon_link(url.merge({"#{name}[move_to]" => 'lower'}), :method => method,
:title => l(:label_sort_lower), :class => 'icon-only icon-move-down') +
icon_link(url.merge({"#{name}[move_to]" => 'lowest'}), :method => method,
:title => l(:label_sort_lowest), :class => 'icon-only icon-move-bottom')
end
def breadcrumb(*args)
......
@current_section += 1
if @current_section > 1
content_tag('div',
link_to('', options[:edit_section_links].merge(:section => @current_section),
:class => 'icon-only icon-edit'),
icon_link(options[:edit_section_links].merge(:section => @current_section),
:class => 'icon-only icon-edit',
:title => l(:button_edit_section)),
:class => 'contextual',
:title => l(:button_edit_section),
:id => "section-#{@current_section}") + heading.html_safe
else
heading
......
return self
end
def icon_link_content(options = {})
title = options[:title]
title.nil? ? '' : content_tag(:span, title, :class => 'hidden-for-sighted')
end
def link_to_content_update(text, url_params = {}, html_options = {})
link_to(text, url_params, html_options)
end
app/helpers/email_addresses_helper.rb
# Returns a link to enable or disable notifications for the address
def toggle_email_address_notify_link(address)
if address.notify?
link_to '',
icon_link(
user_email_address_path(address.user, address, :notify => '0'),
:method => :put, :remote => true,
:title => l(:label_disable_notifications),
:class => 'icon icon-email'
:class => 'icon icon-email')
else
link_to '',
icon_link(
user_email_address_path(address.user, address, :notify => '1'),
:method => :put, :remote => true,
:title => l(:label_enable_notifications),
:class => 'icon icon-email-disabled'
:class => 'icon icon-email-disabled')
end
end
end
app/helpers/issues_helper.rb
# Link to the attachment if it has not been removed
value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
if options[:only_path] != false && atta.is_text?
value += link_to('',
{ :controller => 'attachments', :action => 'show',
:id => atta, :filename => atta.filename },
:class => 'icon icon-magnifier')
value += icon_link({ :controller => 'attachments', :action => 'show',
:id => atta, :filename => atta.filename },
:class => 'icon icon-magnifier',
:title => l(:button_view))
end
else
value = content_tag("i", h(value)) if value
app/helpers/journals_helper.rb
editable = User.current.logged? && (User.current.allowed_to?(:edit_issue_notes, issue.project) || (journal.user == User.current && User.current.allowed_to?(:edit_own_issue_notes, issue.project)))
links = []
if !journal.notes.blank?
links << link_to('',
quoted_issue_path(issue, :journal_id => journal),
:remote => true,
:method => 'post',
:title => l(:button_quote),
:class => 'icon-only icon-comment'
) if options[:reply_links]
links << link_to('',
edit_journal_path(journal),
:remote => true,
:method => 'get',
:title => l(:button_edit),
:class => 'icon-only icon-edit'
) if editable
links << link_to('',
journal_path(journal, :notes => ""),
:remote => true,
:method => 'put', :data => {:confirm => l(:text_are_you_sure)},
:title => l(:button_delete),
:class => 'icon-only icon-del'
) if editable
links << icon_link(quoted_issue_path(issue, :journal_id => journal),
:remote => true,
:method => 'post',
:title => l(:button_quote),
:class => 'icon-only icon-comment'
) if options[:reply_links]
links << icon_link(edit_journal_path(journal),
:remote => true,
:method => 'get',
:title => l(:button_edit),
:class => 'icon-only icon-edit'
) if editable
links << icon_link(journal_path(journal, :notes => ""),
:remote => true,
:method => 'put', :data => {:confirm => l(:text_are_you_sure)},
:title => l(:button_delete),
:class => 'icon-only icon-del'
) if editable
end
content << content_tag('div', links.join(' ').html_safe, :class => 'contextual') unless links.empty?
content << textilizable(journal, :notes)
app/helpers/watchers_helper.rb
:object_id => object.id,
:user_id => user}
s << ' '
s << link_to('', url,
:remote => true, :method => 'delete',
:class => "delete icon-only icon-del",
:title => l(:button_delete))
s << icon_link(url, :remote => true, :method => 'delete',
:class => "delete icon-only icon-del",
:title => l(:button_delete))
end
content << content_tag('li', s, :class => "user-#{user.id}")
end
app/views/attachments/_links.html.erb
<div class="attachments">
<div class="contextual">
<%= link_to('',
container_attachments_edit_path(container),
:title => l(:label_edit_attachments),
:class => 'icon-only icon-edit'
) if options[:editable] %>
<%= icon_link(container_attachments_edit_path(container),
:title => l(:label_edit_attachments),
:class => 'icon-only icon-edit'
) if options[:editable] %>
</div>
<% for attachment in attachments %>
<p><%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%>
<% if attachment.is_text? %>
<%= link_to '',
{ :controller => 'attachments', :action => 'show',
:id => attachment, :filename => attachment.filename },
:class => 'icon icon-magnifier',
:title => l(:button_view) %>
<%= icon_link({ :controller => 'attachments', :action => 'show',
:id => attachment, :filename => attachment.filename },
:class => 'icon icon-magnifier',
:title => l(:button_view)) %>
<% end %>
<%= " - #{attachment.description}" unless attachment.description.blank? %>
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
<% if options[:deletable] %>
<%= link_to '', attachment_path(attachment),
:data => {:confirm => l(:text_are_you_sure)},
:method => :delete,
:class => 'delete icon-only icon-del',
:title => l(:button_delete) %>
<%= icon_link(attachment_path(attachment),
:data => {:confirm => l(:text_are_you_sure)},
:method => :delete,
:class => 'delete icon-only icon-del',
:title => l(:button_delete)) %>
<% end %>
<% if options[:author] %>
<span class="author"><%= attachment.author %>, <%= format_time(attachment.created_on) %></span>
app/views/issues/_attributes.html.erb
<% if @issue.safe_attribute?('category_id') && @issue.project.issue_categories.any? %>
<p><%= f.select :category_id, (@issue.project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true, :required => @issue.required_attribute?('category_id') %>
<%= link_to('',
new_project_issue_category_path(@issue.project),
:remote => true,
:method => 'get',
:title => l(:label_issue_category_new),
:tabindex => 200,
:class => 'icon-only icon-add'
) if User.current.allowed_to?(:manage_categories, @issue.project) %></p>
<%= icon_link(new_project_issue_category_path(@issue.project),
:remote => true,
:method => 'get',
:title => l(:label_issue_category_new),
:tabindex => 200,
:class => 'icon-only icon-add'
) if User.current.allowed_to?(:manage_categories, @issue.project) %></p>
<% end %>
<% if @issue.safe_attribute?('fixed_version_id') && @issue.assignable_versions.any? %>
<p><%= f.select :fixed_version_id, version_options_for_select(@issue.assignable_versions, @issue.fixed_version), :include_blank => true, :required => @issue.required_attribute?('fixed_version_id') %>
<%= link_to('',
new_project_version_path(@issue.project),
:remote => true,
:method => 'get',
:title => l(:label_version_new),
:tabindex => 200,
:class => 'icon-only icon-add'
) if User.current.allowed_to?(:manage_versions, @issue.project) %>
<%= icon_link(new_project_version_path(@issue.project),
:remote => true,
:method => 'get',
:title => l(:label_version_new),
:tabindex => 200,
:class => 'icon-only icon-add'
) if User.current.allowed_to?(:manage_versions, @issue.project) %>
</p>
<% end %>
</div>
app/views/issues/_relations.html.erb
<td class="status"><%= other_issue.status.name %></td>
<td class="start_date"><%= format_date(other_issue.start_date) %></td>
<td class="due_date"><%= format_date(other_issue.due_date) %></td>
<td class="buttons"><%= link_to('',
relation_path(relation),
:remote => true,
:method => :delete,
:data => {:confirm => l(:text_are_you_sure)},
:title => l(:label_relation_delete),
:class => 'icon-only icon-link-break'
) if User.current.allowed_to?(:manage_issue_relations, @project) %></td>
<td class="buttons"><%= icon_link(relation_path(relation),
:remote => true,
:method => :delete,
:data => {:confirm => l(:text_are_you_sure)},
:title => l(:label_relation_delete),
:class => 'icon-only icon-link-break'
) if User.current.allowed_to?(:manage_issue_relations, @project) %></td>
</tr>
<% end %>
</table>
app/views/my/blocks/_timelog.html.erb
<td class="hours"><%= html_hours("%.2f" % entry.hours) %></td>
<td class="buttons">
<% if entry.editable_by?(@user) -%>
<%= link_to '', {:controller => 'timelog', :action => 'edit', :id => entry},
:title => l(:button_edit),
:class => 'icon-only icon-edit' %>
<%= link_to '', {:controller => 'timelog', :action => 'destroy', :id => entry},
:data => {:confirm => l(:text_are_you_sure)}, :method => :delete,
:title => l(:button_delete),
:class => 'icon-only icon-del' %>
<%= icon_link({:controller => 'timelog', :action => 'edit', :id => entry},
:title => l(:button_edit),
:class => 'icon-only icon-edit') %>
<%= icon_link({:controller => 'timelog', :action => 'destroy', :id => entry},
:data => {:confirm => l(:text_are_you_sure)}, :method => :delete,
:title => l(:button_delete),
:class => 'icon-only icon-del') %>
<% end -%>
</td>
</tr>
app/views/news/show.html.erb
<% @comments.each do |comment| %>
<% next if comment.new_record? %>
<div class="contextual">
<%= link_to_if_authorized '', {:controller => 'comments', :action => 'destroy', :id => @news, :comment_id => comment},
:data => {:confirm => l(:text_are_you_sure)}, :method => :delete,
:title => l(:button_delete),
:class => 'icon-only icon-del' %>
<%= icon_link_if_authorized({:controller => 'comments', :action => 'destroy', :id => @news, :comment_id => comment},
:data => {:confirm => l(:text_are_you_sure)}, :method => :delete,
:title => l(:button_delete),
:class => 'icon-only icon-del') %>
</div>
<h4><%= avatar(comment.author, :size => "24") %><%= authoring comment.created_on, comment.author %></h4>
<div class="wiki">
app/views/reports/issue_report.html.erb
<div class="splitcontentleft">
<h3>
<%=l(:field_tracker)%>&nbsp;
<%= link_to '', project_issues_report_details_path(@project, :detail => 'tracker'), :class => 'icon-only icon-zoom-in' %>
<%= icon_link project_issues_report_details_path(@project, :detail => 'tracker'),
:class => 'icon-only icon-zoom-in',
:title => l(:label_zoom_in)
%>
</h3>
<%= render :partial => 'simple', :locals => { :data => @issues_by_tracker, :field_name => "tracker_id", :rows => @trackers } %>
<br />
<h3>
<%=l(:field_priority)%>&nbsp;
<%= link_to '', project_issues_report_details_path(@project, :detail => 'priority'), :class => 'icon-only icon-zoom-in' %>
<%= icon_link project_issues_report_details_path(@project, :detail => 'priority'),
:class => 'icon-only icon-zoom-in',
:title => l(:label_zoom_in)
%>
</h3>
<%= render :partial => 'simple', :locals => { :data => @issues_by_priority, :field_name => "priority_id", :rows => @priorities } %>
<br />
<h3>
<%=l(:field_assigned_to)%>&nbsp;
<%= link_to '', project_issues_report_details_path(@project, :detail => 'assigned_to'), :class => 'icon-only icon-zoom-in' %>
<%= icon_link project_issues_report_details_path(@project, :detail => 'assigned_to'),
:class => 'icon-only icon-zoom-in',
:title => l(:label_zoom_in)
%>
</h3>
<%= render :partial => 'simple', :locals => { :data => @issues_by_assigned_to, :field_name => "assigned_to_id", :rows => @assignees } %>
<br />
<h3>
<%=l(:field_author)%>&nbsp;
<%= link_to '', project_issues_report_details_path(@project, :detail => 'author'), :class => 'icon-only icon-zoom-in' %>
<%= icon_link project_issues_report_details_path(@project, :detail => 'author'),
:class => 'icon-only icon-zoom-in',
:title => l(:label_zoom_in)
%>
</h3>
<%= render :partial => 'simple', :locals => { :data => @issues_by_author, :field_name => "author_id", :rows => @authors } %>
<br />
......
<div class="splitcontentright">
<h3>
<%=l(:field_version)%>&nbsp;
<%= link_to '', project_issues_report_details_path(@project, :detail => 'version'), :class => 'icon-only icon-zoom-in' %>
<%= icon_link project_issues_report_details_path(@project, :detail => 'version'),
:class => 'icon-only icon-zoom-in',
:title => l(:label_zoom_in)
%>
</h3>
<%= render :partial => 'simple', :locals => { :data => @issues_by_version, :field_name => "fixed_version_id", :rows => @versions } %>
<br />
<% if @project.children.any? %>
<h3>
<%=l(:field_subproject)%>&nbsp;
<%= link_to '', project_issues_report_details_path(@project, :detail => 'subproject'), :class => 'icon-only icon-zoom-in' %>
<%= icon_link project_issues_report_details_path(@project, :detail => 'subproject'),
:class => 'icon-only icon-zoom-in',
:title => l(:label_zoom_in)
%>
</h3>
<%= render :partial => 'simple', :locals => { :data => @issues_by_subproject, :field_name => "project_id", :rows => @subprojects } %>
<br />
<% end %>
<h3>
<%=l(:field_category)%>&nbsp;
<%= link_to '', project_issues_report_details_path(@project, :detail => 'category'), :class => 'icon-only icon-zoom-in' %>
<%= icon_link project_issues_report_details_path(@project, :detail => 'category'),
:class => 'icon-only icon-zoom-in',
:title => l(:label_zoom_in)
%>
</h3>
<%= render :partial => 'simple', :locals => { :data => @issues_by_category, :field_name => "category_id", :rows => @categories } %>
<br />
app/views/repositories/_related_issues.html.erb
<ul>
<% @changeset.issues.visible.each do |issue| %>
<li id="<%= "related-issue-#{issue.id}" %>"><%= link_to_issue issue %>
<%= link_to('',
{:controller => 'repositories', :action => 'remove_related_issue',
:id => @project, :repository_id => @repository.identifier_param,
:rev => @changeset.identifier, :issue_id => issue},
:remote => true,
:method => :delete,
:data => {:confirm => l(:text_are_you_sure)},
:title => l(:label_relation_delete),
:class => 'icon-only icon-link-break'
) if manage_allowed %>
<%= icon_link({:controller => 'repositories', :action => 'remove_related_issue',
:id => @project, :repository_id => @repository.identifier_param,
:rev => @changeset.identifier, :issue_id => issue},
:remote => true,
:method => :delete,
:data => {:confirm => l(:text_are_you_sure)},
:title => l(:label_relation_delete),
:class => 'icon-only icon-link-break'
) if manage_allowed %>
</li>
<% end %>
</ul>
app/views/roles/permissions.html.erb
<th><%=l(:label_permissions)%></th>
<% @roles.each do |role| %>
<th>
<%= link_to_function('',
"toggleCheckboxesBySelector('input.role-#{role.id}')",
:title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}",
:class => 'icon-only icon-checked') %>
<%= icon_link_to_function("toggleCheckboxesBySelector('input.role-#{role.id}')",
:title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}",
:class => 'icon-only icon-checked') %>
<%= content_tag(role.builtin? ? 'em' : 'span', role.name) %>
</th>
<% end %>
app/views/settings/_repositories.html.erb
) %>
</td>
<td class="buttons">
<%= link_to('', '#',
:class => 'delete-commit-keywords icon-only icon-del') %>
<%= icon_link('#',
:class => 'delete-commit-keywords icon-only icon-del',
:title => l(:button_delete)
) %>
</td>
</tr>
<% end %>
......
<td></td>
<td></td>
<td class="buttons">
<%= link_to('', '#',
:class => 'add-commit-keywords icon-only icon-add') %>
<%= icon_link('#',
:class => 'add-commit-keywords icon-only icon-add',
:title => l(:button_add)
) %>
</td>
</tr>
</tbody>
app/views/timelog/_list.html.erb
<%= raw @query.inline_columns.map {|column| "<td class=\"#{column.css_classes}\">#{column_content(column, entry)}</td>"}.join %>
<td class="buttons">
<% if entry.editable_by?(User.current) -%>
<%= link_to '', edit_time_entry_path(entry),
:title => l(:button_edit),
:class => 'icon icon-edit' %>
<%= link_to '', time_entry_path(entry),
:data => {:confirm => l(:text_are_you_sure)},
:method => :delete,
:title => l(:button_delete),
:class => 'icon-only icon-del' %>
<%= icon_link edit_time_entry_path(entry),
:title => l(:button_edit),
:class => 'icon icon-edit' %>
<%= icon_link time_entry_path(entry),
:data => {:confirm => l(:text_are_you_sure)},
:method => :delete,
:title => l(:button_delete),
:class => 'icon-only icon-del' %>
<% end -%>
</td>
</tr>
test/unit/helpers/application_helper_test.rb
result = textilizable(raw, :edit_section_links => {:controller => 'wiki', :action => 'edit', :project_id => '1', :id => 'Test'}).gsub("\n", "")
# heading that contains inline code
assert_match Regexp.new('<div class="contextual" title="Edit this section" id="section-4">' +
'<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=4"></a></div>' +
assert_match Regexp.new('<div class="contextual" id="section-4">' +
'<a class="icon-only icon-edit" title="Edit this section" href="/projects/1/wiki/Test/edit\?section=4">' +
'<span class="hidden-for-sighted">Edit this section</span>' +
'</a></div>' +
'<a name="Subtitle-with-inline-code"></a>' +
'<h2 >Subtitle with <code>inline code</code><a href="#Subtitle-with-inline-code" class="wiki-anchor">&para;</a></h2>'),
result
# last heading
assert_match Regexp.new('<div class="contextual" title="Edit this section" id="section-5">' +
'<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=5"></a></div>' +
assert_match Regexp.new('<div class="contextual" id="section-5">' +
'<a class="icon-only icon-edit" title="Edit this section" href="/projects/1/wiki/Test/edit\?section=5">' +
'<span class="hidden-for-sighted">Edit this section</span>' +
'</a></div>' +
'<a name="Subtitle-after-pre-tag"></a>' +
'<h2 >Subtitle after pre tag<a href="#Subtitle-after-pre-tag" class="wiki-anchor">&para;</a></h2>'),
result
(1-1/3)