script story.Display(???,???) how to use

6 views
Skip to first unread message

okido

unread,
Aug 26, 2008, 4:27:07 PM8/26/08
to TiddlyWiki
Hi All,

I made the following script to created new tiddlers with a four digit
number that is incremented automatically.

<script>
var newBody = ' <<tiddler Formview>>' ; // text to be used ** form
tiddler **
var newNummer = DataTiddler.getData("run_data","nmr"); // get
new tiddler 4 digit number
var dt = new Date(); var NewTags="";
var newTitle = String('000' +
newNummer).substring(String('000' + newNummer).length,(String('000' +
newNummer).length)-4);

store.saveTiddler(newTitle, newTitle, newBody,
config.options.txtUserName, dt, newTags); // save new tiddler
displayMessage('New Record created');

DataTiddler.setData("run_data","nmr",newNummer+1); //
increase variable for tiddler names by 1

newTmp = '0012'; // if this is replaced with newTitle the
browser crashes

story.displayTiddler(this,newTmp); // show newly made
tiddler

</script>

As long as I use the string newTmp the script works, but replaced with
newTitle the script crashes.

Any suggestions???

Okido

Eric Shulman

unread,
Aug 26, 2008, 5:18:09 PM8/26/08
to TiddlyWiki
>         var newTitle = String('000' +
> newNummer).substring(String('000' + newNummer).length,(String('000' +
> newNummer).length)-4);

Although I'm not sure why your code seems to 'crash the browser', one
thing of note:
javascript is "weakly typed", so you can simplify the above expression
in your code by writing it like this:

var newTitle='000'+newNummer;
newTitle=newTitle.substr(newTitle.length-4,4);

In the first line, concatenating a string literal with a numeric
variable results in string variable named 'newTitle'. Then, in the
following line, there's no need to explicitly recast the type using
String(...), since the variable is already of the desired type.

Also, the first param in story.displayTiddler(...) is supposed to be
one of:
A) a *tiddler* DOM element
B) null (or string literal "top")
C) string literal "bottom"

In your inline <script>...</script> code, reference to "this" is
indeterminate, and is definitely not the right value to use. Instead,
you should write:
story.displayTiddler(story.findContainingTiddler(place),newTitle);
where 'place' is a variable that is automatically defined by
InlineJavascriptPlugin, and refers to the immediately surrounding DOM
element that contains the script being invoked. Then,
story.findContainingTiddler() searches outward from that 'place' to
identify the *tiddler* DOM element in which the script.

HTH,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

P.S. Although I've responded here, questions regarding *programming*
for TiddlyWiki are best posted to the TiddlyWikiDev GoogleGroup.
While the dividing line between user and developer discussions is not
always clearly defined, the intent is to try to avoid overloading the
general TW user group with too many highly technical discussions.

okido

unread,
Aug 27, 2008, 11:28:27 AM8/27/08
to TiddlyWiki
Thanks Eric,

I will give it a go this evening.
Some polishing of my js and dom knowlegde is needed.

Have a nice day, Okido
Reply all
Reply to author
Forward
0 new messages