> > use an explicitly-scoped function declaration to add your
> > functions to the global "window" object, which allows them to persist
> > even after the eval() processing has completed.
> Thanks Eric - that's enabled me to get a lot further. However, now
> I'm having a little problem with...
>
> >>> access 'tiddler-relative' DOM information using
> >>> story.findContainingTiddler(place) (from tiddlytools)
>
> Correct me if I'm wrong but the above seems to return the *first* (ie
> topmost) tiddler in the story. If I do:
> story.findContainingTiddler(event.target)
> it does indeed find the "tiddler-relative" tiddler ;)
> window.clicker = function(event)
> {
> alert(story.findContainingTiddler(place).id); // first tiddler in
> story
> alert(story.findContainingTiddler(event.target).id); // this tiddler
>
> }
The value of 'place' is correct *during* the processing of the
<script>...</script> block. However, once that script has been
completed, the value of place is no longer in scope. The problem
arises because your script defines a 'click handler' global window.*
function that persists *after* the script is finished. Thus, by the
time that your click handler is invoked, 'place' is no longer in
context and can refer to a different tiddler than the one which
contains the <script>...</script> code.
For your particular purposes, using "event.target" instead of 'place'
is the correct approach. Note: different browsers have different ways
of representing the internals of the event object. For cross-browser
compatibility, you should not reference event.target directly.
Instead, to get the target element for a given event, use the TW core
function, resolveTarget(event), which is defined as follows:
// Resolve the target object of an event
function resolveTarget(e)
{
var obj;
if(e.target)
obj = e.target;
else if(e.srcElement)
obj = e.srcElement;
if(obj.nodeType == 3) // defeat Safari bug
obj = obj.parentNode;
return obj;
}
enjoy,
-e
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" 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/TiddlyWiki?hl=en
-~----------~----~----~----~------~----~------~--~---