On Nov 12, 12:21 pm, Eric Shulman <[EMAIL PROTECTED]> wrote:
> > > 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

ah - that's good to know - thanks Eric.

Now - please bare with me here... I'm trying to get my head around the
scoping issues I'm seeing.  Going back to my original post, your
advice to get an onclick attr to call an inline script function (to
get around eval scoping issues) was to attach my function (my event
handler) to the window object- which I did, thusly:

<script>
window.doStuff = function...
</script>

Note - inside a script block.  Now, sorry if my trimmed down version
in the previous misled you... it *is* in a script block (here) and I
thought you'd realise that was "a given".  So, rejigged, here's what
fails (here anyway):

<script>
window.clicker = function(event)
{
  alert(story.findContainingTiddler(place).id); // first tiddler
  alert(story.findContainingTiddler(event.target).id); // this tiddler
}
</script>

So, are we saying that this function, once attached to the window,
retains the original "place" no matter how many other tiddlers come
along and redo the same attachment (and fill up the story with the
exact same code) I'll only ever get the first "place" ... er...
rendered?  (I'd have thought the last one would overwrite all previous
but what do I know...)

TIA
Ruzz

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to