On Oct 18, 9:20 am, FND <[email protected]> wrote:
> As you've pointed out, one problem is defining and determining what the
> active tiddler is.

Well, one solution is to set accessKey properties in a tiddler's
toolbar buttons when that tiddler gets the mouse focus, and unset them
when the tiddler loses the mouse focus.  After enough digging I found
that the onTiddlerMouseOver and onTiddlerMouseOut functions are called
at the appropriate times and can be changed to call new code.

> Any contributions in this area would be most welcome.

A patch, using the solution I described, is copied below.  I'm sure
some of these methods don't really belong to Story, and my
attributeNamed method may already exist in jQuery by another name.
Comments welcome.

--- Lingo.js.orig.20091019b     2009-10-19 16:16:04.000000000 -0700
+++ Lingo.js    2009-10-19 16:22:11.000000000 -0700
@@ -368,11 +368,13 @@

 merge(config.commands.closeTiddler,{
        text: "close",
-       tooltip: "Close this tiddler"});
+       tooltip: "Close this tiddler"},
+       accessKey: "W");

 merge(config.commands.closeOthers,{
        text: "close others",
-       tooltip: "Close all other tiddlers"});
+       tooltip: "Close all other tiddlers"},
+       accessKey: "R");

 merge(config.commands.closeAll,{
        text: "close all",
@@ -382,7 +384,8 @@
        text: "edit",
        tooltip: "Edit this tiddler",
        readOnlyText: "view",
-       readOnlyTooltip: "View the source of this tiddler"});
+       readOnlyTooltip: "View the source of this tiddler"},
+       accessKey: "E");

 merge(config.commands.saveTiddler,{
        text: "done",
--- Story.js.orig.20091019b     2009-10-18 14:37:46.000000000 -0700
+++ Story.js    2009-10-19 16:52:24.000000000 -0700
@@ -287,15 +287,72 @@
        }
 };

+//# In HTML terms, each tiddler has a child: <div class="toolbar">
+//# Return tiddler's first child "div" element with a class of
"toolbar"
+Story.prototype.findToolbar = function(e)
+{
+       var divs = e.getElementsByTagName("div");
+       for (var index = 0; index < divs.length; index++) {
+               var div = divs[index];
+               if (div.className == "toolbar") {
+                       return div;
+               }
+       }
+       return null;
+}
+
+//# Unfortunately, instead of element.attribtes["href"] the DOM has
element.attributes[N].name=="commandname" and element.attributes
[N].value for some numerical N
+//# This makes the syntax a little more like element.attributes
["href"]
+Story.prototype.attributeNamed = function(e, name)
+{
+       var attribs = e.attributes;
+       for (var index = 0; index < attribs.length; index++) {
+               var attrib = attribs[index];
+               if (attrib.name == name) {
+                       return attrib.value;
+               }
+       }
+       return null;
+}
+
+//Activate toolbar-button access keys when a tiddler gets mouse focus
+//# In HTML terms, each toolbar has a series of buttons: <a
href="javascript:;" title="Close this tiddler" class="button
command_closeTiddler" commandname="closeTiddler"
tiddler="GettingStarted">close</a>
+//# The buttons contain a commandname attribute, corresponding to a
member of config.commands
+//# Look up the accessKey field from that member, and copy it to the
buttons' accesskey property
+Story.prototype.addToolbarAccessKeys = function(e)
+{
+       var buttons = e.childNodes;
+       for (var index = 0; index < buttons.length; index++) {
+               var button = buttons[index];
+               var commandname = story.attributeNamed(button, "commandname");
+               button.accessKey = config.commands[commandname].accessKey;
+               }
+       }
+}
+
+// Deactivate toolbar-button access keys when a tiddler loses mouse
focus
+//# Easiest to remove all access keys
+Story.prototype.removeToolbarAccessKeys = function(e)
+{
+       var buttons = e.childNodes;
+       for (var index = 0; index < buttons.length; index++) {
+               var button = buttons[index];
+               button.accessKey = "";
+               }
+       }
+}
+
 //# Default tiddler onmouseover/out event handlers
 Story.prototype.onTiddlerMouseOver = function(e)
 {
        addClass(this, "selected");
+       story.addToolbarAccessKeys(story.findToolbar(this));
 };

 Story.prototype.onTiddlerMouseOut = function(e)
 {
        removeClass(this,"selected");
+       story.removeToolbarAccessKeys(story.findToolbar(this));
 };

 //# Default tiddler ondblclick event handler


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/tiddlywikidev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to