Access to tiddler contents via js

Skip to first unread message

moby007

unread,
Nov 19, 2007, 8:43:20 AM11/19/07
to TiddlyWikiDev
Hi everyone,

at my university we provide help through a callmanager but sadly our
call manager doesnt support default answers/faqs. I want to use
tiddywiki to save/manage default answers/faqs and copy/paste them to
our callmanager. I wrote an plugin which adds a copy button to the
edit line and which copies the tiddlers title to my clipboard and from
there i can easily paste it.

My question:
But i dont need the tiddlers title i need its content, but have no
clue at all how to access it.

My plugin so far :)

<div title="CopyTiddlerToClipboardPlugin" modifier="sw"
modified="200711190002" created="200711050001" tags="copy tiddlers
content" server.page.revision="200711190002" server.type="file">
<pre>//{{{
version.extensions.copyToClip = {major: 0, minor: 1, revision: 1,
date: new Date(2007,11,19)};
//based on: http://www.jeffothy.com/weblog/clipboard-copy

config.commands.copyToClip = {
text: 'copy',
tooltip: 'Copy this tiddles\'s content to your clipboard',
hideReadOnly: false,
handler: function(event,src,title) {
config.commands.copyToClip.exeCopy(title);
return false;
},
exeCopy: function(inElement) {
if (inElement.createTextRange) {
var range = inElement.createTextRange();
if (range &amp;&amp; BodyLoaded==1)
range.execCommand('Copy');
} else {
var flashcopier = 'flashcopier';
if(!document.getElementById(flashcopier)) {
var divholder = document.createElement('div');
divholder.id = flashcopier;
document.body.appendChild(divholder);
}
document.getElementById(flashcopier).innerHTML = '';
var divinfo = '&lt;embed src=&quot;_clipboard.swf&quot;
flashvars=&quot;clipboard='+encodeURIComponent("Hallo, \n\n" +inElement
+ "\n\nViele Gr&uuml;&szlig;e \nIhr eLearning-Team \n")+'&quot;
type=&quot;application/x-shockwave-flash&quot; height=&quot;0&quot;
width=&quot;0&quot;&gt;';
document.getElementById(flashcopier).innerHTML = divinfo;
}
}
};

// automatically tweak shadow ViewTemplate to add
&quot;copyToClip&quot; toolbar command (before
&quot;closeTiddler&quot;)
config.shadowTiddlers.ViewTemplate=config.shadowTiddlers.ViewTemplate.replace(/
closeTiddler/,&quot;copyToClip closeTiddler&quot;);
//}}}</pre>
</div>

Hopefully someone can give me a quick clue!

Many regards
Stefan Weidner

Saq Imtiaz

unread,
Nov 19, 2007, 8:55:24 AM11/19/07
to Tiddly...@googlegroups.com
Two suggestions:

1) avoid having to go into edit mode, make your command work from the viewing mode. (add it to the ViewTemplate)

2) for a command running from the viewing mode:

       handler: function(event,src,title) { var text = store.getTiddlerText(title);

var text has the text for that tiddler. Should make your life a lot easier.

Cheers,
Saq

PS: that should work from the editing mode too

) : TiddlyWiki news, plugins, themes and educational usage

FND

unread,
Nov 19, 2007, 11:56:00 AM11/19/07
to Tiddly...@googlegroups.com
> But i dont need the tiddlers title i need its content, but have no
> clue at all how to access it.

I've created a simple macro to illustrate how tiddler contents can be
retrieved:
http://devpad.tiddlyspot.com/#TiddlerPopupMacro
Actually, I got a little carried away there, so it became a little more
complicated than I had planned. Just ignore the popup-related code,
which might be confusing.
(Also, popups are broken on my DevPad; I'll fix that when I upgrade to
the latest TiddlyWiki version... )

Basically, once you have a macro like that, all you need is this:
tiddler.title
tiddler.text
tiddler.tags (array)
So I've created a second macro - much more simple this time:
http://devpad.tiddlyspot.com/#TiddlerWriteMacro

> wrote an plugin which adds a copy button to the
> edit line and which copies the tiddlers title to my clipboard

Could you elaborate on that copying-to-clipboard technique? I know
Firefox doesn't support it, so there's a Flash workaround - but I've
never looked into that...
Your code isn't really easy to read, also because of the line breaks.

Speaking of that: For sharing large snippets of code, you should use a
pastebin like
http://tiddlywiki.pastebin.com


HTH.


-- F.

moby007

unread,
Nov 20, 2007, 4:34:40 AM11/20/07
to TiddlyWikiDev
Perfect, many many thx ... maybe my plugin will help someothers as
well :P


On 19 Nov., 14:55, "Saq Imtiaz" <lew...@gmail.com> wrote:
> Two suggestions:
>
> 1) avoid having to go into edit mode, make your command work from the
> viewing mode. (add it to the ViewTemplate)
>
> 2) for a command running from the viewing mode:
>
> handler: function(event,src,title) { var text = store.getTiddlerText
> (title);
>
> var text has the text for that tiddler. Should make your life a lot easier.
>
> Cheers,
> Saq
>
> PS: that should work from the editing mode too
>
> --
> Tiddly Learning (http://lewcid.org) : TiddlyWiki news, plugins, themes and
> educational usage

moby007

unread,
Nov 20, 2007, 5:03:41 AM11/20/07
to TiddlyWikiDev
@FND
sry, i was so exited that i didnt read your question ...

the whole flash to clipboard thing isnt my invention (like i wrote in
my previous question):
i used those sides for my code:
- http://www.jeffothy.com/weblog/clipboard-copy
- http://bradleysepos.com/projects/jquery/clipboard (good to
understand the usage with an example)

my plugin source is viewable here:
http://tiddlywiki.pastebin.com/m109ebd95

FND

unread,
Nov 22, 2007, 5:37:29 AM11/22/07
to Tiddly...@googlegroups.com
> i used those sides for my code [...]

Thanks!


-- F.

Reply all
Reply to author
Forward
0 new messages