Inline script (Wikify Output??)

230 views
Skip to first unread message

Mike

unread,
Nov 24, 2009, 10:45:26 AM11/24/09
to TiddlyWiki
Here is my script:

<script src="images/array_it.js" show>
function random_imglink(){
var ry=Math.floor(Math.random()*array_name.length)
if (ry==0)
ry=1
var pre='[>img(400px+,auto)[Random Picture|'
var dir='images/'
var post=']]'
document.write(' '+pre+''+dir+''+array_name[ry]+''+post+' ')
}
random_imglink()
</script>

Which provides the text output (slightly different each time due to
the random array)
[>img(400px+,auto)[Random Picture|images/famslide-2.jpg]]

What do I need to do to "Wikify" this output so I see the picture
instead of the text?

Thanks,

Mike

Mark S.

unread,
Nov 24, 2009, 11:59:52 AM11/24/09
to TiddlyWiki
You can try

wikify(' '+pre+''+dir+''+array_name[ry]+''+post+' ',place) ;

Mark
Message has been deleted

Mike

unread,
Nov 24, 2009, 1:08:02 PM11/24/09
to TiddlyWiki
Thank You !
Works perfect, knew I was missing something simple. . .
(Lost last reply ?)

Have a great day !

Mike

Tobias Beer

unread,
Nov 25, 2009, 4:43:09 AM11/25/09
to TiddlyWiki
Use semicolons. Why? Google for it.

Tobias Beer

unread,
Nov 25, 2009, 4:45:12 AM11/25/09
to TiddlyWiki
One more thing... this is a neat little script ;-) Tobias.

Mike

unread,
Nov 25, 2009, 9:51:29 PM11/25/09
to TiddlyWiki
thx - too bad I didn't write it . . . (the script)
found it somewhere on the web and modified (getting the array from a
batch file !)

Will work on cleaning it up a little, also not sure about the line(s)
if (ry==0)
ry=1
thinking that is removing the first pick in the array - [0] (need to
investigate further)
(might be able to eliminate both lines . . .)

Sample array
array_name=[];
array_name[0]='images/ddr_0001_bodywork.jpg';
array_name[1]='images/ddr_0002_licht.jpg';
array_name[2]='images/ddr_0004_retina_reflector.jpg';
array_name[3]='images/ddr_0005_virus.jpg';
array_name[4]='images/ddr_0006_deathstar.jpg';
array_name[5]='images/ddr_0008_pulsar.jpg';
array_name[6]='images/ddr_0009_lovehate.jpg';
array_name[7]='images/ddr_0010_afx_efx.jpg';
array_name[8]='images/ddr_0011_construct.jpg';
array_name[9]='images/ddr_0012_wavez.jpg';
array_name[10]='images/ddr_0013_freezeframed.jpg';
array_name[11]='images/ddr_0014_rustpuppet.jpg';
array_name[12]='images/ddr_0015_phaseshifter.jpg';
array_name[13]='images/ddr_0016_signal_to_noise.jpg';
array_name[14]='images/ddr_0018_d-generation.jpg';
array_name[15]='images/ddr_0020_angel_of_deaf.jpg';
array_name[16]='images/ddr_0021_secure_bsd.jpg';
array_name[17]='images/ddr_0022_replication_breakbeats.jpg';
array_name[18]='images/ddr_0024_holdonto.jpg';
array_name[19]='images/ddr_0027_trinkwasser.jpg';
array_name[20]='images/ddr_0028_neotek_idoru.jpg';
array_name[21]='images/ddr_0030_pandora_complex.jpg';
array_name[22]='images/ddr_0046_retroactive.jpg';
array_name[23]='images/ddr_0049_downward.jpg';
array_name[24]='images/ddr_0050_biotech.jpg';
array_name[25]='images/ddr_0053_eastside.jpg';
array_name[26]='images/ddr_0055_remodulat.jpg';
array_name[27]='images/ddr_0058_sidewinder.jpg';
array_name[28]='images/ddr_0062_mis_fit.jpg';
array_name[29]='images/ddr_0063_discord.jpg';
array_name[30]='images/ddr_0064_phreak_ov_nature.jpg';

Vincent Yeh

unread,
Aug 13, 2012, 10:10:14 AM8/13/12
to tiddl...@googlegroups.com
Mark,

Thanks a lot for the post. Saved me big time!

However, I found it not changing the text alignment.

For example, I had an element, place, which contains left-aligned text "left text" before I did

wikify ( " centered text ", place );   // The " content text " does contain a leading and an ending white space.

Afterwards the content of place got changed to "centered text", but remains left-aligned.

The text decorations, such as "__underlined__" and "//italic//", and CSS style settings, such as @@color:blue;blue text@@, all seem to work fine.

Am I missing something for text alignment here?

Vincent

Eric Shulman

unread,
Aug 13, 2012, 1:53:14 PM8/13/12
to TiddlyWiki
> For example, I had an element, place, which contains left-aligned text
> "left text" before I did
> wikify ( " centered text ", place );   // The " content text " does contain
> a leading and an ending white space.
> Afterwards the content of place got changed to "centered text", but remains
> left-aligned.
> The text decorations, such as "__underlined__" and "//italic//", and CSS
> style settings, such as @@color:blue;blue text@@, all seem to work fine.
> Am I missing something for text alignment here?

The use of leading/trailing whitespace to center text is *only*
recognized by the TW table syntax:

|this is left justified |
| this is right justified|
| this is centered |

To center normal TW text content, you need to wrap it in a DIV element
with CSS style="text-align:center", like this:
wikify ( "@@display:block;text-align:center;centered text@@",
place );

For improved readability, you can install:
http://www.TiddlyTools.com/#StyleSheetShortcuts
and then add:
[[StyleSheetShortcuts]]
to your StyleSheet. You can then use the TW CSS *wrapper* syntax
"{{center{...}}}" to control the style of the content, like this:
wikify ( "{{center{{centered text}}", place );

Alternatively, you could set the center style for the entire "place"
element, like this:
place.style.textAlign="center";
Note, however, that this will affect all content in that element (not
just the newly wikified output)

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

HELP ME TO HELP YOU - MAKE A CONTRIBUTION TO MY "TIP JAR"...
http://www.TiddlyTools.com/#Donations

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:
http://www.TiddlyTools.com/#Contact

Vincent Yeh

unread,
Aug 13, 2012, 11:31:01 PM8/13/12
to tiddl...@googlegroups.com

So I have to take care of the text alignment. I see. Thanks a lot, Eric.

Vincent
Reply all
Reply to author
Forward
0 new messages