New plugin - ScriptButtonPlugin

22 views
Skip to first unread message

Lyall

unread,
Aug 12, 2011, 12:25:43 AM8/12/11
to tiddl...@googlegroups.com
A simple macro to allow you to execute arbitrary javascript on a button click.

http://www.remotely-helpful.com/TiddlyWiki/ScriptButtonPlugin.html

Hopefully, someone finds it useful.

...Lyall

Eric Shulman

unread,
Aug 12, 2011, 5:37:34 AM8/12/11
to TiddlyWiki
On Aug 11, 9:25 pm, Lyall <Lyall.Pea...@gmail.com> wrote:
> A simple macro to allow you to execute arbitrary javascript on a button
> click.
> http://www.remotely-helpful.com/TiddlyWiki/ScriptButtonPlugin.html

see http://www.TiddlyTools.com/#InlineJavascriptPlugin

Usage:

<script label="..." title="..." key="...">
...
any javascript you want
...
</script>

Note that this syntax is not a *macro*... it is an extension to the
TWCore "formatters" that allows you to specify a label, along with
optional tooltip ("title") and accelerator key (e.g. CTRL-SHIFT-X)
definitions and then use ANY script code you want in between the
<script> and </script> markers, including use of multiple lines with
the code block, as well as embeddeding both single- and double-quotes
within the code syntax, and even using ">>" (the 'end-of-macro'
sequence) without problems.

You can have the script generate and insert output into the current
tiddler, simply by constructing a text string with the desired output
and then returning it as the last action of the script:

<script label="show time">
var t="The time is now: "+new Date().formatString("0hh:0mm:0ss");
return t;
</script>

In addition, when processing the script code, all calls to
document.write() are automatically converted and their output buffered
in order to prevent them from corrupting the running TW document
content. The buffered output is then processed for wiki-syntax
formatting and displayed immediately following the embedded script.
The plugin also gives you access to the current 'place' (the DOM
element container where output is being placed), so that you can also
write your own custom code to generate and insert DOM elements
directly into the tiddler output.

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios
"Small Tools for Big Ideas!"(tm)
--------------------------------
TiddlyTools needs your ongoing financial support to pay the bills:
http://www.TiddlyTools.com/#Donations
Please contribute as generously and as often as you can.
--------------------------------

Lyall

unread,
Aug 12, 2011, 9:25:36 AM8/12/11
to tiddl...@googlegroups.com
Cool, but it does not appear do what was asked of me.

Specifically, I was asked to give a 'button' which executed arbitrary code on click, not execute javascript on display of the tiddler.
I feel that these are two distinctly different ways of doing stuff.

I am not saying that my plugin is better, it's a simple hack, but the requirement was that a tiddler had a button, which if clicked, would execute arbitrary code, whereas, what you are describing, appears to execute javascript on display of the tidder - a slightly different result.

...Lyall

Eric Shulman

unread,
Aug 12, 2011, 12:40:04 PM8/12/11
to TiddlyWiki


On Aug 12, 6:25 am, Lyall <Lyall.Pea...@gmail.com> wrote:
> Cool, but it does not appear do what was asked of me.
>
> Specifically, I was asked to give a 'button' which executed arbitrary code
> on click, not execute javascript on display of the tiddler.

Your understanding of what the plugin does is incorrect. The syntax I
indicated does NOT execute the script on display of the tiddler. It
creates an ONCLICK button.

Please read the plugin documentation regarding using the label="..."
syntax to create *ONCLICK HANDLERS*

InlineJavascriptPlugin does *everything* your macro can do and a whole
lot more, but without syntax limitations, plus buffered output and
protection against 'bad code' (i.e., use of document.write(...)). The
plugin also invokes the script inside a try/catch block, so that
*fatal* execution errors in arbitrary code won't crash TiddlyWiki, and
instead report their error text (using the TWCore message box
function).

-e





Lyall

unread,
Aug 12, 2011, 11:21:56 PM8/12/11
to tiddl...@googlegroups.com
Cool.
I only knocked mine up for someone else. I had assumed they had trawled through the plugins available at TiddlyTools.
My bad.
Still, it was interesting fiddling with tiddlywiki again.

Reply all
Reply to author
Forward
0 new messages