Using javascript

26 views
Skip to first unread message

Edgar Javison

unread,
Sep 10, 2006, 4:13:07 AM9/10/06
to Tiddl...@googlegroups.com
Hello.  I may have missed this, but I'd like to know how I could use third-party javascripts in my TW.

--
Edgar Javison

We are each of us angels with only one wing, and we can only fly by embracing one another.  ~ Luciano de Crescenzo

Daniel Baird

unread,
Sep 10, 2006, 5:34:05 AM9/10/06
to Tiddl...@googlegroups.com
On 9/10/06, Edgar Javison <we.do....@gmail.com> wrote:
> Hello. I may have missed this, but I'd like to know how I could use
> third-party javascripts in my TW.

You can, but often you need to rewrite the startup parts a little.

Or, if you aren't that hot with Javascript, mention the external
library here and ask if anyone else has got it going. You might get
lucky and find someone who's already done it, or, some developer might
think it's useful and kludge it up for you.

Cheers

;D


--
Daniel Baird
http://tiddlyspot.com (free, effortless TiddlyWiki hosting)
http://danielbaird.com (TiddlyW;nks! :: Whiteboard Koala :: Blog ::
Things That Suck)

Edgar Javison

unread,
Sep 10, 2006, 5:53:49 AM9/10/06
to Tiddl...@googlegroups.com
Ok, I will.  So, here goes:

I have Eric Shulman's InlineJavascriptPlugin and been working around to embed this script into my mainmenu:

<script type="text/javascript" src=" http://embed.technorati.com/embed/y7n4ruq9mj.js"></script>

I tried loading a script from a source url and it worked!  Unfortunately, it only returned the result of the script and I couldn't open my TW anymore!  Good thing I had a backup file, so I didn't lose my file.

I also tried creating a LoadScripts tiddler and put <<tiddler LoadScripts>> in the mainmenu.  All it did was return the TW codes rather than what I was expecting.

Can someone help me?

Daniel Baird

unread,
Sep 10, 2006, 7:27:57 AM9/10/06
to Tiddl...@googlegroups.com
On 9/10/06, Edgar Javison <we.do....@gmail.com> wrote:
> Ok, I will. So, here goes:
>
> I have Eric Shulman's InlineJavascriptPlugin and been working around to
> embed this script into my mainmenu:
>
> <script type="text/javascript" src="
> http://embed.technorati.com/embed/y7n4ruq9mj.js"></script>
>
> I tried loading a script from a source url and it worked! Unfortunately, it
> only returned the result of the script and I couldn't open my TW anymore!
> Good thing I had a backup file, so I didn't lose my file.
>
> I also tried creating a LoadScripts tiddler and put <<tiddler LoadScripts>>
> in the mainmenu. All it did was return the TW codes rather than what I was
> expecting.
>
> Can someone help me?

When I looked at the Javascript at that URL, it looks like it just
adds some elements to the page with document.write.

Have you tried just pasting the html directly in to the tiddler
(inside html tags)?

Edgar Javison

unread,
Sep 10, 2006, 7:59:14 AM9/10/06
to Tiddl...@googlegroups.com
I did.  And it showed nothing.

On 9/10/06, Daniel Baird <danie...@gmail.com> wrote:

Eric Shulman

unread,
Sep 10, 2006, 10:16:52 AM9/10/06
to TiddlyWiki
> > I have Eric Shulman's InlineJavascriptPlugin and been working around to
> > embed this script into my mainmenu:
> >
> > <script type="text/javascript" src="
> > http://embed.technorati.com/embed/y7n4ruq9mj.js"></script>

InlineJavascript does not recognize (and does not need) the "type=..."
attribute. Remove that syntax and it should work:

<script src="..."></script>

Note: normally, javascript that invokes document.write() will
completely replace the content of your currently loaded TW document
(fortunately, this doesn't affect the saved file content, just the
loaded image)

However, InlineJavascriptPlugin automatically "defangs"
document.write() prior to invokation of the script, so it writes its
output into the tiddler in which it is placed, rather than trying to
overwrite the whole document.

Daniel Baird wrote:
> Have you tried just pasting the html directly in to the tiddler
> (inside html tags)?

Unfortunately, when wikify passes the source to the browser, it
processes the HTML but does NOT run any embedded <script>...</script>
code.

-e
HTH,
Eric Shulman
TiddlyTools / ELS Design Studios

Chris Lawley

unread,
Sep 10, 2006, 10:27:22 AM9/10/06
to Tiddl...@googlegroups.com

On 10 Sep 2006, Edgar Javison wrote:

> Unfortunately, it only returned the result of the script and I couldn't
> open my TW anymore! Good thing I had a backup file, so I didn't lose my
> file.


Whilst I'd be the last person to decry backups, you can easily open
your broken TW file in a _plain text_ editor and remove (or fix) the
offending tiddler.


Of course if you choose to use a word processor, we'll all laugh ;)

chris :-)

Edgar Javison

unread,
Sep 10, 2006, 10:45:12 AM9/10/06
to Tiddl...@googlegroups.com
On 9/10/06, Eric Shulman <elsd...@gmail.com> wrote:

> > I have Eric Shulman's InlineJavascriptPlugin and been working around to
> > embed this script into my mainmenu:
> >
> > <script type="text/javascript" src="
> > http://embed.technorati.com/embed/y7n4ruq9mj.js"></script>

InlineJavascript does not recognize (and does not need) the "type=..."
attribute.  Remove that syntax and it should work:

<script src="..."></script>

I took out the "type=..." attribute and still nothing was displayed in the place where the embedded item was supposed to be.

Edgar Javison

unread,
Sep 10, 2006, 10:47:34 AM9/10/06
to Tiddl...@googlegroups.com
I was a bit tense when that happened.  Good thing I could download my TW from my server.  Now, before I make any editing, I make a fresh copy of my TW.

Thanks for telling me that I could edit it through a text editor.  I'll keep that in mind next time around...

Chris Lawley

unread,
Sep 10, 2006, 11:26:39 AM9/10/06
to Tiddl...@googlegroups.com

On 10 Sep 2006, Edgar Javison wrote:


> Thanks for telling me that I could edit it through a text editor. I'll
> keep that in mind next time around...

It's strange, it should be so obvious - it's "only" HTML and
javascript after all, but it seems so much more and not something a
simple editor could handle!

I guess you spotted in the options that you can have TW make backup
copies when you use its save feature?


chris :-)

Edgar Javison

unread,
Sep 10, 2006, 11:42:32 AM9/10/06
to Tiddl...@googlegroups.com
Yes, but TW creates sooooo many backup copies!  I wish it would overwrite what it last backed-up instead of create a new back-up everytime you save.  Don't you think so?

On 9/10/06, Chris Lawley <ch...@art-en-soul.cix.co.uk> wrote:

Saq Imtiaz

unread,
Sep 10, 2006, 11:45:51 AM9/10/06
to Tiddl...@googlegroups.com
On 9/10/06, Edgar Javison <we.do....@gmail.com> wrote:
Yes, but TW creates sooooo many backup copies!  I wish it would overwrite what it last backed-up instead of create a new back-up everytime you save.  Don't you think so?

Try this plugin for a  rolling 10 backups system:
http://lewcid.googlepages.com/mm.html#BackupTweaks

You can change the options and set it to  overwrite the same backup.
Cheers,
Saq

Edgar Javison

unread,
Sep 10, 2006, 12:13:25 PM9/10/06
to Tiddl...@googlegroups.com
Thanks!!!  I've imported it to my TW already and will see how it works.

If I want only 5 rolling backups, where in the plugin do I edit this?  I have a fair idea, but I just want your confirmation.

Eric Shulman

unread,
Sep 10, 2006, 12:25:06 PM9/10/06
to TiddlyWiki
> However, InlineJavascriptPlugin automatically "defangs"
> document.write() prior to invokation of the script, so it writes its
> output into the tiddler in which it is placed, rather than trying to
> overwrite the whole document.

oops! The document.write() 'fixup' feature currently only works for
scripts that are defined *inline* (i.e., NOT using the src="..."
syntax). However, your script *can* work without modification in TW,
by using just a tiny bit of "digital gymnastics" to embed the source
code directly in a tiddler instead of using an external src="..." URL
reference:

First, use "save link as..." from your browser to create a *local file*
containing the script code from the remote URL:
http://embed.technorati.com/embed/y7n4ruq9mj.js

Then, open the .js file in a text editor (*not* the browser) and also
open your TW document (in the browser). Copy/paste the contents from
the .js file into a new tiddler (e.g., "TechnoratiScript"):
<script>
**paste script code here**
</script>
As soon as you press "done", the script will be invoked and you should
see the desired results...

I am working on a way to extend the same 'fixup' handling to script
libraries (i.e., included via src="...") but, for now at least, the
copy/paste approach should provide a viable workaround.

HTH,
-e

Edgar Javison

unread,
Sep 10, 2006, 12:37:52 PM9/10/06
to Tiddl...@googlegroups.com
YES!!!!  It worked!!!!  Thanks a million!

Now, I can invoke this in the MainMenu with <<tiddler TechnoratiScript>> and it should work, ay?

Edgar Javison

unread,
Sep 10, 2006, 1:01:38 PM9/10/06
to Tiddl...@googlegroups.com
It is now in my TW at Tiddlyspot and it's working just the way I envisioned it to.

Got one last question.  Technorati suggests an automated ping to inform it that I have updated my blog.  They say all I have to do is "enter http://rpc.technorati.com/rpc/ping into my weblog tool's configuration for Pings and Notifications".  Is this still in my TW?

Saq Imtiaz

unread,
Sep 10, 2006, 1:13:01 PM9/10/06
to Tiddl...@googlegroups.com
Find your AdvancedOptions tiddler (its a shadowed tiddler), edit and add the following line at the end:
<<option txtMaxBackups>>

Now, you can configure the number of backups from the AdvancedOptions tiddler, and the value is saved in a cookie.

Alternatively, if you just want to change it once and permanently, find the following line in the plugin:
if (!config.options.txtMaxBackups) config.options.txtMaxBackups="10";
and change it to:
if (!config.options.txtMaxBackups) config.options.txtMaxBackups="1";
Cheers,
Saq

On 9/10/06, Edgar Javison < we.do....@gmail.com> wrote:

Eric Shulman

unread,
Sep 10, 2006, 1:18:11 PM9/10/06
to TiddlyWiki
> Now, I can invoke this in the MainMenu with <<tiddler TechnoratiScript>> and
> it should work, ay?

yup... that's the idea.

"Trans-cluding" tiddlers containing inline scripts is a great way to
quickly add little snippets of re-usable javascript code to your
tiddler content. For example,
http://www.TiddlyTools.com/#RefreshTiddler
can be used to add a "refresh" link to any tiddler (clicking the link
forces that tiddler to be redisplayed):
-----
<script label="refresh">
var here=story.findContainingTiddler(place);
if (here)
story.refreshTiddler(here.getAttribute("tiddler"),null,true);
</script>
-----
You can even use some simple parameters via "$n" substitutions. The
syntax for passing parameters to a transcluded tiddler uses the
TiddlerWithParamsPlugin in TW2.0.x... and is built-in to TW2.1:
-----
<<tiddler TiddlerName with: param1 param2 param3...>>
-----
Before the content from TiddlerName is transcluded, it is scanned for
substitution markers (e.g., $1, $2, $3, etc.), which are replaced by
the "param1", "param2", "param3", values. Then, when the content is
rendered and the inline script is invoked, the substituted values are
used within the script.

For example, check out
http://www.TiddlyTools.com/#ScrollBox
It provides a simple way to display tiddler content inside a scrollable
fixed-height area:
-----
@@display:block;height:$2;overflow:auto;<<tiddler
$1>>@@@@display:block;text-align:right;^^scroll for more...^^@@
-----
The syntax to use it is:
<<tiddler ScrollBox with: TiddlerName height>>
where TiddlerName is the tiddler with the content to be displayed, and
'height' is any CSS-compliant vertical measurement (e.g., "20em",
"500px", etc), used to limit the height of the display area.

enjoy,

Eric Shulman

unread,
Sep 10, 2006, 1:26:51 PM9/10/06
to TiddlyWiki
> You can even use some simple parameters via "$n" substitutions. The
...

> For example, check out
> http://www.TiddlyTools.com/#ScrollBox

oops! While the ScrollBox tiddler does use $1 and $2 substitutions, it
doesn't actually contain any inline javascript.

Here's a better example that uses parameter passing AND inline scripts
together:
http://www.TiddlyTools.com/#ReplaceTiddlerTitle
This script lets you change the title that is *displayed* on a tiddler,
without renaming the tiddler itself. For example: A tiddler called
"ThisIsAnUglyTiddlerName" can be displayed as "Welcome to my blog!"
when it is actually rendered.

-e

Daniel Baird

unread,
Sep 10, 2006, 5:46:47 PM9/10/06
to Tiddl...@googlegroups.com
On 9/11/06, Eric Shulman <elsd...@gmail.com> wrote:
> Daniel Baird wrote:
> > Have you tried just pasting the html directly in to the tiddler
> > (inside html tags)?
>
> Unfortunately, when wikify passes the source to the browser, it
> processes the HTML but does NOT run any embedded <script>...</script>
> code.
>

What I meant was that the script seemed to just write out some divs
and other html elements.. it seems like you could look through the
javascript and work out what those elements were, and type those in
literally.

;D

Edgar Javison

unread,
Sep 10, 2006, 6:40:58 PM9/10/06
to Tiddl...@googlegroups.com
On 9/11/06, Eric Shulman <elsd...@gmail.com> wrote:

> You can even use some simple parameters via "$n" substitutions.  The
...
> For example, check out
>    http://www.TiddlyTools.com/#ScrollBox




Should the RefreshTiddler and ScrollBox tiddlers be tagged as systemConfig in order to work?  Or shall they simply just be invoked from within the tiddlers where one wants them to work?

Eric Shulman

unread,
Sep 10, 2006, 7:13:30 PM9/10/06
to TiddlyWiki
> Should the RefreshTiddler and ScrollBox tiddlers be tagged as systemConfig
> in order to work? Or shall they simply just be invoked from within the
> tiddlers where one wants them to work?

Don't tag them. Inline scripts are invoked when the tiddlers they are
contained in are rendered. Note that RefreshTiddler is an example of
an 'onclick' script. Rather than invoking the enclosed javascript code
right away, a link is embedded in the tiddler content (using the text
from the label="..." plugin script syntax) and the code is only
actually performed when the link is subsequently clicked.

-e

Reply all
Reply to author
Forward
0 new messages