Accessibility: Use Uploaded File Descriptions
The file upload dialog asks for a description of the image or file to be uploaded. Use this as the default alt-text for the image and as a title attribute for a file link.
This commit is contained in:
parent
179a0a9cb2
commit
0eb723e125
|
@ -47,6 +47,11 @@ class Web < ActiveRecord::Base
|
||||||
WikiFile.find_by_file_name(file_name) != nil
|
WikiFile.find_by_file_name(file_name) != nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def description(file_name)
|
||||||
|
file = WikiFile.find_by_file_name(file_name)
|
||||||
|
file.description if file
|
||||||
|
end
|
||||||
|
|
||||||
def markup
|
def markup
|
||||||
read_attribute('markup').to_sym
|
read_attribute('markup').to_sym
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
{ 'multipart' => true , 'accept-charset' => 'utf-8' }) do %>
|
{ 'multipart' => true , 'accept-charset' => 'utf-8' }) do %>
|
||||||
<div class="inputFieldWithPrompt">
|
<div class="inputFieldWithPrompt">
|
||||||
<%= hidden_field 'file', 'file_name' %>
|
<%= hidden_field 'file', 'file_name' %>
|
||||||
<label for="file_content"><b>Content of <%= h @file_name %> to upload</b> (required):</label>
|
<label for="file_content"><b>Content of <%= h @file_name %> to upload</b>:</label>
|
||||||
<br />
|
<br />
|
||||||
<input type="file" id="file_content" name="file[content]" size="40" />
|
<input type="file" id="file_content" name="file[content]" size="40" />
|
||||||
<br />
|
<br />
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
<%= link_to :back %> and edit the wiki page that refers to the file.
|
<%= link_to :back %> and edit the wiki page that refers to the file.
|
||||||
</div>
|
</div>
|
||||||
<div class="inputFieldWithPrompt">
|
<div class="inputFieldWithPrompt">
|
||||||
<label for="file_description"><b>Description</b> (optional):</label>
|
<label for="file_description"><b>Description</b>:</label>
|
||||||
<br/>
|
<br/>
|
||||||
<%= text_field "file", "description", "size" => 40 %>
|
<%= text_field "file", "description", "size" => 40 %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -17,15 +17,16 @@ class AbstractUrlGenerator
|
||||||
known_page = web.has_page?(name)
|
known_page = web.has_page?(name)
|
||||||
else
|
else
|
||||||
known_page = web.has_file?(name)
|
known_page = web.has_file?(name)
|
||||||
|
description = web.description(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
case link_type
|
case link_type
|
||||||
when :show
|
when :show
|
||||||
page_link(mode, name, text, web.address, known_page)
|
page_link(mode, name, text, web.address, known_page)
|
||||||
when :file
|
when :file
|
||||||
file_link(mode, name, text, web.address, known_page)
|
file_link(mode, name, text, web.address, known_page, description)
|
||||||
when :pic
|
when :pic
|
||||||
pic_link(mode, name, text, web.address, known_page)
|
pic_link(mode, name, text, web.address, known_page, description)
|
||||||
else
|
else
|
||||||
raise "Unknown link type: #{link_type}"
|
raise "Unknown link type: #{link_type}"
|
||||||
end
|
end
|
||||||
|
@ -37,11 +38,12 @@ class UrlGenerator < AbstractUrlGenerator
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def file_link(mode, name, text, web_address, known_file)
|
def file_link(mode, name, text, web_address, known_file, description)
|
||||||
|
title = CGI::escapeHTML(CGI::unescapeHTML( description || text))
|
||||||
case mode
|
case mode
|
||||||
when :export
|
when :export
|
||||||
if known_file
|
if known_file
|
||||||
%{<a class="existingWikiWord" href="#{CGI.escape(name)}.html">#{text}</a>}
|
%{<a class="existingWikiWord" title="#{title}" href="#{CGI.escape(name)}.html">#{text}</a>}
|
||||||
else
|
else
|
||||||
%{<span class="newWikiWord">#{text}</span>}
|
%{<span class="newWikiWord">#{text}</span>}
|
||||||
end
|
end
|
||||||
|
@ -49,7 +51,7 @@ class UrlGenerator < AbstractUrlGenerator
|
||||||
if known_file
|
if known_file
|
||||||
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
|
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
|
||||||
:id => name
|
:id => name
|
||||||
%{<a class="existingWikiWord" href="#{href}">#{text}</a>}
|
%{<a class="existingWikiWord" title="#{title}" href="#{href}">#{text}</a>}
|
||||||
else
|
else
|
||||||
%{<span class="newWikiWord">#{text}</span>}
|
%{<span class="newWikiWord">#{text}</span>}
|
||||||
end
|
end
|
||||||
|
@ -57,7 +59,7 @@ class UrlGenerator < AbstractUrlGenerator
|
||||||
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
|
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
|
||||||
:id => name
|
:id => name
|
||||||
if known_file
|
if known_file
|
||||||
%{<a class="existingWikiWord" href="#{href}">#{text}</a>}
|
%{<a class="existingWikiWord" title="#{title}" href="#{href}">#{text}</a>}
|
||||||
else
|
else
|
||||||
%{<span class="newWikiWord">#{text}<a href="#{href}">?</a></span>}
|
%{<span class="newWikiWord">#{text}<a href="#{href}">?</a></span>}
|
||||||
end
|
end
|
||||||
|
@ -93,17 +95,18 @@ class UrlGenerator < AbstractUrlGenerator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def pic_link(mode, name, text, web_address, known_pic)
|
def pic_link(mode, name, text, web_address, known_pic, description)
|
||||||
|
alt_text = CGI::escapeHTML(CGI::unescapeHTML( description || text))
|
||||||
case mode
|
case mode
|
||||||
when :export
|
when :export
|
||||||
if known_pic
|
if known_pic
|
||||||
%{<img alt="#{text}" src="#{CGI.escape(name)}" />}
|
%{<img alt="#{alt_text}" src="#{CGI.escape(name)}" />}
|
||||||
else
|
else
|
||||||
%{<img alt="#{text}" src="no image" />}
|
%{<img alt="#{text}" src="no image" />}
|
||||||
end
|
end
|
||||||
when :publish
|
when :publish
|
||||||
if known_pic
|
if known_pic
|
||||||
%{<img alt="#{text}" src="#{CGI.escape(name)}" />}
|
%{<img alt="#{alt_text}" src="#{CGI.escape(name)}" />}
|
||||||
else
|
else
|
||||||
%{<span class="newWikiWord">#{text}</span>}
|
%{<span class="newWikiWord">#{text}</span>}
|
||||||
end
|
end
|
||||||
|
@ -111,7 +114,7 @@ class UrlGenerator < AbstractUrlGenerator
|
||||||
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
|
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
|
||||||
:id => name
|
:id => name
|
||||||
if known_pic
|
if known_pic
|
||||||
%{<img alt="#{text}" src="#{href}" />}
|
%{<img alt="#{alt_text}" src="#{href}" />}
|
||||||
else
|
else
|
||||||
%{<span class="newWikiWord">#{text}<a href="#{href}">?</a></span>}
|
%{<span class="newWikiWord">#{text}<a href="#{href}">?</a></span>}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue