mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-31 05:05:18 +01:00
[Contributed by luke]
Access key hints are now added with Javascript, and are tailored appropriately to the platform (Ctrl for Macs, Alt for Windows). Thanks, Luke! git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@152 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
d695ede1be
commit
5cdc9691d8
9 changed files with 104 additions and 13 deletions
|
|
@ -13,7 +13,7 @@
|
|||
:url => {:controller => 'context', :action => 'order'}
|
||||
%>
|
||||
<br />
|
||||
<a href="javascript:void(0)" onClick="Element.toggle('context_new'); Form.focusFirstElement('context-form');" accesskey="n" title="Create a new context [Alt+n]">Create new context »</a>
|
||||
<a href="javascript:void(0)" onClick="Element.toggle('context_new'); Form.focusFirstElement('context-form');" accesskey="n" title="Create a new context">Create new context »</a>
|
||||
<div id="context_new" class="context_new" style="display:none">
|
||||
<!--[form:context]-->
|
||||
<%= form_remote_tag :url => { :action => "new_context" },
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
<div id="input_box">
|
||||
|
||||
<%= link_to_function( "Add the next action in this context »", "Element.toggle('context_new_action'); Form.focusFirstElement('context-form-new-action');", {:title => "Add the next action [Alt+n]", :accesskey => "n"}) %>
|
||||
<%= link_to_function( "Add the next action in this context »", "Element.toggle('context_new_action'); Form.focusFirstElement('context-form-new-action');", {:title => "Add the next action", :accesskey => "n"}) %>
|
||||
|
||||
<div id="context_new_action" class="context_new" style="display:none">
|
||||
<!--[form:context]-->
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
<%= javascript_include_tag "controls" %>
|
||||
<%= stylesheet_link_tag 'calendar-system.css' %>
|
||||
<%= javascript_include_tag 'calendar', 'calendar-en', 'calendar-setup' %>
|
||||
<%= javascript_include_tag "accesskey-hints" %>
|
||||
|
||||
<link rel="shortcut icon" href="<%= url_for(:controller => 'favicon.ico') %>" />
|
||||
<%= auto_discovery_link_tag(:rss,{:controller => "feed", :action => "na_feed", :name => "#{@session['user']['login']}", :token => "#{@session['user']['word']}"}, {:title => "RSS feed of next actions"}) %>
|
||||
|
|
@ -27,13 +28,13 @@
|
|||
</div>
|
||||
<div id="navcontainer">
|
||||
<ul id="navlist">
|
||||
<li><%= link_to( "Home", {:controller => "todo", :action => "list"}, {:accesskey=>"t", :title=>"Home AccessKey: Alt+T"} ) %></li>
|
||||
<li><%= link_to( "Contexts", {:controller => "context", :action => "list"}, {:accesskey=>"c", :title=>"Contexts AccessKey: Alt+C"} ) %></li>
|
||||
<li><%= link_to( "Projects", {:controller => "project", :action => "list"}, {:accesskey=>"p", :title=>"Projects AccessKey: Alt+P"} ) %></li>
|
||||
<li><%= link_to( "Completed", {:controller => "todo", :action => "completed"}, {:accesskey=>"d", :title=>"Completed AccessKey: Alt+D"} ) %></li>
|
||||
<li><%= link_to( "Home", {:controller => "todo", :action => "list"}, {:accesskey=>"t", :title=>"Home"} ) %></li>
|
||||
<li><%= link_to( "Contexts", {:controller => "context", :action => "list"}, {:accesskey=>"c", :title=>"Contexts"} ) %></li>
|
||||
<li><%= link_to( "Projects", {:controller => "project", :action => "list"}, {:accesskey=>"p", :title=>"Projects"} ) %></li>
|
||||
<li><%= link_to( "Completed", {:controller => "todo", :action => "completed"}, {:accesskey=>"d", :title=>"Completed"} ) %></li>
|
||||
<li><%= link_to( "Notes", {:controller => "note", :action => "index"}, :title => "Show all notes" ) %></li>
|
||||
<li><a href="javascript:toggleAll('notes','block')" accesskey="S" title="Show all notes AccessKey: Alt+S">Show</a></li>
|
||||
<li><a href="javascript:toggleAll('notes','none')" accesskey="H" title="Show all notes AccessKey: Alt+H">Hide</a></li>
|
||||
<li><a href="javascript:toggleAll('notes','block')" accesskey="S" title="Show all notes">Show</a></li>
|
||||
<li><a href="javascript:toggleAll('notes','none')" accesskey="H" title="Hide all notes">Hide</a></li>
|
||||
<li><%= link_to("<span class=\"feed\">RSS</span>", {:controller => "feed", :action => "na_feed", :name => "#{@session['user']['login']}", :token => "#{@session['user']['word']}"}, :title => "Subscribe to an RSS feed of your next actions" ) %></li>
|
||||
<li><%= link_to("<span class=\"feed\">TXT</span>", {:controller => "feed", :action => "na_text", :name => "#{@session['user']['login']}", :token => "#{@session['user']['word']}"}, :title => "View a plain text feed of your next actions" ) %></li>
|
||||
<li><%= link_to "Logout (#{@session['user']['login']}) »", :controller => "login", :action=>"logout"%></li>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
:url => {:controller => 'project', :action => 'order'}
|
||||
%>
|
||||
<br />
|
||||
<a href="javascript:void(0)" onClick="Element.toggle('project_new'); Form.focusFirstElement('project-form');" accesskey="n" title="Create a new project [Alt+n]">Create new project »</a>
|
||||
<a href="javascript:void(0)" onClick="Element.toggle('project_new'); Form.focusFirstElement('project-form');" accesskey="n" title="Create a new project">Create new project »</a>
|
||||
<div id="project_new" class="project_new" style="display:none">
|
||||
<!--[form:project]-->
|
||||
<%= form_remote_tag :url => { :action => "new_project" },
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@
|
|||
|
||||
<div id="input_box">
|
||||
|
||||
<%= link_to_function( "Add the next action in this project »", "Element.toggle('project_new_action'); Form.focusFirstElement('project-form-new-action');", {:title => "Add the next action [Alt+n]", :accesskey => "n"}) %>
|
||||
<%= link_to_function( "Add the next action in this project »", "Element.toggle('project_new_action'); Form.focusFirstElement('project-form-new-action');", {:title => "Add the next action", :accesskey => "n"}) %>
|
||||
|
||||
<div id="project_new_action" class="project_new" style="display:none">
|
||||
<!--[form:project]-->
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
<%= link_to_function(
|
||||
add_string,
|
||||
"Element.toggle('todo_new_action');Form.focusFirstElement('todo-form-new-action');Element.toggle('new_actions');",
|
||||
{:title => "Add the next action [Alt+n]", :accesskey => "n"}) %>
|
||||
{:title => "Add the next action", :accesskey => "n"}) %>
|
||||
|
||||
<div id="todo_new_action" class="context_new" style="display:none">
|
||||
<!--[form:todo]-->
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
* Homepage: http://www.rousette.org.uk/projects/
|
||||
* Author: bsag (http://www.rousette.org.uk/)
|
||||
* Contributors: Nicholas Lee, Lolindrath, Jim Ray, Arnaud Limbourg, Timothy Martens
|
||||
* Contributors: Nicholas Lee, Lolindrath, Jim Ray, Arnaud Limbourg, Timothy Martens, Luke
|
||||
* Version: 1.03
|
||||
* Copyright: (cc) 2004-2005 rousette.org.uk
|
||||
* License: GNU GPL
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
* Homepage: http://www.rousette.org.uk/projects/
|
||||
* Author: bsag (http://www.rousette.org.uk/)
|
||||
* Contributors: Nicholas Lee, Lolindrath, Jim Ray, Arnaud Limbourg, Timothy Martens
|
||||
* Contributors: Nicholas Lee, Lolindrath, Jim Ray, Arnaud Limbourg, Timothy Martens, Luke
|
||||
* Version: 1.031
|
||||
* Copyright: (cc) 2004-2005 rousette.org.uk
|
||||
* License: GNU GPL
|
||||
|
|
|
|||
90
tracks/public/javascripts/accesskey-hints.js
Normal file
90
tracks/public/javascripts/accesskey-hints.js
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* AccessKey Hints
|
||||
*
|
||||
* Checks all HTML elements on this page that can have an accesskey attribute
|
||||
* (<a>, <area>, <button>, <input>, <label>, <legend> and <textarea>)
|
||||
* and creates or appends the title attribute to include platform-specific
|
||||
* hint in the title, i.e. "Alt+S" (Win)
|
||||
* or "Ctrl+S)" (Mac). If a title exists, a space plus the hint wrapped in
|
||||
* parentheses is appended. The only exception is if the title already contains
|
||||
* 'accesskey', 'Alt+' or 'Ctrl+' (case-insensitive) in which case this script
|
||||
* will leave it alone.
|
||||
*
|
||||
* Use the following markup to include the library:
|
||||
* <script type="text/javascript" src="access-key-hints.js"></script>
|
||||
*/
|
||||
|
||||
addEvent(window, "load", addAccessKeyHints);
|
||||
|
||||
function addAccessKeyHints()
|
||||
{
|
||||
var elemTypes = new Array('a','area','button','input','label','legend','textarea');
|
||||
for(var i = 0; i < elemTypes.length; i++)
|
||||
{
|
||||
addHint(document.getElementsByTagName(elemTypes[i]));
|
||||
}
|
||||
}
|
||||
|
||||
function addHint(elems)
|
||||
{
|
||||
var elem;
|
||||
var i = 0;
|
||||
|
||||
processElements:
|
||||
while(elem = elems.item(i++))
|
||||
{
|
||||
var accessKey = elem.getAttributeNode("accesskey");
|
||||
if (!accessKey || !accessKey.value)
|
||||
continue processElements;
|
||||
|
||||
var title = elem.getAttributeNode("title");
|
||||
if (title && title.value)
|
||||
{
|
||||
var overrides = new Array('accesskey','alt+','ctrl+');
|
||||
for (var j=0; j < overrides.length; j++)
|
||||
{
|
||||
if (title.value.toLowerCase().indexOf(overrides[j]) != -1)
|
||||
continue processElements;
|
||||
}
|
||||
elem.setAttribute("title", title.value + ' (' + getHintText(accessKey.value) + ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
elem.setAttribute("title", getHintText(accessKey.value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getHintText(accessKey)
|
||||
{
|
||||
return getModifier() + '+' + accessKey.toUpperCase();
|
||||
}
|
||||
|
||||
function getModifier()
|
||||
{
|
||||
var ua = navigator.userAgent.toLowerCase();
|
||||
if (ua.indexOf('mac') == -1)
|
||||
return 'Alt';
|
||||
else
|
||||
return 'Ctrl';
|
||||
}
|
||||
|
||||
// This is a cross-browser function for event addition.
|
||||
function addEvent(obj, evType, fn)
|
||||
{
|
||||
if (obj.addEventListener)
|
||||
{
|
||||
obj.addEventListener(evType, fn, false);
|
||||
return true;
|
||||
}
|
||||
else if (obj.attachEvent)
|
||||
{
|
||||
var r = obj.attachEvent("on" + evType, fn);
|
||||
return r;
|
||||
}
|
||||
else
|
||||
{
|
||||
alert("Event handler could not be attached");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue