cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
pmroz
Super User

Hyperlinks in Text Box or Text Edit Box?

Is there a way to insert a hyperlink into a text box or text edit box?  I know that you can do this in a JMP table with the expression column type, and that you can create a button box in a window that acts like a hyperlink.  I'm also aware of the << markup syntax for text boxes, but that only lets you do bold, underline and italic.

12 REPLIES 12
Byron_JMP
Staff

Re: Hyperlinks in Text Box or Text Edit Box?

I suspect you're looking for something more sophistocated than this, but...

Names Default To Here( 1 );

	New Window( "Example",
	hlistbox("1",
	wb = Web Browser Box(),
	bb=Button Box( "Take Me to JMP",
		wb << Navigate( "http://www.jmp.com" );
	wb << Set Auto Stretching( 1, 1 );
	wb << Set Max Size( 1000, 1000 );
	)));
JMP Systems Engineer, Health and Life Sciences (Pharma)
pmroz
Super User

Re: Hyperlinks in Text Box or Text Edit Box?

Thanks Byron that's a cool script.  But it's not what I was looking for.  Specifically I want to embed a link into a text box and have it be clickable.  My users are entering comments which can be long and can contain reference links.  I'm working on an approach where I parse out the links and display:

Text block1 (in a text box)

Link1          (as a clickable link)

Text block2 (in a text box)

Link2          (as a clickable link)

Text block3

etc.

That will probably be acceptable to users.

ih
Super User (Alumni) ih
Super User (Alumni)

Re: Hyperlinks in Text Box or Text Edit Box?

If you are okay with the entire box being the link then you could use a button box:

New Window( "Example",
	Text box("Text Block 1"),
	Button box( "http://www.jmp.com/", Web( "http://www.jmp.com/" ), Underline Style( 1 ) )
)
Byron_JMP
Staff

Re: Hyperlinks in Text Box or Text Edit Box?

I think it might be possible to parse the text box contents for an html link (find patterns that start with "//:http") and then append a button box to the text box, with the link in it, for each pattern that is parsed. 

That's going to be pretty complex though. It would be so much better if the links were recognized in the text and were clickable.

JMP Systems Engineer, Health and Life Sciences (Pharma)

Re: Hyperlinks in Text Box or Text Edit Box?

You could use a regular expression to match the hyperlink pattern.

gzmorgan0
Super User (Alumni)

Re: Hyperlinks in Text Box or Text Edit Box?

This solution requires a little extra something, something: a WrapListBox and a MouseBox.

 

Names Default To Here( 1 );
New Window( "WrapListBox",
	Wrap List Box(
		TextBox("This is a long comment to be followed by a link "),
		MouseBox(TextBox(" <u>http://www.jmp.com</u> ",<<Font Color("Blue"),<<Markup ),
		<<setClickEnable( 1 ),
		<<setClick( /* button-down, move, button-release handler */
			Function( {this, clickpt, event}, /*Is Alt Key(),Is Control Key(),Is Shift Key() should be captured on "Pressed" */
				If( event == "Released",
					this << setCursor( "Hand" ) /* switch back to hand immediately */
				,
					this << setCursor( "Finger" ) /* change cursor during drawing */
				);
				If( event == "Released",
				   lnk = word(3,((this << child) << get text),"<>"); 
				   web(lnk);
				   (this<<child) <<FontColor("purple")
				);
			) ) 
		),  //end MouseBox
		TextBox( " followed by more text." )
	)
);

 

gzmorgan0
Super User (Alumni)

Re: Hyperlinks in Text Box or Text Edit Box?

Oh and make the mousebox(textBox) a function or expression that can be used many times, where only the text, the found link, changes. 

pmroz
Super User

Re: Hyperlinks in Text Box or Text Edit Box?

Thanks for your comments and suggestions so far.  I don't have the luxury of knowing where the URLs are in the user comments. 

Here's some sample output:

TextBoxURL.png

 

Here's some sample code.  I made it easy by using URL "markers" <l> and </l>.  I've been playing around with URL location using regex to avoid having to use these markers.  If anyone has a good regular expression for finding URLs let me know.  I'm having varied success with what I've found on the net so far.

 

// link markup example
text = "Periarthritis is defined as: Inflammation of the tissues around a joint. " ||
"<l>http://www.reference.md/files/D010/mD010489.html</l>  As arthralgia, myalgia, tendonitis " ||
"and other musculoskeletal issues are listed events, periarthritis can be considered listed as well. 
Comment: no good sentinel case — not a new signal; one case also reported somnolence and " ||
"another case reported “yawny” which could mean sleepy *<l>http://www.ncbi.nlm.nih.gov/pubmed/12530994</l>";

text_list = {};
link_list = {};
keep_going = 1;
istart     = 1;
linkstart  = "<l>";
linkend    = "</l>";
text_len   = length(text);
i = 0;
while(keep_going,
	start_pos = contains(text, linkstart, istart);
	if (start_pos,
		end_pos = contains(text, linkend, istart);
		if (end_pos,
			i++;
			text_list[i] = substr(text, istart, (start_pos - istart));
			link_list[i] = substr(text, start_pos + 3, (end_pos - start_pos - 3));
			istart = istart + end_pos - istart + 4;
		);
	);
	if (!start_pos,
		i++;
		text_list[i] = substr(text, istart);
		keep_going = 0;
	);
);
tb = {};
lb = {};
nt = nitems(text_list);
nw = new window("Test link",
	vb = vlistbox(
	)
);
for(i = 1, i <= nt, i++,
	tb[i] = text box(text_list[i], << set width(400));
	vb << append(tb[i]);
	if (i < nt,
		one_button = evalinsert("\[lb[i] = button box("^link_list[i]^", web("^link_list[i]^"), << underline style(1) )]\");
		eval(parse(one_button));
		vb << append(lb[i]);
	);
);

Re: Hyperlinks in Text Box or Text Edit Box?

See Regex() function. It might be useful. The regular expression would be pretty simple.

 

Names Default to Here( 1 );

text = "Periarthritis is defined as: Inflammation of the tissues around a joint. " ||
"<l>http://www.reference.md/files/D010/mD010489.html</l>  As arthralgia, myalgia, tendonitis " ||
"and other musculoskeletal issues are listed events, periarthritis can be considered listed as well. 
Comment: no good sentinel case — not a new signal; one case also reported somnolence and " ||
"another case reported “yawny” which could mean sleepy *<l>http://www.ncbi.nlm.nih.gov/pubmed/12530994</l>";

Regex( text,
	"<l>(.+?)</l>",
	"\1"
);