mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 07:40:12 +01:00
Added Luke's patch to re-factor the accesskey-hints.js file using JSON notation.
Fixes #223. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@205 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
0ee4b8f6d1
commit
c18db17054
2 changed files with 51 additions and 72 deletions
|
|
@ -13,20 +13,17 @@
|
||||||
* Use the following markup to include the library:
|
* Use the following markup to include the library:
|
||||||
* <script type="text/javascript" src="access-key-hints.js"></script>
|
* <script type="text/javascript" src="access-key-hints.js"></script>
|
||||||
*/
|
*/
|
||||||
|
var accessKeyHintsAdder = {
|
||||||
|
|
||||||
addEvent(window, "load", addAccessKeyHints);
|
run : function() {
|
||||||
|
|
||||||
function addAccessKeyHints()
|
|
||||||
{
|
|
||||||
var elemTypes = new Array('a','area','button','input','label','legend','textarea');
|
var elemTypes = new Array('a','area','button','input','label','legend','textarea');
|
||||||
for(var i = 0; i < elemTypes.length; i++)
|
for(var i = 0; i < elemTypes.length; i++)
|
||||||
{
|
{
|
||||||
addHint(document.getElementsByTagName(elemTypes[i]));
|
this.addHint(document.getElementsByTagName(elemTypes[i]));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
function addHint(elems)
|
addHint : function(elems) {
|
||||||
{
|
|
||||||
var elem;
|
var elem;
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|
||||||
|
|
@ -46,22 +43,20 @@ function addHint(elems)
|
||||||
if (title.value.toLowerCase().indexOf(overrides[j]) != -1)
|
if (title.value.toLowerCase().indexOf(overrides[j]) != -1)
|
||||||
continue processElements;
|
continue processElements;
|
||||||
}
|
}
|
||||||
elem.setAttribute("title", title.value + ' (' + getHintText(accessKey.value) + ')');
|
elem.setAttribute("title", title.value + ' (' + this.getHintText(accessKey.value) + ')');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
elem.setAttribute("title", getHintText(accessKey.value));
|
elem.setAttribute("title", this.getHintText(accessKey.value));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
function getHintText(accessKey)
|
getHintText : function(accessKey) {
|
||||||
{
|
return this.getModifier() + '+' + accessKey.toUpperCase();
|
||||||
return getModifier() + '+' + accessKey.toUpperCase();
|
},
|
||||||
}
|
|
||||||
|
|
||||||
function getModifier()
|
getModifier : function() {
|
||||||
{
|
|
||||||
var ua = navigator.userAgent.toLowerCase();
|
var ua = navigator.userAgent.toLowerCase();
|
||||||
if (ua.indexOf('mac') == -1)
|
if (ua.indexOf('mac') == -1)
|
||||||
return 'Alt';
|
return 'Alt';
|
||||||
|
|
@ -69,22 +64,6 @@ function getModifier()
|
||||||
return 'Ctrl';
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Event.observe(window, "load", accessKeyHintsAdder.run.bindAsEventListener(accessKeyHintsAdder));
|
||||||
Loading…
Add table
Add a link
Reference in a new issue