> > 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.
> 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.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...)
When the <script>...</script> is processed, InlineJavascriptPlugin
(ILJS) automatically defines a local 'place' variable. This value is
*not* a global variable, and is only valid during the actual
processing of the <script>...</script>. One the script has been
processed, the 'place' variable defined by ILJS goes away. However,
the window.clicker() function you declared in the script is will still
be defined (since it was added to the global 'window' object).
I think your confusion arises because there is 'window.place' variable
that *is* globally-defined, and usually refers to the last tiddler
that was rendered (which is not necessarily the same tiddler at that
which contains your HTML/script content). Note that, in the absence
of a locally-defined 'place' variable (i.e., the one created by ILJS),
any reference to 'place' within your function will implicitly access
'window.place'.
Thus, when your window.clicker() function is defined in the context of
the inline script processing, 'place' refers to the variable created
by ILJS, but when your globally-defined function is later invoked,
'place' refers to 'window.place'... a complete different variable,
that does point to the 'containing tiddler' as described by the plugin
documentation.
In conclusion, the correct (and only) way to get the current
containing tiddler from a globally-defined onclick event handler is as
we've already discussed:
var place=story.findContainingTiddler(resolveTarget(event));
-e
>
> 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
-~----------~----~----~----~------~----~------~--~---