> bug: when a label is provided, the wrong "place" is passed to _out().
> The link is passed instead of the containing tiddler. This seems to
> fix it.
>
> link.code="function _out(place){"+fixup
> +"\n};_out(story.findContainingTiddler(this));"
This is NOT a bug, and is correct as-is. Inline scripts can occur in
NON-tiddler DOM elements (such as mainMenu, header, sidebar). The
"place" value that is used is the immediately containing element in
which the script is evaluated. For 'onclick' scripts, this element is
the 'link' itself (as you noted). This is BY DESIGN: it allows you to
directly reference or modify the link text to reflect any 'stateful'
conditions set by the script:
<script label="enable">
if (place.innerHTML=="enable") {
config.options.txtSomething="some value";
place.innerHTML="disable";
} else {
config.options.txtSomething="some other value";
place.innerHTML="enable";
}
return false;
</script>
Using document.write() doesn't actually make any sense in a TiddlyWiki
document and if it was left alone, it would *completely overwrite the
entire document*!!! As a convenience when pasting in scripts from
other sources, InlineJavascriptPlugin automatically converts
document.write() to "place.innerHTML=(...)" so that it won't corrupt
the document, but you should avoid using document.write() whenever you
can.
As you already know, to render wiki-syntax output for regular (non-
click) inline scripts you can simply return a text string containing
wiki-syntax.
> when a label is provided, the return value is discarded. I tried to
> work around this by using document.write(wikify*...) but I get quite
> lost when dealing with the wikify* family. I understand the reasoning
> about considering the return value the rc from a click handler, but
> would it be possible to accept as the return value an object with the
> click handler rc and something to be wikified like it is for unlabeled
> scripts?
The return code from an onclick script is NOT discarded! It is
returned directly to the browser that invokes the script.. and MUST be
a BOOLEAN (not a text string). This return value is usually equal to
FALSE, indicating that the click event was processed. This is
critically important for InternetExplorer. Without returning 'false',
IE will try to navigate away from the current document!!! If there
are tiddler changes, this triggers the 'unsaved changes' warning
message, and if there aren't tiddler changes it just makes an
unexpected 'page transition' sound (sometimes referred to as "IE click
disease")
To render output from 'onclick' scripts, you absolutely SHOULD use
wikify()... it's easy:
<script label="something to click on">
var out="... wiki-syntax content...";
wikify(out,place.parentNode);
return false;
</script>
Note the use of "place.parentNode" in the example above... as noted
above, "place" is the link text... and therefore "place.parentNode" is
the containing *element* in which that link text occurs, and
wikify(out,place.parentNode) appends content to THAT containing
element. Of course, if you want to append to the end of the
containing *tiddler*, you can always write:
wikify(out,story.findContainingTiddler(place));
By using the coding techniques described above, you should be able to
accomplish what you want without making changes to the plugin...
(which would BREAK all sorts of existing scripts!)
HTH,